pngz
easy png io library that converts all images into 8 bit RGBA.
Loading...
Searching...
No Matches
pngz.c File Reference
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include "pngz.h"
Include dependency graph for pngz.c:

Go to the source code of this file.

Functions

pixel ** pngz_alloc_pixels (unsigned rows, unsigned cols)
 allocate a pixel buffer.
 
unsigned char ** pngz_alloc_bytes (unsigned rows, unsigned cols)
 allocate raw pixel byte buffer.
 
int pngz_free_pixels (pixel **pixels, unsigned rows)
 safely free pixel buffer.
 
int pngz_free_bytes (unsigned char **bytes, unsigned rows)
 safely free pixel buffer.
 
int pngz_free (pngz *z)
 free a pngz structs pixels.
 
int pngz_pack_pixels (unsigned char **bytes_src, pixel **pixels_dest, unsigned rows, unsigned cols)
 pack pixels with bytes.
 
int pngz_unpack_pixels (pixel **pixels_src, unsigned char **bytes_dest, unsigned rows, unsigned cols)
 unpack pixels into raw byte ptrs.
 
int pngz_load_from (pngz *z, char *path)
 load a pngz from a path directly passed into the call, just indirectly calls the standard pngz_load()
 
int pngz_load (pngz *z)
 load a pngz object into memory
 
int pngz_save (pngz z)
 write a png back out to file
 
int pngz_save_as (pngz z, char *path)
 write a png back out to file with a new name
 
void pngz_print (pngz z)
 print a pngz ztruct contents.
 
void pngz_print_pixel (pixel p)
 print out a single pixels rgba values in hex.
 
void print_indent (int indent)
 
void pngz_print_indent (pngz z, int indent)
 print a pngz ztruct contents.
 
void pngz_print_pixel_indent (pixel p, int indent)
 print out a single pixels rgba values.
 

Function Documentation

◆ pngz_alloc_bytes()

unsigned char ** pngz_alloc_bytes ( unsigned  rows,
unsigned  cols 
)

allocate raw pixel byte buffer.

Parameters
rowsnumber of rows to allocate
colsnumber bytes per row to allocate
Returns
a ptr to buffer, returns null and sets errno on failure

Definition at line 66 of file pngz.c.

◆ pngz_alloc_pixels()

pixel ** pngz_alloc_pixels ( unsigned  rows,
unsigned  cols 
)

allocate a pixel buffer.

every pixel will be represented as a struct

Parameters
rowsnumber of rows to allocate
colsnumber pixels per col to allocate
Returns
exit code, setting errno on failure

Definition at line 37 of file pngz.c.

◆ pngz_free()

int pngz_free ( pngz z)

free a pngz structs pixels.

Parameters
zpngz* with pixels loaded into memory
Returns
exit code, error if you try to free a NULL ptr

Definition at line 155 of file pngz.c.

References pngz::height, pngz::pixels, and pngz_free_pixels().

Here is the call graph for this function:

◆ pngz_free_bytes()

int pngz_free_bytes ( unsigned char **  bytes,
unsigned  rows 
)

safely free pixel buffer.

Parameters
bytes2D pixel bytes of size [rows][cols * 4]
rowsnumber of rows to free
Returns
exit code

Definition at line 124 of file pngz.c.

◆ pngz_free_pixels()

int pngz_free_pixels ( pixel **  pixels,
unsigned  rows 
)

safely free pixel buffer.

Parameters
pixels2D pixel ptr of size [rows][cols]
rowsnumber of rows to free
Returns
exit code

Definition at line 93 of file pngz.c.

◆ pngz_load()

int pngz_load ( pngz z)

load a pngz object into memory

Parameters
zpngz* easy png ptr to load into
Returns
exit code

Definition at line 231 of file pngz.c.

References pngz::height, pngz::path, pngz::pixels, pngz_alloc_bytes(), pngz_alloc_pixels(), pngz_free_bytes(), pngz_pack_pixels(), and pngz::width.

Here is the call graph for this function:

◆ pngz_load_from()

int pngz_load_from ( pngz z,
char *  path 
)

load a pngz from a path directly passed into the call, just indirectly calls the standard pngz_load()

Parameters
zpngz* easy png ptr to load into
pathchar* path to read from
Returns
exit code

Definition at line 219 of file pngz.c.

References pngz::path, and pngz_load().

Here is the call graph for this function:

◆ pngz_pack_pixels()

int pngz_pack_pixels ( unsigned char **  bytes_src,
pixel **  pixels_dest,
unsigned  rows,
unsigned  cols 
)

pack pixels with bytes.

Parameters
bytes_srcunpacked pixel byte source
pixels_destpacked pixel destination
rowsrows of pixels
colscols of pixels (IN PIXELS NOT BYTES)
Returns
exit code

Definition at line 170 of file pngz.c.

References pixel::r.

◆ pngz_print()

void pngz_print ( pngz  z)

print a pngz ztruct contents.

Parameters
zpngz to print
Returns
void

Definition at line 403 of file pngz.c.

References pngz::cols, pngz::pixels, and pngz::rows.

◆ pngz_print_indent()

void pngz_print_indent ( pngz  z,
int  indent 
)

print a pngz ztruct contents.

Parameters
zpngz to print
indentint for how much to indent this print
Returns
void

Definition at line 445 of file pngz.c.

References pngz::height, pngz::pixels, print_indent(), and pngz::width.

Here is the call graph for this function:

◆ pngz_print_pixel()

void pngz_print_pixel ( pixel  p)

print out a single pixels rgba values in hex.

Parameters
punsigned char* to the pixel to print
Returns
void

Definition at line 422 of file pngz.c.

References pixel::a, pixel::g, and pixel::r.

◆ pngz_print_pixel_indent()

void pngz_print_pixel_indent ( pixel  p,
int  indent 
)

print out a single pixels rgba values.

Parameters
punsigned char* to the pixel to print
indentint for how much to indent this print
Returns
void

Definition at line 469 of file pngz.c.

References pixel::a, pixel::g, print_indent(), and pixel::r.

Here is the call graph for this function:

◆ pngz_save()

int pngz_save ( pngz  z)

write a png back out to file

Parameters
zpngz* easy png ptr to write to file
Returns
exit code

Definition at line 328 of file pngz.c.

References pngz::path, and pngz_save_as().

Here is the call graph for this function:

◆ pngz_save_as()

int pngz_save_as ( pngz  z,
char *  path 
)

write a png back out to file with a new name

Parameters
pathchar* file path to save to
zpngz* easy png ptr to write to file
Returns
exit code

Definition at line 339 of file pngz.c.

References pngz::height, pngz::pixels, pngz_alloc_bytes(), pngz_free_bytes(), pngz_unpack_pixels(), and pngz::width.

Here is the call graph for this function:

◆ pngz_unpack_pixels()

int pngz_unpack_pixels ( pixel **  pixels_src,
unsigned char **  bytes_dest,
unsigned  rows,
unsigned  cols 
)

unpack pixels into raw byte ptrs.

Parameters
pixels_srcpacked pixel source
bytes_destunpacked byte destination
rowsrows of pixels
colscols of pixels (IN PIXELS NOT BYTES)
Returns
exit code

Definition at line 197 of file pngz.c.

References pixel::r.

◆ print_indent()

void print_indent ( int  indent)

Definition at line 431 of file pngz.c.