pngz
easy png io library that converts all images into 8 bit RGBA.
Loading...
Searching...
No Matches
pngz.h
Go to the documentation of this file.
1/* pngz.h
2 * samantha jane
3 * easy png
4 *--------------------------------------------------------------------------80*/
5
6#ifndef _PNGZ_H_
7#define _PNGZ_H_
8
9#include <png.h>
10/**
11 * pixel in RGBA8 format.
12 */
13typedef struct pixel {
14 /** channel values */
15 unsigned char r, g, b, a;
17
18/**
19 * easy png structure.
20 * always contains RGBA8 color (0x0 - 0xFFFFFF).
21 * pixel buffer is [height][width] pixels ([rows][cols])
22 */
23typedef struct pngz {
24 /** default path to load from and save to */
25 char* path;
26 /** png height in pixels (Y domain)*/
27 unsigned height;
28 /** png width in pixels (X domain)*/
29 unsigned width;
30 /** [height][width] pixel buffer (Y, X)*/
33
34/* prototypes */
35
36/* allocate & free */
37pixel** pngz_alloc_pixels(unsigned rows, unsigned cols);
38unsigned char** pngz_alloc_bytes(unsigned rows, unsigned cols);
39int pngz_free_pixels(pixel** pixels, unsigned rows);
40int pngz_free_bytes(unsigned char** bytes, unsigned rows);
41int pngz_free(pngz* z);
42
43/* load and save */
45 unsigned char** bytes_src, pixel** pixels_dest,
46 unsigned rows, unsigned cols
47);
49 pixel** pixels_src, unsigned char** bytes_dest,
50 unsigned rows, unsigned cols
51);
52int pngz_load(pngz* z);
53int pngz_load_from(pngz* z, char* path);
54int pngz_save(pngz z);
55int pngz_save_as(pngz z, char* path);
56
57/* print */
58void pngz_print(pngz z);
60void pngz_print_indent(pngz z, int indent);
61void pngz_print_pixel_indent(pixel p, int indent);
62
63#endif
int pngz_unpack_pixels(pixel **pixels_src, unsigned char **bytes_dest, unsigned rows, unsigned cols)
unpack pixels into raw byte ptrs.
Definition pngz.c:206
int pngz_load(pngz *z)
load a pngz object into memory
Definition pngz.c:240
int pngz_free_bytes(unsigned char **bytes, unsigned rows)
safely free pixel buffer.
Definition pngz.c:131
unsigned char ** pngz_alloc_bytes(unsigned rows, unsigned cols)
allocate raw pixel byte buffer.
Definition pngz.c:67
int pngz_load_from(pngz *z, char *path)
load a pngz from a path directly passed into the call, just a wrapper for standard pngz_load()
Definition pngz.c:229
void pngz_print_pixel_indent(pixel p, int indent)
print out a single pixels rgba values.
Definition pngz.c:468
int pngz_save(pngz z)
write a png back out to file, wrapper for pngz_save_as()
Definition pngz.c:331
void pngz_print_indent(pngz z, int indent)
print a pngz ztruct contents.
Definition pngz.c:444
int pngz_free(pngz *z)
free a pngz structs pixels.
Definition pngz.c:164
void pngz_print_pixel(pixel p)
print out a single pixels rgba values in hex.
Definition pngz.c:420
int pngz_free_pixels(pixel **pixels, unsigned rows)
safely free pixel buffer.
Definition pngz.c:97
pixel ** pngz_alloc_pixels(unsigned rows, unsigned cols)
allocate a pixel buffer.
Definition pngz.c:37
int pngz_pack_pixels(unsigned char **bytes_src, pixel **pixels_dest, unsigned rows, unsigned cols)
pack bytes into pixels.
Definition pngz.c:179
void pngz_print(pngz z)
print a pngz ztruct contents.
Definition pngz.c:401
int pngz_save_as(pngz z, char *path)
write a png back out to file with a new name
Definition pngz.c:342
pixel in RGBA8 format.
Definition pngz.h:13
unsigned char r
channel values
Definition pngz.h:15
unsigned char b
Definition pngz.h:15
unsigned char g
Definition pngz.h:15
unsigned char a
Definition pngz.h:15
easy png structure.
Definition pngz.h:23
char * path
default path to load from and save to
Definition pngz.h:25
unsigned height
png height in pixels (Y domain)
Definition pngz.h:27
pixel ** pixels
[height][width] pixel buffer (Y, X)
Definition pngz.h:31
unsigned width
png width in pixels (X domain)
Definition pngz.h:29