home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 July / CMCD0704.ISO / Software / Freeware / Utilitare / VisualBoyAdvance-1.7.2 / win32 / include / cximage / ximapng.h < prev    next >
C/C++ Source or Header  |  2004-02-29  |  3KB  |  91 lines

  1. /*
  2.  * File:    ximapng.h
  3.  * Purpose:    PNG Image Class Loader and Writer
  4.  */
  5. /* === C R E D I T S  &  D I S C L A I M E R S ==============
  6.  * CxImagePNG (c) 07/Aug/2001 Davide Pizzolato - www.xdp.it
  7.  * Permission is given by the author to freely redistribute and include
  8.  * this code in any program as long as this credit is given where due.
  9.  *
  10.  * CxImage version 5.99a 08/Feb/2004
  11.  * See the file history.htm for the complete bugfix and news report.
  12.  *
  13.  * Special thanks to Troels Knakkergaard for new features, enhancements and bugfixes
  14.  *
  15.  * original CImagePNG  and CImageIterator implementation are:
  16.  * Copyright:    (c) 1995, Alejandro Aguilar Sierra <asierra(at)servidor(dot)unam(dot)mx>
  17.  *
  18.  * libpng version 1.2.1 - December 12, 2001
  19.  * Copyright (c) 1998-2001 Glenn Randers-Pehrson
  20.  *
  21.  * COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
  22.  * OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
  23.  * THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
  24.  * OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
  25.  * CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
  26.  * THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
  27.  * SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
  28.  * PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
  29.  * THIS DISCLAIMER.
  30.  *
  31.  * Use at your own risk!
  32.  * ==========================================================
  33.  */
  34. #if !defined(__ximaPNG_h)
  35. #define __ximaPNG_h
  36.  
  37. #include "ximage.h"
  38.  
  39. #if CXIMAGE_SUPPORT_PNG
  40.  
  41. extern "C" {
  42. #include "../png/png.h"
  43. }
  44.  
  45. class CxImagePNG: public CxImage
  46. {
  47. public:
  48.     CxImagePNG(): CxImage(CXIMAGE_FORMAT_PNG) {}
  49.  
  50. //    bool Load(const char * imageFileName){ return CxImage::Load(imageFileName,CXIMAGE_FORMAT_PNG);}
  51. //    bool Save(const char * imageFileName){ return CxImage::Save(imageFileName,CXIMAGE_FORMAT_PNG);}
  52.     bool Decode(CxFile * hFile);
  53.     bool Decode(FILE *hFile) { CxIOFile file(hFile); return Decode(&file); }
  54.  
  55. #if CXIMAGE_SUPPORT_ENCODE
  56.     bool Encode(CxFile * hFile);
  57.     bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); }
  58. #endif // CXIMAGE_SUPPORT_ENCODE
  59.  
  60. protected:
  61.     void ima_png_error(png_struct *png_ptr, char *message);
  62.     void expand2to4bpp(BYTE* prow);
  63.  
  64.     static void user_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  65.     {
  66.         CxFile* hFile = (CxFile*)png_ptr->io_ptr;
  67.         if (hFile->Read(data,1,length) != length) png_error(png_ptr, "Read Error");
  68.     }
  69.  
  70.     static void user_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  71.     {
  72.         CxFile* hFile = (CxFile*)png_ptr->io_ptr;
  73.         if (hFile->Write(data,1,length) != length) png_error(png_ptr, "Write Error");
  74.     }
  75.  
  76.     static void user_flush_data(png_structp png_ptr)
  77.     {
  78.         CxFile* hFile = (CxFile*)png_ptr->io_ptr;
  79.         if (!hFile->Flush()) png_error(png_ptr, "Flush Error");
  80.     }
  81.     static void user_error_fn(png_structp png_ptr,png_const_charp error_msg)
  82.     {
  83.         strncpy((char*)png_ptr->error_ptr,error_msg,255);
  84.         longjmp(png_ptr->jmpbuf, 1);
  85.     }
  86. };
  87.  
  88. #endif
  89.  
  90. #endif
  91.