Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/image/decoders/nsJPEGDecoder.h
Line
Count
Source (jump to first uncovered line)
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 mozilla_image_decoders_nsJPEGDecoder_h
8
#define mozilla_image_decoders_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 "nsIInputStream.h"
19
#include "nsIPipe.h"
20
#include "qcms.h"
21
22
extern "C" {
23
#include "jpeglib.h"
24
}
25
26
#include <setjmp.h>
27
28
namespace mozilla {
29
namespace image {
30
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;
35
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;
46
47
class RasterImage;
48
struct Orientation;
49
50
class nsJPEGDecoder : public Decoder
51
{
52
public:
53
  virtual ~nsJPEGDecoder();
54
55
0
  DecoderType GetType() const override { return DecoderType::JPEG; }
56
57
  void NotifyDone();
58
59
protected:
60
  nsresult InitInternal() override;
61
  LexerResult DoDecode(SourceBufferIterator& aIterator,
62
                       IResumable* aOnResume) override;
63
  nsresult FinishInternal() override;
64
65
  Maybe<Telemetry::HistogramID> SpeedHistogram() const override;
66
67
protected:
68
  Orientation ReadOrientationFromEXIF();
69
  void OutputScanlines(bool* suspend);
70
71
private:
72
  friend class DecoderFactory;
73
74
  // Decoders should only be instantiated via DecoderFactory.
75
  nsJPEGDecoder(RasterImage* aImage, Decoder::DecodeStyle aDecodeStyle);
76
77
  enum class State
78
  {
79
    JPEG_DATA,
80
    FINISHED_JPEG_DATA
81
  };
82
83
  void FinishRow(uint32_t aLastSourceRow);
84
  LexerTransition<State> ReadJPEGData(const char* aData, size_t aLength);
85
  LexerTransition<State> FinishedJPEGData();
86
87
  StreamingLexer<State> mLexer;
88
89
public:
90
  struct jpeg_decompress_struct mInfo;
91
  struct jpeg_source_mgr mSourceMgr;
92
  decoder_error_mgr mErr;
93
  jstate mState;
94
95
  uint32_t mBytesToSkip;
96
97
  const JOCTET* mSegment;   // The current segment we are decoding from
98
  uint32_t mSegmentLen;     // amount of data in mSegment
99
100
  JOCTET* mBackBuffer;
101
  uint32_t mBackBufferLen; // Offset of end of active backtrack data
102
  uint32_t mBackBufferSize; // size in bytes what mBackBuffer was created with
103
  uint32_t mBackBufferUnreadLen; // amount of data currently in mBackBuffer
104
105
  JOCTET * mProfile;
106
  uint32_t mProfileLength;
107
108
  qcms_profile* mInProfile;
109
  qcms_transform* mTransform;
110
111
  bool mReading;
112
113
  const Decoder::DecodeStyle mDecodeStyle;
114
115
  uint32_t mCMSMode;
116
};
117
118
} // namespace image
119
} // namespace mozilla
120
121
#endif // mozilla_image_decoders_nsJPEGDecoder_h