xref: /freebsd/contrib/pnglite/pnglite.h (revision 80aa931900c863a5d088c49b560488ab32f2d1d9)
1*80aa9319SToomas Soome /*
2*80aa9319SToomas Soome  *  pnglite.h - Interface for pnglite library
3*80aa9319SToomas Soome  *	Copyright (c) 2007 Daniel Karling
4*80aa9319SToomas Soome  *
5*80aa9319SToomas Soome  *	This software is provided 'as-is', without any express or implied
6*80aa9319SToomas Soome  *	warranty. In no event will the authors be held liable for any damages
7*80aa9319SToomas Soome  *	arising from the use of this software.
8*80aa9319SToomas Soome  *
9*80aa9319SToomas Soome  *	Permission is granted to anyone to use this software for any purpose,
10*80aa9319SToomas Soome  *	including commercial applications, and to alter it and redistribute it
11*80aa9319SToomas Soome  *	freely, subject to the following restrictions:
12*80aa9319SToomas Soome  *
13*80aa9319SToomas Soome  *	1. The origin of this software must not be misrepresented; you must not
14*80aa9319SToomas Soome  *	   claim that you wrote the original software. If you use this software
15*80aa9319SToomas Soome  *	   in a product, an acknowledgment in the product documentation would be
16*80aa9319SToomas Soome  *	   appreciated but is not required.
17*80aa9319SToomas Soome  *
18*80aa9319SToomas Soome  *	2. Altered source versions must be plainly marked as such, and must not
19*80aa9319SToomas Soome  *	   be misrepresented as being the original software.
20*80aa9319SToomas Soome  *
21*80aa9319SToomas Soome  *	3. This notice may not be removed or altered from any source
22*80aa9319SToomas Soome  *	   distribution.
23*80aa9319SToomas Soome  *
24*80aa9319SToomas Soome  *	Daniel Karling
25*80aa9319SToomas Soome  *	daniel.karling@gmail.com
2672c59f17SToomas Soome  */
2772c59f17SToomas Soome 
2872c59f17SToomas Soome 
2972c59f17SToomas Soome #ifndef _PNGLITE_H_
3072c59f17SToomas Soome #define	_PNGLITE_H_
3172c59f17SToomas Soome 
3272c59f17SToomas Soome #include <string.h>
3372c59f17SToomas Soome 
3472c59f17SToomas Soome #ifdef __cplusplus
3572c59f17SToomas Soome extern "C" {
3672c59f17SToomas Soome #endif
3772c59f17SToomas Soome 
3872c59f17SToomas Soome /*
39*80aa9319SToomas Soome  *	Enumerations for pnglite.
40*80aa9319SToomas Soome  *	Negative numbers are error codes and 0 and up are okay responses.
4172c59f17SToomas Soome  */
4272c59f17SToomas Soome 
43*80aa9319SToomas Soome enum {
4472c59f17SToomas Soome 	PNG_DONE			= 1,
4572c59f17SToomas Soome 	PNG_NO_ERROR			= 0,
4672c59f17SToomas Soome 	PNG_FILE_ERROR			= -1,
4772c59f17SToomas Soome 	PNG_HEADER_ERROR		= -2,
4872c59f17SToomas Soome 	PNG_IO_ERROR			= -3,
4972c59f17SToomas Soome 	PNG_EOF_ERROR			= -4,
5072c59f17SToomas Soome 	PNG_CRC_ERROR			= -5,
5172c59f17SToomas Soome 	PNG_MEMORY_ERROR		= -6,
5272c59f17SToomas Soome 	PNG_ZLIB_ERROR			= -7,
5372c59f17SToomas Soome 	PNG_UNKNOWN_FILTER		= -8,
5472c59f17SToomas Soome 	PNG_NOT_SUPPORTED		= -9,
5572c59f17SToomas Soome 	PNG_WRONG_ARGUMENTS		= -10
5672c59f17SToomas Soome };
5772c59f17SToomas Soome 
5872c59f17SToomas Soome /*
59*80aa9319SToomas Soome  *	The five different kinds of color storage in PNG files.
6072c59f17SToomas Soome  */
6172c59f17SToomas Soome 
62*80aa9319SToomas Soome enum {
6372c59f17SToomas Soome 	PNG_GREYSCALE			= 0,
6472c59f17SToomas Soome 	PNG_TRUECOLOR			= 2,
6572c59f17SToomas Soome 	PNG_INDEXED			= 3,
6672c59f17SToomas Soome 	PNG_GREYSCALE_ALPHA		= 4,
6772c59f17SToomas Soome 	PNG_TRUECOLOR_ALPHA		= 6
6872c59f17SToomas Soome };
6972c59f17SToomas Soome 
70*80aa9319SToomas Soome typedef struct {
7172c59f17SToomas Soome 	void			*zs;		/* pointer to z_stream */
72*80aa9319SToomas Soome 	int			fd;
73*80aa9319SToomas Soome 	unsigned char		*image;
7472c59f17SToomas Soome 
7572c59f17SToomas Soome 	unsigned char		*png_data;
7672c59f17SToomas Soome 	unsigned		png_datalen;
7772c59f17SToomas Soome 
7872c59f17SToomas Soome 	unsigned		width;
7972c59f17SToomas Soome 	unsigned		height;
8072c59f17SToomas Soome 	unsigned char		depth;
8172c59f17SToomas Soome 	unsigned char		color_type;
8272c59f17SToomas Soome 	unsigned char		compression_method;
8372c59f17SToomas Soome 	unsigned char		filter_method;
8472c59f17SToomas Soome 	unsigned char		interlace_method;
8572c59f17SToomas Soome 	unsigned char		bpp;
8672c59f17SToomas Soome 
8772c59f17SToomas Soome 	unsigned char		*readbuf;
8872c59f17SToomas Soome 	unsigned		readbuflen;
8972c59f17SToomas Soome } png_t;
9072c59f17SToomas Soome 
91*80aa9319SToomas Soome 
9272c59f17SToomas Soome /*
93*80aa9319SToomas Soome  *	Function: png_open
94*80aa9319SToomas Soome  *
95*80aa9319SToomas Soome  *	This function is used to open a png file with the internal file
96*80aa9319SToomas Soome  *	IO system.
97*80aa9319SToomas Soome  *
98*80aa9319SToomas Soome  *	Parameters:
99*80aa9319SToomas Soome  *		png - Empty png_t struct.
100*80aa9319SToomas Soome  *		filename - Filename of the file to be opened.
101*80aa9319SToomas Soome  *
102*80aa9319SToomas Soome  *	Returns:
103*80aa9319SToomas Soome  *		PNG_NO_ERROR on success, otherwise an error code.
10472c59f17SToomas Soome  */
10572c59f17SToomas Soome 
106*80aa9319SToomas Soome int png_open(png_t *png, const char *filename);
10772c59f17SToomas Soome 
10872c59f17SToomas Soome /*
109*80aa9319SToomas Soome  *	Function: png_print_info
110*80aa9319SToomas Soome  *
111*80aa9319SToomas Soome  *	This function prints some info about the opened png file to stdout.
112*80aa9319SToomas Soome  *
113*80aa9319SToomas Soome  *	Parameters:
114*80aa9319SToomas Soome  *		png - png struct to get info from.
11572c59f17SToomas Soome  */
11672c59f17SToomas Soome 
11772c59f17SToomas Soome void png_print_info(png_t *png);
11872c59f17SToomas Soome 
11972c59f17SToomas Soome /*
120*80aa9319SToomas Soome  *	Function: png_error_string
121*80aa9319SToomas Soome  *
122*80aa9319SToomas Soome  *	This function translates an error code to a human readable string.
123*80aa9319SToomas Soome  *
124*80aa9319SToomas Soome  *	Parameters:
125*80aa9319SToomas Soome  *		error - Error code.
126*80aa9319SToomas Soome  *
127*80aa9319SToomas Soome  *	Returns:
128*80aa9319SToomas Soome  *		Pointer to string.
12972c59f17SToomas Soome  */
13072c59f17SToomas Soome 
13172c59f17SToomas Soome char *png_error_string(int error);
13272c59f17SToomas Soome 
13372c59f17SToomas Soome /*
134*80aa9319SToomas Soome  *	Function: png_get_data
135*80aa9319SToomas Soome  *
136*80aa9319SToomas Soome  *	This function decodes the opened png file and stores the result in data.
137*80aa9319SToomas Soome  *	data should be big enough to hold the decoded png.
138*80aa9319SToomas Soome  *	Required size will be:
139*80aa9319SToomas Soome  *
140*80aa9319SToomas Soome  *	> width*height*(bytes per pixel)
141*80aa9319SToomas Soome  *
142*80aa9319SToomas Soome  *	Parameters:
143*80aa9319SToomas Soome  *		data - Where to store result.
144*80aa9319SToomas Soome  *
145*80aa9319SToomas Soome  *	Returns:
146*80aa9319SToomas Soome  *		PNG_NO_ERROR on success, otherwise an error code.
14772c59f17SToomas Soome  */
14872c59f17SToomas Soome 
149*80aa9319SToomas Soome int png_get_data(png_t *png, uint8_t *data);
15072c59f17SToomas Soome 
15172c59f17SToomas Soome /*
152*80aa9319SToomas Soome  *	Function: png_close
153*80aa9319SToomas Soome  *
154*80aa9319SToomas Soome  *	Closes an open png file pointer.
155*80aa9319SToomas Soome  *
156*80aa9319SToomas Soome  *	Parameters:
157*80aa9319SToomas Soome  *		png - png to close.
158*80aa9319SToomas Soome  *
159*80aa9319SToomas Soome  *	Returns:
160*80aa9319SToomas Soome  *		PNG_NO_ERROR
16172c59f17SToomas Soome  */
16272c59f17SToomas Soome 
163*80aa9319SToomas Soome int png_close(png_t *png);
16472c59f17SToomas Soome 
16572c59f17SToomas Soome #ifdef __cplusplus
16672c59f17SToomas Soome }
16772c59f17SToomas Soome #endif
168*80aa9319SToomas Soome 
169*80aa9319SToomas Soome #endif /* _PNGLITE_H_ */
170