1 // pngdib.h
2 
3 #ifndef __PNGDIB_H__
4 #define __PNGDIB_H__
5 
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
9 
10 #define PNGDIB_HEADER_VERSION          20200
11 #define PNGDIB_HEADER_VERSION_STRING   "2.2.0"
12 
13 
14 // error codes returned by read_png_to_dib() and/or
15 //   write_dib_to_png()
16 
17 #define PNGD_E_SUCCESS   0
18 #define PNGD_E_ERROR     1   // unspecified error
19 #define PNGD_E_VERSION   2   // struct size problem
20 #define PNGD_E_NOMEM     3   // could not alloc memory
21 #define PNGD_E_UNSUPP    4   // unsupported image type
22 #define PNGD_E_LIBPNG    5   // libpng error (corrupt PNG?)
23 #define PNGD_E_BADBMP    6   // corrupt or unsupported DIB
24 #define PNGD_E_BADPNG    7   // corrupt or unsupported PNG
25 #define PNGD_E_READ      8   // couldn't read PNG file
26 #define PNGD_E_WRITE     9   // couldn't write PNG file
27 
28 struct PNGD_COLOR_struct {
29 	unsigned char red, green, blue, reserved;
30 };
31 
32 typedef struct PNGD_D2PINFO_struct {
33 	DWORD           structsize;      // sizeof(PNGD_D2PINFO)
34 	DWORD           flags;
35 #define PNGD_INTERLACED        0x00000001
36 #define PNGD_NO_GAMMA_LABEL    0x00000002
37 
38 	const char*     pngfn;          // PNG filename to write
39 
40 	LPBITMAPINFOHEADER    lpdib;
41 	int             dibsize;        // can be 0
42 
43 	VOID*           lpbits;         // can be NULL
44 	int             bitssize;       // can be 0
45 
46 	char*           software;       // (NULL==don't include)
47 // added in v2.0
48 	char*           errmsg;          // user can set to null or 100-char buffer
49 } PNGD_D2PINFO;
50 
51 
52 typedef struct PNGD_IMAGEINFO_struct {
53 	DWORD           structsize;    // sizeof(PNGD_IMAGEINFO)
54 	DWORD           flags;
55 
56 } PNGD_IMAGEINFO;
57 
58 typedef struct PNGD_P2DINFO_struct {
59 	DWORD           structsize;      // sizeof(PNGD_P2DINFO)
60 
61 	DWORD           flags;           // combination of below:
62 #define PNGD_USE_BKGD          0x00000001
63 #define PNGD_USE_CUSTOM_BG     0x00000002
64 #define PNGD_GAMMA_CORRECTION  0x00000004
65 #define PNGD_USE_HEAPALLOC     0x00000008
66 
67 #define PNGD_BG_RETURNED     0x00010000 // return value only
68 #define PNGD_RES_RETURNED    0x00020000 // set if xres,yres,res_units are valid
69 #define PNGD_GAMMA_RETURNED  0x00040000 // set if file_gamma is valid
70 
71 	const char*     pngfn;           // PNG filename to read
72 
73 	LPBITMAPINFOHEADER    lpdib;     // return value only
74 	int             dibsize;         // return value only
75 	int             palette_offs;    // return value only
76 	int             bits_offs;       // return value only
77 	RGBQUAD*        palette;         // return value only
78 	int             palette_colors;  // return value only
79 	VOID*           lpbits;          // return value only
80 // added in v2.0  (size=48)
81 	struct PNGD_COLOR_struct bgcolor; // IN OUT
82 	char*           errmsg;          // user can set to null or 100-char buffer
83 // added in v2.1  (size=88)
84 	int             color_type;
85 	int             bits_per_sample;
86 	int             bits_per_pixel;
87 	int             interlace;
88 	int             res_x,res_y;
89 	int             res_units;
90 	int             reserved1;
91 	double          file_gamma;
92 // added in v2.2   (size=96)
93 	HANDLE          heap;
94 	int             reserved2;
95 
96 } PNGD_P2DINFO;
97 
98 
99 
100 int read_png_to_dib(PNGD_P2DINFO *p2dinfo);
101 
102 int write_dib_to_png(PNGD_D2PINFO *d2pinfo);
103 
104 char* pngdib_get_version_string(void);
105 int pngdib_get_version(void);
106 
107 #ifdef __cplusplus
108 }
109 #endif
110 
111 #endif /* __PNGDIB_H__ */
112