Module: graphics.image

Source: ./graphics/image.reef


Overview

graphics/image.reef - Image types and pixel operations Part of reef-stdlib graphics module


Types

PixelFormat (enum)

Variants:

  • RGBA8
  • BGRA8
  • RGB8
  • BGR8
  • Grayscale8
  • GrayscaleAlpha16
  • Alpha8

Image

Fields:

Name Type
width int
height int
format PixelFormat
stride int
data [uint8]

Functions

fn bytes_per_pixel(format: PixelFormat): int

Get bytes per pixel for a format

fn has_alpha(format: PixelFormat): bool

Check if format has alpha channel

fn create_image(width: int, height: int, format: PixelFormat): Image

Create image with specified format

fn create_image_rgba(width: int, height: int): Image

Create RGBA image (most common)

fn create_image_rgb(width: int, height: int): Image

Create RGB image (no alpha)

fn create_image_grayscale(width: int, height: int): Image

Create grayscale image

fn get_pixel(img: Image, x: int, y: int): option.Option[core.Color]

Get pixel at (x, y) as Color The pixel at (x, y), or None when the coordinate is outside the image.

ROADMAP §8.3: this returned core.transparent() out of range, which is indistinguishable from a genuinely transparent pixel -- a caller reading past the edge got a plausible colour and no indication anything was wrong.

Callers that are in-bounds by construction (a clipped blit loop) should unwrap: if the invariant ever breaks, a panic is a better outcome than a silently wrong pixel. Callers doing deliberate edge sampling want get_pixel_or, where the fallback is written at the call site rather than hidden in here.

fn get_pixel_or(img: Image, x: int, y: int, fallback: core.Color): core.Color

The pixel at (x, y), or fallback when the coordinate is outside the image.

The _or twin for deliberate edge sampling -- a blur or resample that reads past the border and wants a defined value there. get_pixel is the source of truth; this exists so the fallback is a decision written at the call site instead of the invisible core.transparent() that used to be baked in.

fn clone_image(img: Image): Image

Clone an image

fn sub_image(img: Image, r: core.Rect): Image

Create a sub-image (view into original - copies data)

fn flip_horizontal(img: Image): Image

Flip image horizontally (left-right mirror)

fn flip_vertical(img: Image): Image

Flip image vertically (top-bottom mirror)

fn rotate_90(img: Image): Image

Rotate image 90 degrees clockwise

fn rotate_180(img: Image): Image

Rotate image 180 degrees

fn rotate_270(img: Image): Image

Rotate image 270 degrees clockwise (= 90 counter-clockwise)

fn scale_nearest(img: Image, new_width: int, new_height: int): Image

Scale image using nearest-neighbor interpolation

fn crop(img: Image, x: int, y: int, w: int, h: int): Image

Crop a region from the image


Procedures

proc set_pixel(img: Image, x: int, y: int, c: core.Color)

Set pixel at (x, y) from Color

proc clear(img: Image, c: core.Color)

Clear entire image to a color

proc fill_rect(img: Image, r: core.Rect, c: core.Color)

Fill a rectangle with a color

proc copy_rect(src: Image, src_rect: core.Rect, dst: Image, dst_x: int, dst_y: int)

Copy a rectangle from source to destination

proc blit(src: Image, dst: Image, dst_x: int, dst_y: int)

Blit (copy) source image onto destination (no alpha blending)

proc blit_alpha(src: Image, dst: Image, dst_x: int, dst_y: int)

Blit with alpha blending


Generated by reefc doc