forked from ftrvxmtrx/tga
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tga.go
65 lines (55 loc) · 1.12 KB
/
tga.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package tga
type rawHeader struct {
IdLength uint8
PaletteType uint8
ImageType uint8
PaletteFirst uint16
PaletteLength uint16
PaletteBPP uint8
OriginX uint16
OriginY uint16
Width uint16
Height uint16
BPP uint8
Flags uint8
}
type rawFooter struct {
ExtAreaOffset uint32
DevDirOffset uint32
Signature [18]byte // tgaSignature
}
const (
flagOriginRight = 1 << 4
flagOriginTop = 1 << 5
flagAlphaSizeMask = 0x0f
)
const (
imageTypePaletted = 1
imageTypeTrueColor = 2
imageTypeMonoChrome = 3
imageTypeMask = 3
imageTypeFlagRLE = 1 << 3
)
const (
tgaRawHeaderSize = 18
tgaRawFooterSize = 26
)
const (
extAreaAttrTypeOffset = 0x1ee
)
const (
attrTypeAlpha = 3
attrTypePremultipliedAlpha = 4
)
var tgaSignature = []byte("TRUEVISION-XFILE.\x00")
func newFooter() *rawFooter {
f := &rawFooter{}
copy(f.Signature[:], tgaSignature)
return f
}
func newExtArea(attrType byte) []byte {
area := make([]byte, extAreaAttrTypeOffset+1)
area[0], area[1] = 0xef, 0x01 // size
area[extAreaAttrTypeOffset] = attrType
return area
}