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 #include "SurfacePipe.h"
14 // On Windows systems, RasterImage.h brings in 'windows.h', which defines INT32.
15 // But the jpeg decoder has its own definition of INT32. To avoid build issues,
16 // we need to undefine the version from 'windows.h'.
27 namespace mozilla::image
{
30 struct jpeg_error_mgr pub
; // "public" fields for IJG library
31 jmp_buf setjmp_buffer
; // For handling catastropic errors
35 JPEG_HEADER
, // Reading JFIF headers
36 JPEG_START_DECOMPRESS
,
37 JPEG_DECOMPRESS_PROGRESSIVE
, // Output progressive pixels
38 JPEG_DECOMPRESS_SEQUENTIAL
, // Output sequential pixels
40 JPEG_SINK_NON_JPEG_TRAILER
, // Some image files have a
48 class nsJPEGDecoder
: public Decoder
{
50 virtual ~nsJPEGDecoder();
52 DecoderType
GetType() const override
{ return DecoderType::JPEG
; }
57 nsresult
InitInternal() override
;
58 LexerResult
DoDecode(SourceBufferIterator
& aIterator
,
59 IResumable
* aOnResume
) override
;
60 nsresult
FinishInternal() override
;
62 Maybe
<Telemetry::HistogramID
> SpeedHistogram() const override
;
65 EXIFData
ReadExifData() const;
66 WriteState
OutputScanlines();
69 friend class DecoderFactory
;
71 // Decoders should only be instantiated via DecoderFactory.
72 nsJPEGDecoder(RasterImage
* aImage
, Decoder::DecodeStyle aDecodeStyle
);
74 enum class State
{ JPEG_DATA
, FINISHED_JPEG_DATA
};
76 void FinishRow(uint32_t aLastSourceRow
);
77 LexerTransition
<State
> ReadJPEGData(const char* aData
, size_t aLength
);
78 LexerTransition
<State
> FinishedJPEGData();
80 StreamingLexer
<State
> mLexer
;
83 struct jpeg_decompress_struct mInfo
;
84 struct jpeg_source_mgr mSourceMgr
;
85 decoder_error_mgr mErr
;
88 uint32_t mBytesToSkip
;
90 const JOCTET
* mSegment
; // The current segment we are decoding from
91 uint32_t mSegmentLen
; // amount of data in mSegment
94 uint32_t mBackBufferLen
; // Offset of end of active backtrack data
95 uint32_t mBackBufferSize
; // size in bytes what mBackBuffer was created with
96 uint32_t mBackBufferUnreadLen
; // amount of data currently in mBackBuffer
99 uint32_t mProfileLength
;
105 const Decoder::DecodeStyle mDecodeStyle
;
110 } // namespace mozilla::image
112 #endif // mozilla_image_decoders_nsJPEGDecoder_h