package core:image/png

⌘K
Ctrl+K
or
/

    Overview

    Copyright 2021 Jeroen van Rijn <nom@duclavier.com>.

    Made available under Odin's BSD-2 license.
    
    List of contributors:
    	Jeroen van Rijn: Initial implementation.
    	Ginger Bill:     Cosmetic changes.
    
    These are a few useful utility functions to work with PNG images.
    
    

    package png implements a PNG image reader

    The PNG specification is at https://www.w3.org/TR/PNG/.

    Types

    CIE_1931 ¶

    CIE_1931 :: struct #packed {
    	x: f32,
    	y: f32,
    }

    CIE_1931_Raw ¶

    CIE_1931_Raw :: struct #packed {
    	x: u32be,
    	y: u32be,
    }

    Error ¶

    Error :: image.Error

    Exif ¶

    Exif :: struct {
    	byte_order: enum int {
    		little_endian, 
    		big_endian, 
    	},
    	data:       []u8,
    }
    Related Procedures With Returns

    Filter_Params ¶

    Filter_Params :: struct #packed {
    	src:      []u8,
    	dest:     []u8,
    	width:    int,
    	height:   int,
    	depth:    int,
    	channels: int,
    	rescale:  bool,
    }
    Related Procedures With Parameters

    Image ¶

    Image :: image.Image

    Options ¶

    Options :: image.Options

    PLTE ¶

    PLTE :: struct #packed {
    	entries: [256][3]u8,
    	used:    u16,
    }
    Related Procedures With Returns

    PLTE_Entry ¶

    PLTE_Entry :: [3]u8

    Row_Filter ¶

    Row_Filter :: enum u8 {
    	None    = 0, 
    	Sub     = 1, 
    	Up      = 2, 
    	Average = 3, 
    	Paeth   = 4, 
    }

    Signature ¶

    Signature :: enum u64be {
    	// 0x89504e470d0a1a0a
    	PNG = 9894494448401390090, 
    }

    Text ¶

    Text :: struct {
    	keyword:           string,
    	keyword_localized: string,
    	language:          string,
    	text:              string,
    }
    Related Procedures With Parameters
    Related Procedures With Returns

    cHRM ¶

    cHRM :: struct #packed {
    	w: CIE_1931,
    	r: CIE_1931,
    	g: CIE_1931,
    	b: CIE_1931,
    }
    Related Procedures With Returns

    cHRM_Raw ¶

    cHRM_Raw :: struct #packed {
    	w: CIE_1931_Raw,
    	r: CIE_1931_Raw,
    	g: CIE_1931_Raw,
    	b: CIE_1931_Raw,
    }

    gAMA ¶

    gAMA :: struct {
    	gamma_100k: u32be,
    }

    hIST ¶

    hIST :: struct #packed {
    	entries: [256]u16,
    	used:    u16,
    }
    Related Procedures With Returns

    iCCP ¶

    iCCP :: struct {
    	name:    string,
    	profile: []u8,
    }
    Related Procedures With Parameters
    Related Procedures With Returns

    pHYs ¶

    pHYs :: struct #packed {
    	ppu_x: u32be,
    	ppu_y: u32be,
    	unit:  pHYs_Unit,
    }
    Related Procedures With Parameters
    Related Procedures With Returns

    pHYs_Unit ¶

    pHYs_Unit :: enum u8 {
    	Unknown = 0, 
    	Meter   = 1, 
    }

    sPLT ¶

    sPLT :: struct #packed {
    	name:    string,
    	depth:   u8,
    	entries: union {
    		[][4]u8, 
    		[][4]u16, 
    	},
    	used:    u16,
    }
    Related Procedures With Parameters
    Related Procedures With Returns

    sRGB ¶

    sRGB :: struct #packed {
    	intent: sRGB_Rendering_Intent,
    }
    Related Procedures With Returns

    sRGB_Rendering_Intent ¶

    sRGB_Rendering_Intent :: enum u8 {
    	Perceptual            = 0, 
    	Relative_colorimetric = 1, 
    	Saturation            = 2, 
    	Absolute_colorimetric = 3, 
    }

    tIME ¶

    tIME :: struct #packed {
    	year:   u16be,
    	month:  u8,
    	day:    u8,
    	hour:   u8,
    	minute: u8,
    	second: u8,
    }
     

    Other chunks

    Related Procedures With Returns

    Constants

    INCHES_PER_METER ¶

    INCHES_PER_METER :: 1000.0 / 25.4

    MAX_CHUNK_SIZE ¶

    MAX_CHUNK_SIZE :: min(#config(PNG_MAX_CHUNK_SIZE, 16_777_216), 268_435_456)
     

    For chunks other than IDAT with a variable size like zTXT and eXIf,

    limit their size to 16 MiB each by default. Max of 256 MiB each.
    

    MAX_IDAT_SIZE ¶

    MAX_IDAT_SIZE :: min(#config(PNG_MAX_IDAT_SIZE, _MAX_IDAT_DEFAULT), _MAX_IDAT)

    depth_scale_table ¶

    depth_scale_table: []u8 : []u8{0, 0xff, 0x55, 0, 0x11, 0, 0, 0, 0x01}

    Variables

    ADAM7_X_ORIG ¶

    ADAM7_X_ORIG: []int = …

    ADAM7_X_SPACING ¶

    ADAM7_X_SPACING: []int = …

    ADAM7_Y_ORIG ¶

    ADAM7_Y_ORIG: []int = …

    ADAM7_Y_SPACING ¶

    ADAM7_Y_SPACING: []int = …

    Procedures

    append_chunk ¶

    append_chunk :: proc(list: ^[dynamic]image.PNG_Chunk, src: image.PNG_Chunk, allocator := context.allocator) -> (err: image.Error) {…}

    chrm ¶

    chrm :: proc(c: image.PNG_Chunk) -> (res: cHRM, ok: bool) {…}

    chunk_type_to_name ¶

    chunk_type_to_name :: proc(type: ^image.PNG_Chunk_Type) -> string {…}

    copy_chunk ¶

    copy_chunk :: proc(src: image.PNG_Chunk, allocator := context.allocator) -> (dest: image.PNG_Chunk, err: image.Error) {…}

    core_time ¶

    core_time :: proc(c: image.PNG_Chunk) -> (t: time.Time, ok: bool) {…}

    defilter ¶

    defilter :: proc(img: ^image.Image, filter_bytes: ^bytes.Buffer, header: ^image.PNG_IHDR, options: image.Options) -> (err: image.Error) {…}

    defilter_16 ¶

    defilter_16 :: proc(params: ^Filter_Params) -> bool {…}

    defilter_8 ¶

    defilter_8 :: proc(params: ^Filter_Params) -> (ok: bool) {…}

    defilter_less_than_8 ¶

    defilter_less_than_8 :: proc(params: ^Filter_Params) -> bool {…}

    destroy ¶

    destroy :: proc(img: ^image.Image) {…}

    exif ¶

    exif :: proc(c: image.PNG_Chunk) -> (res: Exif, ok: bool) {…}

    filter_paeth ¶

    filter_paeth :: proc(left, up, up_left: u8) -> u8 {…}

    gamma ¶

    gamma :: proc(c: image.PNG_Chunk) -> (res: f32, ok: bool) {…}

    hist ¶

    hist :: proc(c: image.PNG_Chunk) -> (res: hIST, ok: bool) {…}

    iccp ¶

    iccp :: proc(c: image.PNG_Chunk) -> (res: iCCP, ok: bool) {…}

    iccp_destroy ¶

    iccp_destroy :: proc(i: iCCP) {…}

    load_from_bytes ¶

    load_from_bytes :: proc(data: []u8, options: image.Options, allocator: runtime.Allocator) -> (img: ^image.Image, err: image.Error) {…}

    load_from_context ¶

    load_from_context :: proc(ctx: ^$T, options: image.Options = Options{}, allocator := context.allocator) -> (img: ^image.Image, err: image.Error) {…}

    load_from_file ¶

    load_from_file :: proc(filename: string, options: image.Options = Options{}, allocator := context.allocator) -> (img: ^image.Image, err: image.Error) {…}

    phys ¶

    phys :: proc(c: image.PNG_Chunk) -> (res: pHYs, ok: bool) {…}

    phys_to_dpi ¶

    phys_to_dpi :: proc(p: pHYs) -> (x_dpi, y_dpi: f32) {…}

    plte ¶

    plte :: proc(c: image.PNG_Chunk) -> (res: PLTE, ok: bool) {…}

    read_chunk ¶

    read_chunk :: proc(ctx: ^$T) -> (chunk: image.PNG_Chunk, err: image.Error) {…}

    read_header ¶

    read_header :: proc(ctx: ^$T) -> (image.PNG_IHDR, image.Error) {…}

    sbit ¶

    sbit :: proc(c: image.PNG_Chunk) -> (res: [4]u8, ok: bool) {…}

    splt ¶

    splt :: proc(c: image.PNG_Chunk) -> (res: sPLT, ok: bool) {…}

    splt_destroy ¶

    splt_destroy :: proc(s: sPLT) {…}

    srgb ¶

    srgb :: proc(c: image.PNG_Chunk) -> (res: sRGB, ok: bool) {…}

    text ¶

    text :: proc(c: image.PNG_Chunk) -> (res: Text, ok: bool) {…}

    text_destroy ¶

    text_destroy :: proc(text: Text) {…}

    time ¶

    time :: proc(c: image.PNG_Chunk) -> (res: tIME, ok: bool) {…}

    Procedure Groups

    Source Files

    Generation Information

    Generated with odin version dev-2024-04 (vendor "odin") Windows_amd64 @ 2024-04-19 21:09:18.679783300 +0000 UTC