source: liacs/MIR2010/SourceCode/cximage/ximapng.h@ 292

Last change on this file since 292 was 95, checked in by Rick van der Zwet, 15 years ago

Bad boy, improper move of directory

File size: 2.3 KB
Line 
1/*
2 * File: ximapng.h
3 * Purpose: PNG Image Class Loader and Writer
4 */
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
8 *
9 * Special thanks to Troels Knakkergaard for new features, enhancements and bugfixes
10 *
11 * original CImagePNG and CImageIterator implementation are:
12 * Copyright: (c) 1995, Alejandro Aguilar Sierra <asierra(at)servidor(dot)unam(dot)mx>
13 *
14 * libpng Copyright (c) 1998-2003 Glenn Randers-Pehrson
15 * ==========================================================
16 */
17#if !defined(__ximaPNG_h)
18#define __ximaPNG_h
19
20#include "ximage.h"
21
22#if CXIMAGE_SUPPORT_PNG
23
24extern "C" {
25#include "png/png.h"
26}
27
28class CxImagePNG: public CxImage
29{
30public:
31 CxImagePNG(): CxImage(CXIMAGE_FORMAT_PNG) {}
32
33// bool Load(const TCHAR * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_PNG);}
34// bool Save(const TCHAR * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_PNG);}
35 bool Decode(CxFile * hFile);
36 bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); }
37
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
42
43protected:
44 void ima_png_error(png_struct *png_ptr, char *message);
45 void expand2to4bpp(BYTE* prow);
46
47 static void PNGAPI user_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
48 {
49 CxFile* hFile = (CxFile*)png_get_io_ptr(png_ptr);
50 if (hFile == NULL || hFile->Read(data,1,length) != length) png_error(png_ptr, "Read Error");
51 }
52
53 static void PNGAPI user_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
54 {
55 CxFile* hFile = (CxFile*)png_get_io_ptr(png_ptr);
56 if (hFile == NULL || hFile->Write(data,1,length) != length) png_error(png_ptr, "Write Error");
57 }
58
59 static void PNGAPI user_flush_data(png_structp png_ptr)
60 {
61 CxFile* hFile = (CxFile*)png_get_io_ptr(png_ptr);
62 if (hFile == NULL || !hFile->Flush()) png_error(png_ptr, "Flush Error");
63 }
64
65 static void PNGAPI user_error_fn(png_structp png_ptr,png_const_charp error_msg)
66 {
67 strncpy((char*)png_ptr->error_ptr,error_msg,255);
68 longjmp(png_ptr->jmpbuf, 1);
69 }
70};
71
72#endif
73
74#endif
Note: See TracBrowser for help on using the repository browser.