This commit is contained in:
Alex Yatskov 2019-02-10 14:27:45 -08:00
parent 40c09c36a6
commit 7a092d28fe
3 changed files with 52 additions and 42 deletions

View File

@ -8,7 +8,7 @@ import (
type Sprite struct {
}
type bounds struct {
type box struct {
x1 int
y1 int
x2 int

View File

@ -2,6 +2,7 @@ package dcc
import (
"io"
"log"
"github.com/FooSoft/lazarus/streaming"
)
@ -48,41 +49,14 @@ func readDirection(reader io.ReadSeeker, fileHead fileHeader) (*direction, error
return nil, err
}
frameHeads, err := readFrameHeaders(bitReader, fileHead, *dirHead)
frameHeads, bounds, err := readFrameHeaders(bitReader, fileHead, *dirHead)
if err != nil {
return nil, err
}
var dirData direction
for i, frameHead := range frameHeads {
frameData := frame{
header: frameHead,
bounds: bounds{
x1: int(frameHead.OffsetX),
y1: int(frameHead.OffsetY) - int(frameHead.Height) + 1,
x2: int(frameHead.OffsetX) + int(frameHead.Width),
y2: int(frameHead.OffsetY) + 1,
},
}
dirData.frames = append(dirData.frames, frameData)
if i == 0 {
dirData.bounds = frameData.bounds
} else {
if dirData.bounds.x1 > frameData.bounds.x1 {
dirData.bounds.x1 = frameData.bounds.x1
}
if dirData.bounds.y1 > frameData.bounds.y1 {
dirData.bounds.y1 = frameData.bounds.y1
}
if dirData.bounds.x2 < frameData.bounds.x2 {
dirData.bounds.x2 = frameData.bounds.x2
}
if dirData.bounds.y2 < frameData.bounds.y2 {
dirData.bounds.y2 = frameData.bounds.y2
}
}
dirData := direction{bounds: bounds}
for _, frameHead := range frameHeads {
dirData.frames = append(dirData.frames, newFrame(frameHead, *dirHead))
}
var entries []pixelBufferEntry
@ -97,13 +71,14 @@ func readDirection(reader io.ReadSeeker, fileHead fileHeader) (*direction, error
return nil, err
}
log.Println(dirData.bounds)
return &dirData, nil
}
type direction struct {
header directionHeader
frames []frame
bounds bounds
bounds box
}
func (d *direction) decodeStage1(bitReader *streaming.BitReader, entries []pixelBufferEntry) ([]pixelBufferEntry, error) {

View File

@ -17,11 +17,6 @@ type frameHeader struct {
FrameBottomUp bool
}
type frame struct {
header frameHeader
bounds bounds
}
func readFrameHeader(bitReader *streaming.BitReader, dirHead directionHeader) (*frameHeader, error) {
var frameHead frameHeader
@ -53,16 +48,56 @@ func readFrameHeader(bitReader *streaming.BitReader, dirHead directionHeader) (*
return &frameHead, nil
}
func readFrameHeaders(bitReader *streaming.BitReader, fileHead fileHeader, dirHead directionHeader) ([]frameHeader, error) {
var frameHeads []frameHeader
func (h *frameHeader) bounds() box {
return box{
x1: int(h.OffsetX),
y1: int(h.OffsetY) - int(h.Height) + 1,
x2: int(h.OffsetX) + int(h.Width),
y2: int(h.OffsetY) + 1,
}
}
func readFrameHeaders(bitReader *streaming.BitReader, fileHead fileHeader, dirHead directionHeader) ([]frameHeader, box, error) {
var (
frameHeads []frameHeader
boundsAll box
)
for i := 0; i < int(fileHead.FramesPerDir); i++ {
frameHead, err := readFrameHeader(bitReader, dirHead)
if err != nil {
return nil, err
return nil, box{}, err
}
bounds := frameHead.bounds()
if i == 0 {
boundsAll = bounds
} else {
if boundsAll.x1 > bounds.x1 {
boundsAll.x1 = bounds.x1
}
if boundsAll.y1 > bounds.y1 {
boundsAll.y1 = bounds.y1
}
if boundsAll.x2 < bounds.x2 {
boundsAll.x2 = bounds.x2
}
if boundsAll.y2 < bounds.y2 {
boundsAll.y2 = bounds.y2
}
}
frameHeads = append(frameHeads, *frameHead)
}
return frameHeads, nil
return frameHeads, boundsAll, nil
}
type frame struct {
header frameHeader
}
func newFrame(frameHead frameHeader, dirHead directionHeader) frame {
return frame{frameHead}
}