2019-01-09 02:12:53 +00:00
|
|
|
package dcc
|
|
|
|
|
2019-01-22 02:43:21 +00:00
|
|
|
import (
|
|
|
|
"encoding/binary"
|
|
|
|
"io"
|
|
|
|
)
|
2019-01-09 02:12:53 +00:00
|
|
|
|
2019-01-22 02:43:21 +00:00
|
|
|
type Sprite struct {
|
2019-01-09 02:12:53 +00:00
|
|
|
}
|
|
|
|
|
2019-02-10 22:27:45 +00:00
|
|
|
type box struct {
|
2019-02-10 19:41:33 +00:00
|
|
|
x1 int
|
|
|
|
y1 int
|
|
|
|
x2 int
|
|
|
|
y2 int
|
2019-01-17 03:04:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type fileHeader struct {
|
|
|
|
Signature uint8
|
|
|
|
Version uint8
|
|
|
|
DirCount uint8
|
|
|
|
FramesPerDir uint32
|
|
|
|
Tag uint32
|
|
|
|
FinalDc6Size uint32
|
|
|
|
}
|
|
|
|
|
2019-02-10 20:23:35 +00:00
|
|
|
type pixelBufferEntry struct {
|
|
|
|
values [4]byte
|
2019-01-17 03:04:49 +00:00
|
|
|
}
|
|
|
|
|
2019-01-22 02:43:21 +00:00
|
|
|
func NewFromReader(reader io.ReadSeeker) (*Sprite, error) {
|
2019-02-03 22:08:45 +00:00
|
|
|
var fileHead fileHeader
|
|
|
|
if err := binary.Read(reader, binary.LittleEndian, &fileHead); err != nil {
|
2019-01-22 02:43:21 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-02-10 19:41:33 +00:00
|
|
|
var directions []direction
|
2019-02-03 22:08:45 +00:00
|
|
|
for i := 0; i < int(fileHead.DirCount); i++ {
|
2019-01-23 02:49:23 +00:00
|
|
|
var offsetDir uint32
|
|
|
|
if err := binary.Read(reader, binary.LittleEndian, &offsetDir); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
offset, err := reader.Seek(0, io.SeekCurrent)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := reader.Seek(int64(offsetDir), io.SeekStart); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-02-10 19:41:33 +00:00
|
|
|
dirData, err := readDirection(reader, fileHead)
|
|
|
|
if err != nil {
|
2019-01-23 02:49:23 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2019-02-10 19:41:33 +00:00
|
|
|
directions = append(directions, *dirData)
|
2019-01-23 02:49:23 +00:00
|
|
|
|
|
|
|
if _, err := reader.Seek(offset, io.SeekStart); err != nil {
|
2019-01-22 03:34:53 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-09 02:12:53 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|