]> Creatis software - clitk.git/blob - utilities/CxImage/ximapng.h
3fddf5b64febe1a7459550530031a66aeb3a16d1
[clitk.git] / utilities / CxImage / ximapng.h
1 /*\r
2  * File:        ximapng.h\r
3  * Purpose:     PNG Image Class Loader and Writer\r
4  */\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
8  *\r
9  * Special thanks to Troels Knakkergaard for new features, enhancements and bugfixes\r
10  *\r
11  * original CImagePNG  and CImageIterator implementation are:\r
12  * Copyright:   (c) 1995, Alejandro Aguilar Sierra <asierra(at)servidor(dot)unam(dot)mx>\r
13  *\r
14  * libpng Copyright (c) 1998-2003 Glenn Randers-Pehrson\r
15  * ==========================================================\r
16  */\r
17 #if !defined(__ximaPNG_h)\r
18 #define __ximaPNG_h\r
19 \r
20 #include "ximage.h"\r
21 \r
22 #if CXIMAGE_SUPPORT_PNG\r
23 \r
24 extern "C" {\r
25 #include "../png/png.h"\r
26 }\r
27 \r
28 class CxImagePNG: public CxImage\r
29 {\r
30 public:\r
31         CxImagePNG(): CxImage(CXIMAGE_FORMAT_PNG) {}\r
32 \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
37 \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
42 \r
43 protected:\r
44         void ima_png_error(png_struct *png_ptr, char *message);\r
45         void expand2to4bpp(BYTE* prow);\r
46 \r
47         static void PNGAPI user_read_data(png_structp png_ptr, png_bytep data, png_size_t length)\r
48         {\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
51         }\r
52 \r
53         static void PNGAPI user_write_data(png_structp png_ptr, png_bytep data, png_size_t length)\r
54         {\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
57         }\r
58 \r
59         static void PNGAPI user_flush_data(png_structp png_ptr)\r
60         {\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
63         }\r
64 \r
65     static void PNGAPI user_error_fn(png_structp png_ptr,png_const_charp error_msg)\r
66         {\r
67                 strncpy((char*)png_ptr->error_ptr,error_msg,255);\r
68                 longjmp(png_ptr->jmpbuf, 1);\r
69         }\r
70 };\r
71 \r
72 #endif\r
73 \r
74 #endif\r