Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions showcase/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ const std = @import("std");
const root = @import("root");
// cart imports
const carts = .{
// TODO: Enable these when zigimg comes out with a 0.15.1 update
//.{ "zeroman", @import("zeroman") },
//.{ "dvd", @import("dvd") },
.{ "zeroman", @import("zeroman") },
.{ "dvd", @import("dvd") },
.{ "blobs", @import("blobs") },
.{ "plasma", @import("plasma") },
.{ "metalgear-timer", @import("metalgear-timer") },
Expand Down
5 changes: 2 additions & 3 deletions showcase/build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
.raytracer = .{ .path = "carts/raytracer" },
.neopixelpuzzle = .{ .path = "carts/neopixelpuzzle" },
.@"space-shooter" = .{ .path = "carts/space-shooter" },
// TODO: enable these when zigimg gets a 0.15.1 update
//.dvd = .{ .path = "carts/dvd" },
//.zeroman = .{ .path = "carts/zeroman" },
.dvd = .{ .path = "carts/dvd" },
.zeroman = .{ .path = "carts/zeroman" },
},
.paths = .{
"README.md",
Expand Down
4 changes: 2 additions & 2 deletions showcase/carts/dvd/build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
.dependencies = .{
.sycl_badge = .{ .path = "../../.." },
.zigimg = .{
.url = "git+https://github.com/zigimg/zigimg#70a3abe922d65ec13b488b0890970edcf11e0006",
.hash = "zigimg-0.1.0-8_eo2oFJEwDQjDFXp7mdV7KXQiMIRAYCl7Y0z91NdxG2",
.url = "git+https://github.com/zigimg/zigimg#362cdd6bce109f7bc674be134cddd378f52da5d4",
.hash = "zigimg-0.1.0-8_eo2jNrFQD4mu3EAUkfQRmCkyfprdIXc8JQ6uyxhjSQ",
},
},
.paths = .{
Expand Down
34 changes: 17 additions & 17 deletions showcase/carts/dvd/build/convert_gfx.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const std = @import("std");
const allocator = std.heap.c_allocator;
const ArrayListManaged = std.array_list.Managed;
const Image = @import("zigimg").Image;

const ConvertFile = struct {
Expand All @@ -14,14 +13,14 @@ pub fn main() !void {
defer args.deinit();

_ = args.next();
var in_files = ArrayListManaged(ConvertFile).init(allocator);
var in_files: std.ArrayList(ConvertFile) = .empty;
var out_path: []const u8 = undefined;
while (args.next()) |arg| {
if (std.mem.eql(u8, arg, "-i")) {
const path = args.next() orelse return error.MissingArg;
const bits = args.next() orelse return error.MissingArg;
const transparency = args.next() orelse return error.MissingArg;
try in_files.append(.{ .path = path, .bits = @intCast(bits[0] - '0'), .transparency = transparency[0] == 't' });
try in_files.append(allocator, .{ .path = path, .bits = @intCast(bits[0] - '0'), .transparency = transparency[0] == 't' });
} else if (std.mem.eql(u8, arg, "-o")) {
out_path = args.next() orelse return error.MissingArg;
}
Expand All @@ -31,28 +30,29 @@ pub fn main() !void {
defer out_file.close();

var writer_buf: [4096]u8 = undefined;
var writer = out_file.writer(&writer_buf);
try writer.interface.writeAll("const PackedIntSlice = @import(\"packed_int_array\").PackedIntSlice;\n");
try writer.interface.writeAll("const DisplayColor = @import(\"cart-api\").DisplayColor;\n\n");
var out_file_writer = out_file.writer(&writer_buf);
const writer = &out_file_writer.interface;
try writer.writeAll("const PackedIntSlice = @import(\"packed_int_array\").PackedIntSlice;\n");
try writer.writeAll("const DisplayColor = @import(\"cart-api\").DisplayColor;\n\n");

for (in_files.items) |in_file| {
try convert(in_file, &writer.interface);
try convert(in_file, writer);
}

try writer.flush();
}

fn convert(args: ConvertFile, writer: *std.Io.Writer) !void {
const N = 8 / args.bits;

var image = try Image.fromFilePath(allocator, args.path);
defer image.deinit();
var buffer: [8192]u8 = undefined;
var image = try Image.fromFilePath(allocator, args.path, &buffer);
defer image.deinit(allocator);

var colors = ArrayListManaged(Color).init(allocator);
defer colors.deinit();
if (args.transparency) try colors.append(.{ .r = 31, .g = 0, .b = 31 });
var indices = try ArrayListManaged(usize).initCapacity(allocator, image.width * image.height);
defer indices.deinit();
var colors: std.ArrayList(Color) = .empty;
defer colors.deinit(allocator);
if (args.transparency) try colors.append(allocator, .{ .r = 31, .g = 0, .b = 31 });
var indices: std.ArrayList(usize) = try .initCapacity(allocator, image.width * image.height);
defer indices.deinit(allocator);
var it = image.iterator();
while (it.next()) |pixel| {
const color = Color{
Expand Down Expand Up @@ -109,10 +109,10 @@ pub const Color = packed struct(u16) {
}
};

fn getIndex(colors: *ArrayListManaged(Color), color: Color) !usize {
fn getIndex(colors: *std.ArrayList(Color), color: Color) !usize {
for (colors.items, 0..) |c, i| {
if (c.eql(color)) return i;
}
try colors.append(color);
try colors.append(allocator, color);
return colors.items.len - 1;
}
4 changes: 2 additions & 2 deletions showcase/carts/zeroman/build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
.dependencies = .{
.sycl_badge = .{ .path = "../../.." },
.zigimg = .{
.url = "git+https://github.com/zigimg/zigimg#7144f698850afd968fa87e04b95343d819912a33",
.hash = "zigimg-0.1.0-8_eo2h6XEgAR6UkBiCtWECcml0gtx0oIXE3MX7sPCZof",
.url = "git+https://github.com/zigimg/zigimg#362cdd6bce109f7bc674be134cddd378f52da5d4",
.hash = "zigimg-0.1.0-8_eo2jNrFQD4mu3EAUkfQRmCkyfprdIXc8JQ6uyxhjSQ",
},
},
.paths = .{
Expand Down
30 changes: 16 additions & 14 deletions showcase/carts/zeroman/build/convert_gfx.zig
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,46 @@ pub fn main() !void {
defer args.deinit();

_ = args.next();
var in_files = std.ArrayList(ConvertFile).init(allocator);
var in_files: std.ArrayList(ConvertFile) = .empty;
var out_path: []const u8 = undefined;
while (args.next()) |arg| {
if (std.mem.eql(u8, arg, "-i")) {
const path = args.next() orelse return error.MissingArg;
const bits = args.next() orelse return error.MissingArg;
const transparency = args.next() orelse return error.MissingArg;
try in_files.append(.{ .path = path, .bits = @intCast(bits[0] - '0'), .transparency = transparency[0] == 't' });
try in_files.append(allocator, .{ .path = path, .bits = @intCast(bits[0] - '0'), .transparency = transparency[0] == 't' });
} else if (std.mem.eql(u8, arg, "-o")) {
out_path = args.next() orelse return error.MissingArg;
}
}
std.debug.print("{s}\n", .{out_path});

const out_file = try std.fs.cwd().createFile(out_path, .{});
defer out_file.close();

const writer = out_file.writer();
var writer_buf: [4096]u8 = undefined;
var out_file_writer = out_file.writer(&writer_buf);
const writer = &out_file_writer.interface;
try writer.writeAll("const PackedIntSlice = @import(\"packed_int_array\").PackedIntSlice;\n");
try writer.writeAll("const DisplayColor = @import(\"cart-api\").DisplayColor;\n\n");

for (in_files.items) |in_file| {
try convert(in_file, writer);
}
try writer.flush();
}

fn convert(args: ConvertFile, writer: std.fs.File.Writer) !void {
fn convert(args: ConvertFile, writer: *std.Io.Writer) !void {
const N = 8 / args.bits;

var image = try Image.fromFilePath(allocator, args.path);
defer image.deinit();
var buffer: [4096]u8 = undefined;
var image = try Image.fromFilePath(allocator, args.path, &buffer);
defer image.deinit(allocator);

var colors = std.ArrayList(Color).init(allocator);
defer colors.deinit();
if (args.transparency) try colors.append(.{ .r = 31, .g = 0, .b = 31 });
var indices = try std.ArrayList(usize).initCapacity(allocator, image.width * image.height);
defer indices.deinit();
var colors: std.ArrayList(Color) = .empty;
defer colors.deinit(allocator);
if (args.transparency) try colors.append(allocator, .{ .r = 31, .g = 0, .b = 31 });
var indices: std.ArrayList(usize) = try .initCapacity(allocator, image.width * image.height);
defer indices.deinit(allocator);
var it = image.iterator();
while (it.next()) |pixel| {
const color = Color{
Expand All @@ -60,7 +63,6 @@ fn convert(args: ConvertFile, writer: std.fs.File.Writer) !void {
const index = try getIndex(&colors, color);
indices.appendAssumeCapacity(index);
}
std.debug.print("{} colors: {any}\n", .{ colors.items.len, colors.items });
var packed_data = try allocator.alloc(u8, indices.items.len / N);
defer allocator.free(packed_data);
for (packed_data, 0..) |_, i| {
Expand Down Expand Up @@ -111,6 +113,6 @@ fn getIndex(colors: *std.ArrayList(Color), color: Color) !usize {
for (colors.items, 0..) |c, i| {
if (c.eql(color)) return i;
}
try colors.append(color);
try colors.append(allocator, color);
return colors.items.len - 1;
}
Loading