1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-06-24 08:05:24 +00:00
OpenDiablo2/d2common/d2util/palette.go
Brendan Porter ca45be0948
Adds error handling everywhere (#743)
* adds error handling, returns early from funcs where it makes sense

* fixes build errors

* merge ballresin PR with upstream

* adds error handling, returns early from funcs where it makes sense

* fixes build errors

* merge ballresin PR with upstream

Co-authored-by: dknuth <dknuth0101@gmail.com>
2020-09-23 13:30:54 -04:00

31 lines
659 B
Go

package d2util
import (
"log"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
)
func ImgIndexToRGBA(indexData []byte, palette d2interface.Palette) []byte {
bytesPerPixel := 4
colorData := make([]byte, len(indexData)*bytesPerPixel)
for i := 0; i < len(indexData); i++ {
// Index zero is hardcoded transparent regardless of palette
if indexData[i] == 0 {
continue
}
c, err := palette.GetColor(int(indexData[i]))
if err != nil {
log.Print(err)
}
colorData[i*bytesPerPixel] = c.R()
colorData[i*bytesPerPixel+1] = c.G()
colorData[i*bytesPerPixel+2] = c.B()
colorData[i*bytesPerPixel+3] = c.A()
}
return colorData
}