core/image/png
png
Types
22CIE_1931
CIE_1931 :: struct #packed {
x: f32,
y: f32,
}SourceCIE_1931_Raw
CIE_1931_Raw :: struct #packed {
x: u32be,
y: u32be,
}SourceError
Error :: ErrorSourceFilter_Params
Filter_Params :: struct #packed {
src: []u8,
dest: []u8,
width: int,
height: int,
depth: int,
channels: int,
rescale: bool,
}SourceImage
Image :: ImageSourceOptions
Options :: OptionsSourcePLTE
PLTE :: struct #packed {
entries: [256]PLTE_Entry,
used: u16,
}SourcePLTE_Entry
PLTE_Entry :: RGB_PixelSourceRow_Filter
Row_Filter :: enum u8 {
None = 0,
Sub = 1,
Up = 2,
Average = 3,
Paeth = 4,
}SourceSignature
Signature :: enum u64be {
// 0x89504e470d0a1a0a
PNG = 0x89 << 56 | 'P' << 48 | 'N' << 40 | 'G' << 32 | '\r' << 24 | '\n' << 16 | 0x1a << 8 | '\n',
}SourceText
Text :: struct {
keyword: string,
keyword_localized: string,
language: string,
text: string,
}SourcecHRM
cHRM :: struct #packed {
w: CIE_1931,
r: CIE_1931,
g: CIE_1931,
b: CIE_1931,
}SourcecHRM_Raw
cHRM_Raw :: struct #packed {
w: CIE_1931_Raw,
r: CIE_1931_Raw,
g: CIE_1931_Raw,
b: CIE_1931_Raw,
}SourcegAMA
gAMA :: struct {
gamma_100k: u32be,
}SourcehIST
hIST :: struct #packed {
entries: [256]u16,
used: u16,
}SourceiCCP
iCCP :: struct {
name: string,
profile: []u8,
}SourcepHYs
pHYs :: struct #packed {
ppu_x: u32be,
ppu_y: u32be,
unit: pHYs_Unit,
}SourcepHYs_Unit
pHYs_Unit :: enum u8 {
Unknown = 0,
Meter = 1,
}SourcesPLT
sPLT :: struct #packed {
name: string,
depth: u8,
entries: union {
[][4]u8,
[][4]u16,
},
used: u16,
}SourcesRGB
sRGB :: struct #packed {
intent: sRGB_Rendering_Intent,
}SourcesRGB_Rendering_Intent
sRGB_Rendering_Intent :: enum u8 {
Perceptual = 0,
Relative_colorimetric = 1,
Saturation = 2,
Absolute_colorimetric = 3,
}SourcetIME
tIME :: struct #packed {
year: u16be,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
}SourceOther chunks
Constants
6INCHES_PER_METER
INCHES_PER_METER :: 1000.0 / 25.4SourceMAX_CHUNK_SIZE
MAX_CHUNK_SIZE :: min(#config(PNG_MAX_CHUNK_SIZE, 16_777_216), 268_435_456)SourceFor 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)Source_MAX_IDAT
_MAX_IDAT :: (65535 /* Width */ * 65535 /* Height */ * 2 /* 16-bit */) + 65535Source_MAX_IDAT_DEFAULT
_MAX_IDAT_DEFAULT :: ( 8192 /* Width */ * 8192 /* Height */ * 2 /* 16-bit */) + 8192SourceLimit chunk sizes. By default: IDAT = 8k x 8k x 16-bits + 8k filter bytes. The total number of pixels defaults to 64 Megapixel and can be tuned in image/common.odin.
depth_scale_table
depth_scale_table :: []u8SourceVariables
4ADAM7_X_ORIG
ADAM7_X_ORIG :: []int = []int{ 0,4,0,2,0,1,0 }SourceADAM7_X_SPACING
ADAM7_X_SPACING :: []int = []int{ 8,8,4,4,2,2,1 }SourceADAM7_Y_ORIG
ADAM7_Y_ORIG :: []int = []int{ 0,0,4,0,2,0,1 }SourceADAM7_Y_SPACING
ADAM7_Y_SPACING :: []int = []int{ 8,8,8,4,4,2,2 }SourceProcedures
32append_chunk
append_chunk :: proc(list: ^[dynamic]image.PNG_Chunk, src: image.PNG_Chunk, allocator: mem.Allocator = context.allocator) -> (err: Error)Sourcechrm
chrm :: proc(c: image.PNG_Chunk) -> (res: cHRM, ok: bool)Sourcechunk_type_to_name
chunk_type_to_name :: proc(type: ^image.PNG_Chunk_Type) -> (string)Sourcecompute_buffer_size
compute_buffer_size :: proc(width: int, height: int, channels: int, depth: int, extra_row_bytes: int = int(0)) -> (size: int)SourceGeneral helper functions
copy_chunk
copy_chunk :: proc(src: image.PNG_Chunk, allocator: mem.Allocator = context.allocator) -> (dest: image.PNG_Chunk, err: Error)Sourcecore_time
core_time :: proc(c: image.PNG_Chunk) -> (t: coretime.Time, ok: bool)Sourcedefilter
defilter :: proc(img: ^Image, filter_bytes: ^bytes.Buffer, header: ^image.PNG_IHDR, options: Options) -> (err: Error)Sourcedefilter_16
defilter_16 :: proc(params: ^Filter_Params) -> (bool)Sourcedefilter_8
defilter_8 :: proc(params: ^Filter_Params) -> (ok: bool)Sourcedefilter_less_than_8
defilter_less_than_8 :: proc(params: ^Filter_Params) -> (bool)Sourcedestroy
destroy :: proc(img: ^Image)SourceCleanup of image-specific data.
There are other helpers for cleanup of PNG-specific data.
Those are named *_destroy, where * is the name of the helper.exif
exif :: proc(c: image.PNG_Chunk) -> (res: image.Exif, ok: bool)Sourcefilter_paeth
filter_paeth :: proc(left: u8, up: u8, up_left: u8) -> (u8)Sourcegamma
gamma :: proc(c: image.PNG_Chunk) -> (res: f32, ok: bool)SourceChunk helpers
hist
hist :: proc(c: image.PNG_Chunk) -> (res: hIST, ok: bool)Sourceiccp
iccp :: proc(c: image.PNG_Chunk) -> (res: iCCP, ok: bool)Sourceiccp_destroy
iccp_destroy :: proc(i: iCCP)Sourceload_from_bytes
load_from_bytes :: proc(data: []u8, options: Options = Options{}, allocator: mem.Allocator = context.allocator) -> (img: ^Image, err: Error)Sourceload_from_context
load_from_context :: proc(ctx: ^C, options: Options = Options{}, allocator: mem.Allocator = context.allocator) -> (img: ^Image, err: Error)Sourceload_from_file
load_from_file :: proc(filename: string, options: Options = Options{}, allocator: mem.Allocator = context.allocator) -> (img: ^Image, err: Error)Sourcephys
phys :: proc(c: image.PNG_Chunk) -> (res: pHYs, ok: bool)Sourcephys_to_dpi
phys_to_dpi :: proc(p: pHYs) -> (x_dpi: f32, y_dpi: f32)Sourceplte
plte :: proc(c: image.PNG_Chunk) -> (res: PLTE, ok: bool)Sourceread_chunk
read_chunk :: proc(ctx: ^C) -> (chunk: image.PNG_Chunk, err: Error)SourceImplementation starts here
read_header
read_header :: proc(ctx: ^C) -> (image.PNG_IHDR, Error)Sourcesbit
sbit :: proc(c: image.PNG_Chunk) -> (res: [4]u8, ok: bool)Sourcesplt
splt :: proc(c: image.PNG_Chunk) -> (res: sPLT, ok: bool)Sourcesplt_destroy
splt_destroy :: proc(s: sPLT)Sourcesrgb
srgb :: proc(c: image.PNG_Chunk) -> (res: sRGB, ok: bool)Sourcetext
text :: proc(c: image.PNG_Chunk) -> (res: Text, ok: bool)Sourcetext_destroy
text_destroy :: proc(text: Text)Sourcetime
time :: proc(c: image.PNG_Chunk) -> (res: tIME, ok: bool)Source