3
* Purpose: PNG Image Class Loader and Writer
5
/* ==========================================================
6
* CxImagePNG (c) 07/Aug/2001 Davide Pizzolato - www.xdp.it
7
* For conditions of distribution and use, see copyright notice in ximage.h
9
* Special thanks to Troels Knakkergaard for new features, enhancements and bugfixes
11
* original CImagePNG and CImageIterator implementation are:
12
* Copyright: (c) 1995, Alejandro Aguilar Sierra <asierra(at)servidor(dot)unam(dot)mx>
14
* libpng Copyright (c) 1998-2003 Glenn Randers-Pehrson
15
* ==========================================================
17
#if !defined(__ximaPNG_h)
22
#if CXIMAGE_SUPPORT_PNG
25
#include "../png/png.h"
28
class CxImagePNG: public CxImage
31
CxImagePNG(): CxImage(CXIMAGE_FORMAT_PNG) {}
33
// bool Load(const char * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_PNG);}
34
// bool Save(const char * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_PNG);}
35
bool Decode(CxFile * hFile);
36
bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); }
38
#if CXIMAGE_SUPPORT_ENCODE
39
bool Encode(CxFile * hFile);
40
bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); }
41
#endif // CXIMAGE_SUPPORT_ENCODE
44
void ima_png_error(png_struct *png_ptr, char *message);
45
void expand2to4bpp(BYTE* prow);
47
static void user_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
49
CxFile* hFile = (CxFile*)png_ptr->io_ptr;
50
if (hFile->Read(data,1,length) != length) png_error(png_ptr, "Read Error");
53
static void user_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
55
CxFile* hFile = (CxFile*)png_ptr->io_ptr;
56
if (hFile->Write(data,1,length) != length) png_error(png_ptr, "Write Error");
59
static void user_flush_data(png_structp png_ptr)
61
CxFile* hFile = (CxFile*)png_ptr->io_ptr;
62
if (!hFile->Flush()) png_error(png_ptr, "Flush Error");
64
static void user_error_fn(png_structp png_ptr,png_const_charp error_msg)
66
strncpy((char*)png_ptr->error_ptr,error_msg,255);
67
longjmp(png_ptr->jmpbuf, 1);