UXImage
UXImage is a width × height grid of packed 0xAARRGGBB pixels. It is the
model behind the image well, canvas layers and thumbnails. A backend uploads
and draws these images. The pixel arithmetic (compositing a sub-image in,
clearing a region, cropping one out) lives here and can be tested without a
backend. Colours pack and unpack through
UXColor.
#use <UXKit>Overview
Section titled “Overview”UXImage* im = UXImage.make(64, 64);im.fill(UXColor.rgba(255, 255, 255, 255));im.fillRect(8, 8, 48, 48, UXColor.rgba(30, 90, 200, 255));UXImage* thumb = im.subImage(0, 0, 32, 32);Every mutation is clipped to the bounds. Writing off the edge writes nothing, and reading off the edge reads zero, so a blit near a corner needs no arithmetic from the caller.
Topics
Section titled “Topics”Making · make · width / height Pixels · setPixel · pixelAt · setPixelRaw / pixelRaw · inBounds Regions · fill · fillRect · blit · subImage Drawing · drawIn Packing · pack / unpack
drawIn
Section titled “drawIn”void drawIn(UXGraphics* g, UXRect src, UXRect dst, i32 alpha)Draws the region src of this image into a view’s drawRect at dst, scaled,
with an overall alpha. It goes through
UXGraphics.drawPixels, which may
cache by this image’s pixel buffer, so change the pixels and the old ones may be
drawn.
static UXImage* make(i32 width, i32 height)A new image, zero-filled (transparent black). Degenerate sizes become 1×1.
width / height
Section titled “width / height”i32 width(void)i32 height(void)The dimensions.
setPixel
Section titled “setPixel”void setPixel(i32 x, i32 y, UXColor* c)Writes one pixel; out of bounds writes nothing.
pixelAt
Section titled “pixelAt”UXColor* pixelAt(i32 x, i32 y)Reads one pixel as a colour; out of bounds reads transparent black.
setPixelRaw / pixelRaw
Section titled “setPixelRaw / pixelRaw”void setPixelRaw(i32 x, i32 y, u32 v)u32 pixelRaw(i32 x, i32 y)The packed-word forms, for tight loops.
inBounds
Section titled “inBounds”bool inBounds(i32 x, i32 y)The clip test every mutation uses.
void fill(UXColor* c)Sets every pixel to one colour.
fillRect
Section titled “fillRect”void fillRect(i32 rx, i32 ry, i32 rw, i32 rh, UXColor* c)A rectangle, clipped to bounds.
void blit(UXImage* src, i32 dx, i32 dy)Copies src in with its top-left at (dx, dy), clipped. It overwrites
pixels with no alpha blending; compositing belongs to the graphics seam.
subImage
Section titled “subImage”UXImage* subImage(i32 rx, i32 ry, i32 rw, i32 rh)A new image cropped out of this one. Out-of-bounds source pixels come back as transparent black.
pack / unpack
Section titled “pack / unpack”static u32 pack(UXColor* c)static UXColor* unpack(u32 v)Conversion between the 0xAARRGGBB word and
UXColor. It is public so pixel loops and
tests can use both forms.