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