3 #ifndef PNGDIB_H_INCLUDED
4 #define PNGDIB_H_INCLUDED
13 // the V2 compatibility layer isn't UNICODE compatible
14 #define PNGDIB_V2COMPATIBLE 0
17 // If you don't need to be compatible with PNGDIB v1.x and v2.x,
18 // you can define this to 0 and save a few bytes.
19 #ifndef PNGDIB_V2COMPATIBLE
20 #define PNGDIB_V2COMPATIBLE 1
23 #define PNGDIB_HEADER_VERSION 30001
26 #define PNGDIB_DEFAULT_SCREEN_GAMMA 2.20000
27 #define PNGDIB_DEFAULT_FILE_GAMMA 0.45455
30 #define PNGDIB_DECL __stdcall
35 // error codes returned by pngdib_*_run()
37 #define PNGD_E_SUCCESS 0
38 #define PNGD_E_ERROR 1 // unspecified error
39 #define PNGD_E_VERSION 2 // struct size problem
40 #define PNGD_E_NOMEM 3 // could not alloc memory
41 #define PNGD_E_UNSUPP 4 // unsupported image type
42 #define PNGD_E_LIBPNG 5 // libpng error (corrupt PNG?)
43 #define PNGD_E_BADBMP 6 // corrupt or unsupported DIB
44 #define PNGD_E_BADPNG 7 // corrupt or unsupported PNG
45 #define PNGD_E_READ 8 // couldn't read PNG file
46 #define PNGD_E_WRITE 9 // couldn't write PNG file
48 #if (PNGDIB_V2COMPATIBLE) || defined(PNGDIB_INTERNALS)
50 struct PNGD_COLOR_struct
{
51 unsigned char red
, green
, blue
, reserved
;
57 #if PNGDIB_V2COMPATIBLE
59 typedef struct PNGD_D2PINFO_struct
{
60 DWORD structsize
; // sizeof(PNGD_D2PINFO)
62 #define PNGD_INTERLACED 0x00000001
63 #define PNGD_NO_GAMMA_LABEL 0x00000002
64 #define PNGD_DIB_ALPHA32 0x00000010
66 char* pngfn
; // PNG filename to write
68 LPBITMAPINFOHEADER lpdib
;
69 int dibsize
; // can be 0
71 VOID
* lpbits
; // can be NULL
72 int bitssize
; // can be 0
74 char* software
; // (NULL==don't include)
76 char* errmsg
; // user can set to null or 100-char buffer
80 typedef struct PNGD_IMAGEINFO_struct
{
81 DWORD structsize
; // sizeof(PNGD_IMAGEINFO)
86 typedef struct PNGD_P2DINFO_struct
{
87 DWORD structsize
; // sizeof(PNGD_P2DINFO)
89 DWORD flags
; // combination of below:
90 #define PNGD_USE_BKGD 0x00000001
91 #define PNGD_USE_CUSTOM_BG 0x00000002
92 #define PNGD_GAMMA_CORRECTION 0x00000004
93 #define PNGD_USE_HEAPALLOC 0x00000008
94 //#define PNGD_DIB_ALPHA32 0x00000010 already defined above
96 #define PNGD_BG_RETURNED 0x00010000 // return value only
97 #define PNGD_RES_RETURNED 0x00020000 // set if xres,yres,res_units are valid
98 #define PNGD_GAMMA_RETURNED 0x00040000 // set if file_gamma is valid
100 char* pngfn
; // PNG filename to read
102 LPBITMAPINFOHEADER lpdib
; // return value only
103 int dibsize
; // return value only
104 int palette_offs
; // return value only
105 int bits_offs
; // return value only
106 RGBQUAD
* palette
; // return value only
107 int palette_colors
; // return value only
108 VOID
* lpbits
; // return value only
109 // added in v2.0 (size=48)
110 struct PNGD_COLOR_struct bgcolor
; // IN OUT
111 char* errmsg
; // user can set to null or 100-char buffer
112 // added in v2.1 (size=88)
121 // added in v2.2 (size=96)
127 int read_png_to_dib(PNGD_P2DINFO
*p2dinfo
);
128 int write_dib_to_png(PNGD_D2PINFO
*d2pinfo
);
130 #endif // PNGDIB_V2COMPATIBLE
133 // public definitions
135 typedef void* (PNGDIB_DECL
*pngdib_malloc_cb_type
)(void *userdata
, int memblksize
);
136 typedef void (PNGDIB_DECL
*pngdib_free_cb_type
)(void *userdata
, void *memblk
);
137 typedef void* (PNGDIB_DECL
*pngdib_realloc_cb_type
)(void *userdata
, void *memblk
, int memblksize
);
139 struct pngdib_common_struct
;
140 typedef struct pngdib_common_struct PNGDIB
;
143 #define PNGD_ST_D2P 1
144 #define PNGD_ST_P2D 2
147 #ifdef PNGDIB_INTERNALS
149 // definitions for internal library use only
151 #define PNGDIB_ERRMSG_MAX 200
154 struct pngdib_common_struct
{
158 pngdib_malloc_cb_type malloc_function
;
159 pngdib_free_cb_type free_function
;
160 pngdib_realloc_cb_type realloc_function
;
165 struct pngdib_common_struct common
;
167 const BITMAPINFOHEADER
* pdib
;
172 TCHAR
* output_filename
;
173 char* software_id_string
;
174 int file_gamma_valid
;
179 struct pngdib_common_struct common
;
181 int input_method
; // 0=filename, 1=memory
182 TCHAR
* input_filename
;
183 unsigned char* input_memblk
;
184 int input_memblk_size
;
185 int input_memblk_curpos
;
187 int use_file_bg_flag
;
188 int use_custom_bg_flag
;
189 struct PNGD_COLOR_struct bgcolor
;
190 int gamma_correction
; // should we gamma correct (using screen_gamma)?
193 BITMAPINFOHEADER
* pdib
;
207 int res_valid
; // are res_x, res_y, res_units valid?
209 int gamma_returned
; // set if we know the file gamma
210 int bgcolor_returned
;
213 #undef _PNGD_DEFINE_COMMON_FIELDS
216 #endif // PNGDIB_INTERNALS
218 ///////////// d2p functions
220 #define pngdib_d2p_init() _pngdib_init(PNGD_ST_D2P,PNGDIB_HEADER_VERSION)
222 PNGDIB_EXT
int PNGDIB_DECL
pngdib_d2p_set_dib(PNGDIB
*d2p
,
223 const BITMAPINFOHEADER
* pdib
, int dibsize
,
224 const void* pbits
, int bitssize
);
226 PNGDIB_EXT
void PNGDIB_DECL
pngdib_d2p_set_interlace(PNGDIB
*d2p
, int interlaced
);
227 PNGDIB_EXT
int PNGDIB_DECL
pngdib_d2p_set_png_filename(PNGDIB
*d2p
, const TCHAR
*fn
);
228 PNGDIB_EXT
int PNGDIB_DECL
pngdib_d2p_set_software_id(PNGDIB
*d2p
, const TCHAR
*s
);
229 PNGDIB_EXT
void PNGDIB_DECL
pngdib_d2p_set_gamma_label(PNGDIB
*d2p
, int flag
, double file_gamma
);
231 PNGDIB_EXT
int PNGDIB_DECL
pngdib_d2p_run(PNGDIB
*d2p
);
235 //////////// p2d functions
237 #define pngdib_p2d_init() _pngdib_init(PNGD_ST_P2D,PNGDIB_HEADER_VERSION)
239 PNGDIB_EXT
int PNGDIB_DECL
pngdib_p2d_set_png_filename(PNGDIB
*p2d
, const TCHAR
*fn
);
240 PNGDIB_EXT
void PNGDIB_DECL
pngdib_p2d_set_png_memblk(PNGDIB
*p2d
, const void *mem
, int memsize
);
242 PNGDIB_EXT
void PNGDIB_DECL
pngdib_p2d_set_use_file_bg(PNGDIB
*p2d
, int flag
);
243 PNGDIB_EXT
void PNGDIB_DECL
pngdib_p2d_set_custom_bg(PNGDIB
*p2d
, unsigned char r
,
244 unsigned char g
, unsigned char b
);
245 PNGDIB_EXT
void PNGDIB_DECL
pngdib_p2d_set_gamma_correction(PNGDIB
*p2d
, int flag
, double screen_gamma
);
247 PNGDIB_EXT
int PNGDIB_DECL
pngdib_p2d_run(PNGDIB
*p2d
);
249 PNGDIB_EXT
int PNGDIB_DECL
pngdib_p2d_get_dib(PNGDIB
*p2d
, BITMAPINFOHEADER
**ppdib
, int *pdibsize
);
250 PNGDIB_EXT
int PNGDIB_DECL
pngdib_p2d_get_dibbits(PNGDIB
*p2d
, void **ppbits
, int *pbitsoffset
, int *pbitssize
);
251 PNGDIB_EXT
int PNGDIB_DECL
pngdib_p2d_get_palette(PNGDIB
*p2d
, RGBQUAD
**ppal
, int *ppaloffset
, int *ppalnumcolors
);
253 PNGDIB_EXT
int PNGDIB_DECL
pngdib_p2d_get_colortype(PNGDIB
*p2d
);
254 PNGDIB_EXT
int PNGDIB_DECL
pngdib_p2d_get_bitspersample(PNGDIB
*p2d
);
255 PNGDIB_EXT
int PNGDIB_DECL
pngdib_p2d_get_bitsperpixel(PNGDIB
*p2d
);
256 PNGDIB_EXT
int PNGDIB_DECL
pngdib_p2d_get_samplesperpixel(PNGDIB
*p2d
);
257 PNGDIB_EXT
int PNGDIB_DECL
pngdib_p2d_get_interlace(PNGDIB
*p2d
);
258 PNGDIB_EXT
int PNGDIB_DECL
pngdib_p2d_get_density(PNGDIB
*p2d
, int *pres_x
, int *pres_y
, int *pres_units
);
259 PNGDIB_EXT
int PNGDIB_DECL
pngdib_p2d_get_file_gamma(PNGDIB
*p2d
, double *pgamma
);
260 PNGDIB_EXT
int PNGDIB_DECL
pngdib_p2d_get_bgcolor(PNGDIB
*p2d
, unsigned char *pr
, unsigned char *pg
, unsigned char *pb
);
262 PNGDIB_EXT
void PNGDIB_DECL
pngdib_p2d_free_dib(PNGDIB
*p2d
, BITMAPINFOHEADER
*pdib
);
264 //////////// common functions
266 PNGDIB_EXT PNGDIB
* PNGDIB_DECL
_pngdib_init(int structtype
, int caller_header_vers
);
268 PNGDIB_EXT
int PNGDIB_DECL
pngdib_done(PNGDIB
*xx
);
270 PNGDIB_EXT
void PNGDIB_DECL
pngdib_setcallback_malloc(PNGDIB
*xx
,
271 pngdib_malloc_cb_type mallocfunc
,
272 pngdib_free_cb_type freefunc
,
273 pngdib_realloc_cb_type reallocfunc
);
275 PNGDIB_EXT
void PNGDIB_DECL
pngdib_set_userdata(PNGDIB
*xx
, void *userdata
);
276 PNGDIB_EXT
void* PNGDIB_DECL
pngdib_get_userdata(PNGDIB
*xx
);
277 PNGDIB_EXT TCHAR
* PNGDIB_DECL
pngdib_get_error_msg(PNGDIB
*xx
);
279 PNGDIB_EXT TCHAR
* PNGDIB_DECL
pngdib_get_version_string(void);
280 PNGDIB_EXT
int PNGDIB_DECL
pngdib_get_version(void);
282 PNGDIB_EXT
void PNGDIB_DECL
pngdib_set_dibalpha32(PNGDIB
*xx
, int flag
);
291 #endif // PNGDIB_H_INCLUDED