Backed out changeset 177eae915693 (bug 1206581) for bustage
[gecko.git] / image / decoders / nsJPEGDecoder.h
blob318b46a0bb5b4f1f0fe0bdf7e981aa04b5478bb8
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 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/. */
7 #ifndef mozilla_image_decoders_nsJPEGDecoder_h
8 #define mozilla_image_decoders_nsJPEGDecoder_h
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
16 #include "Decoder.h"
18 #include "nsIInputStream.h"
19 #include "nsIPipe.h"
20 #include "qcms.h"
22 extern "C" {
23 #include "jpeglib.h"
26 #include <setjmp.h>
28 namespace mozilla {
29 namespace image {
31 typedef struct {
32 struct jpeg_error_mgr pub; // "public" fields for IJG library
33 jmp_buf setjmp_buffer; // For handling catastropic errors
34 } decoder_error_mgr;
36 typedef enum {
37 JPEG_HEADER, // Reading JFIF headers
38 JPEG_START_DECOMPRESS,
39 JPEG_DECOMPRESS_PROGRESSIVE, // Output progressive pixels
40 JPEG_DECOMPRESS_SEQUENTIAL, // Output sequential pixels
41 JPEG_DONE,
42 JPEG_SINK_NON_JPEG_TRAILER, // Some image files have a
43 // non-JPEG trailer
44 JPEG_ERROR
45 } jstate;
47 class RasterImage;
48 struct Orientation;
50 class nsJPEGDecoder : public Decoder
52 public:
53 virtual ~nsJPEGDecoder();
55 virtual void SetSampleSize(int aSampleSize) override
57 mSampleSize = aSampleSize;
60 virtual void InitInternal() override;
61 virtual void WriteInternal(const char* aBuffer, uint32_t aCount) override;
62 virtual void FinishInternal() override;
64 virtual Telemetry::ID SpeedHistogram() override;
65 void NotifyDone();
67 protected:
68 Orientation ReadOrientationFromEXIF();
69 void OutputScanlines(bool* suspend);
71 private:
72 friend class DecoderFactory;
74 // Decoders should only be instantiated via DecoderFactory.
75 nsJPEGDecoder(RasterImage* aImage, Decoder::DecodeStyle aDecodeStyle);
77 public:
78 struct jpeg_decompress_struct mInfo;
79 struct jpeg_source_mgr mSourceMgr;
80 decoder_error_mgr mErr;
81 jstate mState;
83 uint32_t mBytesToSkip;
85 const JOCTET* mSegment; // The current segment we are decoding from
86 uint32_t mSegmentLen; // amount of data in mSegment
88 JOCTET* mBackBuffer;
89 uint32_t mBackBufferLen; // Offset of end of active backtrack data
90 uint32_t mBackBufferSize; // size in bytes what mBackBuffer was created with
91 uint32_t mBackBufferUnreadLen; // amount of data currently in mBackBuffer
93 JOCTET * mProfile;
94 uint32_t mProfileLength;
96 qcms_profile* mInProfile;
97 qcms_transform* mTransform;
99 bool mReading;
101 const Decoder::DecodeStyle mDecodeStyle;
103 uint32_t mCMSMode;
105 int mSampleSize;
108 } // namespace image
109 } // namespace mozilla
111 #endif // mozilla_image_decoders_nsJPEGDecoder_h