Skip to documentation
SLOP

tiny.simd.Image

Reference tiny.simd Image

Defined in image.

Called byCallsimageImage3RectconstRowRectmutableRowprivate sourcelib.simd.src.image.testcheckImageInitFailurestest sourcelib.simd.src.image.testtest: image3 borrowed planes and plan...+10 moreRectemptyimagebytesPerRowForprivate sourcelib.simd.src.image.rootroundUpprivate sourcelib.simd.src.image.rootvalidateComponentprivate sourcelib.simd.src.image.rootvalidateDimensionsimageImage
Static calls · unresolved targets: 2 · external targets: 4.

Source

Source: lib/simd/src/image/root.zig:69

zig
pub fn Image(comptime T: type) type {    validateComponent(T);    return struct {        xsize_value: u32,        ysize_value: u32,        bytes_per_row_value: usize,        storage: []u8,        owned: bool,        const Self = @This();        pub fn empty() Self {            return zeroDimensions(0, 0);        }        fn zeroDimensions(width: usize, height: usize) Self {            return .{                .xsize_value = @intCast(width),                .ysize_value = @intCast(height),                .bytes_per_row_value = 0,                .storage = &.{},                .owned = false,            };        }        pub fn init(allocator: std.mem.Allocator, width: usize, height: usize) Error!Self {            try validateDimensions(width, height);            if (width == 0 or height == 0) return zeroDimensions(width, height);            const stride = try bytesPerRowFor(width, @sizeOf(T), vector_size);            const allocation_size = std.math.mul(usize, stride, height) catch                return error.AllocationSizeOverflow;            const storage = try allocator.alignedAlloc(                u8,                .fromByteUnits(storage_alignment),                allocation_size,            );            var result = Self{                .xsize_value = @intCast(width),                .ysize_value = @intCast(height),                .bytes_per_row_value = stride,                .storage = storage,                .owned = true,            };            result.initializePadding(.round_up) catch |err| {                allocator.free(storage);                return err;            };            return result;        }        pub fn initBorrowed(            width: usize,            height: usize,            stride: usize,            storage: []u8,        ) GeometryError!Self {            try validateDimensions(width, height);            if (width == 0 or height == 0) {                if (stride != 0) return error.InvalidStride;                return zeroDimensions(width, height);            }            if (stride % vector_size != 0 or stride % @alignOf(T) != 0) {                return error.InvalidStride;            }            const valid_bytes = std.math.mul(usize, width, @sizeOf(T)) catch                return error.RowSizeOverflow;            if (stride < valid_bytes) return error.InvalidStride;            const required = std.math.mul(usize, stride, height) catch                return error.AllocationSizeOverflow;            if (storage.len < required) return error.BufferTooSmall;            if (@intFromPtr(storage.ptr) % @max(vector_size, @alignOf(T)) != 0) {                return error.MisalignedStorage;            }            return .{                .xsize_value = @intCast(width),                .ysize_value = @intCast(height),                .bytes_per_row_value = stride,                .storage = storage[0..required],                .owned = false,            };        }        pub fn deinit(self: *Self, allocator: std.mem.Allocator) void {            if (self.owned) {                std.debug.assert(self.storage.len != 0);                const aligned: []align(storage_alignment) u8 = @alignCast(self.storage);                allocator.free(aligned);            }            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_value or height > self.ysize_value) {                return error.InvalidShrink;            }            self.xsize_value = @intCast(width);            self.ysize_value = @intCast(height);        }        pub fn initializePaddingForUnalignedAccesses(self: *Self) GeometryError!void {            try self.initializePadding(.unaligned);        }        pub fn xsize(self: *const Self) usize {            return self.xsize_value;        }        pub fn ysize(self: *const Self) usize {            return self.ysize_value;        }        pub fn bytesPerRow(self: *const Self) usize {            return self.bytes_per_row_value;        }        pub fn pixelsPerRow(self: *const Self) usize {            return self.bytes_per_row_value / @sizeOf(T);        }        pub fn bytes(self: *Self) []u8 {            return self.storage;        }        pub fn constBytes(self: *const Self) []const u8 {            return self.storage;        }        pub fn constRow(self: *const Self, y: usize) []const T {            std.debug.assert(y < self.ysize_value);            if (self.bytes_per_row_value == 0) return &.{};            const begin = y * self.bytes_per_row_value;            const row = self.storage[begin..][0..self.bytes_per_row_value];            const ptr: [*]const T = @ptrCast(@alignCast(row.ptr));            return ptr[0..self.pixelsPerRow()];        }        pub fn mutableRow(self: *const Self, y: usize) []T {            std.debug.assert(y < self.ysize_value);            if (self.bytes_per_row_value == 0) return &.{};            const begin = y * self.bytes_per_row_value;            const row = self.storage[begin..][0..self.bytes_per_row_value];            const ptr: [*]T = @ptrCast(@alignCast(row.ptr));            return ptr[0..self.pixelsPerRow()];        }        fn initializePadding(self: *Self, mode: Padding) GeometryError!void {            if (self.xsize_value == 0 or self.ysize_value == 0 or vector_size == 1) return;            const valid_bytes = std.math.mul(                usize,                self.xsize_value,                @sizeOf(T),            ) catch return error.RowSizeOverflow;            const initialize_size = switch (mode) {                .round_up => try roundUp(valid_bytes, vector_size),                .unaligned => std.math.add(                    usize,                    valid_bytes,                    vector_size - @sizeOf(T),                ) catch return error.RowSizeOverflow,            };            if (initialize_size > self.bytes_per_row_value) {                return error.InsufficientRowPadding;            }            for (0..self.ysize_value) |y| {                const begin = y * self.bytes_per_row_value + valid_bytes;                @memset(self.storage[begin..][0 .. initialize_size - valid_bytes], 0);            }        }    };}

Source: lib/simd/src/root.zig:521

zig
pub const Image = image.Image;

Complete caller list

15 direct callers.

Audit

Definitions1
Public names2
Members0
Version26.7.0
Revisiondaab053ee433