mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2025-02-20 23:47:16 -05:00
Some slight DC6 cleanup (#557)
This commit is contained in:
parent
0a78a1adcc
commit
38213e749a
@ -33,3 +33,40 @@ func Load(data []byte) (*DC6, error) {
|
||||
|
||||
return result, err
|
||||
}
|
||||
|
||||
// Decodes the given frame to an indexed color texture
|
||||
func (d *DC6) DecodeFrame(frameIndex int) []byte {
|
||||
frame := d.Frames[frameIndex]
|
||||
|
||||
indexData := make([]byte, frame.Width*frame.Height)
|
||||
x := 0
|
||||
y := int(frame.Height) - 1
|
||||
offset := 0
|
||||
|
||||
for {
|
||||
b := int(frame.FrameData[offset])
|
||||
offset++
|
||||
|
||||
if b == 0x80 {
|
||||
if y == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
y--
|
||||
|
||||
x = 0
|
||||
} else if b&0x80 > 0 {
|
||||
transparentPixels := b & 0x7f
|
||||
x += transparentPixels
|
||||
} else {
|
||||
for i := 0; i < b; i++ {
|
||||
indexData[x+y*int(frame.Width)+i] = frame.FrameData[offset]
|
||||
offset++
|
||||
}
|
||||
|
||||
x += b
|
||||
}
|
||||
}
|
||||
|
||||
return indexData
|
||||
}
|
||||
|
@ -81,46 +81,14 @@ func (a *DC6Animation) decodeDirection(directionIndex int) error {
|
||||
return err
|
||||
}
|
||||
|
||||
indexData := make([]int, dc6Frame.Width*dc6Frame.Height)
|
||||
for i := range indexData {
|
||||
indexData[i] = -1
|
||||
}
|
||||
|
||||
x := 0
|
||||
y := int(dc6Frame.Height) - 1
|
||||
offset := 0
|
||||
|
||||
for {
|
||||
b := int(dc6Frame.FrameData[offset])
|
||||
offset++
|
||||
|
||||
if b == 0x80 {
|
||||
if y == 0 {
|
||||
break
|
||||
}
|
||||
y--
|
||||
x = 0
|
||||
} else if b&0x80 > 0 {
|
||||
transparentPixels := b & 0x7f
|
||||
for i := 0; i < transparentPixels; i++ {
|
||||
indexData[x+y*int(dc6Frame.Width)+i] = -1
|
||||
}
|
||||
x += transparentPixels
|
||||
} else {
|
||||
for i := 0; i < b; i++ {
|
||||
indexData[x+y*int(dc6Frame.Width)+i] = int(dc6Frame.FrameData[offset])
|
||||
offset++
|
||||
}
|
||||
x += b
|
||||
}
|
||||
}
|
||||
indexData := dc6.DecodeFrame(startFrame + i)
|
||||
|
||||
bytesPerPixel := 4
|
||||
colorData := make([]byte, int(dc6Frame.Width)*int(dc6Frame.Height)*bytesPerPixel)
|
||||
|
||||
for i := 0; i < int(dc6Frame.Width*dc6Frame.Height); i++ {
|
||||
// TODO: Is this == -1 or < 1?
|
||||
if indexData[i] < 1 {
|
||||
// Index zero is hardcoded transparent regardless of palette
|
||||
if indexData[i] == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user