limage - xcf/vectors.go
1 package xcf
2
3 import "errors"
4
5 type vectors struct {
6 aIndex uint32
7 paths []vpath
8 }
9
10 type vpath struct {
11 name string
12 tattoo uint32
13 visible, linked bool
14 parasites
15 strokes []stroke
16 }
17
18 type stroke struct {
19 closed bool
20 points []point
21 }
22
23 type point struct {
24 control bool
25 x, y, pressure, xtilt, ytilt, wheel float32
26 }
27
28 func (d *reader) ReadVectors() vectors {
29 v := d.ReadUint32()
30 if v != 1 {
31 d.SetError(ErrUnknownVectorVersion)
32 return vectors{}
33 }
34 var vs vectors
35 vs.aIndex = d.ReadUint32()
36 n := d.ReadUint32()
37 vs.paths = make([]vpath, n)
38 for i := uint32(0); i < n; i++ {
39 vs.paths[i].name = d.ReadString()
40 vs.paths[i].tattoo = d.ReadUint32()
41 vs.paths[i].visible = d.ReadBoolProperty()
42 vs.paths[i].linked = d.ReadBoolProperty()
43 m := d.ReadUint32()
44 k := d.ReadUint32()
45 vs.paths[n].parasites = make(parasites, m)
46 vs.paths[n].strokes = make([]stroke, k)
47 for j := uint32(0); j < m; j++ {
48 vs.paths[i].parasites[j] = d.ReadParasite()
49 }
50 for j := uint32(0); j < k; j++ {
51 b := d.ReadUint32()
52 if b != 1 {
53 d.SetError(ErrUnknownStrokeType)
54 return vs
55 }
56 vs.paths[i].strokes[j].closed = d.ReadBoolProperty()
57 nf := d.ReadUint32()
58 if nf < 2 || nf > 6 {
59 d.SetError(ErrInvalidFloatsNumber)
60 return vs
61 }
62 np := d.ReadUint32()
63 vs.paths[i].strokes[j].points = make([]point, np)
64 for ii := uint32(0); ii < np; ii++ {
65 vs.paths[i].strokes[j].points[ii].control = d.ReadBoolProperty()
66 vs.paths[i].strokes[j].points[ii].x = d.ReadFloat32()
67 vs.paths[i].strokes[j].points[ii].y = d.ReadFloat32()
68 vs.paths[i].strokes[j].points[ii].pressure = 1
69 vs.paths[i].strokes[j].points[ii].xtilt = 0.5
70 vs.paths[i].strokes[j].points[ii].ytilt = 0.5
71 vs.paths[i].strokes[j].points[ii].wheel = 0.5
72 if nf >= 3 {
73 vs.paths[i].strokes[j].points[ii].pressure = d.ReadFloat32()
74 if nf >= 4 {
75 vs.paths[i].strokes[j].points[ii].xtilt = d.ReadFloat32()
76 if nf >= 5 {
77 vs.paths[i].strokes[j].points[ii].ytilt = d.ReadFloat32()
78 if nf == 6 {
79 vs.paths[i].strokes[j].points[ii].wheel = d.ReadFloat32()
80 }
81 }
82 }
83 }
84 }
85 }
86 }
87 return vs
88 }
89
90 // Errors
91 var (
92 ErrUnknownVectorVersion = errors.New("unknown vector version")
93 ErrUnknownStrokeType = errors.New("unknown stroke type")
94 ErrInvalidFloatsNumber = errors.New("invalids number of floats")
95 )
96