• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

GnashImagePng.h

Go to the documentation of this file.
00001 // GnashImagePng.h: libpng wrapper for Gnash.
00002 // 
00003 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
00004 //   Foundation, Inc
00005 // 
00006 // This program is free software; you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License as published by
00008 // the Free Software Foundation; either version 3 of the License, or
00009 // (at your option) any later version.
00010 // 
00011 // This program is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 // 
00016 // You should have received a copy of the GNU General Public License
00017 // along with this program; if not, write to the Free Software
00018 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019 //
00020 
00021 #ifndef GNASH_IMAGE_PNG_H
00022 #define GNASH_IMAGE_PNG_H
00023 
00024 #include <memory>
00025 
00026 #include "dsodefs.h"
00027 #include "GnashImage.h"
00028 #include <boost/scoped_array.hpp>
00029 
00030 
00031 extern "C" {
00032 #ifdef HAVE_PNG_H
00033 #include <png.h>
00034 #else
00035 #warning "This system doesn't have png.h installed!"
00036 #endif
00037 }
00038 
00039 // Forward declarations
00040 namespace gnash { class IOChannel; }
00041 
00042 namespace gnash {
00043 
00044 class PngImageInput : public ImageInput
00045 {
00046 
00047 public:
00048 
00050     //
00054     PngImageInput(boost::shared_ptr<IOChannel> in);
00055     
00056     ~PngImageInput();
00057     
00059     void read();
00060 
00062     //
00064     size_t getHeight() const;
00065 
00067     //
00069     size_t getWidth() const;
00070 
00072     //
00076     void readScanline(unsigned char* imageData);
00077 
00079     //
00081     DSOEXPORT static std::auto_ptr<ImageInput> create(
00082             boost::shared_ptr<IOChannel> in)
00083     {
00084         std::auto_ptr<ImageInput> ret ( new PngImageInput(in) );
00085         if (ret.get()) ret->read();
00086         return ret;
00087     }
00088 
00089 private:
00090 
00091     // State needed for input.
00092     png_structp _pngPtr;
00093     png_infop _infoPtr;
00094     boost::scoped_array<png_bytep> _rowPtrs;
00095     boost::scoped_array<png_byte> _pixelData;
00096    
00097     // A counter for keeping track of the last row copied.
00098     size_t _currentRow;
00099 
00100     void init();
00101 
00102     // Return number of components (i.e. == 3 for RGB
00103     // data).
00104     size_t getComponents() const;
00105 
00106 };
00107 
00108 // Class object for writing PNG image data.
00109 class PngImageOutput : public ImageOutput
00110 {
00111 
00112 public:
00113 
00115     //
00119     PngImageOutput(boost::shared_ptr<IOChannel> out, size_t width,
00120             size_t height, int quality);
00121     
00122     ~PngImageOutput();
00123 
00124     void writeImageRGB(const unsigned char* rgbData);
00125     
00126     void writeImageRGBA(const unsigned char* rgbaData);
00127 
00128     static std::auto_ptr<ImageOutput> create(boost::shared_ptr<IOChannel> out,
00129             size_t width, size_t height, int quality);
00130     
00131 private:
00132 
00134     void init();
00135 
00137     png_structp _pngPtr;
00138     png_infop _infoPtr;
00139     
00140 };
00141 
00142 } // namespace gnash
00143 
00144 
00145 
00146 #endif

Generated on Thu Sep 30 2010 14:34:58 for Gnash by  doxygen 1.7.1