Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef GNASH_IMAGE_JPEG_H
00024 #define GNASH_IMAGE_JPEG_H
00025
00026 #include "dsodefs.h"
00027 #include <csetjmp>
00028 #include "GnashImage.h"
00029
00030
00033 namespace jpeg {
00034
00035
00036
00037 #undef HAVE_STDLIB_H
00038 extern "C" {
00039 #include <jpeglib.h>
00040 }
00041 #undef HAVE_STDLIB_H
00042
00043 }
00044
00045
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
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
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
00155 if (ret.get()) ret->readHeader(maxHeaderBytes);
00156 return ret;
00157 }
00158
00160
00165 void errorOccurred(const char* msg);
00166
00167
00168 };
00169
00170
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 }
00209
00210
00211 #endif // JPEG_H
00212
00213
00214
00215
00216
00217
00218