xref: /illumos-gate/usr/src/common/pnglite/pnglite.h (revision 9890ff83)
1*9890ff83SToomas Soome /*
2*9890ff83SToomas Soome  *  pnglite.h - Interface for pnglite library
3*9890ff83SToomas Soome  *	Copyright (c) 2007 Daniel Karling
4*9890ff83SToomas Soome  *
5*9890ff83SToomas Soome  *	This software is provided 'as-is', without any express or implied
6*9890ff83SToomas Soome  *	warranty. In no event will the authors be held liable for any damages
7*9890ff83SToomas Soome  *	arising from the use of this software.
8*9890ff83SToomas Soome  *
9*9890ff83SToomas Soome  *	Permission is granted to anyone to use this software for any purpose,
10*9890ff83SToomas Soome  *	including commercial applications, and to alter it and redistribute it
11*9890ff83SToomas Soome  *	freely, subject to the following restrictions:
12*9890ff83SToomas Soome  *
13*9890ff83SToomas Soome  *	1. The origin of this software must not be misrepresented; you must not
14*9890ff83SToomas Soome  *	   claim that you wrote the original software. If you use this software
15*9890ff83SToomas Soome  *	   in a product, an acknowledgment in the product documentation would be
16*9890ff83SToomas Soome  *	   appreciated but is not required.
17*9890ff83SToomas Soome  *
18*9890ff83SToomas Soome  *	2. Altered source versions must be plainly marked as such, and must not
19*9890ff83SToomas Soome  *	   be misrepresented as being the original software.
20*9890ff83SToomas Soome  *
21*9890ff83SToomas Soome  *	3. This notice may not be removed or altered from any source
22*9890ff83SToomas Soome  *	   distribution.
23*9890ff83SToomas Soome  *
24*9890ff83SToomas Soome  *	Daniel Karling
25*9890ff83SToomas Soome  *	daniel.karling@gmail.com
26*9890ff83SToomas Soome  */
27*9890ff83SToomas Soome 
28*9890ff83SToomas Soome 
29*9890ff83SToomas Soome #ifndef _PNGLITE_H_
30*9890ff83SToomas Soome #define	_PNGLITE_H_
31*9890ff83SToomas Soome 
32*9890ff83SToomas Soome #include <string.h>
33*9890ff83SToomas Soome 
34*9890ff83SToomas Soome #ifdef __cplusplus
35*9890ff83SToomas Soome extern "C" {
36*9890ff83SToomas Soome #endif
37*9890ff83SToomas Soome 
38*9890ff83SToomas Soome /*
39*9890ff83SToomas Soome  *	Enumerations for pnglite.
40*9890ff83SToomas Soome  *	Negative numbers are error codes and 0 and up are okay responses.
41*9890ff83SToomas Soome  */
42*9890ff83SToomas Soome 
43*9890ff83SToomas Soome enum {
44*9890ff83SToomas Soome 	PNG_DONE			= 1,
45*9890ff83SToomas Soome 	PNG_NO_ERROR			= 0,
46*9890ff83SToomas Soome 	PNG_FILE_ERROR			= -1,
47*9890ff83SToomas Soome 	PNG_HEADER_ERROR		= -2,
48*9890ff83SToomas Soome 	PNG_IO_ERROR			= -3,
49*9890ff83SToomas Soome 	PNG_EOF_ERROR			= -4,
50*9890ff83SToomas Soome 	PNG_CRC_ERROR			= -5,
51*9890ff83SToomas Soome 	PNG_MEMORY_ERROR		= -6,
52*9890ff83SToomas Soome 	PNG_ZLIB_ERROR			= -7,
53*9890ff83SToomas Soome 	PNG_UNKNOWN_FILTER		= -8,
54*9890ff83SToomas Soome 	PNG_NOT_SUPPORTED		= -9,
55*9890ff83SToomas Soome 	PNG_WRONG_ARGUMENTS		= -10
56*9890ff83SToomas Soome };
57*9890ff83SToomas Soome 
58*9890ff83SToomas Soome /*
59*9890ff83SToomas Soome  *	The five different kinds of color storage in PNG files.
60*9890ff83SToomas Soome  */
61*9890ff83SToomas Soome 
62*9890ff83SToomas Soome enum {
63*9890ff83SToomas Soome 	PNG_GREYSCALE			= 0,
64*9890ff83SToomas Soome 	PNG_TRUECOLOR			= 2,
65*9890ff83SToomas Soome 	PNG_INDEXED			= 3,
66*9890ff83SToomas Soome 	PNG_GREYSCALE_ALPHA		= 4,
67*9890ff83SToomas Soome 	PNG_TRUECOLOR_ALPHA		= 6
68*9890ff83SToomas Soome };
69*9890ff83SToomas Soome 
70*9890ff83SToomas Soome typedef struct {
71*9890ff83SToomas Soome 	void			*zs;		/* pointer to z_stream */
72*9890ff83SToomas Soome 	int			fd;
73*9890ff83SToomas Soome 	unsigned char		*image;
74*9890ff83SToomas Soome 
75*9890ff83SToomas Soome 	unsigned char		*png_data;
76*9890ff83SToomas Soome 	unsigned		png_datalen;
77*9890ff83SToomas Soome 
78*9890ff83SToomas Soome 	unsigned		width;
79*9890ff83SToomas Soome 	unsigned		height;
80*9890ff83SToomas Soome 	unsigned char		depth;
81*9890ff83SToomas Soome 	unsigned char		color_type;
82*9890ff83SToomas Soome 	unsigned char		compression_method;
83*9890ff83SToomas Soome 	unsigned char		filter_method;
84*9890ff83SToomas Soome 	unsigned char		interlace_method;
85*9890ff83SToomas Soome 	unsigned char		bpp;
86*9890ff83SToomas Soome 
87*9890ff83SToomas Soome 	unsigned char		*readbuf;
88*9890ff83SToomas Soome 	unsigned		readbuflen;
89*9890ff83SToomas Soome } png_t;
90*9890ff83SToomas Soome 
91*9890ff83SToomas Soome 
92*9890ff83SToomas Soome /*
93*9890ff83SToomas Soome  *	Function: png_open
94*9890ff83SToomas Soome  *
95*9890ff83SToomas Soome  *	This function is used to open a png file with the internal file
96*9890ff83SToomas Soome  *	IO system.
97*9890ff83SToomas Soome  *
98*9890ff83SToomas Soome  *	Parameters:
99*9890ff83SToomas Soome  *		png - Empty png_t struct.
100*9890ff83SToomas Soome  *		filename - Filename of the file to be opened.
101*9890ff83SToomas Soome  *
102*9890ff83SToomas Soome  *	Returns:
103*9890ff83SToomas Soome  *		PNG_NO_ERROR on success, otherwise an error code.
104*9890ff83SToomas Soome  */
105*9890ff83SToomas Soome 
106*9890ff83SToomas Soome int png_open(png_t *png, const char *filename);
107*9890ff83SToomas Soome 
108*9890ff83SToomas Soome /*
109*9890ff83SToomas Soome  *	Function: png_print_info
110*9890ff83SToomas Soome  *
111*9890ff83SToomas Soome  *	This function prints some info about the opened png file to stdout.
112*9890ff83SToomas Soome  *
113*9890ff83SToomas Soome  *	Parameters:
114*9890ff83SToomas Soome  *		png - png struct to get info from.
115*9890ff83SToomas Soome  */
116*9890ff83SToomas Soome 
117*9890ff83SToomas Soome void png_print_info(png_t *png);
118*9890ff83SToomas Soome 
119*9890ff83SToomas Soome /*
120*9890ff83SToomas Soome  *	Function: png_error_string
121*9890ff83SToomas Soome  *
122*9890ff83SToomas Soome  *	This function translates an error code to a human readable string.
123*9890ff83SToomas Soome  *
124*9890ff83SToomas Soome  *	Parameters:
125*9890ff83SToomas Soome  *		error - Error code.
126*9890ff83SToomas Soome  *
127*9890ff83SToomas Soome  *	Returns:
128*9890ff83SToomas Soome  *		Pointer to string.
129*9890ff83SToomas Soome  */
130*9890ff83SToomas Soome 
131*9890ff83SToomas Soome char *png_error_string(int error);
132*9890ff83SToomas Soome 
133*9890ff83SToomas Soome /*
134*9890ff83SToomas Soome  *	Function: png_get_data
135*9890ff83SToomas Soome  *
136*9890ff83SToomas Soome  *	This function decodes the opened png file and stores the result in data.
137*9890ff83SToomas Soome  *	data should be big enough to hold the decoded png.
138*9890ff83SToomas Soome  *	Required size will be:
139*9890ff83SToomas Soome  *
140*9890ff83SToomas Soome  *	> width*height*(bytes per pixel)
141*9890ff83SToomas Soome  *
142*9890ff83SToomas Soome  *	Parameters:
143*9890ff83SToomas Soome  *		data - Where to store result.
144*9890ff83SToomas Soome  *
145*9890ff83SToomas Soome  *	Returns:
146*9890ff83SToomas Soome  *		PNG_NO_ERROR on success, otherwise an error code.
147*9890ff83SToomas Soome  */
148*9890ff83SToomas Soome 
149*9890ff83SToomas Soome int png_get_data(png_t *png, uint8_t *data);
150*9890ff83SToomas Soome 
151*9890ff83SToomas Soome /*
152*9890ff83SToomas Soome  *	Function: png_close
153*9890ff83SToomas Soome  *
154*9890ff83SToomas Soome  *	Closes an open png file pointer.
155*9890ff83SToomas Soome  *
156*9890ff83SToomas Soome  *	Parameters:
157*9890ff83SToomas Soome  *		png - png to close.
158*9890ff83SToomas Soome  *
159*9890ff83SToomas Soome  *	Returns:
160*9890ff83SToomas Soome  *		PNG_NO_ERROR
161*9890ff83SToomas Soome  */
162*9890ff83SToomas Soome 
163*9890ff83SToomas Soome int png_close(png_t *png);
164*9890ff83SToomas Soome 
165*9890ff83SToomas Soome #ifdef __cplusplus
166*9890ff83SToomas Soome }
167*9890ff83SToomas Soome #endif
168*9890ff83SToomas Soome 
169*9890ff83SToomas Soome #endif /* _PNGLITE_H_ */
170