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#include <stdint.h>
11/**
12 * pixel in RGBA8 format.
13 */
14typedef struct PNGZ_Pixel {
15 /** channel values */
16 uint8_t r, g, b, a;
18
19/**
20 * easy png based image structure.
21 * always contains RGBA8 color (0x0 - 0xFFFFFF).
22 * pixel buffer is [height][width] pixels ([rows][cols])
23 */
24typedef struct PNGZ_Image {
25 /** default path to load from and save to */
26 const char* path;
27 /** [height][width] pixel buffer (Y, X)*/
29 /** png height in pixels (Y domain)*/
30 unsigned height;
31 /** png width in pixels (X domain)*/
32 unsigned width;
34
35/* prototypes */
36
37/* allocate & free */
38int PNGZ_AllocPixels(PNGZ_Pixel*** pixels_ptr, const unsigned rows, const unsigned cols);
39int PNGZ_AllocBytes(uint8_t*** bytes_ptr, const unsigned rows, const unsigned cols);
40int PNGZ_FreePixels(PNGZ_Pixel** pixels, const unsigned rows);
41int PNGZ_FreeBytes(uint8_t** bytes, const unsigned rows);
42int PNGZ_Free(PNGZ_Image* z);
43
44/* load and save */
46 uint8_t** bytes_src, PNGZ_Pixel** pixels_dest,
47 const unsigned rows, const unsigned cols
48);
50 PNGZ_Pixel** pixels_src, uint8_t** bytes_dest,
51 const unsigned rows, const unsigned cols
52);
53int PNGZ_Load(PNGZ_Image* z);
54int PNGZ_LoadFrom(PNGZ_Image* z, const char* path);
55int PNGZ_Save(const PNGZ_Image z);
56int PNGZ_SaveAs(const PNGZ_Image z, const char* path);
57int PNGZ_Copy(const PNGZ_Image z_src, PNGZ_Image* z_dest);
58
59/* print */
60int PNGZ_PrintImage(const PNGZ_Image z);
61int PNGZ_PrintPixel(const PNGZ_Pixel p);
62int PNGZ_PrintImageIndent(const PNGZ_Image z, const int indent);
63int PNGZ_PrintPixelIndent(const PNGZ_Pixel p, const int indent);
64
65#endif
int PNGZ_PrintPixelIndent(const PNGZ_Pixel p, const int indent)
int PNGZ_Load(PNGZ_Image *z)
load a pngz object into memory
Definition pngz.c:296
int PNGZ_AllocPixels(PNGZ_Pixel ***pixels_ptr, const unsigned rows, const unsigned cols)
allocate a pixel buffer.
Definition pngz.c:36
int PNGZ_BytesToPixels(uint8_t **bytes_src, PNGZ_Pixel **pixels_dest, const unsigned rows, const unsigned cols)
pack bytes into pixels.
Definition pngz.c:183
int PNGZ_PrintImage(const PNGZ_Image z)
print a pngz ztruct contents.
Definition pngz.c:456
int PNGZ_FreePixels(PNGZ_Pixel **pixels, const unsigned rows)
safely free pixel buffer.
Definition pngz.c:100
int PNGZ_PrintPixel(const PNGZ_Pixel p)
print out a single pixels rgba values in hex.
Definition pngz.c:475
int PNGZ_Copy(const PNGZ_Image z_src, PNGZ_Image *z_dest)
copies the pixel data from one pngz to another.
Definition pngz.c:257
int PNGZ_AllocBytes(uint8_t ***bytes_ptr, const unsigned rows, const unsigned cols)
allocate raw pixel byte buffer.
Definition pngz.c:68
int PNGZ_PixelsToBytes(PNGZ_Pixel **pixels_src, uint8_t **bytes_dest, const unsigned rows, const unsigned cols)
unpack pixels into raw byte ptrs.
Definition pngz.c:223
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()
Definition pngz.c:285
int PNGZ_PrintImageIndent(const PNGZ_Image z, const int indent)
print a pngz ztruct contents.
Definition pngz.c:499
int PNGZ_Save(const PNGZ_Image z)
write a png back out to file, wrapper for pngz_save_as()
Definition pngz.c:386
int PNGZ_Free(PNGZ_Image *z)
free a pngz structs pixels.
Definition pngz.c:168
int PNGZ_SaveAs(const PNGZ_Image z, const char *path)
write a png back out to file with a new name
Definition pngz.c:397
int PNGZ_FreeBytes(uint8_t **bytes, const unsigned rows)
safely free pixel buffer.
Definition pngz.c:135
easy png based image structure.
Definition pngz.h:24
PNGZ_Pixel ** pixels
[height][width] pixel buffer (Y, X)
Definition pngz.h:28
unsigned height
png height in pixels (Y domain)
Definition pngz.h:30
const char * path
default path to load from and save to
Definition pngz.h:26
unsigned width
png width in pixels (X domain)
Definition pngz.h:32
pixel in RGBA8 format.
Definition pngz.h:14
uint8_t a
Definition pngz.h:16
uint8_t b
Definition pngz.h:16
uint8_t g
Definition pngz.h:16
uint8_t r
channel values
Definition pngz.h:16