@@ -3,7 +3,6 @@ const builtin = @import("builtin");
33const options = @import ("options" );
44const phantom = @import ("phantom" );
55const vizops = @import ("vizops" );
6- const zigimg = @import ("zigimg" );
76
87const 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 ;
98
@@ -49,54 +48,21 @@ pub fn main() void {
4948
5049 const scene = surface .createScene (@enumFromInt (@intFromEnum (sceneBackendType ))) catch | e | @panic (@errorName (e ));
5150
52- const format = phantom .painting .image .formats .gif .create (alloc ) catch | e | @panic (@errorName (e ));
51+ const format = phantom .painting .image .formats .zigimg .create (alloc ) catch | e | @panic (@errorName (e ));
5352 defer format .deinit ();
5453
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 ));
54+ const image = format .readBuffer (@embedFile ("example.gif" )) catch | e | @panic (@errorName (e ));
5955 defer image .deinit ();
6056
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 )));
66- }
67-
6857 const fb = scene .createNode (.NodeFrameBuffer , .{
69- .source = buffers . items [ 0 ]. dupe ( ) catch | e | @panic (@errorName (e )),
58+ .source = image . buffer ( 0 ) catch | e | @panic (@errorName (e )),
7059 }) catch | e | @panic (@errorName (e ));
7160
7261 while (true ) {
7362 _ = scene .frame (fb ) catch | e | @panic (@errorName (e ));
7463
7564 fb .setProperties (.{
76- .source = buffers . items [ scene .seq % image .animation . frames . items . len ] ,
65+ .source = image . buffer ( scene .seq % image .info (). seqCount ) catch | e | @panic ( @errorName ( e )) ,
7766 }) catch | e | @panic (@errorName (e ));
7867 }
7968}
80-
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 ;
100- }
101- return fb ;
102- }
0 commit comments