Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | * |
michael@0 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #ifndef nsJPEGDecoder_h__ |
michael@0 | 8 | #define nsJPEGDecoder_h__ |
michael@0 | 9 | |
michael@0 | 10 | #include "RasterImage.h" |
michael@0 | 11 | /* On Windows systems, RasterImage.h brings in 'windows.h', which defines INT32. |
michael@0 | 12 | * But the jpeg decoder has its own definition of INT32. To avoid build issues, |
michael@0 | 13 | * we need to undefine the version from 'windows.h'. */ |
michael@0 | 14 | #undef INT32 |
michael@0 | 15 | |
michael@0 | 16 | #include "Decoder.h" |
michael@0 | 17 | |
michael@0 | 18 | #include "nsAutoPtr.h" |
michael@0 | 19 | |
michael@0 | 20 | #include "nsIInputStream.h" |
michael@0 | 21 | #include "nsIPipe.h" |
michael@0 | 22 | #include "qcms.h" |
michael@0 | 23 | |
michael@0 | 24 | extern "C" { |
michael@0 | 25 | #include "jpeglib.h" |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | #include <setjmp.h> |
michael@0 | 29 | |
michael@0 | 30 | namespace mozilla { |
michael@0 | 31 | namespace image { |
michael@0 | 32 | |
michael@0 | 33 | typedef struct { |
michael@0 | 34 | struct jpeg_error_mgr pub; /* "public" fields for IJG library*/ |
michael@0 | 35 | jmp_buf setjmp_buffer; /* For handling catastropic errors */ |
michael@0 | 36 | } decoder_error_mgr; |
michael@0 | 37 | |
michael@0 | 38 | typedef enum { |
michael@0 | 39 | JPEG_HEADER, /* Reading JFIF headers */ |
michael@0 | 40 | JPEG_START_DECOMPRESS, |
michael@0 | 41 | JPEG_DECOMPRESS_PROGRESSIVE, /* Output progressive pixels */ |
michael@0 | 42 | JPEG_DECOMPRESS_SEQUENTIAL, /* Output sequential pixels */ |
michael@0 | 43 | JPEG_DONE, |
michael@0 | 44 | JPEG_SINK_NON_JPEG_TRAILER, /* Some image files have a */ |
michael@0 | 45 | /* non-JPEG trailer */ |
michael@0 | 46 | JPEG_ERROR |
michael@0 | 47 | } jstate; |
michael@0 | 48 | |
michael@0 | 49 | class RasterImage; |
michael@0 | 50 | class Orientation; |
michael@0 | 51 | |
michael@0 | 52 | class nsJPEGDecoder : public Decoder |
michael@0 | 53 | { |
michael@0 | 54 | public: |
michael@0 | 55 | nsJPEGDecoder(RasterImage &aImage, Decoder::DecodeStyle aDecodeStyle); |
michael@0 | 56 | virtual ~nsJPEGDecoder(); |
michael@0 | 57 | |
michael@0 | 58 | virtual void InitInternal(); |
michael@0 | 59 | virtual void WriteInternal(const char* aBuffer, uint32_t aCount, DecodeStrategy aStrategy); |
michael@0 | 60 | virtual void FinishInternal(); |
michael@0 | 61 | |
michael@0 | 62 | virtual Telemetry::ID SpeedHistogram(); |
michael@0 | 63 | void NotifyDone(); |
michael@0 | 64 | |
michael@0 | 65 | protected: |
michael@0 | 66 | Orientation ReadOrientationFromEXIF(); |
michael@0 | 67 | void OutputScanlines(bool* suspend); |
michael@0 | 68 | |
michael@0 | 69 | public: |
michael@0 | 70 | struct jpeg_decompress_struct mInfo; |
michael@0 | 71 | struct jpeg_source_mgr mSourceMgr; |
michael@0 | 72 | decoder_error_mgr mErr; |
michael@0 | 73 | jstate mState; |
michael@0 | 74 | |
michael@0 | 75 | uint32_t mBytesToSkip; |
michael@0 | 76 | |
michael@0 | 77 | const JOCTET *mSegment; // The current segment we are decoding from |
michael@0 | 78 | uint32_t mSegmentLen; // amount of data in mSegment |
michael@0 | 79 | |
michael@0 | 80 | JOCTET *mBackBuffer; |
michael@0 | 81 | uint32_t mBackBufferLen; // Offset of end of active backtrack data |
michael@0 | 82 | uint32_t mBackBufferSize; // size in bytes what mBackBuffer was created with |
michael@0 | 83 | uint32_t mBackBufferUnreadLen; // amount of data currently in mBackBuffer |
michael@0 | 84 | |
michael@0 | 85 | JOCTET *mProfile; |
michael@0 | 86 | uint32_t mProfileLength; |
michael@0 | 87 | |
michael@0 | 88 | qcms_profile *mInProfile; |
michael@0 | 89 | qcms_transform *mTransform; |
michael@0 | 90 | |
michael@0 | 91 | bool mReading; |
michael@0 | 92 | |
michael@0 | 93 | const Decoder::DecodeStyle mDecodeStyle; |
michael@0 | 94 | |
michael@0 | 95 | uint32_t mCMSMode; |
michael@0 | 96 | }; |
michael@0 | 97 | |
michael@0 | 98 | } // namespace image |
michael@0 | 99 | } // namespace mozilla |
michael@0 | 100 | |
michael@0 | 101 | #endif // nsJPEGDecoder_h__ |