authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2024-12-30 02:05:10 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2024-12-30 02:05:10 -08:00
log51da26f311b7e60ae65117414f02841c83dd69f5
tree8cbb12da2335da01f720e67e997b44851ba722d2
parent64cfdaabc303a26095c5b5f9146f87ba6997a031

tidy


3 files changed, 15 insertions(+), 4 deletions(-)

LinearRgb.zig+3-2
......@@ -30,14 +30,15 @@ pub fn eql(x: Self, y: Self) bool {
3030
3131// https://www.w3.org/TR/WCAG/#dfn-relative-luminance
3232pub fn relative_luminance(x: Self) f32 {
33 return (0.2126 * x.r) + (0.7152 * x.g) + (0.0722 * x.b);
33 const r, const g, const b, _ = x.to_array();
34 return (0.2126 * r) + (0.7152 * g) + (0.0722 * b);
3435}
3536
3637pub usingnamespace _x.mixin(@This(), f32, .r, .g, .b);
3738
3839// https://gamedev.stackexchange.com/a/194038
3940pub fn to_srgb(x: Self) color.sRGB {
40 const v: vec4 = x.to_array();
41 const v = x.to_vec();
4142 const cutoff = v < @as(vec4, @splat(0.0031308));
4243 const higher = @as(vec4, @splat(1.055)) * std.math.pow(vec4, v, @splat(1.0 / 2.4)) - @as(vec4, @splat(0.055));
4344 const lower = v * @as(vec4, @splat(12.92));
YUV.zig+1-2
......@@ -40,6 +40,5 @@ pub fn to_srgb(x: Self) color.sRGB {
4040}
4141
4242pub fn normal(x: Self) vec4 {
43 const v: vec4 = x.to_array();
44 return v * @as(vec4, .{ 255, 255, 255, 1 });
43 return x.to_vec() * @as(vec4, .{ 255, 255, 255, 1 });
4544}
_x.zig+11
......@@ -9,6 +9,9 @@ pub fn mixin(
99) type {
1010 return struct {
1111 pub fn to_vec(x: T) @Vector(4, f32) {
12 if (I == f32) {
13 return x.to_array();
14 }
1215 return .{
1316 @floatFromInt(@field(x, @tagName(f1))),
1417 @floatFromInt(@field(x, @tagName(f2))),
......@@ -18,6 +21,14 @@ pub fn mixin(
1821 }
1922
2023 pub fn from_vec(in: @Vector(4, f32)) T {
24 if (I == f32) {
25 var x: T = undefined;
26 @field(x, @tagName(f1)) = in[0];
27 @field(x, @tagName(f2)) = in[1];
28 @field(x, @tagName(f3)) = in[2];
29 x.a = in[3];
30 return x;
31 }
2132 var x: T = undefined;
2233 @field(x, @tagName(f1)) = @intFromFloat(in[0]);
2334 @field(x, @tagName(f2)) = @intFromFloat(in[1]);