Skip to content

Commit a055440

Browse files
feat: use new zigimg compatibility module
1 parent 5ec2dbf commit a055440

File tree

3 files changed

+7
-51
lines changed

3 files changed

+7
-51
lines changed

build.zig

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ 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-
2520
const options = b.addOptions();
2621
options.addOption(Phantom.DisplayBackendType, "display_backend", display_backend);
2722
options.addOption(Phantom.SceneBackendType, "scene_backend", scene_backend);
@@ -37,7 +32,6 @@ pub fn build(b: *std.Build) void {
3732

3833
exe_compositor.addModule("phantom", phantom.module("phantom"));
3934
exe_compositor.addModule("vizops", vizops.module("vizops"));
40-
exe_compositor.addModule("zigimg", zigimg.module("zigimg"));
4135
exe_compositor.addOptions("options", options);
4236
b.installArtifact(exe_compositor);
4337
}

build.zig.zon

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
.url = "https://github.com/PhantomUIx/display-uefi/archive/cca33aa75ed0b9790ad61cc0fd583a7ece240715.tar.gz",
88
.hash = "1220fec48cb9d68b2da146f7660afc1d0afdee60ad1b9c4d754cbd3aa2dd009baea9",
99
},
10-
.@"phantom.image.gif" = .{
11-
.url = "https://github.com/PhantomUIx/image-gif/archive/fd2949f098d6ab5b59dc1b542bb255a01d59d3a9.tar.gz",
12-
.hash = "1220b315f3a8ef4af55026b704713a0bb4bf14a54a17e8196bfe9c236c0feafa752f",
10+
.@"phantom.compat.zigimg" = .{
11+
.url = "https://github.com/PhantomUIx/compat-zigimg/archive/e8fcb8681bdfcd0b4f1151f207fe4a6c89c1d1b6.tar.gz",
12+
.hash = "1220be41c35eb8b3c0428b02ae9c4639d80310da1b00f9d5f8aad2a90ca5b0c754d7",
1313
},
1414
.phantom = .{
1515
.url = "https://github.com/PhantomUIx/core/archive/0cbea8f53e650f4864bf41c372c330a050710c10.tar.gz",
@@ -19,9 +19,5 @@
1919
.url = "https://github.com/MidstallSoftware/vizops/archive/8b8499e195d8cf66e9b13ed1c80b24ee27420a29.tar.gz",
2020
.hash = "1220f478cda5edf75a0b837e04c741631e4136e422b4257ccbd09d4cccaf736ac312",
2121
},
22-
.zigimg = .{
23-
.url = "https://github.com/zigimg/zigimg/archive/281d3a0e7599e8c3e174ecc00a259e5e039c9870.tar.gz",
24-
.hash = "12203ffe8b358a125a40c6683715bc634e244a4e8fda191c01cc4084e5bfc9e0007b",
25-
},
2622
},
2723
}

src/compositor.zig

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ const builtin = @import("builtin");
33
const options = @import("options");
44
const phantom = @import("phantom");
55
const vizops = @import("vizops");
6-
const zigimg = @import("zigimg");
76

87
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;
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

Comments
 (0)