Skip to content

Commit 3061417

Browse files
feat: bad apple
1 parent 8a44055 commit 3061417

File tree

4 files changed

+64
-268
lines changed

4 files changed

+64
-268
lines changed

build.zig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ pub fn build(b: *std.Build) void {
1717
.optimize = optimize,
1818
});
1919

20+
const zigimg = b.dependency("zigimg", .{
21+
.target = target,
22+
.optimize = optimize,
23+
});
24+
2025
const options = b.addOptions();
2126
options.addOption(Phantom.DisplayBackendType, "display_backend", display_backend);
2227
options.addOption(Phantom.SceneBackendType, "scene_backend", scene_backend);
@@ -32,6 +37,7 @@ pub fn build(b: *std.Build) void {
3237

3338
exe_compositor.addModule("phantom", phantom.module("phantom"));
3439
exe_compositor.addModule("vizops", vizops.module("vizops"));
40+
exe_compositor.addModule("zigimg", zigimg.module("zigimg"));
3541
exe_compositor.addOptions("options", options);
3642
b.installArtifact(exe_compositor);
3743
}

build.zig.zon

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,24 @@
44
.paths = .{"."},
55
.dependencies = .{
66
.@"phantom.display.uefi" = .{
7-
.url = "https://github.com/PhantomUIx/display-uefi/archive/71314fc70e4720ab66b9538d8743e6b967e3b928.tar.gz",
8-
.hash = "1220cb9f94c87805b41564dfc422e4c0dcc36178fa5c913d9de2bd5375ac463e5f73",
7+
.url = "https://github.com/PhantomUIx/display-uefi/archive/cca33aa75ed0b9790ad61cc0fd583a7ece240715.tar.gz",
8+
.hash = "1220fec48cb9d68b2da146f7660afc1d0afdee60ad1b9c4d754cbd3aa2dd009baea9",
9+
},
10+
.@"phantom.image.gif" = .{
11+
.url = "https://github.com/PhantomUIx/image-gif/archive/fd2949f098d6ab5b59dc1b542bb255a01d59d3a9.tar.gz",
12+
.hash = "1220b315f3a8ef4af55026b704713a0bb4bf14a54a17e8196bfe9c236c0feafa752f",
913
},
1014
.phantom = .{
11-
.url = "https://github.com/PhantomUIx/core/archive/92d373915c90fc7131f0dee91b21509d55986b4d.tar.gz",
12-
.hash = "12202f1aca5b17b007426c00cae559cc5a38f06a9a441e381cc20e5e3e967293e8a4",
15+
.url = "https://github.com/PhantomUIx/core/archive/0cbea8f53e650f4864bf41c372c330a050710c10.tar.gz",
16+
.hash = "1220e811950ddd80422a486e322fdd78c55814560743da88bb9d32a890a3e0421626",
1317
},
1418
.vizops = .{
1519
.url = "https://github.com/MidstallSoftware/vizops/archive/8b8499e195d8cf66e9b13ed1c80b24ee27420a29.tar.gz",
1620
.hash = "1220f478cda5edf75a0b837e04c741631e4136e422b4257ccbd09d4cccaf736ac312",
1721
},
22+
.zigimg = .{
23+
.url = "https://github.com/zigimg/zigimg/archive/281d3a0e7599e8c3e174ecc00a259e5e039c9870.tar.gz",
24+
.hash = "12203ffe8b358a125a40c6683715bc634e244a4e8fda191c01cc4084e5bfc9e0007b",
25+
},
1826
},
1927
}

src/compositor.zig

Lines changed: 46 additions & 264 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ const builtin = @import("builtin");
33
const options = @import("options");
44
const phantom = @import("phantom");
55
const 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

710
const displayBackendType: phantom.display.BackendType = @enumFromInt(@intFromEnum(options.display_backend));
811
const displayBackend = phantom.display.Backend(displayBackendType);
@@ -11,253 +14,6 @@ const sceneBackendType: phantom.scene.BackendType = @enumFromInt(@intFromEnum(op
1114
const sceneBackend = phantom.scene.Backend(sceneBackendType);
1215

1316
pub 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
}

src/example.gif

8.69 MB
Loading

0 commit comments

Comments
 (0)