examples: update zigimg usage

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2022-08-20 22:43:04 -07:00
parent dc00067ec1
commit 37c3045314
3 changed files with 22 additions and 22 deletions

View file

@ -65,12 +65,12 @@ pub fn init(app: *App, core: *mach.Core) !void {
const atlas_img_region = try app.texture_atlas_data.reserve(core.allocator, @truncate(u32, img.width), @truncate(u32, img.height));
const img_uv_data = atlas_img_region.getUVData(atlas_float_size);
switch (img.pixels.?) {
.Rgba32 => |pixels| app.texture_atlas_data.set(atlas_img_region, pixels),
.Rgb24 => |pixels| {
switch (img.pixels) {
.rgba32 => |pixels| app.texture_atlas_data.set(atlas_img_region, pixels),
.rgb24 => |pixels| {
const data = try rgb24ToRgba32(core.allocator, pixels);
defer data.deinit(core.allocator);
app.texture_atlas_data.set(atlas_img_region, data.Rgba32);
app.texture_atlas_data.set(atlas_img_region, data.rgba32);
},
else => @panic("unsupported image color format"),
}
@ -300,11 +300,11 @@ pub fn resize(app: *App, _: *mach.Core, _: u32, _: u32) !void {
app.update_vertex_uniform_buffer = true;
}
fn rgb24ToRgba32(allocator: std.mem.Allocator, in: []zigimg.color.Rgb24) !zigimg.color.ColorStorage {
const out = try zigimg.color.ColorStorage.init(allocator, .Rgba32, in.len);
fn rgb24ToRgba32(allocator: std.mem.Allocator, in: []zigimg.color.Rgb24) !zigimg.color.PixelStorage {
const out = try zigimg.color.PixelStorage.init(allocator, .rgba32, in.len);
var i: usize = 0;
while (i < in.len) : (i += 1) {
out.Rgba32[i] = zigimg.color.Rgba32{ .R = in[i].R, .G = in[i].G, .B = in[i].B, .A = 255 };
out.rgba32[i] = zigimg.color.Rgba32{ .r = in[i].r, .g = in[i].g, .b = in[i].b, .a = 255 };
}
return out;
}