| ... | @@ -3,6 +3,7 @@ | ... | @@ -3,6 +3,7 @@ |
| 3 | const std = @import("std"); | 3 | const std = @import("std"); |
| 4 | const Self = @This(); | 4 | const Self = @This(); |
| 5 | const color = @import("./mod.zig"); | 5 | const color = @import("./mod.zig"); |
| | 6 | const _x = @import("./_x.zig"); |
| 6 | | 7 | |
| 7 | y: u8, | 8 | y: u8, |
| 8 | cb: u8, | 9 | cb: u8, |
| ... | @@ -25,3 +26,17 @@ pub fn initYCbCr(y: u8, cb: u8, cr: u8) Self { | ... | @@ -25,3 +26,17 @@ pub fn initYCbCr(y: u8, cb: u8, cr: u8) Self { |
| 25 | pub fn eql(x: Self, y: Self) bool { | 26 | pub fn eql(x: Self, y: Self) bool { |
| 26 | return x.y == y.y and x.cb == y.cb and x.cr == y.cr and x.a == y.a; | 27 | return x.y == y.y and x.cb == y.cb and x.cr == y.cr and x.a == y.a; |
| 27 | } | 28 | } |
| | 29 | |
| | 30 | pub usingnamespace _x.mixin(@This(), .y, .cb, .cr); |
| | 31 | |
| | 32 | pub fn to_srgb(x: Self) color.sRGB { |
| | 33 | // zig fmt: off |
| | 34 | const f = x.to_vec(); |
| | 35 | return color.sRGB.from_vec(.{ |
| | 36 | @max(0, @min(255, f[0] + 1.402 * (f[2]-128))), |
| | 37 | @max(0, @min(255, f[0] - 0.34414 * (f[1]-128) - 0.71414 * (f[2]-128))), |
| | 38 | @max(0, @min(255, f[0] + 1.772 * (f[1]-128))), |
| | 39 | @max(0, @min(255, f[3])), |
| | 40 | }); |
| | 41 | // zig fmt: on |
| | 42 | } |