Gnash  0.8.11dev
GnashImageJpeg.h
Go to the documentation of this file.
1 // GnashImageJpeg.h: Jpeg reader, for Gnash.
2 //
3 // Copyright (C) 2008, 2009, 2010, 2011, 2012
4 // Free Software Foundation, Inc.
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 //
20 //
21 // Original version by Thatcher Ulrich <tu@tulrich.com> 2002
22 //
23 
24 #ifndef GNASH_IMAGE_JPEG_H
25 #define GNASH_IMAGE_JPEG_H
26 
27 #include <csetjmp>
28 
29 #include "dsodefs.h"
30 #include "GnashImage.h"
31 
32 // jpeglib.h redefines HAVE_STDLIB_H. This silences
33 // the warnings, but it's not good.
34 #undef HAVE_STDLIB_H
35 extern "C" {
36 #include <jpeglib.h>
37 }
38 #undef HAVE_STDLIB_H
39 
40 // Forward declarations
41 namespace gnash { class IOChannel; }
42 
43 namespace gnash {
44 namespace image {
45 
47 //
49 class JpegInput : public Input
50 {
51 
52 private:
53 
54  const char* _errorOccurred;
55 
56  std::jmp_buf _jmpBuf;
57 
58  // State needed for input.
59  jpeg_decompress_struct m_cinfo;
60  jpeg_error_mgr m_jerr;
61 
62  bool _compressorOpened;
63 
64 public:
65 
67  //
71  DSOEXPORT JpegInput(boost::shared_ptr<IOChannel> in);
72 
74  //
78  void DSOEXPORT readHeader(unsigned int maxHeaderBytes);
79 
80  ~JpegInput();
81 
83  void read();
84 
86  //
90 
92  //
94  void finishImage();
95 
97  //
99  size_t getHeight() const;
100 
102  //
104  size_t getWidth() const;
105 
107  //
109  size_t getComponents() const;
110 
112  //
116  void readScanline(unsigned char* rgbData);
117 
119  //
121  static std::auto_ptr<Input> create(boost::shared_ptr<IOChannel> in)
122  {
123  std::auto_ptr<Input> ret(new JpegInput(in));
124  // might throw an exception (I guess)
125  if (ret.get()) ret->read();
126  return ret;
127  }
128 
132  //
136  DSOEXPORT static std::auto_ptr<GnashImage> readSWFJpeg2WithTables(
137  JpegInput& loader);
138 
140  //
142  //
145  static std::auto_ptr<JpegInput> createSWFJpeg2HeaderOnly(
146  boost::shared_ptr<IOChannel> in, unsigned int maxHeaderBytes)
147  {
148  std::auto_ptr<JpegInput> ret (new JpegInput(in));
149  // might throw an exception
150  if (ret.get()) ret->readHeader(maxHeaderBytes);
151  return ret;
152  }
153 
155  //
160  void errorOccurred(const char* msg);
161 
162 
163 };
164 
165 // Class for writing JPEG image data.
166 class JpegOutput : public Output
167 {
168 
169 public:
170 
172  //
177  JpegOutput(boost::shared_ptr<IOChannel> out, size_t width,
178  size_t height, int quality);
179 
180  ~JpegOutput();
181 
183  //
185  virtual void writeImageRGB(const unsigned char* rgbData);
186 
188  //
190  //
192  virtual void writeImageRGBA(const unsigned char* rgbaData);
193 
195  //
200  static std::auto_ptr<Output> create(boost::shared_ptr<IOChannel> out,
201  size_t width, size_t height, int quality);
202 
203 private:
204 
205  jpeg_compress_struct m_cinfo;
206  jpeg_error_mgr m_jerr;
207 
208 };
209 
210 } // namespace image
211 } // namespace gnash
212 
213 #endif // JPEG_H
214 
215 // Local Variables:
216 // mode: C++
217 // c-basic-offset: 8
218 // tab-width: 8
219 // indent-tabs-mode: t
220 // End:
Definition: GnashImageJpeg.h:166
~JpegOutput()
Definition: GnashImageJpeg.cpp:585
Definition: klash_part.cpp:329
void read()
Begin processing the image data.
Definition: GnashImageJpeg.cpp:299
static std::auto_ptr< Output > create(boost::shared_ptr< IOChannel > out, size_t width, size_t height, int quality)
Create a JpegOutput, transferring ownership to the caller.
Definition: GnashImageJpeg.cpp:623
size_t getWidth() const
Get the image&#39;s width in pixels.
Definition: GnashImageJpeg.cpp:383
DSOEXPORT void discardPartialBuffer()
Discard any data sitting in our input buffer.
Definition: GnashImageJpeg.cpp:244
Definition: klash_part.cpp:329
DSOEXPORT JpegInput(boost::shared_ptr< IOChannel > in)
Construct a JpegInput object to read from an IOChannel.
Definition: GnashImageJpeg.cpp:214
static std::auto_ptr< JpegInput > createSWFJpeg2HeaderOnly(boost::shared_ptr< IOChannel > in, unsigned int maxHeaderBytes)
Create a JPEG &#39;loader&#39; object by reading a JPEG header.
Definition: GnashImageJpeg.h:145
void DSOEXPORT readHeader(unsigned int maxHeaderBytes)
Read the JPEG header information only.
Definition: GnashImageJpeg.cpp:256
void readScanline(unsigned char *rgbData)
Read a scanline&#39;s worth of image data into the given buffer.
Definition: GnashImageJpeg.cpp:399
#define DSOEXPORT
Definition: dsodefs.h:55
virtual void writeImageRGB(const unsigned char *rgbData)
Write RGB image data using the parameters supplied at construction.
Definition: GnashImageJpeg.cpp:593
static DSOEXPORT std::auto_ptr< GnashImage > readSWFJpeg2WithTables(JpegInput &loader)
For reading SWF JPEG2-style image data, using pre-loaded headers stored in the given JpegInput object...
Definition: GnashImageJpeg.cpp:445
Definition: GnashImage.h:333
static std::auto_ptr< Input > create(boost::shared_ptr< IOChannel > in)
Create a JpegInput and transfer ownership to the caller.
Definition: GnashImageJpeg.h:121
void finishImage()
Complete processing the image and clean up.
Definition: GnashImageJpeg.cpp:357
Class for reading JPEG image data.
Definition: GnashImageJpeg.h:49
void errorOccurred(const char *msg)
This function is called when libjpeg encounters an error.
Definition: GnashImageJpeg.cpp:428
virtual void writeImageRGBA(const unsigned char *rgbaData)
Write RGBA image data using the parameters supplied at construction.
Definition: GnashImageJpeg.cpp:606
size_t getComponents() const
Get number of components (channels)
Definition: GnashImageJpeg.cpp:391
~JpegInput()
Definition: GnashImageJpeg.cpp:231
JpegOutput(boost::shared_ptr< IOChannel > out, size_t width, size_t height, int quality)
Constract a JpegOutput for writing to an IOChannel.
Definition: GnashImageJpeg.cpp:563
size_t getHeight() const
Get the image&#39;s height in pixels.
Definition: GnashImageJpeg.cpp:374
The base class for reading image data.
Definition: GnashImage.h:261