1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/image/decoders/nsJPEGDecoder.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,101 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef nsJPEGDecoder_h__ 1.11 +#define nsJPEGDecoder_h__ 1.12 + 1.13 +#include "RasterImage.h" 1.14 +/* On Windows systems, RasterImage.h brings in 'windows.h', which defines INT32. 1.15 + * But the jpeg decoder has its own definition of INT32. To avoid build issues, 1.16 + * we need to undefine the version from 'windows.h'. */ 1.17 +#undef INT32 1.18 + 1.19 +#include "Decoder.h" 1.20 + 1.21 +#include "nsAutoPtr.h" 1.22 + 1.23 +#include "nsIInputStream.h" 1.24 +#include "nsIPipe.h" 1.25 +#include "qcms.h" 1.26 + 1.27 +extern "C" { 1.28 +#include "jpeglib.h" 1.29 +} 1.30 + 1.31 +#include <setjmp.h> 1.32 + 1.33 +namespace mozilla { 1.34 +namespace image { 1.35 + 1.36 +typedef struct { 1.37 + struct jpeg_error_mgr pub; /* "public" fields for IJG library*/ 1.38 + jmp_buf setjmp_buffer; /* For handling catastropic errors */ 1.39 +} decoder_error_mgr; 1.40 + 1.41 +typedef enum { 1.42 + JPEG_HEADER, /* Reading JFIF headers */ 1.43 + JPEG_START_DECOMPRESS, 1.44 + JPEG_DECOMPRESS_PROGRESSIVE, /* Output progressive pixels */ 1.45 + JPEG_DECOMPRESS_SEQUENTIAL, /* Output sequential pixels */ 1.46 + JPEG_DONE, 1.47 + JPEG_SINK_NON_JPEG_TRAILER, /* Some image files have a */ 1.48 + /* non-JPEG trailer */ 1.49 + JPEG_ERROR 1.50 +} jstate; 1.51 + 1.52 +class RasterImage; 1.53 +class Orientation; 1.54 + 1.55 +class nsJPEGDecoder : public Decoder 1.56 +{ 1.57 +public: 1.58 + nsJPEGDecoder(RasterImage &aImage, Decoder::DecodeStyle aDecodeStyle); 1.59 + virtual ~nsJPEGDecoder(); 1.60 + 1.61 + virtual void InitInternal(); 1.62 + virtual void WriteInternal(const char* aBuffer, uint32_t aCount, DecodeStrategy aStrategy); 1.63 + virtual void FinishInternal(); 1.64 + 1.65 + virtual Telemetry::ID SpeedHistogram(); 1.66 + void NotifyDone(); 1.67 + 1.68 +protected: 1.69 + Orientation ReadOrientationFromEXIF(); 1.70 + void OutputScanlines(bool* suspend); 1.71 + 1.72 +public: 1.73 + struct jpeg_decompress_struct mInfo; 1.74 + struct jpeg_source_mgr mSourceMgr; 1.75 + decoder_error_mgr mErr; 1.76 + jstate mState; 1.77 + 1.78 + uint32_t mBytesToSkip; 1.79 + 1.80 + const JOCTET *mSegment; // The current segment we are decoding from 1.81 + uint32_t mSegmentLen; // amount of data in mSegment 1.82 + 1.83 + JOCTET *mBackBuffer; 1.84 + uint32_t mBackBufferLen; // Offset of end of active backtrack data 1.85 + uint32_t mBackBufferSize; // size in bytes what mBackBuffer was created with 1.86 + uint32_t mBackBufferUnreadLen; // amount of data currently in mBackBuffer 1.87 + 1.88 + JOCTET *mProfile; 1.89 + uint32_t mProfileLength; 1.90 + 1.91 + qcms_profile *mInProfile; 1.92 + qcms_transform *mTransform; 1.93 + 1.94 + bool mReading; 1.95 + 1.96 + const Decoder::DecodeStyle mDecodeStyle; 1.97 + 1.98 + uint32_t mCMSMode; 1.99 +}; 1.100 + 1.101 +} // namespace image 1.102 +} // namespace mozilla 1.103 + 1.104 +#endif // nsJPEGDecoder_h__