~ubuntu-branches/ubuntu/gutsy/amsn/gutsy

« back to all changes in this revision

Viewing changes to utils/TkCximage/src/CxImage/ximapng.h

  • Committer: Bazaar Package Importer
  • Author(s): Theodore Karkoulis
  • Date: 2006-01-04 15:26:02 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060104152602-ipe1yg00rl3nlklv
Tags: 0.95-1
New Upstream Release (closes: #345052, #278575).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
24
extern "C" {
 
25
#include "../png/png.h"
 
26
}
 
27
 
 
28
class CxImagePNG: public CxImage
 
29
{
 
30
public:
 
31
        CxImagePNG(): CxImage(CXIMAGE_FORMAT_PNG) {}
 
32
 
 
33
//      bool Load(const char * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_PNG);}
 
34
//      bool Save(const char * 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
 
 
43
protected:
 
44
        void ima_png_error(png_struct *png_ptr, char *message);
 
45
        void expand2to4bpp(BYTE* prow);
 
46
 
 
47
        static void user_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
 
48
        {
 
49
                CxFile* hFile = (CxFile*)png_ptr->io_ptr;
 
50
                if (hFile->Read(data,1,length) != length) png_error(png_ptr, "Read Error");
 
51
        }
 
52
 
 
53
        static void user_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
 
54
        {
 
55
                CxFile* hFile = (CxFile*)png_ptr->io_ptr;
 
56
                if (hFile->Write(data,1,length) != length) png_error(png_ptr, "Write Error");
 
57
        }
 
58
 
 
59
        static void user_flush_data(png_structp png_ptr)
 
60
        {
 
61
                CxFile* hFile = (CxFile*)png_ptr->io_ptr;
 
62
                if (!hFile->Flush()) png_error(png_ptr, "Flush Error");
 
63
        }
 
64
    static void user_error_fn(png_structp png_ptr,png_const_charp error_msg)
 
65
        {
 
66
                strncpy((char*)png_ptr->error_ptr,error_msg,255);
 
67
                longjmp(png_ptr->jmpbuf, 1);
 
68
        }
 
69
};
 
70
 
 
71
#endif
 
72
 
 
73
#endif