diff --git a/packages/media/build.zig.zon b/packages/media/build.zig.zon index f2b991b..357797a 100644 --- a/packages/media/build.zig.zon +++ b/packages/media/build.zig.zon @@ -1,7 +1,7 @@ .{ .name = .media, .version = "0.0.0", - .minimum_zig_version = "0.16.0", + .minimum_zig_version = "0.17.0", .paths = .{ "src", "build.zig", diff --git a/packages/media/src/png.zig b/packages/media/src/png.zig index 6eb7681..ca15baf 100644 --- a/packages/media/src/png.zig +++ b/packages/media/src/png.zig @@ -1,5 +1,6 @@ const std = @import("std"); +const Crc = std.hash.crc.@"CRC-32/ISO-HDLC"; const Format = @import("Format.zig"); pub const format: Format = .{ @@ -72,11 +73,11 @@ pub const Header = struct { return .{ .width = width, .height = height, - .bit_depth = @enumFromInt(bit_depth), - .color_type = @enumFromInt(color_type), - .compression_method = @enumFromInt(compression_method), - .filter_method = @enumFromInt(filter_method), - .interlace_method = @enumFromInt(interlace_method), + .bit_depth = @fromBackingInt(bit_depth), + .color_type = @fromBackingInt(color_type), + .compression_method = @fromBackingInt(compression_method), + .filter_method = @fromBackingInt(filter_method), + .interlace_method = @fromBackingInt(interlace_method), }; } @@ -93,7 +94,7 @@ pub const BitDepth = enum(u8) { @"16" = 16, pub fn range(self: BitDepth) usize { - return @as(usize, 2) << @intCast(@intFromEnum(self)); + return @as(usize, 2) << @intCast(@backingInt(self)); } test "refAllDecls" { @@ -109,15 +110,15 @@ pub const ColorType = enum(u8) { rgba = 6, pub fn paletteUsed(self: ColorType) bool { - return @intFromEnum(self) & 0b0000_0001 != 0; + return @backingInt(self) & 0b0000_0001 != 0; } pub fn colorUsed(self: ColorType) bool { - return @intFromEnum(self) & 0b0000_0010 != 0; + return @backingInt(self) & 0b0000_0010 != 0; } pub fn alphaChannelUsed(self: ColorType) bool { - return @intFromEnum(self) & 0b0000_0100 != 0; + return @backingInt(self) & 0b0000_0100 != 0; } test "refAllDecls" { @@ -331,7 +332,7 @@ const RenderingIntent = enum(u8) { if (chunk.data.len != 1) return error.InvalidPng; const rendering_intent = chunk.data[0]; if (rendering_intent > 3) return error.InvalidPng; - return @enumFromInt(rendering_intent); + return @fromBackingInt(rendering_intent); } test "refAllDecls" { @@ -361,7 +362,7 @@ pub const PhysicalPixelDimensions = struct { return .{ .pixels_per_unit_x = pixels_per_unit_x, .pixels_per_unit_y = pixels_per_unit_y, - .unit = @enumFromInt(unit), + .unit = @fromBackingInt(unit), }; } @@ -455,7 +456,7 @@ pub const ChunkType = enum(u32) { } pub fn fromBytes(bytes: *const [4]u8) ChunkType { - return @enumFromInt(fromName(bytes)); + return @fromBackingInt(fromName(bytes)); } pub fn toBytes(self: ChunkType) [4]u8 { @@ -507,11 +508,11 @@ pub const StandardKeyword = enum { Comment, pub const map: std.StaticStringMap(StandardKeyword) = blk: { - const fields = @typeInfo(StandardKeyword).@"enum".fields; + const field_names = @typeInfo(StandardKeyword).@"enum".field_names; - var kvs_list: [fields.len]struct { []const u8, StandardKeyword } = undefined; - for (fields, 0..) |field, i| { - kvs_list[i] = .{ field.name, @field(StandardKeyword, field.name) }; + var kvs_list: [field_names.len]struct { []const u8, StandardKeyword } = undefined; + for (field_names, 0..) |field_name, i| { + kvs_list[i] = .{ field_name, @field(StandardKeyword, field_name) }; } break :blk .initComptime(kvs_list); @@ -582,7 +583,7 @@ pub fn decodeChunk(buffer: []const u8) !?struct { Chunk, []const u8 } { const crc = std.mem.readInt(u32, rest[0..4], .big); rest = rest[4..]; - if (std.hash.crc.Crc32IsoHdlc.hash(data) != crc) { + if (Crc.hash(data) != crc) { return error.InvalidPng; } @@ -627,7 +628,7 @@ pub fn encodeChunks(chunks: []const Chunk, writer: *std.Io.Writer) !void { try writer.writeAll(magic); for (chunks) |chunk| { - var crc: std.hash.crc.Crc32IsoHdlc = .init(); + var crc: Crc = .init(); var data: []const u8 = chunk.data; while (data.len > 0) {