зеркало из https://github.com/mozilla/pjs.git
Bug 513681 - part 10 - make decoder implementations inherit from Decoder.r=joe,a=blocker
This commit is contained in:
Родитель
064bc19283
Коммит
9d4d51368a
|
@ -48,12 +48,11 @@
|
|||
#include "nsIInputStream.h"
|
||||
#include "RasterImage.h"
|
||||
#include "imgIContainerObserver.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsIInterfaceRequestorUtils.h"
|
||||
|
||||
#include "prlog.h"
|
||||
|
||||
using namespace mozilla::imagelib;
|
||||
namespace mozilla {
|
||||
namespace imagelib {
|
||||
|
||||
#ifdef PR_LOGGING
|
||||
PRLogModuleInfo *gBMPLog = PR_NewLogModule("BMPDecoder");
|
||||
|
@ -63,8 +62,6 @@ PRLogModuleInfo *gBMPLog = PR_NewLogModule("BMPDecoder");
|
|||
#define LINE(row) ((mBIH.height < 0) ? (-mBIH.height - (row)) : ((row) - 1))
|
||||
#define PIXEL_OFFSET(row, col) (LINE(row) * mBIH.width + col)
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsBMPDecoder, imgIDecoder)
|
||||
|
||||
nsBMPDecoder::nsBMPDecoder()
|
||||
{
|
||||
mColors = nsnull;
|
||||
|
@ -84,18 +81,10 @@ nsBMPDecoder::~nsBMPDecoder()
|
|||
free(mRow);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsBMPDecoder::Init(imgIContainer *aImage,
|
||||
imgIDecoderObserver *aObserver,
|
||||
PRUint32 aFlags)
|
||||
nsresult
|
||||
nsBMPDecoder::InitInternal()
|
||||
{
|
||||
NS_ABORT_IF_FALSE(aImage->GetType() == imgIContainer::TYPE_RASTER,
|
||||
"wrong type of imgIContainer for decoding into");
|
||||
|
||||
PR_LOG(gBMPLog, PR_LOG_DEBUG, ("nsBMPDecoder::Init(%p)\n", aImage));
|
||||
|
||||
mImage = static_cast<RasterImage*>(aImage);
|
||||
mObserver = aObserver;
|
||||
mFlags = aFlags;
|
||||
PR_LOG(gBMPLog, PR_LOG_DEBUG, ("nsBMPDecoder::Init(%p)\n", mImage.get()));
|
||||
|
||||
// Fire OnStartDecode at init time to support bug 512435
|
||||
if (!(mFlags & imgIDecoder::DECODER_FLAG_HEADERONLY) && mObserver)
|
||||
|
@ -104,7 +93,8 @@ NS_IMETHODIMP nsBMPDecoder::Init(imgIContainer *aImage,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsBMPDecoder::Close(PRUint32 aFlags)
|
||||
nsresult
|
||||
nsBMPDecoder::ShutdownInternal(PRUint32 aFlags)
|
||||
{
|
||||
PR_LOG(gBMPLog, PR_LOG_DEBUG, ("nsBMPDecoder::Close()\n"));
|
||||
|
||||
|
@ -122,11 +112,6 @@ NS_IMETHODIMP nsBMPDecoder::Close(PRUint32 aFlags)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsBMPDecoder::Flush()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// ----------------------------------------
|
||||
// Actual Data Processing
|
||||
// ----------------------------------------
|
||||
|
@ -167,8 +152,8 @@ NS_METHOD nsBMPDecoder::CalcBitShift()
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBMPDecoder::Write(const char* aBuffer, PRUint32 aCount)
|
||||
nsresult
|
||||
nsBMPDecoder::WriteInternal(const char* aBuffer, PRUint32 aCount)
|
||||
{
|
||||
// No forgiveness
|
||||
if (mError)
|
||||
|
@ -672,3 +657,6 @@ void nsBMPDecoder::ProcessInfoHeader()
|
|||
mBIH.colors = LITTLE_TO_NATIVE32(mBIH.colors);
|
||||
mBIH.important_colors = LITTLE_TO_NATIVE32(mBIH.important_colors);
|
||||
}
|
||||
|
||||
} // namespace imagelib
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -41,9 +41,12 @@
|
|||
#define _nsBMPDecoder_h
|
||||
|
||||
#include "nsAutoPtr.h"
|
||||
#include "imgIDecoder.h"
|
||||
#include "imgIDecoderObserver.h"
|
||||
#include "gfxColor.h"
|
||||
#include "Decoder.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace imagelib {
|
||||
|
||||
struct BMPFILEHEADER {
|
||||
char signature[2]; // String "BM"
|
||||
|
@ -131,35 +134,28 @@ enum ERLEState {
|
|||
eRLEStateAbsoluteModePadded ///< As above, but another byte of data has to be read as padding
|
||||
};
|
||||
|
||||
namespace mozilla {
|
||||
namespace imagelib {
|
||||
class RasterImage;
|
||||
} // namespace imagelib
|
||||
} // namespace mozilla
|
||||
|
||||
/**
|
||||
* Decoder for BMP-Files, as used by Windows and OS/2
|
||||
*/
|
||||
class nsBMPDecoder : public imgIDecoder
|
||||
class nsBMPDecoder : public Decoder
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_IMGIDECODER
|
||||
|
||||
nsBMPDecoder();
|
||||
~nsBMPDecoder();
|
||||
|
||||
virtual nsresult InitInternal();
|
||||
virtual nsresult WriteInternal(const char* aBuffer, PRUint32 aCount);
|
||||
virtual nsresult ShutdownInternal(PRUint32 aFlags);
|
||||
|
||||
private:
|
||||
|
||||
/** Calculates the red-, green- and blueshift in mBitFields using
|
||||
* the bitmasks from mBitFields */
|
||||
NS_METHOD CalcBitShift();
|
||||
|
||||
nsCOMPtr<imgIDecoderObserver> mObserver;
|
||||
|
||||
nsRefPtr<mozilla::imagelib::RasterImage> mImage;
|
||||
PRUint32 mFlags;
|
||||
|
||||
PRUint32 mPos;
|
||||
|
||||
BMPFILEHEADER mBFH;
|
||||
|
@ -223,5 +219,9 @@ inline void Set4BitPixel(PRUint32*& aDecoded, PRUint8 aData,
|
|||
}
|
||||
}
|
||||
|
||||
} // namespace imagelib
|
||||
} // namespace mozilla
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -84,6 +84,9 @@ mailing address.
|
|||
#include "gfxPlatform.h"
|
||||
#include "qcms.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace imagelib {
|
||||
|
||||
/*
|
||||
* GETN(n, s) requests at least 'n' bytes available from 'q', at start of state 's'
|
||||
*
|
||||
|
@ -101,13 +104,8 @@ mailing address.
|
|||
|
||||
/* Get a 16-bit value stored in little-endian format */
|
||||
#define GETINT16(p) ((p)[1]<<8|(p)[0])
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// GIF Decoder Implementation
|
||||
// This is an adaptor between GIF2 and imgIDecoder
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsGIFDecoder2, imgIDecoder)
|
||||
|
||||
nsGIFDecoder2::nsGIFDecoder2()
|
||||
: mCurrentRow(-1)
|
||||
|
@ -130,26 +128,9 @@ nsGIFDecoder2::~nsGIFDecoder2()
|
|||
{
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
/** imgIDecoder methods **/
|
||||
//******************************************************************************
|
||||
|
||||
//******************************************************************************
|
||||
/* void init (in imgIContainer aImage,
|
||||
in imgIDecoderObserver aObsever,
|
||||
in unsigned long aFlags); */
|
||||
NS_IMETHODIMP nsGIFDecoder2::Init(imgIContainer *aImage,
|
||||
imgIDecoderObserver *aObserver,
|
||||
PRUint32 aFlags)
|
||||
nsresult
|
||||
nsGIFDecoder2::InitInternal()
|
||||
{
|
||||
NS_ABORT_IF_FALSE(aImage->GetType() == imgIContainer::TYPE_RASTER,
|
||||
"wrong type of imgIContainer for decoding into");
|
||||
|
||||
// Store parameters
|
||||
mImage = static_cast<mozilla::imagelib::RasterImage*>(aImage);
|
||||
mObserver = aObserver;
|
||||
mFlags = aFlags;
|
||||
|
||||
// Fire OnStartDecode at init time to support bug 512435
|
||||
if (!(mFlags & imgIDecoder::DECODER_FLAG_HEADERONLY) && mObserver)
|
||||
mObserver->OnStartDecode(nsnull);
|
||||
|
@ -161,14 +142,8 @@ NS_IMETHODIMP nsGIFDecoder2::Init(imgIContainer *aImage,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//******************************************************************************
|
||||
/** nsIOutputStream methods **/
|
||||
//******************************************************************************
|
||||
|
||||
//******************************************************************************
|
||||
/* void close (); */
|
||||
NS_IMETHODIMP nsGIFDecoder2::Close(PRUint32 aFlags)
|
||||
nsresult
|
||||
nsGIFDecoder2::ShutdownInternal(PRUint32 aFlags)
|
||||
{
|
||||
// Send notifications if appropriate
|
||||
if (!(mFlags & imgIDecoder::DECODER_FLAG_HEADERONLY) &&
|
||||
|
@ -180,15 +155,6 @@ NS_IMETHODIMP nsGIFDecoder2::Close(PRUint32 aFlags)
|
|||
|
||||
PR_FREEIF(mGIFStruct.local_colormap);
|
||||
|
||||
mImage = nsnull;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
/* void flush (); */
|
||||
NS_IMETHODIMP nsGIFDecoder2::Flush()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -237,10 +203,8 @@ nsGIFDecoder2::FlushImageData()
|
|||
return rv;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
/* void write (in string aBuffer, in PRUint32 aCount); */
|
||||
NS_IMETHODIMP
|
||||
nsGIFDecoder2::Write(const char *aBuffer, PRUint32 aCount)
|
||||
nsresult
|
||||
nsGIFDecoder2::WriteInternal(const char *aBuffer, PRUint32 aCount)
|
||||
{
|
||||
// Don't forgive previously flagged errors
|
||||
if (mError)
|
||||
|
@ -1227,3 +1191,6 @@ nsresult nsGIFDecoder2::GifWrite(const PRUint8 *buf, PRUint32 len)
|
|||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace imagelib
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -42,8 +42,7 @@
|
|||
#define _nsGIFDecoder2_h
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "imgIDecoder.h"
|
||||
#include "imgIContainer.h"
|
||||
#include "Decoder.h"
|
||||
#include "imgIDecoderObserver.h"
|
||||
|
||||
#include "GIF2.h"
|
||||
|
@ -51,21 +50,21 @@
|
|||
namespace mozilla {
|
||||
namespace imagelib {
|
||||
class RasterImage;
|
||||
} // namespace imagelib
|
||||
} // namespace mozilla
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// nsGIFDecoder2 Definition
|
||||
|
||||
class nsGIFDecoder2 : public imgIDecoder
|
||||
class nsGIFDecoder2 : public Decoder
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_IMGIDECODER
|
||||
|
||||
nsGIFDecoder2();
|
||||
~nsGIFDecoder2();
|
||||
|
||||
virtual nsresult InitInternal();
|
||||
virtual nsresult WriteInternal(const char* aBuffer, PRUint32 aCount);
|
||||
virtual nsresult ShutdownInternal(PRUint32 aFlags);
|
||||
|
||||
private:
|
||||
/* These functions will be called when the decoder has a decoded row,
|
||||
* frame size information, etc. */
|
||||
|
@ -83,9 +82,6 @@ private:
|
|||
|
||||
inline int ClearCode() const { return 1 << mGIFStruct.datasize; }
|
||||
|
||||
nsRefPtr<mozilla::imagelib::RasterImage> mImage;
|
||||
nsCOMPtr<imgIDecoderObserver> mObserver;
|
||||
PRUint32 mFlags;
|
||||
PRInt32 mCurrentRow;
|
||||
PRInt32 mLastFlushedRow;
|
||||
|
||||
|
@ -109,4 +105,7 @@ private:
|
|||
gif_struct mGIFStruct;
|
||||
};
|
||||
|
||||
} // namespace imagelib
|
||||
} // namespace mozilla
|
||||
|
||||
#endif
|
||||
|
|
|
@ -53,9 +53,8 @@
|
|||
#include "nsIProperties.h"
|
||||
#include "nsISupportsPrimitives.h"
|
||||
|
||||
using namespace mozilla::imagelib;
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsICODecoder, imgIDecoder)
|
||||
namespace mozilla {
|
||||
namespace imagelib {
|
||||
|
||||
#define ICONCOUNTOFFSET 4
|
||||
#define DIRENTRYOFFSET 6
|
||||
|
@ -87,18 +86,9 @@ nsICODecoder::~nsICODecoder()
|
|||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsICODecoder::Init(imgIContainer *aImage,
|
||||
imgIDecoderObserver *aObserver,
|
||||
PRUint32 aFlags)
|
||||
nsresult
|
||||
nsICODecoder::InitInternal()
|
||||
{
|
||||
NS_ABORT_IF_FALSE(aImage->GetType() == imgIContainer::TYPE_RASTER,
|
||||
"wrong type of imgIContainer for decoding into");
|
||||
|
||||
// Grab parameters
|
||||
mImage = static_cast<RasterImage*>(aImage);
|
||||
mObserver = aObserver;
|
||||
mFlags = aFlags;
|
||||
|
||||
// Fire OnStartDecode at init time to support bug 512435
|
||||
if (!(mFlags & imgIDecoder::DECODER_FLAG_HEADERONLY) && mObserver)
|
||||
mObserver->OnStartDecode(nsnull);
|
||||
|
@ -106,7 +96,8 @@ NS_IMETHODIMP nsICODecoder::Init(imgIContainer *aImage,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsICODecoder::Close(PRUint32 aFlags)
|
||||
nsresult
|
||||
nsICODecoder::ShutdownInternal(PRUint32 aFlags)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
|
@ -148,13 +139,8 @@ NS_IMETHODIMP nsICODecoder::Close(PRUint32 aFlags)
|
|||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsICODecoder::Flush()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsICODecoder::Write(const char* aBuffer, PRUint32 aCount)
|
||||
nsresult
|
||||
nsICODecoder::WriteInternal(const char* aBuffer, PRUint32 aCount)
|
||||
{
|
||||
// No forgiveness
|
||||
if (mError)
|
||||
|
@ -552,3 +538,6 @@ void nsICODecoder::ProcessInfoHeader() {
|
|||
mBIH.colors = LITTLE_TO_NATIVE32(mBIH.colors);
|
||||
mBIH.important_colors = LITTLE_TO_NATIVE32(mBIH.important_colors);
|
||||
}
|
||||
|
||||
} // namespace imagelib
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -42,16 +42,14 @@
|
|||
#define _nsICODecoder_h
|
||||
|
||||
#include "nsAutoPtr.h"
|
||||
#include "imgIDecoder.h"
|
||||
#include "imgIContainer.h"
|
||||
#include "Decoder.h"
|
||||
#include "imgIDecoderObserver.h"
|
||||
#include "nsBMPDecoder.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace imagelib {
|
||||
|
||||
class RasterImage;
|
||||
} // namespace imagelib
|
||||
} // namespace mozilla
|
||||
|
||||
struct IconDirEntry
|
||||
{
|
||||
|
@ -71,15 +69,17 @@ struct IconDirEntry
|
|||
PRUint32 mImageOffset;
|
||||
};
|
||||
|
||||
class nsICODecoder : public imgIDecoder
|
||||
class nsICODecoder : public Decoder
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_IMGIDECODER
|
||||
|
||||
nsICODecoder();
|
||||
virtual ~nsICODecoder();
|
||||
|
||||
virtual nsresult InitInternal();
|
||||
virtual nsresult WriteInternal(const char* aBuffer, PRUint32 aCount);
|
||||
virtual nsresult ShutdownInternal(PRUint32 aFlags);
|
||||
|
||||
private:
|
||||
// Private helper methods
|
||||
void ProcessDirEntry(IconDirEntry& aTarget);
|
||||
|
@ -89,11 +89,6 @@ private:
|
|||
|
||||
PRUint32 CalcAlphaRowSize();
|
||||
|
||||
private:
|
||||
nsRefPtr<mozilla::imagelib::RasterImage> mImage;
|
||||
nsCOMPtr<imgIDecoderObserver> mObserver;
|
||||
PRUint32 mFlags;
|
||||
|
||||
PRUint32 mPos;
|
||||
PRUint16 mNumIcons;
|
||||
PRUint16 mCurrIcon;
|
||||
|
@ -120,5 +115,7 @@ private:
|
|||
PRPackedBool mError;
|
||||
};
|
||||
|
||||
} // namespace imagelib
|
||||
} // namespace mozilla
|
||||
|
||||
#endif
|
||||
|
|
|
@ -47,20 +47,10 @@
|
|||
|
||||
#include "ImageErrors.h"
|
||||
|
||||
using namespace mozilla::imagelib;
|
||||
|
||||
NS_IMPL_THREADSAFE_ADDREF(nsIconDecoder)
|
||||
NS_IMPL_THREADSAFE_RELEASE(nsIconDecoder)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(nsIconDecoder)
|
||||
NS_INTERFACE_MAP_ENTRY(imgIDecoder)
|
||||
NS_INTERFACE_MAP_END_THREADSAFE
|
||||
|
||||
namespace mozilla {
|
||||
namespace imagelib {
|
||||
|
||||
nsIconDecoder::nsIconDecoder() :
|
||||
mImage(nsnull),
|
||||
mObserver(nsnull),
|
||||
mFlags(imgIDecoder::DECODER_FLAG_NONE),
|
||||
mWidth(-1),
|
||||
mHeight(-1),
|
||||
mPixBytesRead(0),
|
||||
|
@ -76,21 +66,9 @@ nsIconDecoder::~nsIconDecoder()
|
|||
{ }
|
||||
|
||||
|
||||
/** imgIDecoder methods **/
|
||||
|
||||
NS_IMETHODIMP nsIconDecoder::Init(imgIContainer *aImage,
|
||||
imgIDecoderObserver *aObserver,
|
||||
PRUint32 aFlags)
|
||||
nsresult
|
||||
nsIconDecoder::InitInternal()
|
||||
{
|
||||
|
||||
// Grab parameters
|
||||
NS_ABORT_IF_FALSE(aImage->GetType() == imgIContainer::TYPE_RASTER,
|
||||
"wrong type of imgIContainer for decoding into");
|
||||
|
||||
mImage = static_cast<RasterImage*>(aImage);
|
||||
mObserver = aObserver;
|
||||
mFlags = aFlags;
|
||||
|
||||
// Fire OnStartDecode at init time to support bug 512435
|
||||
if (!(mFlags & imgIDecoder::DECODER_FLAG_HEADERONLY) && mObserver)
|
||||
mObserver->OnStartDecode(nsnull);
|
||||
|
@ -98,7 +76,8 @@ NS_IMETHODIMP nsIconDecoder::Init(imgIContainer *aImage,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsIconDecoder::Close(PRUint32 aFlags)
|
||||
nsresult
|
||||
nsIconDecoder::ShutdownInternal(PRUint32 aFlags)
|
||||
{
|
||||
// If we haven't notified of completion yet for a full/success decode, we
|
||||
// didn't finish. Notify in error mode
|
||||
|
@ -107,17 +86,11 @@ NS_IMETHODIMP nsIconDecoder::Close(PRUint32 aFlags)
|
|||
!mNotifiedDone)
|
||||
NotifyDone(/* aSuccess = */ PR_FALSE);
|
||||
|
||||
mImage = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsIconDecoder::Flush()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIconDecoder::Write(const char *aBuffer, PRUint32 aCount)
|
||||
nsresult
|
||||
nsIconDecoder::WriteInternal(const char *aBuffer, PRUint32 aCount)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
|
@ -242,3 +215,5 @@ nsIconDecoder::NotifyDone(PRBool aSuccess)
|
|||
mNotifiedDone = PR_TRUE;
|
||||
}
|
||||
|
||||
} // namespace imagelib
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -41,18 +41,15 @@
|
|||
#ifndef nsIconDecoder_h__
|
||||
#define nsIconDecoder_h__
|
||||
|
||||
#include "imgIDecoder.h"
|
||||
#include "Decoder.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#include "imgIContainer.h"
|
||||
#include "imgIDecoderObserver.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace imagelib {
|
||||
class RasterImage;
|
||||
} // namespace imagelib
|
||||
} // namespace mozilla
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// The icon decoder is a decoder specifically tailored for loading icons
|
||||
|
@ -73,18 +70,17 @@ class RasterImage;
|
|||
//
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsIconDecoder : public imgIDecoder
|
||||
class nsIconDecoder : public Decoder
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_IMGIDECODER
|
||||
|
||||
nsIconDecoder();
|
||||
virtual ~nsIconDecoder();
|
||||
|
||||
nsRefPtr<mozilla::imagelib::RasterImage> mImage;
|
||||
nsCOMPtr<imgIDecoderObserver> mObserver;
|
||||
PRUint32 mFlags;
|
||||
virtual nsresult InitInternal();
|
||||
virtual nsresult WriteInternal(const char* aBuffer, PRUint32 aCount);
|
||||
virtual nsresult ShutdownInternal(PRUint32 aFlags);
|
||||
|
||||
PRUint8 mWidth;
|
||||
PRUint8 mHeight;
|
||||
PRUint32 mPixBytesRead;
|
||||
|
@ -104,5 +100,7 @@ enum {
|
|||
iconStateError = 4
|
||||
};
|
||||
|
||||
} // namespace imagelib
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // nsIconDecoder_h__
|
||||
|
|
|
@ -54,8 +54,6 @@
|
|||
|
||||
#include "gfxPlatform.h"
|
||||
|
||||
using namespace mozilla::imagelib;
|
||||
|
||||
extern "C" {
|
||||
#include "iccjpeg.h"
|
||||
|
||||
|
@ -73,7 +71,10 @@ ycc_rgb_convert_argb (j_decompress_ptr cinfo,
|
|||
JSAMPARRAY output_buf, int num_rows);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsJPEGDecoder, imgIDecoder)
|
||||
static void cmyk_convert_rgb(JSAMPROW row, JDIMENSION width);
|
||||
|
||||
namespace mozilla {
|
||||
namespace imagelib {
|
||||
|
||||
#if defined(PR_LOGGING)
|
||||
PRLogModuleInfo *gJPEGlog = PR_NewLogModule("JPEGDecoder");
|
||||
|
@ -90,8 +91,6 @@ METHODDEF(void) skip_input_data (j_decompress_ptr jd, long num_bytes);
|
|||
METHODDEF(void) term_source (j_decompress_ptr jd);
|
||||
METHODDEF(void) my_error_exit (j_common_ptr cinfo);
|
||||
|
||||
static void cmyk_convert_rgb(JSAMPROW row, JDIMENSION width);
|
||||
|
||||
/* Normal JFIF markers can't have more bytes than this. */
|
||||
#define MAX_JPEG_MARKER_LENGTH (((PRUint32)1 << 16) - 1)
|
||||
|
||||
|
@ -136,23 +135,9 @@ nsJPEGDecoder::~nsJPEGDecoder()
|
|||
}
|
||||
|
||||
|
||||
/** imgIDecoder methods **/
|
||||
|
||||
/* void init (in imgIContainer aImage,
|
||||
in imgIDecoderObserver aObserver,
|
||||
in unsigned long aFlags); */
|
||||
NS_IMETHODIMP nsJPEGDecoder::Init(imgIContainer *aImage,
|
||||
imgIDecoderObserver *aObserver,
|
||||
PRUint32 aFlags)
|
||||
nsresult
|
||||
nsJPEGDecoder::InitInternal()
|
||||
{
|
||||
NS_ABORT_IF_FALSE(aImage->GetType() == imgIContainer::TYPE_RASTER,
|
||||
"wrong type of imgIContainer for decoding into");
|
||||
|
||||
/* Grab the parameters. */
|
||||
mImage = static_cast<RasterImage*>(aImage);
|
||||
mObserver = aObserver;
|
||||
mFlags = aFlags;
|
||||
|
||||
/* Fire OnStartDecode at init time to support bug 512435 */
|
||||
if (!(mFlags & imgIDecoder::DECODER_FLAG_HEADERONLY) && mObserver)
|
||||
mObserver->OnStartDecode(nsnull);
|
||||
|
@ -190,9 +175,8 @@ NS_IMETHODIMP nsJPEGDecoder::Init(imgIContainer *aImage,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/* void close (); */
|
||||
NS_IMETHODIMP nsJPEGDecoder::Close(PRUint32 aFlags)
|
||||
nsresult
|
||||
nsJPEGDecoder::ShutdownInternal(PRUint32 aFlags)
|
||||
{
|
||||
PR_LOG(gJPEGlog, PR_LOG_DEBUG,
|
||||
("[this=%p] nsJPEGDecoder::Close\n", this));
|
||||
|
@ -230,14 +214,8 @@ NS_IMETHODIMP nsJPEGDecoder::Close(PRUint32 aFlags)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void flush (); */
|
||||
NS_IMETHODIMP nsJPEGDecoder::Flush()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
nsresult nsJPEGDecoder::Write(const char *aBuffer, PRUint32 aCount)
|
||||
nsresult
|
||||
nsJPEGDecoder::WriteInternal(const char *aBuffer, PRUint32 aCount)
|
||||
{
|
||||
mSegment = (const JOCTET *)aBuffer;
|
||||
mSegmentLen = aCount;
|
||||
|
@ -933,6 +911,9 @@ term_source (j_decompress_ptr jd)
|
|||
decoder->NotifyDone(/* aSuccess = */ PR_TRUE);
|
||||
}
|
||||
|
||||
} // namespace imagelib
|
||||
} // namespace mozilla
|
||||
|
||||
|
||||
/**************** YCbCr -> Cairo's RGB24/ARGB32 conversion: most common case **************/
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
* we need to undefine the version from 'windows.h'. */
|
||||
#undef INT32
|
||||
|
||||
#include "imgIDecoder.h"
|
||||
#include "Decoder.h"
|
||||
|
||||
#include "nsAutoPtr.h"
|
||||
|
||||
|
@ -62,6 +62,9 @@ extern "C" {
|
|||
|
||||
#include <setjmp.h>
|
||||
|
||||
namespace mozilla {
|
||||
namespace imagelib {
|
||||
|
||||
typedef struct {
|
||||
struct jpeg_error_mgr pub; /* "public" fields for IJG library*/
|
||||
jmp_buf setjmp_buffer; /* For handling catastropic errors */
|
||||
|
@ -78,31 +81,24 @@ typedef enum {
|
|||
JPEG_ERROR
|
||||
} jstate;
|
||||
|
||||
namespace mozilla {
|
||||
namespace imagelib {
|
||||
class RasterImage;
|
||||
} // namespace imagelib
|
||||
} // namespace mozilla
|
||||
|
||||
class nsJPEGDecoder : public imgIDecoder
|
||||
class nsJPEGDecoder : public Decoder
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_IMGIDECODER
|
||||
|
||||
nsJPEGDecoder();
|
||||
virtual ~nsJPEGDecoder();
|
||||
|
||||
virtual nsresult InitInternal();
|
||||
virtual nsresult WriteInternal(const char* aBuffer, PRUint32 aCount);
|
||||
virtual nsresult ShutdownInternal(PRUint32 aFlags);
|
||||
|
||||
void NotifyDone(PRBool aSuccess);
|
||||
|
||||
protected:
|
||||
nsresult OutputScanlines(PRBool* suspend);
|
||||
|
||||
public:
|
||||
nsRefPtr<mozilla::imagelib::RasterImage> mImage;
|
||||
nsCOMPtr<imgIDecoderObserver> mObserver;
|
||||
|
||||
PRUint32 mFlags;
|
||||
PRUint8 *mImageData;
|
||||
|
||||
struct jpeg_decompress_struct mInfo;
|
||||
|
@ -130,4 +126,7 @@ public:
|
|||
PRPackedBool mNotifiedDone;
|
||||
};
|
||||
|
||||
} // namespace imagelib
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // nsJPEGDecoder_h__
|
||||
|
|
|
@ -59,7 +59,8 @@
|
|||
|
||||
#include "gfxPlatform.h"
|
||||
|
||||
using namespace mozilla::imagelib;
|
||||
namespace mozilla {
|
||||
namespace imagelib {
|
||||
|
||||
#ifdef PR_LOGGING
|
||||
static PRLogModuleInfo *gPNGLog = PR_NewLogModule("PNGDecoder");
|
||||
|
@ -80,9 +81,6 @@ static PRLogModuleInfo *gPNGDecoderAccountingLog =
|
|||
static const PRUint8 pngSignatureBytes[] =
|
||||
{ 137, 80, 78, 71, 13, 10, 26, 10 };
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsPNGDecoder, imgIDecoder)
|
||||
|
||||
nsPNGDecoder::nsPNGDecoder() :
|
||||
mPNG(nsnull), mInfo(nsnull),
|
||||
mCMSLine(nsnull), interlacebuf(nsnull),
|
||||
|
@ -220,16 +218,10 @@ void nsPNGDecoder::EndImageFrame()
|
|||
mObserver->OnStopFrame(nsnull, numFrames - 1);
|
||||
}
|
||||
|
||||
|
||||
/** imgIDecoder methods **/
|
||||
|
||||
/* void init (in imgIContainer aImage,
|
||||
imgIDecoderObserver aObserver,
|
||||
unsigned long aFlags); */
|
||||
NS_IMETHODIMP nsPNGDecoder::Init(imgIContainer *aImage,
|
||||
imgIDecoderObserver *aObserver,
|
||||
PRUint32 aFlags)
|
||||
nsresult
|
||||
nsPNGDecoder::InitInternal()
|
||||
{
|
||||
|
||||
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
|
||||
static png_byte color_chunks[]=
|
||||
{ 99, 72, 82, 77, '\0', /* cHRM */
|
||||
|
@ -248,12 +240,6 @@ NS_IMETHODIMP nsPNGDecoder::Init(imgIContainer *aImage,
|
|||
116, 73, 77, 69, '\0', /* tIME */
|
||||
122, 84, 88, 116, '\0'}; /* zTXt */
|
||||
#endif
|
||||
NS_ABORT_IF_FALSE(aImage->GetType() == imgIContainer::TYPE_RASTER,
|
||||
"wrong type of imgIContainer for decoding into");
|
||||
|
||||
mImage = static_cast<RasterImage*>(aImage);
|
||||
mObserver = aObserver;
|
||||
mFlags = aFlags;
|
||||
|
||||
// Fire OnStartDecode at init time to support bug 512435
|
||||
if (!(mFlags & imgIDecoder::DECODER_FLAG_HEADERONLY) && mObserver)
|
||||
|
@ -308,8 +294,8 @@ NS_IMETHODIMP nsPNGDecoder::Init(imgIContainer *aImage,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void close (); */
|
||||
NS_IMETHODIMP nsPNGDecoder::Close(PRUint32 aFlags)
|
||||
nsresult
|
||||
nsPNGDecoder::ShutdownInternal(PRUint32 aFlags)
|
||||
{
|
||||
if (mPNG)
|
||||
png_destroy_read_struct(&mPNG, mInfo ? &mInfo : NULL, NULL);
|
||||
|
@ -321,18 +307,11 @@ NS_IMETHODIMP nsPNGDecoder::Close(PRUint32 aFlags)
|
|||
!mNotifiedDone)
|
||||
NotifyDone(/* aSuccess = */ PR_FALSE);
|
||||
|
||||
mImage = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void flush (); */
|
||||
NS_IMETHODIMP nsPNGDecoder::Flush()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPNGDecoder::Write(const char *aBuffer, PRUint32 aCount)
|
||||
nsresult
|
||||
nsPNGDecoder::WriteInternal(const char *aBuffer, PRUint32 aCount)
|
||||
{
|
||||
// We use gotos, so we need to declare variables here
|
||||
nsresult rv;
|
||||
|
@ -933,3 +912,5 @@ nsPNGDecoder::warning_callback(png_structp png_ptr, png_const_charp warning_msg)
|
|||
PR_LOG(gPNGLog, PR_LOG_WARNING, ("libpng warning: %s\n", warning_msg));
|
||||
}
|
||||
|
||||
} // namespace imagelib
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -41,9 +41,8 @@
|
|||
#ifndef nsPNGDecoder_h__
|
||||
#define nsPNGDecoder_h__
|
||||
|
||||
#include "imgIDecoder.h"
|
||||
#include "Decoder.h"
|
||||
|
||||
#include "imgIContainer.h"
|
||||
#include "imgIDecoderObserver.h"
|
||||
#include "gfxASurface.h"
|
||||
|
||||
|
@ -56,18 +55,17 @@
|
|||
namespace mozilla {
|
||||
namespace imagelib {
|
||||
class RasterImage;
|
||||
} // namespace imagelib
|
||||
} // namespace mozilla
|
||||
|
||||
class nsPNGDecoder : public imgIDecoder
|
||||
class nsPNGDecoder : public Decoder
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_IMGIDECODER
|
||||
|
||||
nsPNGDecoder();
|
||||
virtual ~nsPNGDecoder();
|
||||
|
||||
virtual nsresult InitInternal();
|
||||
virtual nsresult WriteInternal(const char* aBuffer, PRUint32 aCount);
|
||||
virtual nsresult ShutdownInternal(PRUint32 aFlags);
|
||||
|
||||
void CreateFrame(png_uint_32 x_offset, png_uint_32 y_offset,
|
||||
PRInt32 width, PRInt32 height,
|
||||
gfxASurface::gfxImageFormat format);
|
||||
|
@ -77,10 +75,6 @@ public:
|
|||
void NotifyDone(PRBool aSuccess);
|
||||
|
||||
public:
|
||||
nsRefPtr<mozilla::imagelib::RasterImage> mImage;
|
||||
nsCOMPtr<imgIDecoderObserver> mObserver;
|
||||
PRUint32 mFlags;
|
||||
|
||||
png_structp mPNG;
|
||||
png_infop mInfo;
|
||||
nsIntRect mFrameRect;
|
||||
|
@ -121,4 +115,7 @@ public:
|
|||
png_const_charp warning_msg);
|
||||
};
|
||||
|
||||
} // namespace imagelib
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // nsPNGDecoder_h__
|
||||
|
|
|
@ -119,7 +119,13 @@ nsresult
|
|||
Decoder::Shutdown(PRUint32 aFlags)
|
||||
{
|
||||
// Implementation-specific shutdown
|
||||
return ShutdownInternal(aFlags);
|
||||
nsresult rv = ShutdownInternal(aFlags);
|
||||
|
||||
// Get rid of our strong references
|
||||
mImage = nsnull;
|
||||
mObserver = nsnull;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Загрузка…
Ссылка в новой задаче