std1.0.0-beta-7 SafeC docs

std :: gui::gui_png

Struct std::GuiImage

#include <std/gui/gui_png.h> source

struct GuiImage {
    &heap unsigned char pixels;
    int width;
    int height;
    int premultiplied;
}

Fields

§&heap unsigned char pixelssource

widthheight4 bytes, RGBA8888, R first

§int widthsource
§int heightsource
§int premultipliedsource

1: color channels are premultiplied by alpha (an image a GuiCanvas drew into); 0: straight alpha (as decoded from PNG)

Methods

§static struct GuiImage new(int width, int height)source · definition

A transparent width x height image (premultiplied; ready for GuiCanvas::for_image). Free with free().

§static struct GuiImage from_window(const &GuiWindow win)source · definition

A premultiplied copy of a window's pixel buffer (a screenshot).

§int load_png_file(const &char path)source · definition

Reads and decodes a PNG file. 1 = ok.

§int save_png(const &char path) constsource · definition

Writes the image as an RGBA PNG file (stored, uncompressed DEFLATE; straight alpha). 1 = ok.

§void premultiply()source · definition

Converts between straight and premultiplied alpha in place (no-op when already in that form).

§void unpremultiply()source · definition
§struct GuiImage copy() constsource · definition
§struct GuiImage scaled(int width, int height) constsource · definition

A resampled copy: area-averaging when shrinking (no aliasing), bilinear when enlarging. Keeps the alpha form.

§unsigned int get_pixel(int x, int y) constsource · definition

0xRRGGBBAA as stored / unblended store; 0 / no-op out of bounds.

§void set_pixel(int x, int y, unsigned int rgba)source · definition
§int load_png([]const unsigned char data)source · definition

Decodes a PNG file's bytes (already read into memory) into this image in place ('struct GuiImage img; img.load_png(data)'). Returns 1 on success, 0 on failure (unsupported feature or malformed input) — the image is left zeroed on failure.

§void draw(&GuiWindow win, int x, int y) constsource · definition

Draws this image with its top-left at (x, y) into 'win' (straight copy through GuiWindow::set_pixel(), no blending) — works with any GuiImage, PNG-decoded or otherwise constructed.

§void drop()source · definition
§void free() consumesource · definition

= drop()