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