lazarus/formats/dcc/direction.go

91 lines
2.2 KiB
Go
Raw Permalink Normal View History

2019-02-10 20:23:35 +00:00
package dcc
import (
"io"
2019-02-10 22:27:45 +00:00
"log"
2019-02-10 20:23:35 +00:00
"github.com/FooSoft/lazarus/streaming"
)
type directionHeader struct {
CodedSize uint32
HasRawPixelEncoding bool
CompressEqualCells bool
Variable0Bits uint8
WidthBits uint8
HeightBits uint8
OffsetXBits uint8
OffsetYBits uint8
OptionalBytesBits uint8
CodedBytesBits uint8
}
func readDirectionHeader(bitReader *streaming.BitReader) (*directionHeader, error) {
2019-02-10 20:23:35 +00:00
var dirHead directionHeader
dirHead.CodedSize = uint32(bitReader.ReadUint(32))
dirHead.HasRawPixelEncoding = bitReader.ReadBool()
dirHead.CompressEqualCells = bitReader.ReadBool()
dirHead.Variable0Bits = uint8(bitReader.ReadUint(4))
dirHead.WidthBits = uint8(bitReader.ReadUint(4))
dirHead.HeightBits = uint8(bitReader.ReadUint(4))
dirHead.OffsetXBits = uint8(bitReader.ReadInt(4))
dirHead.OffsetYBits = uint8(bitReader.ReadInt(4))
dirHead.OptionalBytesBits = uint8(bitReader.ReadUint(4))
dirHead.CodedBytesBits = uint8(bitReader.ReadUint(4))
if err := bitReader.Error(); err != nil {
return nil, err
}
return &dirHead, nil
2019-02-10 20:23:35 +00:00
}
func readDirection(reader io.ReadSeeker, fileHead fileHeader) (*direction, error) {
bitReader := streaming.NewBitReader(reader)
dirHead, err := readDirectionHeader(bitReader)
if err != nil {
2019-02-10 20:23:35 +00:00
return nil, err
}
2019-02-11 00:41:47 +00:00
frameHeads, dirBounds, err := readFrameHeaders(bitReader, fileHead, *dirHead)
2019-02-10 20:23:35 +00:00
if err != nil {
return nil, err
}
2019-02-11 00:41:47 +00:00
dirData := direction{bounds: dirBounds}
2019-02-10 22:27:45 +00:00
for _, frameHead := range frameHeads {
2019-02-11 00:41:47 +00:00
dirData.frames = append(dirData.frames, newFrame(frameHead, dirBounds))
2019-02-10 20:23:35 +00:00
}
var entries []pixelBufferEntry
entries, err = dirData.decodeStage1(bitReader, entries)
2019-02-10 20:23:35 +00:00
if err != nil {
return nil, err
}
entries, err = dirData.decodeStage2(bitReader, entries)
2019-02-10 20:23:35 +00:00
if err != nil {
return nil, err
}
2019-02-10 22:27:45 +00:00
log.Println(dirData.bounds)
2019-02-10 20:23:35 +00:00
return &dirData, nil
}
type direction struct {
header directionHeader
frames []frame
2019-02-10 22:27:45 +00:00
bounds box
}
func (d *direction) decodeStage1(bitReader *streaming.BitReader, entries []pixelBufferEntry) ([]pixelBufferEntry, error) {
2019-02-10 20:23:35 +00:00
return nil, nil
}
func (d *direction) decodeStage2(bitReader *streaming.BitReader, entries []pixelBufferEntry) ([]pixelBufferEntry, error) {
2019-02-10 20:23:35 +00:00
return nil, nil
}