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
|
|
|
|
|
|
|
#ifndef nsJPEGDecoder_h__
|
|
|
|
#define nsJPEGDecoder_h__
|
|
|
|
|
2010-08-14 08:09:49 +04: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 06:30:46 +04:00
|
|
|
#include "Decoder.h"
|
2001-01-23 01:01:03 +03:00
|
|
|
|
2010-08-14 08:09:49 +04:00
|
|
|
#include "nsAutoPtr.h"
|
2001-01-23 01:01:03 +03:00
|
|
|
|
2001-02-21 02:45:51 +03:00
|
|
|
#include "imgIDecoderObserver.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 {
|
|
|
|
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 08:09:49 +04:00
|
|
|
class RasterImage;
|
|
|
|
|
2010-08-23 06:30:46 +04:00
|
|
|
class nsJPEGDecoder : public Decoder
|
2001-01-23 01:01:03 +03:00
|
|
|
{
|
|
|
|
public:
|
2011-09-29 17:17:13 +04:00
|
|
|
nsJPEGDecoder(RasterImage &aImage, imgIDecoderObserver* aObserver);
|
2001-01-23 01:01:03 +03:00
|
|
|
virtual ~nsJPEGDecoder();
|
|
|
|
|
2010-09-12 19:22:30 +04:00
|
|
|
virtual void InitInternal();
|
2012-08-22 19:56:38 +04:00
|
|
|
virtual void WriteInternal(const char* aBuffer, uint32_t aCount);
|
2010-09-12 19:22:30 +04:00
|
|
|
virtual void FinishInternal();
|
2010-08-23 06:30:46 +04:00
|
|
|
|
2011-09-23 00:25:56 +04:00
|
|
|
virtual Telemetry::ID SpeedHistogram();
|
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:
|
2011-09-29 10:19:26 +04:00
|
|
|
void OutputScanlines(bool* suspend);
|
2001-01-23 01:01:03 +03:00
|
|
|
|
2001-02-21 01:43:56 +03:00
|
|
|
public:
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t *mImageData;
|
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
|
|
|
|
2008-01-24 18:59:32 +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
|
|
|
|
|
|
|
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
|
|
|
|
2007-07-24 02:02:17 +04:00
|
|
|
JOCTET *mProfile;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mProfileLength;
|
2007-07-24 02:02:17 +04:00
|
|
|
|
2009-04-07 20:02:11 +04: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-08-22 19:56:38 +04:00
|
|
|
uint32_t mCMSMode;
|
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
|
|
|
|
|
2001-01-23 01:01:03 +03:00
|
|
|
#endif // nsJPEGDecoder_h__
|