Gnash 0.8.10dev
GnashImageJpeg.h
Go to the documentation of this file.
00001 // GnashImageJpeg.h:  Jpeg reader, for Gnash.
00002 // 
00003 //   Copyright (C) 2008, 2009, 2010, 2011 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 <csetjmp>
00027 
00028 #include "dsodefs.h"
00029 #include "GnashImage.h"
00030 
00031 // jpeglib.h redefines HAVE_STDLIB_H. This silences
00032 // the warnings, but it's not good.
00033 #undef HAVE_STDLIB_H
00034 extern "C" {
00035 #include <jpeglib.h>
00036 }
00037 #undef HAVE_STDLIB_H
00038 
00039 // Forward declarations
00040 namespace gnash { class IOChannel; }
00041 
00042 namespace gnash {
00043 namespace image {
00044 
00046 //
00048 class JpegInput : public Input
00049 {
00050 
00051 private:
00052 
00053     const char* _errorOccurred;
00054 
00055     std::jmp_buf _jmpBuf;
00056 
00057     // State needed for input.
00058     jpeg_decompress_struct m_cinfo;
00059     jpeg_error_mgr m_jerr;
00060 
00061     bool _compressorOpened;
00062 
00063 public:
00064 
00066     //
00070     DSOEXPORT JpegInput(boost::shared_ptr<IOChannel> in);
00071 
00073     //
00077     void DSOEXPORT readHeader(unsigned int maxHeaderBytes);
00078 
00079     ~JpegInput();
00080 
00082     void read();
00083 
00085     //
00088     DSOEXPORT void discardPartialBuffer();
00089 
00091     //
00093     void finishImage();
00094 
00096     //
00098     size_t getHeight() const;
00099 
00101     //
00103     size_t getWidth() const;
00104 
00106     //
00108     size_t getComponents() const;
00109 
00111     //
00115     void readScanline(unsigned char* rgbData);
00116 
00118     //
00120     static std::auto_ptr<Input> create(boost::shared_ptr<IOChannel> in)
00121     {
00122         std::auto_ptr<Input> ret(new JpegInput(in));
00123         // might throw an exception (I guess)
00124         if (ret.get()) ret->read();
00125         return ret;
00126     }
00127 
00131     //
00135     DSOEXPORT static std::auto_ptr<GnashImage> readSWFJpeg2WithTables(
00136             JpegInput& loader);
00137 
00139     //
00141     //
00144     static std::auto_ptr<JpegInput> createSWFJpeg2HeaderOnly(
00145             boost::shared_ptr<IOChannel> in, unsigned int maxHeaderBytes)
00146     {
00147         std::auto_ptr<JpegInput> ret (new JpegInput(in));
00148         // might throw an exception
00149         if (ret.get()) ret->readHeader(maxHeaderBytes);
00150         return ret;
00151     }
00152 
00154     //
00159     void errorOccurred(const char* msg);
00160 
00161 
00162 };
00163 
00164 // Class for writing JPEG image data.
00165 class JpegOutput : public Output
00166 {
00167 
00168 public:
00169 
00171     //
00176     JpegOutput(boost::shared_ptr<IOChannel> out, size_t width,
00177             size_t height, int quality);
00178     
00179     ~JpegOutput();
00180 
00182     //
00184     virtual void writeImageRGB(const unsigned char* rgbData);
00185 
00187     //
00189     //
00191     virtual void writeImageRGBA(const unsigned char* rgbaData);
00192 
00194     //
00199     static std::auto_ptr<Output> create(boost::shared_ptr<IOChannel> out,
00200             size_t width, size_t height, int quality);
00201     
00202 private:
00203 
00204     jpeg_compress_struct m_cinfo;
00205     jpeg_error_mgr m_jerr;
00206     
00207 };
00208 
00209 } // namespace image
00210 } // namespace gnash
00211 
00212 #endif // JPEG_H
00213 
00214 // Local Variables:
00215 // mode: C++
00216 // c-basic-offset: 8 
00217 // tab-width: 8
00218 // indent-tabs-mode: t
00219 // End: