@@ -3,6 +3,9 @@ const builtin = @import("builtin");
33const options = @import ("options" );
44const phantom = @import ("phantom" );
55const vizops = @import ("vizops" );
6+ const zigimg = @import ("zigimg" );
7+
8+ const alloc = if (builtin .link_libc ) std .heap .c_allocator else if (builtin .os .tag == .uefi ) std .os .uefi .pool_allocator else std .heap .page_allocator ;
69
710const displayBackendType : phantom.display.BackendType = @enumFromInt (@intFromEnum (options .display_backend ));
811const displayBackend = phantom .display .Backend (displayBackendType );
@@ -11,253 +14,6 @@ const sceneBackendType: phantom.scene.BackendType = @enumFromInt(@intFromEnum(op
1114const sceneBackend = phantom .scene .Backend (sceneBackendType );
1215
1316pub fn main () void {
14- const colors : []const [17 ]vizops.color.Any = &.{
15- .{
16- .{
17- .uint8 = .{
18- .sRGB = .{
19- .value = .{ 0xf7 , 0x76 , 0x8e , 0xff },
20- },
21- },
22- },
23- .{
24- .uint8 = .{
25- .sRGB = .{
26- .value = .{ 0xff , 0x9e , 0x64 , 0xff },
27- },
28- },
29- },
30- .{
31- .uint8 = .{
32- .sRGB = .{
33- .value = .{ 0xe0 , 0xaf , 0x68 , 0xff },
34- },
35- },
36- },
37- .{
38- .uint8 = .{
39- .sRGB = .{
40- .value = .{ 0x9e , 0xce , 0x6a , 0xff },
41- },
42- },
43- },
44- .{
45- .uint8 = .{
46- .sRGB = .{
47- .value = .{ 0x73 , 0xda , 0xca , 0xff },
48- },
49- },
50- },
51- .{
52- .uint8 = .{
53- .sRGB = .{
54- .value = .{ 0xb4 , 0xf9 , 0xf8 , 0xff },
55- },
56- },
57- },
58- .{
59- .uint8 = .{
60- .sRGB = .{
61- .value = .{ 0x2a , 0xc3 , 0xde , 0xff },
62- },
63- },
64- },
65- .{
66- .uint8 = .{
67- .sRGB = .{
68- .value = .{ 0x7d , 0xcf , 0xff , 0xff },
69- },
70- },
71- },
72- .{
73- .uint8 = .{
74- .sRGB = .{
75- .value = .{ 0x7a , 0xa2 , 0xf7 , 0xff },
76- },
77- },
78- },
79- .{
80- .uint8 = .{
81- .sRGB = .{
82- .value = .{ 0xbb , 0x9a , 0xf7 , 0xff },
83- },
84- },
85- },
86- .{
87- .uint8 = .{
88- .sRGB = .{
89- .value = .{ 0xc0 , 0xca , 0xf5 , 0xff },
90- },
91- },
92- },
93- .{
94- .uint8 = .{
95- .sRGB = .{
96- .value = .{ 0xa9 , 0xb1 , 0xd6 , 0xff },
97- },
98- },
99- },
100- .{
101- .uint8 = .{
102- .sRGB = .{
103- .value = .{ 0x9a , 0xa5 , 0xce , 0xff },
104- },
105- },
106- },
107- .{
108- .uint8 = .{
109- .sRGB = .{
110- .value = .{ 0xcf , 0xc9 , 0xc2 , 0xff },
111- },
112- },
113- },
114- .{
115- .uint8 = .{
116- .sRGB = .{
117- .value = .{ 0x56 , 0x5f , 0x89 , 0xff },
118- },
119- },
120- },
121- .{
122- .uint8 = .{
123- .sRGB = .{
124- .value = .{ 0x41 , 0x48 , 0x68 , 0xff },
125- },
126- },
127- },
128- .{
129- .uint8 = .{
130- .sRGB = .{
131- .value = .{ 0x1a , 0x1b , 0x26 , 0xff },
132- },
133- },
134- },
135- },
136- .{
137- .{
138- .uint8 = .{
139- .sRGB = .{
140- .value = .{ 0xf7 , 0x76 , 0x8e , 0xff },
141- },
142- },
143- },
144- .{
145- .uint8 = .{
146- .sRGB = .{
147- .value = .{ 0xff , 0x9e , 0x64 , 0xff },
148- },
149- },
150- },
151- .{
152- .uint8 = .{
153- .sRGB = .{
154- .value = .{ 0xe0 , 0xaf , 0x68 , 0xff },
155- },
156- },
157- },
158- .{
159- .uint8 = .{
160- .sRGB = .{
161- .value = .{ 0x9e , 0xce , 0x6a , 0xff },
162- },
163- },
164- },
165- .{
166- .uint8 = .{
167- .sRGB = .{
168- .value = .{ 0x73 , 0xda , 0xca , 0xff },
169- },
170- },
171- },
172- .{
173- .uint8 = .{
174- .sRGB = .{
175- .value = .{ 0xb4 , 0xf9 , 0xf8 , 0xff },
176- },
177- },
178- },
179- .{
180- .uint8 = .{
181- .sRGB = .{
182- .value = .{ 0x2a , 0xc3 , 0xde , 0xff },
183- },
184- },
185- },
186- .{
187- .uint8 = .{
188- .sRGB = .{
189- .value = .{ 0x7d , 0xcf , 0xff , 0xff },
190- },
191- },
192- },
193- .{
194- .uint8 = .{
195- .sRGB = .{
196- .value = .{ 0x7a , 0xa2 , 0xf7 , 0xff },
197- },
198- },
199- },
200- .{
201- .uint8 = .{
202- .sRGB = .{
203- .value = .{ 0xbb , 0x9a , 0xf7 , 0xff },
204- },
205- },
206- },
207- .{
208- .uint8 = .{
209- .sRGB = .{
210- .value = .{ 0xc0 , 0xca , 0xf5 , 0xff },
211- },
212- },
213- },
214- .{
215- .uint8 = .{
216- .sRGB = .{
217- .value = .{ 0xa9 , 0xb1 , 0xd6 , 0xff },
218- },
219- },
220- },
221- .{
222- .uint8 = .{
223- .sRGB = .{
224- .value = .{ 0x9a , 0xa5 , 0xce , 0xff },
225- },
226- },
227- },
228- .{
229- .uint8 = .{
230- .sRGB = .{
231- .value = .{ 0xcf , 0xc9 , 0xc2 , 0xff },
232- },
233- },
234- },
235- .{
236- .uint8 = .{
237- .sRGB = .{
238- .value = .{ 0x56 , 0x5f , 0x89 , 0xff },
239- },
240- },
241- },
242- .{
243- .uint8 = .{
244- .sRGB = .{
245- .value = .{ 0x41 , 0x48 , 0x68 , 0xff },
246- },
247- },
248- },
249- .{
250- .uint8 = .{
251- .sRGB = .{
252- .value = .{ 0x24 , 0x28 , 0x3b , 0xff },
253- },
254- },
255- },
256- },
257- };
258-
259- const alloc = if (builtin .link_libc ) std .heap .c_allocator else if (builtin .os .tag == .uefi ) std .os .uefi .pool_allocator else std .heap .page_allocator ;
260-
26117 var display = displayBackend .Display .init (alloc , .compositor );
26218 defer display .deinit ();
26319
@@ -293,28 +49,54 @@ pub fn main() void {
29349
29450 const scene = surface .createScene (@enumFromInt (@intFromEnum (sceneBackendType ))) catch | e | @panic (@errorName (e ));
29551
296- var children : [17 ]* phantom.scene.Node = undefined ;
52+ const format = phantom .painting .image .formats .gif .create (alloc ) catch | e | @panic (@errorName (e ));
53+ defer format .deinit ();
29754
298- for (& children , colors [0 ]) | * child , color | {
299- child .* = scene .createNode (.NodeRect , .{
300- .color = color ,
301- .size = vizops .vector .Float32Vector2 .init ([_ ]f32 { 100.0 / 17.0 , 100.0 }),
302- }) catch | e | @panic (@errorName (e ));
55+ //const image = format.readBuffer(@embedFile("example.gif")) catch |e| @panic(@errorName(e));
56+ //defer image.deinit();
57+
58+ const image = zigimg .Image .fromMemory (alloc , @embedFile ("example.gif" )) catch | e | @panic (@errorName (e ));
59+ defer image .deinit ();
60+
61+ var buffers = std .ArrayList (* phantom .painting .fb .Base ).initCapacity (alloc , image .animation .frames .items .len ) catch | e | @panic (@errorName (e ));
62+ defer buffers .deinit ();
63+
64+ for (0.. image .animation .frames .items .len ) | i | {
65+ buffers .appendAssumeCapacity (createFrameBuffer (image , i ) catch | e | @panic (@errorName (e )));
30366 }
30467
305- const flex = scene .createNode (.NodeFlex , .{
306- .direction = phantom .painting .Axis .horizontal ,
307- .children = children ,
68+ const fb = scene .createNode (.NodeFrameBuffer , .{
69+ .source = buffers .items [0 ],
30870 }) catch | e | @panic (@errorName (e ));
309- defer flex .deinit ();
31071
311- var i : usize = 0 ;
312- while (i < 5 ) : (i += 1 ) {
313- _ = scene .frame (flex ) catch | e | @panic (@errorName (e ));
72+ while (true ) {
73+ _ = scene .frame (fb ) catch | e | @panic (@errorName (e ));
74+
75+ fb .setProperties (.{
76+ .source = buffers .items [scene .seq % image .animation .frames .items .len ],
77+ }) catch | e | @panic (@errorName (e ));
78+ }
79+ }
31480
315- const currPalette = scene .seq % colors .len ;
316- for (children , colors [currPalette ]) | child , color | {
317- child .setProperties (.{ .color = color }) catch | e | @panic (@errorName (e ));
318- }
81+ fn createFrameBuffer (image : zigimg.Image , frameIndex : usize ) ! * phantom.painting.fb.Base {
82+ const frame = & image .animation .frames .items [frameIndex ];
83+
84+ const fb = try phantom .painting .fb .AllocatedFrameBuffer .create (alloc , .{
85+ .res = .{ .value = .{ image .width , image .height } },
86+ .colorspace = .sRGB ,
87+ .colorFormat = .{ .rgb = @splat (8 ) },
88+ });
89+ errdefer fb .deinit ();
90+
91+ var i : usize = 0 ;
92+ for (frame .pixels .indexed4 .indices ) | indic | {
93+ const pixel = frame .pixels .indexed4 .palette [indic ];
94+ try fb .write (i , &[_ ]u8 {
95+ pixel .r ,
96+ pixel .g ,
97+ pixel .b ,
98+ });
99+ i += 3 ;
319100 }
101+ return fb ;
320102}
0 commit comments