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 DSOEXPORT 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(std::shared_ptr<IOChannel> in);
72 
74  //
78  void DSOEXPORT readHeader(unsigned int maxHeaderBytes);
79 
80  ~JpegInput();
81 
83  void read();
84 
86  //
89  DSOEXPORT void discardPartialBuffer();
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::unique_ptr<Input> create(std::shared_ptr<IOChannel> in)
122  {
123  std::unique_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::unique_ptr<GnashImage> readSWFJpeg2WithTables(
137  JpegInput& loader);
138 
140  //
142  //
145  static std::unique_ptr<JpegInput> createSWFJpeg2HeaderOnly(
146  std::shared_ptr<IOChannel> in, unsigned int maxHeaderBytes)
147  {
148  std::unique_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(std::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::unique_ptr<Output> create(std::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
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
Definition: klash_part.cpp:329
static std::unique_ptr< Input > create(std::shared_ptr< IOChannel > in)
Create a JpegInput and transfer ownership to the caller.
Definition: GnashImageJpeg.h:121
Definition: klash_part.cpp:329
#define DSOEXPORT
Definition: dsodefs.h:55
Definition: GnashImage.h:331
Class for reading JPEG image data.
Definition: GnashImageJpeg.h:49
static std::unique_ptr< JpegInput > createSWFJpeg2HeaderOnly(std::shared_ptr< IOChannel > in, unsigned int maxHeaderBytes)
Create a JPEG &#39;loader&#39; object by reading a JPEG header.
Definition: GnashImageJpeg.h:145
The base class for reading image data.
Definition: GnashImage.h:259
as_value getHeight(DisplayObject &o)
Definition: DisplayObject.cpp:356