General 2D image types and procedures to be used with other image related packages.

Collection Info

View Source
Collection
core
Path
image
Entries
98

Source Files

Constants

4

MAX_DIMENSIONS #

Source
MAX_DIMENSIONS :: min(#config(MAX_DIMENSIONS, 8192 * 8192), 65535 * 65535)

67_108_864 pixels max by default. For QOI, the Worst case scenario means all pixels will be encoded as RGBA literals, costing 5 bytes each. This caps memory usage at 320 MiB. The tunable is limited to 4_294_836_225 pixels maximum, or 4 GiB per 8-bit channel. It is not advised to tune it this large. The 64 Megapixel default is considered to be a decent upper bound you won't run into in practice, except in very specific circumstances.

New_TGA_Signature #

Source
New_TGA_Signature :: "TRUEVISION-XFILE.\x00"

Types

63

BMP_Info #

Source
BMP_Info :: BMP_Info

img.metadata is wrapped in a struct in case we need to add to it later without putting it in BMP_Header

Procedures

24

alpha_add_if_missing #

Source
alpha_add_if_missing :: proc(img: ^Image, alpha_key: Alpha_Key = Alpha_Key{}, allocator := context.allocator) -> (ok: bool) {…}

Add alpha channel if missing, in-place. Expects 1..4 channels (Gray, Gray + Alpha, RGB, RGBA). Any other number of channels will be considered an error, returning `false` without modifying the image. If the input image already has an alpha channel, it'll return `true` early (without considering optional keyed alpha). If an image doesn't already have an alpha channel: If the optional `alpha_key` is provided, it will be resolved as follows: - For RGB, if pix = key.rgb -> pix = {0, 0, 0, key.a} - For Gray, if pix = key.r -> pix = {0, key.g} Otherwise, an opaque alpha channel will be added.

alpha_apply_keyed_alpha #

Source
alpha_apply_keyed_alpha :: proc(img: ^Image, alpha_key: Alpha_Key = Alpha_Key{}, allocator := context.allocator) -> (ok: bool) {…}

Add alpha channel if missing, in-place. Expects 1..4 channels (Gray, Gray + Alpha, RGB, RGBA). Any other number of channels will be considered an error, returning `false` without modifying the image. If the input image already has an alpha channel, it'll return `true` early (without considering optional keyed alpha). If an image doesn't already have an alpha channel: If the optional `alpha_key` is provided, it will be resolved as follows: - For RGB, if pix = key.rgb -> pix = {0, 0, 0, key.a} - For Gray, if pix = key.r -> pix = {0, key.g} Otherwise, an opaque alpha channel will be added.

alpha_drop_if_present #

Source
alpha_drop_if_present :: proc(img: ^Image, options: Options = Options{}, alpha_key: Alpha_Key = Alpha_Key{}, allocator := context.allocator) -> (ok: bool) {…}

Drop alpha channel if present, in-place. Expects 1..4 channels (Gray, Gray + Alpha, RGB, RGBA). Any other number of channels will be considered an error, returning `false` without modifying the image. Of the `options`, the following are considered: `.alpha_premultiply` If the image has an alpha channel, returns image data as follows: RGB *= A, Gray = Gray *= A `.blend_background` If `img.background` is set, it'll be blended in like this: RGB = (1 - A) * Background + A * RGB If an image has 1 (Gray) or 3 (RGB) channels, it'll return early without modifying the image, with one exception: `alpha_key` and `img.background` are present, and `.blend_background` is set. In this case a keyed alpha pixel will be replaced with the background color.

apply_palette_rgb #

Source
apply_palette_rgb :: proc(img: ^Image, palette: [256][3]u8, allocator := context.allocator) -> (ok: bool) {…}

Apply palette to 8-bit single-channel image and return an 8-bit RGB image, in-place. If the image given is not a valid 8-bit single channel image, the procedure will return `false` early.

apply_palette_rgba #

Source
apply_palette_rgba :: proc(img: ^Image, palette: [256][4]u8, allocator := context.allocator) -> (ok: bool) {…}

Apply palette to 8-bit single-channel image and return an 8-bit RGBA image, in-place. If the image given is not a valid 8-bit single channel image, the procedure will return `false` early.

blend_pixel #

Source
blend_pixel :: proc(fg: [$N]$T, alpha: $T, bg: [$N]$T) -> (res: $$deferred_return) {…}

blend_single_channel #

Source
blend_single_channel :: proc(fg, alpha, bg: $T) -> (res: $$deferred_return) {…}

compute_buffer_size #

Source
compute_buffer_size :: proc(width, height, channels, depth: int, extra_row_bytes: int = int(0)) -> (size: int) {…}

Function to help with image buffer calculations

expand_grayscale #

Source
expand_grayscale :: proc(img: ^Image, allocator := context.allocator) -> (ok: bool) {…}

Replicates grayscale values into RGB(A) 8- or 16-bit images as appropriate. Returns early with `false` if already an RGB(A) image.

is_valid_color_image #

Source
is_valid_color_image :: proc(img: ^Image) -> (ok: bool) {…}

Does the image have 3 or 4 channels, a valid bit depth (8 or 16), Is the pointer valid, are the dimensions valid?

is_valid_grayscale_image #

Source
is_valid_grayscale_image :: proc(img: ^Image) -> (ok: bool) {…}

Does the image have 1 or 2 channels, a valid bit depth (8 or 16), Is the pointer valid, are the dimensions valid?

is_valid_image #

Source
is_valid_image :: proc(img: ^Image) -> (ok: bool) {…}

Does the image have 1..4 channels, a valid bit depth (8 or 16), Is the pointer valid, are the dimensions valid?

pixels_to_image #

Source
pixels_to_image :: proc(pixels: [][$N]$E, width: int, height: int) -> (img: Image, ok: bool) {…}

Take a slice of pixels (`[]RGBA_Pixel`, etc), and return an `Image` Don't call `destroy` on the resulting `Image`. Instead, delete the original `pixels` slice.

premultiply_alpha #

Source
premultiply_alpha :: proc(img: ^Image) -> (ok: bool) {…}

For all pixels of the image, multiplies R, G and B by Alpha. This is useful mainly for games rendering anti-aliased transparent sprites. Grayscale with alpha images are supported as well. Note that some image formats like QOI explicitly do NOT support premultiplied alpha, so you will end up with a non-standard file.

read_data #

Source
@(optimization_mode="favor_size")
read_data :: proc(z: $C, $T: typeid) -> (res: typeid, err: General_Error) {…}

Helper functions to read and write data from/to a Context, etc.

return_single_channel #

Source
return_single_channel :: proc(img: ^Image, channel: Channel) -> (res: ^Image, ok: bool) {…}

When you have an RGB(A) image, but want a particular channel.

Procedure Groups

4

Variables

3

JFIF_Magic #

Source
JFIF_Magic: [4]u8 = [?]byte{0x4A, 0x46, 0x49, 0x46}

JPEG-specific