michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsJPEGDecoder_h__ michael@0: #define nsJPEGDecoder_h__ michael@0: michael@0: #include "RasterImage.h" michael@0: /* On Windows systems, RasterImage.h brings in 'windows.h', which defines INT32. michael@0: * But the jpeg decoder has its own definition of INT32. To avoid build issues, michael@0: * we need to undefine the version from 'windows.h'. */ michael@0: #undef INT32 michael@0: michael@0: #include "Decoder.h" michael@0: michael@0: #include "nsAutoPtr.h" michael@0: michael@0: #include "nsIInputStream.h" michael@0: #include "nsIPipe.h" michael@0: #include "qcms.h" michael@0: michael@0: extern "C" { michael@0: #include "jpeglib.h" michael@0: } michael@0: michael@0: #include michael@0: michael@0: namespace mozilla { michael@0: namespace image { michael@0: michael@0: typedef struct { michael@0: struct jpeg_error_mgr pub; /* "public" fields for IJG library*/ michael@0: jmp_buf setjmp_buffer; /* For handling catastropic errors */ michael@0: } decoder_error_mgr; michael@0: michael@0: typedef enum { michael@0: JPEG_HEADER, /* Reading JFIF headers */ michael@0: JPEG_START_DECOMPRESS, michael@0: JPEG_DECOMPRESS_PROGRESSIVE, /* Output progressive pixels */ michael@0: JPEG_DECOMPRESS_SEQUENTIAL, /* Output sequential pixels */ michael@0: JPEG_DONE, michael@0: JPEG_SINK_NON_JPEG_TRAILER, /* Some image files have a */ michael@0: /* non-JPEG trailer */ michael@0: JPEG_ERROR michael@0: } jstate; michael@0: michael@0: class RasterImage; michael@0: class Orientation; michael@0: michael@0: class nsJPEGDecoder : public Decoder michael@0: { michael@0: public: michael@0: nsJPEGDecoder(RasterImage &aImage, Decoder::DecodeStyle aDecodeStyle); michael@0: virtual ~nsJPEGDecoder(); michael@0: michael@0: virtual void InitInternal(); michael@0: virtual void WriteInternal(const char* aBuffer, uint32_t aCount, DecodeStrategy aStrategy); michael@0: virtual void FinishInternal(); michael@0: michael@0: virtual Telemetry::ID SpeedHistogram(); michael@0: void NotifyDone(); michael@0: michael@0: protected: michael@0: Orientation ReadOrientationFromEXIF(); michael@0: void OutputScanlines(bool* suspend); michael@0: michael@0: public: michael@0: struct jpeg_decompress_struct mInfo; michael@0: struct jpeg_source_mgr mSourceMgr; michael@0: decoder_error_mgr mErr; michael@0: jstate mState; michael@0: michael@0: uint32_t mBytesToSkip; michael@0: michael@0: const JOCTET *mSegment; // The current segment we are decoding from michael@0: uint32_t mSegmentLen; // amount of data in mSegment michael@0: michael@0: JOCTET *mBackBuffer; michael@0: uint32_t mBackBufferLen; // Offset of end of active backtrack data michael@0: uint32_t mBackBufferSize; // size in bytes what mBackBuffer was created with michael@0: uint32_t mBackBufferUnreadLen; // amount of data currently in mBackBuffer michael@0: michael@0: JOCTET *mProfile; michael@0: uint32_t mProfileLength; michael@0: michael@0: qcms_profile *mInProfile; michael@0: qcms_transform *mTransform; michael@0: michael@0: bool mReading; michael@0: michael@0: const Decoder::DecodeStyle mDecodeStyle; michael@0: michael@0: uint32_t mCMSMode; michael@0: }; michael@0: michael@0: } // namespace image michael@0: } // namespace mozilla michael@0: michael@0: #endif // nsJPEGDecoder_h__