1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-09-16 00:08:29 -04:00
OpenDiablo2/d2common/d2util/palette.go
gravestench 783993470e
Lint error cleanup1 (#779)
* fixed lint error in d2app/app.go

* go fmt entire project

* adding doc.go for d2records

* fixed lint issues in d2core/d2map

* fixed lint error in d2interface/palette.go

* fixed lint error in  d2core/d2hero/hero_state_factory.go

* adding dov.go to d2common/d2geom

* fixing lint errors in d2common/d2loader

* adding doc.go to d2common/d2cache

* adding doc files for d2datautils, d2util, d2path

* adding package doc strings for mapgen, in-geam help screen, and tcp client connection

* removed all cuddling lint errors

* changed stamina equality check to '<=' instead of '<'
2020-10-22 01:12:06 -04:00

32 lines
660 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
}