Gnash  0.8.10
GnashImageJpeg.h
Go to the documentation of this file.
00001 // GnashImageJpeg.h:  Jpeg reader, for Gnash.
00002 // 
00003 //   Copyright (C) 2008, 2009, 2010, 2011, 2012
00004 //   Free Software 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 // Original version by Thatcher Ulrich <tu@tulrich.com> 2002
00022 //
00023 
00024 #ifndef GNASH_IMAGE_JPEG_H
00025 #define GNASH_IMAGE_JPEG_H
00026 
00027 #include <csetjmp>
00028 
00029 #include "dsodefs.h"
00030 #include "GnashImage.h"
00031 
00032 // jpeglib.h redefines HAVE_STDLIB_H. This silences
00033 // the warnings, but it's not good.
00034 #undef HAVE_STDLIB_H
00035 extern "C" {
00036 #include <jpeglib.h>
00037 }
00038 #undef HAVE_STDLIB_H
00039 
00040 // Forward declarations
00041 namespace gnash { class IOChannel; }
00042 
00043 namespace gnash {
00044 namespace image {
00045 
00047 //
00049 class JpegInput : public Input
00050 {
00051 
00052 private:
00053 
00054     const char* _errorOccurred;
00055 
00056     std::jmp_buf _jmpBuf;
00057 
00058     // State needed for input.
00059     jpeg_decompress_struct m_cinfo;
00060     jpeg_error_mgr m_jerr;
00061 
00062     bool _compressorOpened;
00063 
00064 public:
00065 
00067     //
00071     DSOEXPORT JpegInput(boost::shared_ptr<IOChannel> in);
00072 
00074     //
00078     void DSOEXPORT readHeader(unsigned int maxHeaderBytes);
00079 
00080     ~JpegInput();
00081 
00083     void read();
00084 
00086     //
00089     DSOEXPORT void discardPartialBuffer();
00090 
00092     //
00094     void finishImage();
00095 
00097     //
00099     size_t getHeight() const;
00100 
00102     //
00104     size_t getWidth() const;
00105 
00107     //
00109     size_t getComponents() const;
00110 
00112     //
00116     void readScanline(unsigned char* rgbData);
00117 
00119     //
00121     static std::auto_ptr<Input> create(boost::shared_ptr<IOChannel> in)
00122     {
00123         std::auto_ptr<Input> ret(new JpegInput(in));
00124         // might throw an exception (I guess)
00125         if (ret.get()) ret->read();
00126         return ret;
00127     }
00128 
00132     //
00136     DSOEXPORT static std::auto_ptr<GnashImage> readSWFJpeg2WithTables(
00137             JpegInput& loader);
00138 
00140     //
00142     //
00145     static std::auto_ptr<JpegInput> createSWFJpeg2HeaderOnly(
00146             boost::shared_ptr<IOChannel> in, unsigned int maxHeaderBytes)
00147     {
00148         std::auto_ptr<JpegInput> ret (new JpegInput(in));
00149         // might throw an exception
00150         if (ret.get()) ret->readHeader(maxHeaderBytes);
00151         return ret;
00152     }
00153 
00155     //
00160     void errorOccurred(const char* msg);
00161 
00162 
00163 };
00164 
00165 // Class for writing JPEG image data.
00166 class JpegOutput : public Output
00167 {
00168 
00169 public:
00170 
00172     //
00177     JpegOutput(boost::shared_ptr<IOChannel> out, size_t width,
00178             size_t height, int quality);
00179     
00180     ~JpegOutput();
00181 
00183     //
00185     virtual void writeImageRGB(const unsigned char* rgbData);
00186 
00188     //
00190     //
00192     virtual void writeImageRGBA(const unsigned char* rgbaData);
00193 
00195     //
00200     static std::auto_ptr<Output> create(boost::shared_ptr<IOChannel> out,
00201             size_t width, size_t height, int quality);
00202     
00203 private:
00204 
00205     jpeg_compress_struct m_cinfo;
00206     jpeg_error_mgr m_jerr;
00207     
00208 };
00209 
00210 } // namespace image
00211 } // namespace gnash
00212 
00213 #endif // JPEG_H
00214 
00215 // Local Variables:
00216 // mode: C++
00217 // c-basic-offset: 8 
00218 // tab-width: 8
00219 // indent-tabs-mode: t
00220 // End: