• 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 {
00041     class IOChannel;
00042 }
00043 
00044 namespace gnash {
00045 namespace image {
00046 
00047 class PngInput : public Input
00048 {
00049 
00050 public:
00051 
00053     //
00057     PngInput(boost::shared_ptr<IOChannel> in);
00058     
00059     ~PngInput();
00060     
00062     void read();
00063 
00065     //
00067     size_t getHeight() const;
00068 
00070     //
00072     size_t getWidth() const;
00073 
00075     //
00079     void readScanline(unsigned char* imageData);
00080 
00082     //
00084     DSOEXPORT static std::auto_ptr<Input> create(
00085             boost::shared_ptr<IOChannel> in)
00086     {
00087         std::auto_ptr<Input> ret ( new PngInput(in) );
00088         if (ret.get()) ret->read();
00089         return ret;
00090     }
00091 
00092 private:
00093 
00094     // State needed for input.
00095     png_structp _pngPtr;
00096     png_infop _infoPtr;
00097     boost::scoped_array<png_bytep> _rowPtrs;
00098     boost::scoped_array<png_byte> _pixelData;
00099    
00100     // A counter for keeping track of the last row copied.
00101     size_t _currentRow;
00102 
00103     void init();
00104 
00105     // Return number of components (i.e. == 3 for RGB
00106     // data).
00107     size_t getComponents() const;
00108 
00109 };
00110 
00111 // Class object for writing PNG image data.
00112 class PngOutput : public Output
00113 {
00114 
00115 public:
00116 
00118     //
00122     PngOutput(boost::shared_ptr<IOChannel> out, size_t width,
00123             size_t height, int quality);
00124     
00125     ~PngOutput();
00126 
00127     void writeImageRGB(const unsigned char* rgbData);
00128     
00129     void writeImageRGBA(const unsigned char* rgbaData);
00130 
00131     static std::auto_ptr<Output> create(boost::shared_ptr<IOChannel> out,
00132             size_t width, size_t height, int quality);
00133     
00134 private:
00135 
00137     void init();
00138 
00140     png_structp _pngPtr;
00141     png_infop _infoPtr;
00142     
00143 };
00144 
00145 } // namespace image
00146 } // namespace gnash
00147 
00148 
00149 
00150 #endif

Generated on Thu Sep 2 2010 for Gnash by  doxygen 1.7.1