Skip to main content

Module convert

Module convert 

Source
Expand description

Making a one-bit picture from a colour one, ahead of time (game ADR-0085). A tool runs it (a build script, a command); never the device.

The picture is first enlarged to the size it is shown at: by doubling pixels when the scale is a whole number, by a smooth (bilinear) resample when it isn’t, so rows and columns aren’t doubled unevenly. Then each Method makes one style of it, at the enlarged size, so each dot is one screen pixel:

  1. each pixel’s brightness, optionally through a curve;
  2. the stretch: the darkest share of the pixels becomes black, the lightest share white, the rest spread between;
  3. optionally each grey rounded to one of a few levels, so an area is one even pattern;
  4. a 4 × 4 Bayer ordered dither;
  5. optionally the art’s own dark lines drawn solid black on top.

A pixel less than half opaque is see-through: clear in the mask, white in every style.

Structs§

Lines
Which pixels of the art are its dark lines: an opaque art pixel (before enlarging) that is contrast darker than the brightest of its eight neighbours, or at most dark bright. A see-through neighbour counts as white, so a figure’s dark outline is a line; past the picture’s edge there are no neighbours. Brightnesses are 0 to 1, read before the curve.
Method
How one style of a picture is made (the steps at the top of the module).
Rgba
A colour picture: rows of RGBA pixels, 4 bytes each, no padding.

Functions§

convert
The one-bit picture file of image enlarged num / den times (each side rounded to the nearest pixel), one style per method in order, or what is wrong.
png_pixels
PNG file bytes as a colour picture: its width, height and RGBA pixels (Rgba::new), whatever kind of PNG it is (palette, grey, with or without alpha, 16 bits a channel).