+/*\r
+ * File: ximapng.h\r
+ * Purpose: PNG Image Class Loader and Writer\r
+ */\r
+/* ==========================================================\r
+ * CxImagePNG (c) 07/Aug/2001 Davide Pizzolato - www.xdp.it\r
+ * For conditions of distribution and use, see copyright notice in ximage.h\r
+ *\r
+ * Special thanks to Troels Knakkergaard for new features, enhancements and bugfixes\r
+ *\r
+ * original CImagePNG and CImageIterator implementation are:\r
+ * Copyright: (c) 1995, Alejandro Aguilar Sierra <asierra(at)servidor(dot)unam(dot)mx>\r
+ *\r
+ * libpng Copyright (c) 1998-2003 Glenn Randers-Pehrson\r
+ * ==========================================================\r
+ */\r
+#if !defined(__ximaPNG_h)\r
+#define __ximaPNG_h\r
+\r
+#include "ximage.h"\r
+\r
+#if CXIMAGE_SUPPORT_PNG\r
+\r
+extern "C" {\r
+#include "../png/png.h"\r
+}\r
+\r
+class CxImagePNG: public CxImage\r
+{\r
+public:\r
+ CxImagePNG(): CxImage(CXIMAGE_FORMAT_PNG) {}\r
+\r
+// bool Load(const TCHAR * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_PNG);}\r
+// bool Save(const TCHAR * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_PNG);}\r
+ bool Decode(CxFile * hFile);\r
+ bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); }\r
+\r
+#if CXIMAGE_SUPPORT_ENCODE\r
+ bool Encode(CxFile * hFile);\r
+ bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); }\r
+#endif // CXIMAGE_SUPPORT_ENCODE\r
+\r
+protected:\r
+ void ima_png_error(png_struct *png_ptr, char *message);\r
+ void expand2to4bpp(BYTE* prow);\r
+\r
+ static void PNGAPI user_read_data(png_structp png_ptr, png_bytep data, png_size_t length)\r
+ {\r
+ CxFile* hFile = (CxFile*)png_get_io_ptr(png_ptr);\r
+ if (hFile == NULL || hFile->Read(data,1,length) != length) png_error(png_ptr, "Read Error");\r
+ }\r
+\r
+ static void PNGAPI user_write_data(png_structp png_ptr, png_bytep data, png_size_t length)\r
+ {\r
+ CxFile* hFile = (CxFile*)png_get_io_ptr(png_ptr);\r
+ if (hFile == NULL || hFile->Write(data,1,length) != length) png_error(png_ptr, "Write Error");\r
+ }\r
+\r
+ static void PNGAPI user_flush_data(png_structp png_ptr)\r
+ {\r
+ CxFile* hFile = (CxFile*)png_get_io_ptr(png_ptr);\r
+ if (hFile == NULL || !hFile->Flush()) png_error(png_ptr, "Flush Error");\r
+ }\r
+\r
+ static void PNGAPI user_error_fn(png_structp png_ptr,png_const_charp error_msg)\r
+ {\r
+ strncpy((char*)png_ptr->error_ptr,error_msg,255);\r
+ longjmp(png_ptr->jmpbuf, 1);\r
+ }\r
+};\r
+\r
+#endif\r
+\r
+#endif\r