RMGui 0.15.0
C11 retained-mode UI library: layout kernel, style schema, widget painters, fonts, software framebuffer
Loading...
Searching...
No Matches
image_fill.h File Reference

image_fill.h — allocation-free nearest and bilinear RGBA8 sheet painters. More...

#include <stdint.h>
#include "fb.h"

Data Structures

struct  rmgui_nine_insets_t
 Source-pixel widths of the four borders; every field must be nonnegative. More...
struct  rmgui_nine_patch_t
 Nonzero tile_edges repeats edges along their long axis; nonzero tile_center repeats the middle on both axes. More...

Functions

int rmgui_draw_nine_patch (rmgui_fb_t *fb, rmgui_rect_t clip, rmgui_rect_t dst, const rmgui_fb_t *sheet, rmgui_rect_t src, const rmgui_nine_patch_t *patch, int scale_percent, rmgui_color_t tint)
 Composite the nine regions of src into dst, inside dst intersect clip intersect fb.
int rmgui_draw_tile (rmgui_fb_t *fb, rmgui_rect_t clip, rmgui_rect_t dst, const rmgui_fb_t *sheet, rmgui_rect_t src, int origin_x, int origin_y, int scale_percent, rmgui_color_t tint)
 Composite repeated src tiles over dst intersect clip intersect fb using the borrowing, validation, tint and straight-over rules above (no patch argument).
int rmgui_draw_nine_patch_filtered (rmgui_fb_t *fb, rmgui_rect_t clip, rmgui_rect_t dst, const rmgui_fb_t *sheet, rmgui_rect_t src, const rmgui_nine_patch_t *patch, int scale_percent, rmgui_color_t tint)
 Bilinear variants of the painters above: identical arguments, geometry, validation, ownership, tint, straight-over, clipping and return rules.
int rmgui_draw_tile_filtered (rmgui_fb_t *fb, rmgui_rect_t clip, rmgui_rect_t dst, const rmgui_fb_t *sheet, rmgui_rect_t src, int origin_x, int origin_y, int scale_percent, rmgui_color_t tint)
 Repeated bilinear tiles, using the filtered sampling contract above.

Detailed Description

image_fill.h — allocation-free nearest and bilinear RGBA8 sheet painters.

Function Documentation

◆ rmgui_draw_nine_patch()

int rmgui_draw_nine_patch ( rmgui_fb_t * fb,
rmgui_rect_t clip,
rmgui_rect_t dst,
const rmgui_fb_t * sheet,
rmgui_rect_t src,
const rmgui_nine_patch_t * patch,
int scale_percent,
rmgui_color_t tint )

Composite the nine regions of src into dst, inside dst intersect clip intersect fb.

sheet is borrowed read-only, contiguous straight RGBA8; neither its storage nor any other argument is owned or modified except the destination pixel bytes. No allocation, floating point or filtering.

scale_percent must be 1..400. src must have positive extents and lie wholly inside sheet. Insets must be nonnegative, left+right <= src.w and top+bottom <= src.h. Zero insets support 3x1 and 1x3 strips. Empty source regions leave their destination regions untouched.

Each destination border is floor((source_border*scale_percent+50)/100). If a pair sums to more than the destination extent D, the near border becomes floor(D*near/(near+far)) and the far border D-near. Thus corners never overlap. The middle occupies the remainder.

A stretched axis of S source pixels into D destination pixels samples round(i*(S-1)/(D-1)), halves up, or source 0 if D == 1. Corners always stretch on both axes. Tiled edges stretch across their thickness and repeat along their length; a tiled middle repeats on both axes. Each repeat starts at the near corner-inner edge, has period max(1, floor((S*scale_percent+50)/100)), and samples floor(i*S/period) for position i within that period. The far repeat is clipped, not resized. Clipping never changes sampling.

Each sampled channel, including alpha, is multiplied by its tint channel and divided by 255, rounding halves up; {255,255,255,255} is identity. The tinted sample is composited once with rmgui_draw_blend's straight-over rule: RGB = round((a*s+(255-a)*d)/255), alpha = a+round((255-a)*destination_alpha/255), halves up; alpha 0 is untouched.

Returns 0 on success (empty fb, dst or clip paints nothing). Returns -1 without changing any argument for NULL fb, sheet or patch, an invalid scale, source or inset, an empty sheet, or fb == sheet or equal non-NULL pixel pointers. The framebuffer states must satisfy fb.h's contract; source and destination storage must not otherwise overlap. Coordinates may be arbitrary ints; arithmetic and work are bounded by visible pixels.

◆ rmgui_draw_tile()

int rmgui_draw_tile ( rmgui_fb_t * fb,
rmgui_rect_t clip,
rmgui_rect_t dst,
const rmgui_fb_t * sheet,
rmgui_rect_t src,
int origin_x,
int origin_y,
int scale_percent,
rmgui_color_t tint )

Composite repeated src tiles over dst intersect clip intersect fb using the borrowing, validation, tint and straight-over rules above (no patch argument).

The tile periods are max(1, floor((src extent*scale_percent+ 50)/100)). Pixel (x,y) samples source column floor(floor_mod(x-origin_x, period_x)*src.w/period_x), and likewise for y. floor_mod is the nonnegative remainder, including negative offsets.

The origin is in framebuffer/surface coordinates, not relative to dst: moving or clipping dst never makes the pattern swim. Change origin_x or origin_y to animate stripes. Nearest sampling keeps one-pixel lines crisp at fractional scales, including 125% and 150%. Returns 0 or -1 with the same success/no-op and unchanged-on-refusal meanings as nine-patch.

◆ rmgui_draw_nine_patch_filtered()

int rmgui_draw_nine_patch_filtered ( rmgui_fb_t * fb,
rmgui_rect_t clip,
rmgui_rect_t dst,
const rmgui_fb_t * sheet,
rmgui_rect_t src,
const rmgui_nine_patch_t * patch,
int scale_percent,
rmgui_color_t tint )

Bilinear variants of the painters above: identical arguments, geometry, validation, ownership, tint, straight-over, clipping and return rules.

No allocation or floating point; work is bounded by visible pixels.

A stretched axis uses u = i*(S-1)/(D-1), or 0 when D == 1. A tiled axis uses u = floor_mod(position-origin, period)*S/period. Let j = floor(u) and f = floor((u-j)*65536). The near neighbor is j; the far neighbor is j+1, clamped to S-1 for stretching and wrapped to 0 for tiling. Each nine-patch region is filtered independently; neighbors never cross its source boundary. Thus repeated edges wrap, stretched borders clamp, and adjacent sheet sprites cannot bleed into the selected source.

With Q16 fractions fx, fy, the four integer weights are products of {65536-fx, fx} and {65536-fy, fy}, summing to 2^32. Let A = sum(w*a) and C = sum(w*a*c) for each RGB channel. The straight sample is alpha round(A/2^32), RGB round(C/A), halves up; A == 0 is transparent black. Tint is applied after this premultiplied interpolation, then the sample composites once. Transparent source RGB cannot bleed into visible RGB.

◆ rmgui_draw_tile_filtered()

int rmgui_draw_tile_filtered ( rmgui_fb_t * fb,
rmgui_rect_t clip,
rmgui_rect_t dst,
const rmgui_fb_t * sheet,
rmgui_rect_t src,
int origin_x,
int origin_y,
int scale_percent,
rmgui_color_t tint )

Repeated bilinear tiles, using the filtered sampling contract above.