Skip to main content

Module image

Module image 

Source
Expand description

The image table: every PNG in a Bundle the game names, by bundle path, with its size. Screens name a picture by an ImageId from this table; the platform layer decodes and draws it. Only each file’s header is read here, never its pixels.

A one-bit screen’s bundle may hold a one-bit picture file (crate::bitmap) at a PNG’s path in place of the PNG: the table then gives the size of the PNG it was made from (its source size), so the image’s id and size are the same as with the PNG.

As formats (ADR-0007): an image’s size is the ImageInfo kind, read by PngInfo and OneBitInfo, and ImageTable::load_with builds the table with every image format a game registers. Its pixels are the Image kind, which Png reads with the png feature. A game that draws through shuyi-app needs none: the platform decodes a PNG’s pixels when it uploads the picture.

Structs§

Image
An image’s pixels: four bytes each (red, green, blue, alpha), row by row from the top.
ImageId
Names one image of an ImageTable: its interned bundle path. Cheap to copy and compare. Only ImageTable::id makes one, so an id always names an image some table holds.
ImageInfo
An image’s size in pixels. Build it with ImageInfo::new or ImageInfo::checked (ADR-0039).
ImageRect
A rectangle of an image, in image pixels.
ImageTable
Every image the game can draw, by bundle path (/-separated). Build it with ImageTable::new, Default or ImageTable::load (ADR-0039).
Picture
A picture: a rectangle of an image.
Png
PNG read for its pixels (png, .png), with the png feature. Its size is checked first, as PngInfo does, so a picture too big is refused before its pixels are decoded.
PngInfo
PNG read for its size (png, .png): only its header, never its pixels. The size must be one ImageInfo::checked allows.

Constants§

MAX_PNG_BYTES
The most bytes a PNG may have: 64 MiB, what a MAX_SIDE square of 8-bit RGBA pixels takes without compression.
MAX_SIDE
The longest side an image may have, in pixels: what every graphics card the engine runs on (WebGL included) takes as one texture.
PNG_SIGNATURE
The first eight bytes of every PNG file.

Functions§

png_size
Width and height from a PNG’s header, or None if bytes isn’t a PNG.