From c91847d549cc1c30eb15504a15ea9a6d5aa48165 Mon Sep 17 00:00:00 2001 From: "chirs241097@gmail.com" Date: Sun, 12 Jan 2014 14:43:14 +0000 Subject: --- hge/CxImage/ximapng.h | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 hge/CxImage/ximapng.h (limited to 'hge/CxImage/ximapng.h') diff --git a/hge/CxImage/ximapng.h b/hge/CxImage/ximapng.h new file mode 100644 index 0000000..262ea02 --- /dev/null +++ b/hge/CxImage/ximapng.h @@ -0,0 +1,95 @@ +/* + * File: ximapng.h + * Purpose: PNG Image Class Loader and Writer + */ +/* ========================================================== + * CxImagePNG (c) 07/Aug/2001 Davide Pizzolato - www.xdp.it + * For conditions of distribution and use, see copyright notice in ximage.h + * + * Special thanks to Troels Knakkergaard for new features, enhancements and bugfixes + * + * original CImagePNG and CImageIterator implementation are: + * Copyright: (c) 1995, Alejandro Aguilar Sierra + * + * libpng Copyright (c) 1998-2003 Glenn Randers-Pehrson + * ========================================================== + */ +#if !defined(__ximaPNG_h) +#define __ximaPNG_h + +#include "ximage.h" + +#if CXIMAGE_SUPPORT_PNG + +extern "C" { +#ifdef _LINUX + #undef _DLL + #include +#else + #include "../png/png.h" +#endif +} + +class CxImagePNG: public CxImage +{ +public: + CxImagePNG(): CxImage(CXIMAGE_FORMAT_PNG) {} + +// bool Load(const TCHAR * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_PNG);} +// bool Save(const TCHAR * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_PNG);} + bool Decode(CxFile * hFile); + bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); } + +#if CXIMAGE_SUPPORT_ENCODE + bool Encode(CxFile * hFile); + bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); } +#endif // CXIMAGE_SUPPORT_ENCODE + + enum CODEC_OPTION + { + ENCODE_INTERLACE = 0x01, + // Exclusive compression types : 3 bit wide field + ENCODE_COMPRESSION_MASK = 0x0E, + ENCODE_NO_COMPRESSION = 1 << 1, + ENCODE_BEST_SPEED = 2 << 1, + ENCODE_BEST_COMPRESSION = 3 << 1, + ENCODE_DEFAULT_COMPRESSION = 4 << 1 + }; + +protected: + void ima_png_error(png_struct *png_ptr, char *message); + void expand2to4bpp(uint8_t* prow); + + static void PNGAPI user_read_data(png_structp png_ptr, png_bytep data, png_size_t length) + { + CxFile* hFile = (CxFile*)png_get_io_ptr(png_ptr); + if (hFile == NULL || hFile->Read(data,1,length) != length) png_error(png_ptr, "Read Error"); + } + + static void PNGAPI user_write_data(png_structp png_ptr, png_bytep data, png_size_t length) + { + CxFile* hFile = (CxFile*)png_get_io_ptr(png_ptr); + if (hFile == NULL || hFile->Write(data,1,length) != length) png_error(png_ptr, "Write Error"); + } + + static void PNGAPI user_flush_data(png_structp png_ptr) + { + CxFile* hFile = (CxFile*)png_get_io_ptr(png_ptr); + if (hFile == NULL || !hFile->Flush()) png_error(png_ptr, "Flush Error"); + } + + static void PNGAPI user_error_fn(png_structp png_ptr,png_const_charp error_msg) + { +#if PNG_LIBPNG_VER > 10399 + strncpy((char*)png_get_error_ptr(png_ptr),error_msg,255); + longjmp(png_jmpbuf(png_ptr), 1); +#else + strncpy((char*)png_ptr->error_ptr,error_msg,255); + longjmp(png_ptr->jmpbuf, 1); +#endif + } +}; + +#endif + +#endif -- cgit v1.2.3