2001-01-23 01:01:03 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2012-05-21 15:12:37 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2001-01-23 01:01:03 +03:00
|
|
|
|
2015-04-06 02:22:00 +03:00
|
|
|
#ifndef mozilla_image_decoders_nsJPEGDecoder_h
|
|
|
|
#define mozilla_image_decoders_nsJPEGDecoder_h
|
2001-01-23 01:01:03 +03:00
|
|
|
|
2010-08-14 08:09:49 +04:00
|
|
|
#include "RasterImage.h"
|
2014-11-14 20:59:00 +03:00
|
|
|
// On Windows systems, RasterImage.h brings in 'windows.h', which defines INT32.
|
|
|
|
// But the jpeg decoder has its own definition of INT32. To avoid build issues,
|
|
|
|
// we need to undefine the version from 'windows.h'.
|
2010-08-14 08:09:49 +04:00
|
|
|
#undef INT32
|
|
|
|
|
2010-08-23 06:30:46 +04:00
|
|
|
#include "Decoder.h"
|
2001-01-23 01:01:03 +03:00
|
|
|
|
|
|
|
#include "nsIInputStream.h"
|
2001-02-21 01:43:56 +03:00
|
|
|
#include "nsIPipe.h"
|
2009-04-07 20:02:11 +04:00
|
|
|
#include "qcms.h"
|
2001-01-23 01:01:03 +03:00
|
|
|
|
2001-03-23 10:45:00 +03:00
|
|
|
extern "C" {
|
2001-01-23 01:01:03 +03:00
|
|
|
#include "jpeglib.h"
|
2001-03-23 10:45:00 +03:00
|
|
|
}
|
2001-01-23 01:01:03 +03:00
|
|
|
|
2001-02-21 01:43:56 +03:00
|
|
|
#include <setjmp.h>
|
|
|
|
|
2010-08-23 06:30:46 +04:00
|
|
|
namespace mozilla {
|
2012-01-06 20:02:27 +04:00
|
|
|
namespace image {
|
2010-08-23 06:30:46 +04:00
|
|
|
|
2001-01-23 01:01:03 +03:00
|
|
|
typedef struct {
|
2014-11-14 20:59:00 +03:00
|
|
|
struct jpeg_error_mgr pub; // "public" fields for IJG library
|
|
|
|
jmp_buf setjmp_buffer; // For handling catastropic errors
|
2001-01-23 01:01:03 +03:00
|
|
|
} decoder_error_mgr;
|
|
|
|
|
|
|
|
typedef enum {
|
2014-11-14 20:59:00 +03:00
|
|
|
JPEG_HEADER, // Reading JFIF headers
|
2001-01-23 01:01:03 +03:00
|
|
|
JPEG_START_DECOMPRESS,
|
2014-11-14 20:59:00 +03:00
|
|
|
JPEG_DECOMPRESS_PROGRESSIVE, // Output progressive pixels
|
|
|
|
JPEG_DECOMPRESS_SEQUENTIAL, // Output sequential pixels
|
2001-01-23 01:01:03 +03:00
|
|
|
JPEG_DONE,
|
2014-11-14 20:59:00 +03:00
|
|
|
JPEG_SINK_NON_JPEG_TRAILER, // Some image files have a
|
|
|
|
// non-JPEG trailer
|
|
|
|
JPEG_ERROR
|
2001-01-23 01:01:03 +03:00
|
|
|
} jstate;
|
|
|
|
|
2010-08-14 08:09:49 +04:00
|
|
|
class RasterImage;
|
2014-06-19 04:57:51 +04:00
|
|
|
struct Orientation;
|
2010-08-14 08:09:49 +04:00
|
|
|
|
2010-08-23 06:30:46 +04:00
|
|
|
class nsJPEGDecoder : public Decoder
|
2001-01-23 01:01:03 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~nsJPEGDecoder();
|
|
|
|
|
2015-07-31 17:29:03 +03:00
|
|
|
virtual void SetSampleSize(int aSampleSize) override
|
|
|
|
{
|
|
|
|
mSampleSize = aSampleSize;
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void InitInternal() override;
|
|
|
|
virtual void WriteInternal(const char* aBuffer, uint32_t aCount) override;
|
|
|
|
virtual void FinishInternal() override;
|
2010-08-23 06:30:46 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual Telemetry::ID SpeedHistogram() override;
|
2010-09-12 19:22:30 +04:00
|
|
|
void NotifyDone();
|
2008-01-24 18:59:32 +03:00
|
|
|
|
2001-01-23 01:01:03 +03:00
|
|
|
protected:
|
2013-08-25 11:19:43 +04:00
|
|
|
Orientation ReadOrientationFromEXIF();
|
2011-09-29 10:19:26 +04:00
|
|
|
void OutputScanlines(bool* suspend);
|
2001-01-23 01:01:03 +03:00
|
|
|
|
2015-07-23 08:39:56 +03:00
|
|
|
private:
|
|
|
|
friend class DecoderFactory;
|
|
|
|
|
|
|
|
// Decoders should only be instantiated via DecoderFactory.
|
|
|
|
nsJPEGDecoder(RasterImage* aImage, Decoder::DecodeStyle aDecodeStyle);
|
|
|
|
|
2001-02-21 01:43:56 +03:00
|
|
|
public:
|
2001-01-23 01:01:03 +03:00
|
|
|
struct jpeg_decompress_struct mInfo;
|
2007-01-04 23:03:50 +03:00
|
|
|
struct jpeg_source_mgr mSourceMgr;
|
2001-01-23 01:01:03 +03:00
|
|
|
decoder_error_mgr mErr;
|
|
|
|
jstate mState;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mBytesToSkip;
|
2001-02-27 05:25:25 +03:00
|
|
|
|
2014-11-14 20:59:00 +03:00
|
|
|
const JOCTET* mSegment; // The current segment we are decoding from
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mSegmentLen; // amount of data in mSegment
|
2001-02-27 05:25:25 +03:00
|
|
|
|
2014-11-14 20:59:00 +03:00
|
|
|
JOCTET* mBackBuffer;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mBackBufferLen; // Offset of end of active backtrack data
|
|
|
|
uint32_t mBackBufferSize; // size in bytes what mBackBuffer was created with
|
|
|
|
uint32_t mBackBufferUnreadLen; // amount of data currently in mBackBuffer
|
2007-01-04 23:03:50 +03:00
|
|
|
|
2014-11-14 20:59:00 +03:00
|
|
|
JOCTET * mProfile;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mProfileLength;
|
2007-07-24 02:02:17 +04:00
|
|
|
|
2014-11-14 20:59:00 +03:00
|
|
|
qcms_profile* mInProfile;
|
|
|
|
qcms_transform* mTransform;
|
2007-07-24 02:02:17 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mReading;
|
2011-01-13 04:45:13 +03:00
|
|
|
|
2012-11-19 05:18:52 +04:00
|
|
|
const Decoder::DecodeStyle mDecodeStyle;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mCMSMode;
|
2015-07-31 17:29:03 +03:00
|
|
|
|
|
|
|
int mSampleSize;
|
2001-01-23 01:01:03 +03:00
|
|
|
};
|
|
|
|
|
2012-01-06 20:02:27 +04:00
|
|
|
} // namespace image
|
2010-08-23 06:30:46 +04:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2015-04-06 02:22:00 +03:00
|
|
|
#endif // mozilla_image_decoders_nsJPEGDecoder_h
|