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 /** union alias for either height or rows */
27 union {
28 unsigned height;
29 unsigned rows;
30 };
31 /** union alias for either width or cols */
32 union {
33 unsigned width;
34 unsigned cols;
35 };
36 /** [height][width] pixel buffer */
39
40/* prototypes */
41
42/* allocate & free */
43pixel** pngz_alloc_pixels(unsigned rows, unsigned cols);
44unsigned char** pngz_alloc_bytes(unsigned rows, unsigned cols);
45int pngz_free_pixels(pixel** pixels, unsigned rows);
46int pngz_free_bytes(unsigned char** bytes, unsigned rows);
47int pngz_free(pngz* z);
48
49/* load and save */
51 unsigned char** bytes_src, pixel** pixels_dest,
52 unsigned rows, unsigned cols
53);
55 pixel** pixels_src, unsigned char** bytes_dest,
56 unsigned rows, unsigned cols
57);
58int pngz_load(pngz* z);
59int pngz_load_from(pngz* z, char* path);
60int pngz_save(pngz z);
61int pngz_save_as(pngz z, char* path);
62
63/* print */
64void pngz_print(pngz z);
66void pngz_print_indent(pngz z, int indent);
67void pngz_print_pixel_indent(pixel p, int indent);
68
69#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:197
int pngz_load(pngz *z)
load a pngz object into memory
Definition pngz.c:231
int pngz_free_bytes(unsigned char **bytes, unsigned rows)
safely free pixel buffer.
Definition pngz.c:124
unsigned char ** pngz_alloc_bytes(unsigned rows, unsigned cols)
allocate raw pixel byte buffer.
Definition pngz.c:66
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()
Definition pngz.c:219
void pngz_print_pixel_indent(pixel p, int indent)
print out a single pixels rgba values.
Definition pngz.c:469
int pngz_save(pngz z)
write a png back out to file
Definition pngz.c:328
void pngz_print_indent(pngz z, int indent)
print a pngz ztruct contents.
Definition pngz.c:445
int pngz_free(pngz *z)
free a pngz structs pixels.
Definition pngz.c:155
void pngz_print_pixel(pixel p)
print out a single pixels rgba values in hex.
Definition pngz.c:422
int pngz_free_pixels(pixel **pixels, unsigned rows)
safely free pixel buffer.
Definition pngz.c:93
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 pixels with bytes.
Definition pngz.c:170
void pngz_print(pngz z)
print a pngz ztruct contents.
Definition pngz.c:403
int pngz_save_as(pngz z, char *path)
write a png back out to file with a new name
Definition pngz.c:339
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 cols
Definition pngz.h:34
unsigned rows
Definition pngz.h:29
unsigned height
Definition pngz.h:28
pixel ** pixels
[height][width] pixel buffer
Definition pngz.h:37
unsigned width
Definition pngz.h:33