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