pngz
easy png io library that converts all images into 8 bit RGBA.
Loading...
Searching...
No Matches
pngz.h File Reference
#include <png.h>
#include <stdint.h>
Include dependency graph for pngz.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  PNGZ_Pixel
 pixel in RGBA8 format. More...
 
struct  PNGZ_Image
 easy png based image structure. More...
 

Typedefs

typedef struct PNGZ_Pixel PNGZ_Pixel
 pixel in RGBA8 format.
 
typedef struct PNGZ_Image PNGZ_Image
 easy png based image structure.
 

Functions

int PNGZ_AllocPixels (PNGZ_Pixel ***pixels_ptr, const unsigned rows, const unsigned cols)
 allocate a pixel buffer.
 
int PNGZ_AllocBytes (uint8_t ***bytes_ptr, const unsigned rows, const unsigned cols)
 allocate raw pixel byte buffer.
 
int PNGZ_FreePixels (PNGZ_Pixel **pixels, const unsigned rows)
 safely free pixel buffer.
 
int PNGZ_FreeBytes (uint8_t **bytes, const unsigned rows)
 safely free pixel buffer.
 
int PNGZ_Free (PNGZ_Image *z)
 free a pngz structs pixels.
 
int PNGZ_BytesToPixels (uint8_t **bytes_src, PNGZ_Pixel **pixels_dest, const unsigned rows, const unsigned cols)
 pack bytes into pixels.
 
int PNGZ_PixelsToBytes (PNGZ_Pixel **pixels_src, uint8_t **bytes_dest, const unsigned rows, const unsigned cols)
 unpack pixels into raw byte ptrs.
 
int PNGZ_Load (PNGZ_Image *z)
 load a pngz object into memory
 
int PNGZ_LoadFrom (PNGZ_Image *z, const char *path)
 load a pngz from a path directly passed into the call, just a wrapper for standard pngz_load()
 
int PNGZ_Save (const PNGZ_Image z)
 write a png back out to file, wrapper for pngz_save_as()
 
int PNGZ_SaveAs (const PNGZ_Image z, const char *path)
 write a png back out to file with a new name
 
int PNGZ_Copy (const PNGZ_Image z_src, PNGZ_Image *z_dest)
 copies the pixel data from one pngz to another.
 
int PNGZ_PrintImage (const PNGZ_Image z)
 print a pngz ztruct contents.
 
int PNGZ_PrintPixel (const PNGZ_Pixel p)
 print out a single pixels rgba values in hex.
 
int PNGZ_PrintImageIndent (const PNGZ_Image z, const int indent)
 print a pngz ztruct contents.
 
int PNGZ_PrintPixelIndent (const PNGZ_Pixel p, const int indent)
 

Typedef Documentation

◆ PNGZ_Image

typedef struct PNGZ_Image PNGZ_Image

easy png based image structure.

always contains RGBA8 color (0x0 - 0xFFFFFF). pixel buffer is [height][width] pixels ([rows][cols])

◆ PNGZ_Pixel

typedef struct PNGZ_Pixel PNGZ_Pixel

pixel in RGBA8 format.

Function Documentation

◆ PNGZ_AllocBytes()

int PNGZ_AllocBytes ( uint8_t *** bytes_ptr,
const unsigned rows,
const 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 68 of file pngz.c.

◆ PNGZ_AllocPixels()

int PNGZ_AllocPixels ( PNGZ_Pixel *** pixels_ptr,
const unsigned rows,
const 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 36 of file pngz.c.

◆ PNGZ_BytesToPixels()

int PNGZ_BytesToPixels ( uint8_t ** bytes_src,
PNGZ_Pixel ** pixels_dest,
const unsigned rows,
const unsigned cols )

pack bytes into pixels.

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

Definition at line 183 of file pngz.c.

References PNGZ_Pixel::a, PNGZ_Pixel::b, PNGZ_Pixel::g, and PNGZ_Pixel::r.

◆ PNGZ_Copy()

int PNGZ_Copy ( const PNGZ_Image z_src,
PNGZ_Image * z_dest )

copies the pixel data from one pngz to another.

Parameters
z_srcsource pixel buffer, passed by val
z_destdestination pixel buffer, passed by ptr
Returns
exit code

Definition at line 257 of file pngz.c.

References PNGZ_Image::height, PNGZ_Image::pixels, and PNGZ_Image::width.

◆ PNGZ_Free()

int PNGZ_Free ( PNGZ_Image * 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 168 of file pngz.c.

References PNGZ_Image::height, PNGZ_Image::pixels, and PNGZ_FreePixels().

Here is the call graph for this function:

◆ PNGZ_FreeBytes()

int PNGZ_FreeBytes ( uint8_t ** bytes,
const 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 135 of file pngz.c.

◆ PNGZ_FreePixels()

int PNGZ_FreePixels ( PNGZ_Pixel ** pixels,
const 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 100 of file pngz.c.

◆ PNGZ_Load()

int PNGZ_Load ( PNGZ_Image * z)

load a pngz object into memory

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

Definition at line 296 of file pngz.c.

References PNGZ_Image::height, PNGZ_Image::path, PNGZ_Image::pixels, PNGZ_AllocBytes(), PNGZ_AllocPixels(), PNGZ_BytesToPixels(), PNGZ_FreeBytes(), and PNGZ_Image::width.

Here is the call graph for this function:

◆ PNGZ_LoadFrom()

int PNGZ_LoadFrom ( PNGZ_Image * z,
const char * path )

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

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

Definition at line 285 of file pngz.c.

References PNGZ_Image::path, and PNGZ_Load().

Here is the call graph for this function:

◆ PNGZ_PixelsToBytes()

int PNGZ_PixelsToBytes ( PNGZ_Pixel ** pixels_src,
uint8_t ** bytes_dest,
const unsigned rows,
const unsigned cols )

unpack pixels into raw byte ptrs.

expects adequate space, rows by cols in the pixel buffer and rows by cols * 4 in the byte buffer

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 223 of file pngz.c.

References PNGZ_Pixel::r.

◆ PNGZ_PrintImage()

int PNGZ_PrintImage ( const PNGZ_Image z)

print a pngz ztruct contents.

Parameters
zpngz to print
Returns
exit code

Definition at line 456 of file pngz.c.

References PNGZ_Image::height, PNGZ_Image::pixels, and PNGZ_Image::width.

◆ PNGZ_PrintImageIndent()

int PNGZ_PrintImageIndent ( const PNGZ_Image z,
const int indent )

print a pngz ztruct contents.

Parameters
zpngz to print
indentint for how much to indent this print
Returns
exit code

Definition at line 499 of file pngz.c.

References PNGZ_Image::height, PNGZ_Image::pixels, and PNGZ_Image::width.

◆ PNGZ_PrintPixel()

int PNGZ_PrintPixel ( const PNGZ_Pixel p)

print out a single pixels rgba values in hex.

Parameters
punsigned char* to the pixel to print
Returns
exit code

Definition at line 475 of file pngz.c.

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

◆ PNGZ_PrintPixelIndent()

int PNGZ_PrintPixelIndent ( const PNGZ_Pixel p,
const int indent )

◆ PNGZ_Save()

int PNGZ_Save ( const PNGZ_Image z)

write a png back out to file, wrapper for pngz_save_as()

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

Definition at line 386 of file pngz.c.

References PNGZ_Image::path, and PNGZ_SaveAs().

Here is the call graph for this function:

◆ PNGZ_SaveAs()

int PNGZ_SaveAs ( const PNGZ_Image z,
const 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 397 of file pngz.c.

References PNGZ_Image::height, PNGZ_Image::pixels, PNGZ_AllocBytes(), PNGZ_FreeBytes(), PNGZ_PixelsToBytes(), and PNGZ_Image::width.

Here is the call graph for this function: