1
Fork 0

work on dcc decoding

This commit is contained in:
Alex Yatskov 2019-02-10 16:41:47 -08:00
parent 7a092d28fe
commit 12d1f47abd
2 changed files with 79 additions and 5 deletions

View File

@ -49,14 +49,14 @@ func readDirection(reader io.ReadSeeker, fileHead fileHeader) (*direction, error
return nil, err
}
frameHeads, bounds, err := readFrameHeaders(bitReader, fileHead, *dirHead)
frameHeads, dirBounds, err := readFrameHeaders(bitReader, fileHead, *dirHead)
if err != nil {
return nil, err
}
dirData := direction{bounds: bounds}
dirData := direction{bounds: dirBounds}
for _, frameHead := range frameHeads {
dirData.frames = append(dirData.frames, newFrame(frameHead, *dirHead))
dirData.frames = append(dirData.frames, newFrame(frameHead, dirBounds))
}
var entries []pixelBufferEntry

View File

@ -95,9 +95,83 @@ func readFrameHeaders(bitReader *streaming.BitReader, fileHead fileHeader, dirHe
type frame struct {
header frameHeader
nbCellsX int
nbCellsY int
dirOffsetX int
dirOffsetY int
cellSameAsPrevious []bool
cellWidths []int
cellHeights []int
data []byte
}
func newFrame(frameHead frameHeader, dirHead directionHeader) frame {
return frame{frameHead}
func newFrame(frameHead frameHeader, dirBounds box) frame {
frameBounds := frameHead.bounds()
frameData := frame{
header: frameHead,
dirOffsetX: frameBounds.x1 - dirBounds.x1,
dirOffsetY: frameBounds.y1 - dirBounds.y1,
}
widthFirstColumn := 4 - frameData.dirOffsetX%4
frameWidth := frameBounds.x2 - frameBounds.x1
if frameWidth-widthFirstColumn <= 1 {
frameData.nbCellsX = 1
} else {
temp := frameWidth - widthFirstColumn - 1
frameData.nbCellsX = 2 + temp/4
if temp%4 == 0 {
frameData.nbCellsX--
}
}
heightFirstRow := 4 - frameData.dirOffsetY%4
frameHeight := frameBounds.y2 - frameBounds.y1
if frameHeight-heightFirstRow <= 1 {
frameData.nbCellsY = 1
} else {
temp := frameHeight - heightFirstRow - 1
frameData.nbCellsY = 2 + temp/4
if temp%4 == 0 {
frameData.nbCellsY--
}
}
frameData.cellWidths = make([]int, frameData.nbCellsX)
for i := range frameData.cellWidths {
frameData.cellWidths[i] = 4
}
if frameData.nbCellsX == 1 {
frameData.cellWidths[0] = frameWidth
} else {
frameData.cellWidths[0] = widthFirstColumn
nbColumnsExcludingFirstAndLast := frameData.nbCellsX - 2
widthExcludingFirstAndLastColumns := 4 * nbColumnsExcludingFirstAndLast
frameData.cellWidths[frameData.nbCellsX-1] = frameWidth - (widthFirstColumn + widthExcludingFirstAndLastColumns)
}
frameData.cellHeights = make([]int, frameData.nbCellsY)
for i := range frameData.cellHeights {
frameData.cellHeights[i] = 4
}
if frameData.nbCellsY == 1 {
frameData.cellHeights[0] = frameHeight
} else {
frameData.cellHeights[0] = heightFirstRow
nbRowsExcludingFirstAndLast := frameData.nbCellsY - 2
heightExcludingFirstAndLastRows := 4 * nbRowsExcludingFirstAndLast
frameData.cellHeights[frameData.nbCellsY-1] = frameHeight - (heightFirstRow + heightExcludingFirstAndLastRows)
}
frameData.cellSameAsPrevious = make([]bool, frameData.nbCellsX*frameData.nbCellsY)
frameData.data = make([]byte, frameWidth*frameHeight)
return frameData
}