2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifndef nsJPEGDecoder_h__
|
|
|
|
#define nsJPEGDecoder_h__
|
|
|
|
|
2010-08-13 21:09:49 -07:00
|
|
|
#include "RasterImage.h"
|
|
|
|
/* 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'. */
|
|
|
|
#undef INT32
|
|
|
|
|
2010-08-22 19:30:46 -07:00
|
|
|
#include "Decoder.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-13 21:09:49 -07:00
|
|
|
#include "nsAutoPtr.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsIInputStream.h"
|
|
|
|
#include "nsIPipe.h"
|
2009-04-07 09:02:11 -07:00
|
|
|
#include "qcms.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include "jpeglib.h"
|
|
|
|
}
|
|
|
|
|
|
|
|
#include <setjmp.h>
|
|
|
|
|
2010-08-22 19:30:46 -07:00
|
|
|
namespace mozilla {
|
2012-01-06 08:02:27 -08:00
|
|
|
namespace image {
|
2010-08-22 19:30:46 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
typedef struct {
|
|
|
|
struct jpeg_error_mgr pub; /* "public" fields for IJG library*/
|
|
|
|
jmp_buf setjmp_buffer; /* For handling catastropic errors */
|
|
|
|
} decoder_error_mgr;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
JPEG_HEADER, /* Reading JFIF headers */
|
|
|
|
JPEG_START_DECOMPRESS,
|
|
|
|
JPEG_DECOMPRESS_PROGRESSIVE, /* Output progressive pixels */
|
|
|
|
JPEG_DECOMPRESS_SEQUENTIAL, /* Output sequential pixels */
|
|
|
|
JPEG_DONE,
|
|
|
|
JPEG_SINK_NON_JPEG_TRAILER, /* Some image files have a */
|
|
|
|
/* non-JPEG trailer */
|
|
|
|
JPEG_ERROR
|
|
|
|
} jstate;
|
|
|
|
|
2010-08-13 21:09:49 -07:00
|
|
|
class RasterImage;
|
2013-08-25 00:19:43 -07:00
|
|
|
class Orientation;
|
2010-08-13 21:09:49 -07:00
|
|
|
|
2010-08-22 19:30:46 -07:00
|
|
|
class nsJPEGDecoder : public Decoder
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
2013-01-18 13:47:18 -08:00
|
|
|
nsJPEGDecoder(RasterImage &aImage, Decoder::DecodeStyle aDecodeStyle);
|
2007-03-22 10:30:00 -07:00
|
|
|
virtual ~nsJPEGDecoder();
|
|
|
|
|
2010-09-12 08:22:30 -07:00
|
|
|
virtual void InitInternal();
|
2013-12-17 14:04:24 -08:00
|
|
|
virtual void WriteInternal(const char* aBuffer, uint32_t aCount, DecodeStrategy aStrategy);
|
2010-09-12 08:22:30 -07:00
|
|
|
virtual void FinishInternal();
|
2010-08-22 19:30:46 -07:00
|
|
|
|
2011-09-22 13:25:56 -07:00
|
|
|
virtual Telemetry::ID SpeedHistogram();
|
2010-09-12 08:22:30 -07:00
|
|
|
void NotifyDone();
|
2008-01-24 07:59:32 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
protected:
|
2013-08-25 00:19:43 -07:00
|
|
|
Orientation ReadOrientationFromEXIF();
|
2011-09-28 23:19:26 -07:00
|
|
|
void OutputScanlines(bool* suspend);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
public:
|
|
|
|
struct jpeg_decompress_struct mInfo;
|
|
|
|
struct jpeg_source_mgr mSourceMgr;
|
|
|
|
decoder_error_mgr mErr;
|
|
|
|
jstate mState;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mBytesToSkip;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-01-24 07:59:32 -08:00
|
|
|
const JOCTET *mSegment; // The current segment we are decoding from
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mSegmentLen; // amount of data in mSegment
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
JOCTET *mBackBuffer;
|
2012-08-22 08:56:38 -07: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-03-22 10:30:00 -07:00
|
|
|
|
2007-07-23 15:02:17 -07:00
|
|
|
JOCTET *mProfile;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mProfileLength;
|
2007-07-23 15:02:17 -07:00
|
|
|
|
2009-04-07 09:02:11 -07:00
|
|
|
qcms_profile *mInProfile;
|
|
|
|
qcms_transform *mTransform;
|
2007-07-23 15:02:17 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mReading;
|
2011-01-12 17:45:13 -08:00
|
|
|
|
2012-11-18 17:18:52 -08:00
|
|
|
const Decoder::DecodeStyle mDecodeStyle;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mCMSMode;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2012-01-06 08:02:27 -08:00
|
|
|
} // namespace image
|
2010-08-22 19:30:46 -07:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif // nsJPEGDecoder_h__
|