-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.zig
More file actions
66 lines (53 loc) · 2.37 KB
/
example.zig
File metadata and controls
66 lines (53 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const std = @import("std");
const vizops = @import("vizops");
pub fn main() !void {
const alloc = std.heap.page_allocator;
const v = vizops.vector.Float32Vector2.zero()
.add(.{ @as(f32, 1.0), @as(f32, 0.5) })
.sub(@as(f32, 2.0))
.norm(@as(f32, 0.00000001));
std.debug.print("{any}\n", .{v});
const c = vizops.color.types.sRGB(u8).init(.{ @as(u8, 0), @as(u8, 255), @as(u8, 0), @as(u8, 255) })
.channel(.red)
.set(25)
.done()
.channel(.alpha)
.div(10)
.done();
std.debug.print("{} {} {} {} {}\n", .{ c, c.convert(.linearRGB).linearRGB, c.convert(.hsv).hsv, c.convert(.hsl).hsl, c.convert(.cmyk).cmyk });
var buf = std.io.fixedBufferStream(@embedFile("srgb.icc"));
const header = vizops.color.icc.Header.read(buf.reader()) catch |err| {
std.debug.print("Buffer was at {}\n", .{buf.pos});
return err;
};
std.debug.print("{}\n", .{header});
const tags = vizops.color.icc.Tags.read(std.heap.page_allocator, buf.reader()) catch |err| {
std.debug.print("Buffer was at {}\n", .{buf.pos});
return err;
};
defer tags.deinit();
std.debug.print("{}\n", .{tags});
inline for (@typeInfo(vizops.color.fourcc.formats).Struct.decls) |d| {
const f = @field(vizops.color.fourcc.formats, d.name);
std.debug.print("\t{s} - {!any} - 0x{x}", .{ d.name, vizops.color.fourcc.Value.decode(f), f });
if (vizops.color.fourcc.Value.decode(f) catch null) |a| {
std.debug.print(" - {} {!any} {}\n", .{ a.width(), a.forAny(), a.channelSize() });
} else {
std.debug.print("\n", .{});
}
}
const argb16161616f = try vizops.color.fourcc.Value.decode(vizops.color.fourcc.formats.argb16161616f);
const colorBuff = try c.cast(f16).allocWrite(alloc, argb16161616f);
defer alloc.free(colorBuff);
std.debug.print("Color as argb16161616f: {any}\nConverted back: {}\n", .{
colorBuff,
try vizops.color.types.sRGB(f16).read(argb16161616f, colorBuff),
});
//const icc = vizops.color.icc.read(std.heap.page_allocator, buf.reader()) catch |err| {
// std.debug.print("Buffer was at {}\n", .{buf.pos});
// return err;
//};
//defer icc.deinit();
//std.debug.print("{} {}\n", .{ icc, buf.pos });
//for (icc.tagdata.items) |item| std.debug.print("{}\n", .{item});
}