tiny.simd.Image3
Defined in image.
Source
Source: lib/simd/src/image/root.zig:246
zig
pub fn Image3(comptime T: type) type { const ImageT = Image(T); return struct { planes: [3]ImageT, packed_storage: []u8, packing: Packing, const Self = @This(); pub const num_planes: usize = 3; pub fn empty() Self { return .{ .planes = .{ ImageT.empty(), ImageT.empty(), ImageT.empty() }, .packed_storage = &.{}, .packing = .none, }; } pub fn init(allocator: std.mem.Allocator, width: usize, height: usize) Error!Self { try validateDimensions(width, height); if (width == 0 or height == 0) { return .{ .planes = .{ ImageT.zeroDimensions(width, height), ImageT.zeroDimensions(width, height), ImageT.zeroDimensions(width, height), }, .packed_storage = &.{}, .packing = .none, }; } const stride = try bytesPerRowFor(width, @sizeOf(T), vector_size); const plane_size = std.math.mul(usize, stride, height) catch return error.AllocationSizeOverflow; const allocation_size = std.math.mul(usize, plane_size, num_planes) catch return error.AllocationSizeOverflow; const storage = try allocator.alignedAlloc( u8, .fromByteUnits(storage_alignment), allocation_size, ); errdefer allocator.free(storage); var result = empty(); result.packed_storage = storage; result.packing = .owned; for (&result.planes, 0..) |*current_plane, index| { const begin = index * plane_size; current_plane.* = try ImageT.initBorrowed( width, height, stride, storage[begin..][0..plane_size], ); try current_plane.initializePadding(.round_up); } return result; } pub fn initBorrowed( width: usize, height: usize, stride: usize, buffers: [num_planes][]u8, ) GeometryError!Self { var result = empty(); for (&result.planes, buffers) |*current_plane, buffer| { current_plane.* = try ImageT.initBorrowed(width, height, stride, buffer); } return result; } pub fn initPlanes( plane0: *ImageT, plane1: *ImageT, plane2: *ImageT, ) GeometryError!Self { if (plane0 == plane1 or plane0 == plane2 or plane1 == plane2) { return error.AliasedPlanes; } if (!sameSize(plane0, plane1) or !sameSize(plane0, plane2)) { return error.PlaneSizeMismatch; } if (plane0.bytesPerRow() != plane1.bytesPerRow() or plane0.bytesPerRow() != plane2.bytesPerRow()) { return error.PlaneStrideMismatch; } const result = Self{ .planes = .{ plane0.*, plane1.*, plane2.* }, .packed_storage = &.{}, .packing = .none, }; plane0.* = ImageT.empty(); plane1.* = ImageT.empty(); plane2.* = ImageT.empty(); return result; } pub fn deinit(self: *Self, allocator: std.mem.Allocator) void { switch (self.packing) { .owned => { std.debug.assert(self.packed_storage.len != 0); const aligned: []align(storage_alignment) u8 = @alignCast(self.packed_storage); allocator.free(aligned); }, .none => for (&self.planes) |*current_plane| current_plane.deinit(allocator), } self.* = empty(); } pub fn swap(self: *Self, other: *Self) void { std.mem.swap(Self, self, other); } pub fn shrinkTo(self: *Self, width: usize, height: usize) GeometryError!void { if (width > self.xsize() or height > self.ysize()) { return error.InvalidShrink; } for (&self.planes) |*current_plane| try current_plane.shrinkTo(width, height); } pub fn xsize(self: *const Self) usize { return self.planes[0].xsize(); } pub fn ysize(self: *const Self) usize { return self.planes[0].ysize(); } pub fn bytesPerRow(self: *const Self) usize { return self.planes[0].bytesPerRow(); } pub fn pixelsPerRow(self: *const Self) usize { return self.planes[0].pixelsPerRow(); } pub fn plane(self: *const Self, index: usize) *const ImageT { std.debug.assert(index < num_planes); return &self.planes[index]; } pub fn constPlaneRow(self: *const Self, component: usize, y: usize) []const T { std.debug.assert(component < num_planes); return self.planes[component].constRow(y); } pub fn mutablePlaneRow(self: *const Self, component: usize, y: usize) []T { std.debug.assert(component < num_planes); return self.planes[component].mutableRow(y); } };}Source: lib/simd/src/root.zig:523
zig
pub const Image3 = image.Image3;Audit
| Definitions | 1 |
|---|---|
| Public names | 2 |
| Members | 0 |
| Version | 26.7.0 |
| Revision | daab053ee433 |