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

GnashImageJpeg.h

Go to the documentation of this file.
00001 // GnashImageJpeg.h:  Jpeg reader, for Gnash.
00002 // 
00003 //   Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
00004 // 
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 3 of the License, or
00008 // (at your option) any later version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 //
00019 //
00020 // Original version by Thatcher Ulrich <tu@tulrich.com> 2002
00021 //
00022 
00023 #ifndef GNASH_IMAGE_JPEG_H
00024 #define GNASH_IMAGE_JPEG_H
00025 
00026 #include "dsodefs.h"
00027 #include <csetjmp> // for jmp_buf
00028 #include "GnashImage.h"
00029 
00030 
00033 namespace jpeg {
00034 
00035 // jpeglib.h redefines HAVE_STDLIB_H. This silences
00036 // the warnings, but it's not good.
00037 #undef HAVE_STDLIB_H
00038 extern "C" {
00039 #include <jpeglib.h>
00040 }
00041 #undef HAVE_STDLIB_H
00042 
00043 }
00044 
00045 // Forward declarations
00046 namespace gnash { class IOChannel; }
00047 
00048 namespace gnash
00049 {
00050 
00052 //
00054 class JpegImageInput : public ImageInput
00055 {
00056 
00057 private:
00058 
00059     const char* _errorOccurred;
00060 
00061     std::jmp_buf _jmpBuf;
00062 
00063     // State needed for input.
00064     jpeg::jpeg_decompress_struct m_cinfo;
00065     jpeg::jpeg_error_mgr m_jerr;
00066 
00067     bool _compressorOpened;
00068 
00069 public:
00070 
00072     //
00076     DSOEXPORT JpegImageInput(boost::shared_ptr<IOChannel> in);
00077 
00079     //
00083     void DSOEXPORT readHeader(unsigned int maxHeaderBytes);
00084 
00085     ~JpegImageInput();
00086 
00088     void read();
00089 
00091     //
00094     DSOEXPORT void discardPartialBuffer();
00095 
00097     //
00099     void finishImage();
00100 
00102     //
00104     size_t getHeight() const;
00105 
00107     //
00109     size_t getWidth() const;
00110 
00112     //
00114     size_t getComponents() const;
00115 
00117     //
00121     void readScanline(unsigned char* rgbData);
00122 
00124     //
00126     static std::auto_ptr<ImageInput> create(boost::shared_ptr<IOChannel> in)
00127     {
00128         std::auto_ptr<ImageInput> ret(new JpegImageInput(in));
00129         // might throw an exception (I guess)
00130         if (ret.get()) ret->read();
00131         return ret;
00132     }
00133 
00137     //
00141     DSOEXPORT static std::auto_ptr<GnashImage> readSWFJpeg2WithTables(
00142             JpegImageInput& loader);
00143 
00145     //
00147     //
00150     static std::auto_ptr<JpegImageInput> createSWFJpeg2HeaderOnly(
00151             boost::shared_ptr<IOChannel> in, unsigned int maxHeaderBytes)
00152     {
00153         std::auto_ptr<JpegImageInput> ret (new JpegImageInput(in));
00154         // might throw an exception
00155         if (ret.get()) ret->readHeader(maxHeaderBytes);
00156         return ret;
00157     }
00158 
00160     //
00165     void errorOccurred(const char* msg);
00166 
00167 
00168 };
00169 
00170 // Class for writing JPEG image data.
00171 class JpegImageOutput : public ImageOutput
00172 {
00173 
00174 public:
00175 
00177     //
00182     JpegImageOutput(boost::shared_ptr<IOChannel> out, size_t width,
00183             size_t height, int quality);
00184     
00185     ~JpegImageOutput();
00186 
00188     //
00190     void writeImageRGB(const unsigned char* rgbData);
00191 
00193     //
00198     static std::auto_ptr<ImageOutput> create(boost::shared_ptr<IOChannel> out,
00199             size_t width, size_t height, int quality);
00200     
00201 private:
00202 
00203     jpeg::jpeg_compress_struct m_cinfo;
00204     jpeg::jpeg_error_mgr m_jerr;
00205     
00206 };
00207 
00208 } // namespace gnash
00209 
00210 
00211 #endif // JPEG_H
00212 
00213 // Local Variables:
00214 // mode: C++
00215 // c-basic-offset: 8 
00216 // tab-width: 8
00217 // indent-tabs-mode: t
00218 // End:

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