2001-01-22 22:01:03 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2012-05-21 11:12:37 +00: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-22 22:01:03 +00:00
|
|
|
|
|
|
|
#ifndef nsJPEGDecoder_h__
|
|
|
|
#define nsJPEGDecoder_h__
|
|
|
|
|
2010-08-14 04:09:49 +00: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-23 02:30:46 +00:00
|
|
|
#include "Decoder.h"
|
2001-01-22 22:01:03 +00:00
|
|
|
|
2010-08-14 04:09:49 +00:00
|
|
|
#include "nsAutoPtr.h"
|
2001-01-22 22:01:03 +00:00
|
|
|
|
2012-12-18 16:37:15 +00:00
|
|
|
#include "imgDecoderObserver.h"
|
2001-01-22 22:01:03 +00:00
|
|
|
#include "nsIInputStream.h"
|
2001-02-20 22:43:56 +00:00
|
|
|
#include "nsIPipe.h"
|
2009-04-07 16:02:11 +00:00
|
|
|
#include "qcms.h"
|
2001-01-22 22:01:03 +00:00
|
|
|
|
2001-03-23 07:45:00 +00:00
|
|
|
extern "C" {
|
2001-01-22 22:01:03 +00:00
|
|
|
#include "jpeglib.h"
|
2001-03-23 07:45:00 +00:00
|
|
|
}
|
2001-01-22 22:01:03 +00:00
|
|
|
|
2001-02-20 22:43:56 +00:00
|
|
|
#include <setjmp.h>
|
|
|
|
|
2010-08-23 02:30:46 +00:00
|
|
|
namespace mozilla {
|
2012-01-06 16:02:27 +00:00
|
|
|
namespace image {
|
2010-08-23 02:30:46 +00:00
|
|
|
|
2001-01-22 22:01:03 +00: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-14 04:09:49 +00:00
|
|
|
class RasterImage;
|
|
|
|
|
2010-08-23 02:30:46 +00:00
|
|
|
class nsJPEGDecoder : public Decoder
|
2001-01-22 22:01:03 +00:00
|
|
|
{
|
|
|
|
public:
|
2012-12-18 16:37:15 +00:00
|
|
|
nsJPEGDecoder(RasterImage &aImage, imgDecoderObserver* aObserver, Decoder::DecodeStyle aDecodeStyle);
|
2001-01-22 22:01:03 +00:00
|
|
|
virtual ~nsJPEGDecoder();
|
|
|
|
|
2010-09-12 15:22:30 +00:00
|
|
|
virtual void InitInternal();
|
2012-08-22 15:56:38 +00:00
|
|
|
virtual void WriteInternal(const char* aBuffer, uint32_t aCount);
|
2010-09-12 15:22:30 +00:00
|
|
|
virtual void FinishInternal();
|
2010-08-23 02:30:46 +00:00
|
|
|
|
2011-09-22 20:25:56 +00:00
|
|
|
virtual Telemetry::ID SpeedHistogram();
|
2010-09-12 15:22:30 +00:00
|
|
|
void NotifyDone();
|
2008-01-24 15:59:32 +00:00
|
|
|
|
2001-01-22 22:01:03 +00:00
|
|
|
protected:
|
2011-09-29 06:19:26 +00:00
|
|
|
void OutputScanlines(bool* suspend);
|
2001-01-22 22:01:03 +00:00
|
|
|
|
2001-02-20 22:43:56 +00:00
|
|
|
public:
|
2012-08-22 15:56:38 +00:00
|
|
|
uint8_t *mImageData;
|
2001-01-22 22:01:03 +00:00
|
|
|
|
|
|
|
struct jpeg_decompress_struct mInfo;
|
2007-01-04 20:03:50 +00:00
|
|
|
struct jpeg_source_mgr mSourceMgr;
|
2001-01-22 22:01:03 +00:00
|
|
|
decoder_error_mgr mErr;
|
|
|
|
jstate mState;
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mBytesToSkip;
|
2001-02-27 02:25:25 +00:00
|
|
|
|
2008-01-24 15:59:32 +00:00
|
|
|
const JOCTET *mSegment; // The current segment we are decoding from
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mSegmentLen; // amount of data in mSegment
|
2001-02-27 02:25:25 +00:00
|
|
|
|
|
|
|
JOCTET *mBackBuffer;
|
2012-08-22 15:56:38 +00: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 20:03:50 +00:00
|
|
|
|
2007-07-23 22:02:17 +00:00
|
|
|
JOCTET *mProfile;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mProfileLength;
|
2007-07-23 22:02:17 +00:00
|
|
|
|
2009-04-07 16:02:11 +00:00
|
|
|
qcms_profile *mInProfile;
|
|
|
|
qcms_transform *mTransform;
|
2007-07-23 22:02:17 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mReading;
|
2011-01-13 01:45:13 +00:00
|
|
|
|
2012-11-19 01:18:52 +00:00
|
|
|
const Decoder::DecodeStyle mDecodeStyle;
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mCMSMode;
|
2001-01-22 22:01:03 +00:00
|
|
|
};
|
|
|
|
|
2012-01-06 16:02:27 +00:00
|
|
|
} // namespace image
|
2010-08-23 02:30:46 +00:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2001-01-22 22:01:03 +00:00
|
|
|
#endif // nsJPEGDecoder_h__
|