DVUI

fromImageSource

creates a new Texture from an ImageSource

Only valid between Window.begin and Window.end.

Parameters

#
source:ImageSource
ImageSource

Source

Implementation

#
pub fn fromImageSource(source: ImageSource) !Texture {
    return switch (source) {
        .imageFile => |f| try Texture.fromImageFile(f.name, f.bytes, f.interpolation),
        .pixelsPMA => |px| try Texture.fromPixelsPMA(px.rgba, px.width, px.height, px.interpolation),
        .pixels => |px| blk: {
            // Using arena here instead of lifo as this buffer is likely to be large and we
            // prefer that lifo doesn't reallocate as often. Arena is intended for larger,
            // one of allocations and we can still free the buffer here
            const copy = try dvui.currentWindow().arena().dupe(u8, px.rgba);
            defer dvui.currentWindow().arena().free(copy);
            break :blk try Texture.fromPixelsPMA(Color.PMA.sliceFromRGBA(copy), px.width, px.height, px.interpolation);
        },
        .texture => |t| t,
    };
}