2020-09-14 14:47:11 -04:00
|
|
|
package d2util
|
2020-07-08 17:46:45 -04:00
|
|
|
|
2020-09-23 13:30:54 -04:00
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
|
|
|
)
|
2020-07-08 17:46:45 -04:00
|
|
|
|
2020-10-22 02:41:21 -04:00
|
|
|
// ImgIndexToRGBA converts the given indices byte slice and palette into
|
|
|
|
// a byte slice of RGBA values
|
2020-07-08 17:46:45 -04:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-09-23 13:30:54 -04:00
|
|
|
c, err := palette.GetColor(int(indexData[i]))
|
|
|
|
if err != nil {
|
|
|
|
log.Print(err)
|
|
|
|
}
|
2020-10-22 01:12:06 -04:00
|
|
|
|
2020-07-08 17:46:45 -04:00
|
|
|
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
|
|
|
|
}
|