module image.bmp
pub fn write_bmp_to_file(image: Image, filename: Path)
module image.gif
GIF fileformat
pub fn read_gif_from_file(path: Path) -> List[Image]
fn read_gif_from_bytes(data: Bytes) -> List[Image]
enum Version
GIF87aGIF89a
struct Color
r: int64g: int64b: int64
class GifReader
var m_byte_reader: ByteReader
var m_version: Version
var m_width: int64
var m_height: int64
var m_global_color_table_present: bool
var m_palette: Vector[Color]
var m_images: List[Image]
pub fn read() -> List[Image]
fn read_extension()
fn read_image_descriptor()
fn read_block() -> Bytes
fn read_header()
fn read_logical_screen_descriptor()
fn read_color_table(size: int64) -> Vector[Color]
fn read_text(size: int64) -> str
fn read_u16() -> int64
fn read_u8() -> int64
pub fn lzw_decode(data: Bytes) -> Bytes
Decompress LZW encodeded data.
class LzwDecoder
var m_reader: ByteReader
var m_bitbuf: int64
var m_bitcnt: int64
var m_code_bit_size: int64
var m_table: Vector[Bytes]
var m_output: ByteArray
pub fn decode() -> Bytes
fn initialize_table()
fn add_to_table(x?: Bytes)
fn get_next_code() -> int64
fn read_byte() -> int64
fn read_bits(n?: int64) -> int64
fn emit(data?: Bytes)
fn first_char(data?: Bytes) -> Bytes
module image.image
pub fn new_image(width: int64, height: int64, mode: ColorMode) -> Image
pub fn new_empty_image() -> Image
pub fn new_black_image(width: int64, height: int64) -> Image
pub enum ColorMode
GrayScaleGrayScaleAlphaColorColorAlpha
pub class Image
pub var width: int64
pub var height: int64
pub var mode: ColorMode
var bytes_per_pixel: int64
pub var data: Vector[int64]
pub fn get_pixel(x: int64, y: int64, pixel: Pixel)
Get color and store in given pixel
pub fn set_pixel(x: int64, y: int64, pixel: Pixel)
Set given pixel to a certain color
pub struct Pixel
red: int64green: int64blue: int64alpha: int64
pub fn new_pixel() -> Pixel
pub fn copy_pixel(dst: Pixel, src: Pixel)
module image.jpeg
JPEG handling.

See also: https://www.w3.org/Graphics/JPEG/itu-t81.pdf
pub fn read_jpg_from_file(path: Path) -> Image
fn read_jpeg_from_data(data: Bytes) -> Image
class JpegDecoder
var m_reader: ByteReader
var m_huffman_tables: HashMap[int64,Tree]
var m_quant: HashMap[int64,Bytes]
var m_width: int64
var m_height: int64
var m_components: Vector[Component]
var m_image: Image
var m_idct: IDCT
pub fn read_segments()
pub fn get_image() -> Image
fn read_segment()
Read a single JPEG segment
fn huffman_table()
fn define_quantization_table()
fn start_of_frame(n: int64)
Baseline DCT
fn start_of_scan()
fn read_non_ff00() -> Bytes
fn read_component_mcu(bit_reader: BitReader, component: Component, mcu_width: int64, mcu_height: int64) -> [int64]
Read a single MCU data array
fn build_matrix(bit_reader: BitReader, component: Component) -> [int64]
Extract an 8x8 matrix from bits
fn draw_block(x: int64, y: int64, mcu_width: int64, mcu_height: int64, mcu: Vector[[int64]])
Put 8x8 block into the pixels of the image
fn at_end() -> bool
fn read_byte() -> int64
fn read_u16() -> int64
fn read_data(size: int64) -> Bytes
fn zigzag(data: [int64]) -> [int64]
Zig zag pattern:
0, 1, 5, 6, 14, 15, 27, 28
2, 4, 7, 13, 16, 26, 29, 42
3, 8, 12, 17, 25, 30, 41, 43
9, 11, 18, 24, 31, 40, 44, 53
10, 19, 23, 32, 39, 45, 52, 54
20, 22, 33, 38, 46, 51, 55, 60
21, 34, 37, 47, 50, 56, 59, 61
35, 36, 48, 49, 57, 58, 62, 63
struct IDCT
precision: int64table: [float64]
fn new_idct_table() -> IDCT
fn perform_idct(data: [int64], idct: IDCT) -> [int64]
inverse discrete cosine transformation
struct Component
C: int64H: int64V: int64qid: int64dc_coeff: int64T_dc: int64T_ac: int64
fn clamp(value?: float64) -> int64
fn color_conversion(lum: int64, cb: int64, cr: int64, pixel: Pixel)
Convert YCbCr to RGB
fn decode_number(code: int64, bits: int64) -> int64
code = amount of bits
bits = the bit value
Mapping:
bits | values
2 | -3,-2,2,3
3 | -7..-4,4..7
4 | -15..-8,8..15
...
module image.pbm
See also: https://en.wikipedia.org/wiki/Netpbm#File_formats

PBM:
Portable BitMap
P1
0 = white
1 = black

PGM:
P2
Portable GrayMap
0-maxvalue (black to white)

PPM:
Portable PixMap
P3
pub fn write_pbm(image: Image, path: Path)
module image.png
PNG read / write routines

See RFC 2083
pub fn read_png_from_file(path: Path) -> Image
fn read_png_from_bytes(data: Bytes) -> Image
fn read_png_from_stream(reader: ByteReader) -> Image
pub fn write_png_to_file(image: Image, path: Path)
class PngDecoder
var m_byte_reader: ByteReader
var pallete: Vector[Pixel]
var width: int64
var height: int64
var bitdepth: int64
var samples: int64
var bpp: int64
var colortype: int64
pub fn read_image() -> Image
fn read_chunk() -> Chunk
fn parse_header(chunk: Chunk)
fn parse_palette(chunk: Chunk)
fn read_bytes(size?: int64) -> Bytes
fn read_u32_be() -> int64
class PngEncoder
var m_writer: ByteArray
pub fn write(image: Image) -> Bytes
fn write_chunk(chunk: Chunk)
fn pixels_to_buffer(image: Image) -> Bytes
class Sampler
Extract samples with a certain bit depth from a byte array
var m_data: Bytes
var m_depth: int64
var m_index: int64
var m_bit_index: int64
fn get_bits(bits: int64) -> int64
pub fn get_value() -> int64
pub fn new_line()
pub fn complete()
fn to_pixels(data: Bytes, image: Image, colortype: int64, depth: int64, pallete: Vector[Pixel])
fn encode_filter(data: Bytes, width: int64, height: int64, bpp: int64) -> Bytes
Apply filtering as encoding step
fn post_filter(data: Bytes, width: int64, height: int64, bytes_per_line: int64, bpp: int64) -> Bytes
Perform post filtering on a byte basis.
Note that we have no notion of bit depth or color space at this point.
fn average(a: int64, b: int64) -> int64
fn paeth_predictor(a: int64, b: int64, c: int64) -> int64
struct Chunk
chunk_type: int64data: Bytes
fn chunk_type_code(name: str) -> int64
module image.qoi
encoder / decoder for the QOI (quite ok image) format.

See also: https://qoiformat.org/
https://qoiformat.org/qoi-specification.pdf
pub fn read_qoi_from_file(path: Path) -> Image
pub fn write_qoi_to_file(image: Image, path: Path)
class QoiReader
var m_reader: ByteReader
var m_array: Vector[Pixel]
var m_image: Image
var m_width: int64
var m_height: int64
var m_x: int64
var m_y: int64
pub fn read_image() -> Image
fn put_pixel(pixel: Pixel)
fn read_bytes(size?: int64) -> Bytes
fn read_byte() -> int64
fn wrap8(value?: int64) -> int64
class QoiWriter
var m_writer: ByteArray
pub fn write(image: Image) -> Bytes
fn write_byte(value?: int64)