зеркало из https://github.com/mozilla/pjs.git
Bug 688238. imglib: Move Decoder::Init() arguments into the constructor. r=joedrew
This makes the lifetime of the arguments more clear. i.e. that they stay the same for the lifetime of the decoder. --HG-- extra : rebase_source : 99726522b99d9d546f41d1d4e78e44224101e9b3
This commit is contained in:
Родитель
b234bc0b54
Коммит
cde526e2b7
|
@ -63,17 +63,18 @@ 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)
|
||||
|
||||
nsBMPDecoder::nsBMPDecoder()
|
||||
nsBMPDecoder::nsBMPDecoder(RasterImage *aImage, imgIDecoderObserver* aObserver)
|
||||
: Decoder(aImage, aObserver)
|
||||
{
|
||||
mColors = nsnull;
|
||||
mRow = nsnull;
|
||||
mImageData = nsnull;
|
||||
mCurPos = mPos = mNumColors = mRowBytes = 0;
|
||||
mOldLine = mCurLine = 1; // Otherwise decoder will never start
|
||||
mState = eRLEStateInitial;
|
||||
mStateData = 0;
|
||||
mLOH = WIN_HEADER_LENGTH;
|
||||
mUseAlphaData = mHaveAlphaData = PR_FALSE;
|
||||
mColors = nsnull;
|
||||
mRow = nsnull;
|
||||
mImageData = nsnull;
|
||||
mCurPos = mPos = mNumColors = mRowBytes = 0;
|
||||
mOldLine = mCurLine = 1; // Otherwise decoder will never start
|
||||
mState = eRLEStateInitial;
|
||||
mStateData = 0;
|
||||
mLOH = WIN_HEADER_LENGTH;
|
||||
mUseAlphaData = mHaveAlphaData = PR_FALSE;
|
||||
}
|
||||
|
||||
nsBMPDecoder::~nsBMPDecoder()
|
||||
|
|
|
@ -59,7 +59,7 @@ class nsBMPDecoder : public Decoder
|
|||
{
|
||||
public:
|
||||
|
||||
nsBMPDecoder();
|
||||
nsBMPDecoder(RasterImage *aImage, imgIDecoderObserver* aObserver);
|
||||
~nsBMPDecoder();
|
||||
|
||||
// Specifies whether or not the BMP file will contain alpha data
|
||||
|
|
|
@ -107,8 +107,9 @@ namespace imagelib {
|
|||
//////////////////////////////////////////////////////////////////////
|
||||
// GIF Decoder Implementation
|
||||
|
||||
nsGIFDecoder2::nsGIFDecoder2()
|
||||
: mCurrentRow(-1)
|
||||
nsGIFDecoder2::nsGIFDecoder2(RasterImage *aImage, imgIDecoderObserver* aObserver)
|
||||
: Decoder(aImage, aObserver)
|
||||
, mCurrentRow(-1)
|
||||
, mLastFlushedRow(-1)
|
||||
, mImageData(nsnull)
|
||||
, mOldColor(0)
|
||||
|
|
|
@ -58,7 +58,7 @@ class nsGIFDecoder2 : public Decoder
|
|||
{
|
||||
public:
|
||||
|
||||
nsGIFDecoder2();
|
||||
nsGIFDecoder2(RasterImage *aImage, imgIDecoderObserver* aObserver);
|
||||
~nsGIFDecoder2();
|
||||
|
||||
virtual void WriteInternal(const char* aBuffer, PRUint32 aCount);
|
||||
|
|
|
@ -99,7 +99,8 @@ nsICODecoder::GetNumColors()
|
|||
}
|
||||
|
||||
|
||||
nsICODecoder::nsICODecoder()
|
||||
nsICODecoder::nsICODecoder(RasterImage *aImage, imgIDecoderObserver* aObserver)
|
||||
: Decoder(aImage, aObserver)
|
||||
{
|
||||
mPos = mImageOffset = mCurrIcon = mNumIcons = mBPP = mRowBytes = 0;
|
||||
mIsPNG = PR_FALSE;
|
||||
|
@ -317,8 +318,8 @@ nsICODecoder::WriteInternal(const char* aBuffer, PRUint32 aCount)
|
|||
mIsPNG = !memcmp(mSignature, nsPNGDecoder::pngSignatureBytes,
|
||||
PNGSIGNATURESIZE);
|
||||
if (mIsPNG) {
|
||||
mContainedDecoder = new nsPNGDecoder();
|
||||
mContainedDecoder->InitSharedDecoder(mImage, mObserver);
|
||||
mContainedDecoder = new nsPNGDecoder(mImage, mObserver);
|
||||
mContainedDecoder->InitSharedDecoder();
|
||||
mContainedDecoder->Write(mSignature, PNGSIGNATURESIZE);
|
||||
mDataError = mContainedDecoder->HasDataError();
|
||||
if (mContainedDecoder->HasDataError()) {
|
||||
|
@ -386,11 +387,11 @@ nsICODecoder::WriteInternal(const char* aBuffer, PRUint32 aCount)
|
|||
// Init the bitmap decoder which will do most of the work for us
|
||||
// It will do everything except the AND mask which isn't present in bitmaps
|
||||
// bmpDecoder is for local scope ease, it will be freed by mContainedDecoder
|
||||
nsBMPDecoder *bmpDecoder = new nsBMPDecoder();
|
||||
nsBMPDecoder *bmpDecoder = new nsBMPDecoder(mImage, mObserver);
|
||||
mContainedDecoder = bmpDecoder;
|
||||
bmpDecoder->SetUseAlphaData(PR_TRUE);
|
||||
mContainedDecoder->SetSizeDecode(IsSizeDecode());
|
||||
mContainedDecoder->InitSharedDecoder(mImage, mObserver);
|
||||
mContainedDecoder->InitSharedDecoder();
|
||||
|
||||
// The ICO format when containing a BMP does not include the 14 byte
|
||||
// bitmap file header. To use the code of the BMP decoder we need to
|
||||
|
|
|
@ -58,7 +58,7 @@ class nsICODecoder : public Decoder
|
|||
{
|
||||
public:
|
||||
|
||||
nsICODecoder();
|
||||
nsICODecoder(RasterImage *aImage, imgIDecoderObserver* aObserver);
|
||||
virtual ~nsICODecoder();
|
||||
|
||||
// Obtains the width of the icon directory entry
|
||||
|
|
|
@ -50,13 +50,14 @@
|
|||
namespace mozilla {
|
||||
namespace imagelib {
|
||||
|
||||
nsIconDecoder::nsIconDecoder() :
|
||||
mWidth(-1),
|
||||
mHeight(-1),
|
||||
mPixBytesRead(0),
|
||||
mPixBytesTotal(0),
|
||||
mImageData(nsnull),
|
||||
mState(iconStateStart)
|
||||
nsIconDecoder::nsIconDecoder(RasterImage *aImage, imgIDecoderObserver* aObserver)
|
||||
: Decoder(aImage, aObserver),
|
||||
mWidth(-1),
|
||||
mHeight(-1),
|
||||
mPixBytesRead(0),
|
||||
mPixBytesTotal(0),
|
||||
mImageData(nsnull),
|
||||
mState(iconStateStart)
|
||||
{
|
||||
// Nothing to do
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ class nsIconDecoder : public Decoder
|
|||
{
|
||||
public:
|
||||
|
||||
nsIconDecoder();
|
||||
nsIconDecoder(RasterImage *aImage, imgIDecoderObserver* aObserver);
|
||||
virtual ~nsIconDecoder();
|
||||
|
||||
virtual void WriteInternal(const char* aBuffer, PRUint32 aCount);
|
||||
|
|
|
@ -109,7 +109,8 @@ METHODDEF(void) my_error_exit (j_common_ptr cinfo);
|
|||
#define MAX_JPEG_MARKER_LENGTH (((PRUint32)1 << 16) - 1)
|
||||
|
||||
|
||||
nsJPEGDecoder::nsJPEGDecoder()
|
||||
nsJPEGDecoder::nsJPEGDecoder(RasterImage *aImage, imgIDecoderObserver* aObserver)
|
||||
: Decoder(aImage, aObserver)
|
||||
{
|
||||
mState = JPEG_HEADER;
|
||||
mReading = PR_TRUE;
|
||||
|
|
|
@ -86,7 +86,7 @@ class RasterImage;
|
|||
class nsJPEGDecoder : public Decoder
|
||||
{
|
||||
public:
|
||||
nsJPEGDecoder();
|
||||
nsJPEGDecoder(RasterImage *aImage, imgIDecoderObserver* aObserver);
|
||||
virtual ~nsJPEGDecoder();
|
||||
|
||||
virtual void InitInternal();
|
||||
|
|
|
@ -81,13 +81,14 @@ static PRLogModuleInfo *gPNGDecoderAccountingLog =
|
|||
const PRUint8
|
||||
nsPNGDecoder::pngSignatureBytes[] = { 137, 80, 78, 71, 13, 10, 26, 10 };
|
||||
|
||||
nsPNGDecoder::nsPNGDecoder() :
|
||||
mPNG(nsnull), mInfo(nsnull),
|
||||
mCMSLine(nsnull), interlacebuf(nsnull),
|
||||
mInProfile(nsnull), mTransform(nsnull),
|
||||
mHeaderBuf(nsnull), mHeaderBytesRead(0),
|
||||
mChannels(0), mFrameIsHidden(PR_FALSE),
|
||||
mCMSMode(0), mDisablePremultipliedAlpha(PR_FALSE)
|
||||
nsPNGDecoder::nsPNGDecoder(RasterImage *aImage, imgIDecoderObserver* aObserver)
|
||||
: Decoder(aImage, aObserver),
|
||||
mPNG(nsnull), mInfo(nsnull),
|
||||
mCMSLine(nsnull), interlacebuf(nsnull),
|
||||
mInProfile(nsnull), mTransform(nsnull),
|
||||
mHeaderBuf(nsnull), mHeaderBytesRead(0),
|
||||
mChannels(0), mFrameIsHidden(PR_FALSE),
|
||||
mCMSMode(0), mDisablePremultipliedAlpha(PR_FALSE)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ class RasterImage;
|
|||
class nsPNGDecoder : public Decoder
|
||||
{
|
||||
public:
|
||||
nsPNGDecoder();
|
||||
nsPNGDecoder(RasterImage *aImage, imgIDecoderObserver* aObserver);
|
||||
virtual ~nsPNGDecoder();
|
||||
|
||||
virtual void InitInternal();
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
namespace mozilla {
|
||||
namespace imagelib {
|
||||
|
||||
Decoder::Decoder()
|
||||
Decoder::Decoder(RasterImage *aImage, imgIDecoderObserver* aObserver)
|
||||
: mDecodeFlags(0)
|
||||
, mFrameCount(0)
|
||||
, mFailCode(NS_OK)
|
||||
|
@ -54,6 +54,12 @@ Decoder::Decoder()
|
|||
, mDecodeDone(false)
|
||||
, mDataError(false)
|
||||
{
|
||||
// We should always have an image
|
||||
NS_ABORT_IF_FALSE(aImage, "Can't initialize decoder without an image!");
|
||||
|
||||
// Save our paremeters
|
||||
mImage = aImage;
|
||||
mObserver = aObserver;
|
||||
}
|
||||
|
||||
Decoder::~Decoder()
|
||||
|
@ -67,17 +73,10 @@ Decoder::~Decoder()
|
|||
*/
|
||||
|
||||
void
|
||||
Decoder::Init(RasterImage* aImage, imgIDecoderObserver* aObserver)
|
||||
Decoder::Init()
|
||||
{
|
||||
// We should always have an image
|
||||
NS_ABORT_IF_FALSE(aImage, "Can't initialize decoder without an image!");
|
||||
|
||||
// No re-initializing
|
||||
NS_ABORT_IF_FALSE(mImage == nsnull, "Can't re-initialize a decoder!");
|
||||
|
||||
// Save our paremeters
|
||||
mImage = aImage;
|
||||
mObserver = aObserver;
|
||||
NS_ABORT_IF_FALSE(!mInitialized, "Can't re-initialize a decoder!");
|
||||
|
||||
// Fire OnStartDecode at init time to support bug 512435
|
||||
if (!IsSizeDecode() && mObserver)
|
||||
|
@ -90,18 +89,11 @@ Decoder::Init(RasterImage* aImage, imgIDecoderObserver* aObserver)
|
|||
|
||||
// Initializes a decoder whose aImage and aObserver is already being used by a
|
||||
// parent decoder
|
||||
void
|
||||
Decoder::InitSharedDecoder(RasterImage* aImage, imgIDecoderObserver* aObserver)
|
||||
void
|
||||
Decoder::InitSharedDecoder()
|
||||
{
|
||||
// We should always have an image
|
||||
NS_ABORT_IF_FALSE(aImage, "Can't initialize decoder without an image!");
|
||||
|
||||
// No re-initializing
|
||||
NS_ABORT_IF_FALSE(mImage == nsnull, "Can't re-initialize a decoder!");
|
||||
|
||||
// Save our parameters
|
||||
mImage = aImage;
|
||||
mObserver = aObserver;
|
||||
NS_ABORT_IF_FALSE(!mInitialized, "Can't re-initialize a decoder!");
|
||||
|
||||
// Implementation-specific initialization
|
||||
InitInternal();
|
||||
|
|
|
@ -50,7 +50,7 @@ class Decoder
|
|||
{
|
||||
public:
|
||||
|
||||
Decoder();
|
||||
Decoder(RasterImage* aImage, imgIDecoderObserver* aObserver);
|
||||
virtual ~Decoder();
|
||||
|
||||
/**
|
||||
|
@ -61,7 +61,7 @@ public:
|
|||
*
|
||||
* Notifications Sent: TODO
|
||||
*/
|
||||
void Init(RasterImage* aImage, imgIDecoderObserver* aObserver);
|
||||
void Init();
|
||||
|
||||
|
||||
/**
|
||||
|
@ -73,7 +73,7 @@ public:
|
|||
*
|
||||
* Notifications Sent: TODO
|
||||
*/
|
||||
void InitSharedDecoder(RasterImage* aImage, imgIDecoderObserver* aObserver);
|
||||
void InitSharedDecoder();
|
||||
|
||||
/**
|
||||
* Writes data to the decoder.
|
||||
|
|
|
@ -2167,35 +2167,35 @@ RasterImage::InitDecoder(bool aDoSizeDecode)
|
|||
eDecoderType type = GetDecoderType(mSourceDataMimeType.get());
|
||||
CONTAINER_ENSURE_TRUE(type != eDecoderType_unknown, NS_IMAGELIB_ERROR_NO_DECODER);
|
||||
|
||||
nsCOMPtr<imgIDecoderObserver> observer(do_QueryReferent(mObserver));
|
||||
// Instantiate the appropriate decoder
|
||||
switch (type) {
|
||||
case eDecoderType_png:
|
||||
mDecoder = new nsPNGDecoder();
|
||||
mDecoder = new nsPNGDecoder(this, observer);
|
||||
break;
|
||||
case eDecoderType_gif:
|
||||
mDecoder = new nsGIFDecoder2();
|
||||
mDecoder = new nsGIFDecoder2(this, observer);
|
||||
break;
|
||||
case eDecoderType_jpeg:
|
||||
mDecoder = new nsJPEGDecoder();
|
||||
mDecoder = new nsJPEGDecoder(this, observer);
|
||||
break;
|
||||
case eDecoderType_bmp:
|
||||
mDecoder = new nsBMPDecoder();
|
||||
mDecoder = new nsBMPDecoder(this, observer);
|
||||
break;
|
||||
case eDecoderType_ico:
|
||||
mDecoder = new nsICODecoder();
|
||||
mDecoder = new nsICODecoder(this, observer);
|
||||
break;
|
||||
case eDecoderType_icon:
|
||||
mDecoder = new nsIconDecoder();
|
||||
mDecoder = new nsIconDecoder(this, observer);
|
||||
break;
|
||||
default:
|
||||
NS_ABORT_IF_FALSE(0, "Shouldn't get here!");
|
||||
}
|
||||
|
||||
// Initialize the decoder
|
||||
nsCOMPtr<imgIDecoderObserver> observer(do_QueryReferent(mObserver));
|
||||
mDecoder->SetSizeDecode(aDoSizeDecode);
|
||||
mDecoder->SetDecodeFlags(mFrameDecodeFlags);
|
||||
mDecoder->Init(this, observer);
|
||||
mDecoder->Init();
|
||||
CONTAINER_ENSURE_SUCCESS(mDecoder->GetDecoderError());
|
||||
|
||||
// Create a decode worker
|
||||
|
|
Загрузка…
Ссылка в новой задаче