Bug 513681 - part 14 - Coalesce size-setting into superclass.r=joe,a=blocker

This commit is contained in:
Bobby Holley 2010-08-14 13:06:35 -04:00
parent 4f3ce25630
commit 70210cfdd8
8 changed files with 40 additions and 42 deletions

View File

@ -212,13 +212,8 @@ nsBMPDecoder::WriteInternal(const char* aBuffer, PRUint32 aCount)
PRUint32 real_height = (mBIH.height > 0) ? mBIH.height : -mBIH.height;
// Set the size and notify
rv = mImage->SetSize(mBIH.width, real_height);
NS_ENSURE_SUCCESS(rv, rv);
if (mObserver) {
rv = mObserver->OnStartContainer(nsnull, mImage);
NS_ENSURE_SUCCESS(rv, rv);
}
// Post our size to the superclass
PostSize(mBIH.width, real_height);
// We have the size. If we're doing a size decode, we got what
// we came for.

View File

@ -256,9 +256,7 @@ void nsGIFDecoder2::BeginGIF()
mGIFOpen = PR_TRUE;
mImage->SetSize(mGIFStruct.screen_width, mGIFStruct.screen_height);
if (mObserver)
mObserver->OnStartContainer(nsnull, mImage);
PostSize(mGIFStruct.screen_width, mGIFStruct.screen_height);
// If we're doing a size decode, we have what we came for
if (IsSizeDecode())

View File

@ -234,12 +234,7 @@ nsICODecoder::WriteInternal(const char* aBuffer, PRUint32 aCount)
if (mPos == mImageOffset + BITMAPINFOSIZE) {
ProcessInfoHeader();
rv = mImage->SetSize(mDirEntry.mWidth, mDirEntry.mHeight);
NS_ENSURE_SUCCESS(rv, rv);
if (mObserver) {
rv = mObserver->OnStartContainer(nsnull, mImage);
NS_ENSURE_SUCCESS(rv, rv);
}
PostSize(mDirEntry.mWidth, mDirEntry.mHeight);
if (IsSizeDecode())
return NS_OK;

View File

@ -121,10 +121,8 @@ nsIconDecoder::WriteInternal(const char *aBuffer, PRUint32 aCount)
// Grab the Height
mHeight = (PRUint8)*aBuffer;
// Set up the container and signal
mImage->SetSize(mWidth, mHeight);
if (mObserver)
mObserver->OnStartContainer(nsnull, mImage);
// Post our size to the superclass
PostSize(mWidth, mHeight);
// If We're doing a size decode, we're done
if (IsSizeDecode()) {

View File

@ -256,10 +256,8 @@ nsJPEGDecoder::WriteInternal(const char *aBuffer, PRUint32 aCount)
return NS_OK; /* I/O suspension */
}
/* Set Width and height, and notify that the container is ready to go. */
mImage->SetSize(mInfo.image_width, mInfo.image_height);
if (mObserver)
mObserver->OnStartContainer(nsnull, mImage);
// Post our size to the superclass
PostSize(mInfo.image_width, mInfo.image_height);
/* If we're doing a size decode, we're done. */
if (IsSizeDecode())

View File

@ -314,7 +314,6 @@ nsresult
nsPNGDecoder::WriteInternal(const char *aBuffer, PRUint32 aCount)
{
// We use gotos, so we need to declare variables here
nsresult rv;
PRUint32 width = 0;
PRUint32 height = 0;
@ -350,14 +349,8 @@ nsPNGDecoder::WriteInternal(const char *aBuffer, PRUint32 aCount)
if ((width > MOZ_PNG_MAX_DIMENSION) || (height > MOZ_PNG_MAX_DIMENSION))
goto error;
// Set the size
rv = mImage->SetSize(width, height);
if (NS_FAILED(rv))
goto error;
// Notify the observer that the container is up
if (mObserver)
mObserver->OnStartContainer(nsnull, mImage);
// Post our size to the superclass
PostSize(width, height);
}
}
@ -538,7 +531,6 @@ nsPNGDecoder::info_callback(png_structp png_ptr, png_infop info_ptr)
nsPNGDecoder *decoder =
static_cast<nsPNGDecoder*>(png_get_progressive_ptr(png_ptr));
nsresult rv;
/* always decode to 24-bit RGB or 32-bit RGBA */
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
@ -548,14 +540,8 @@ nsPNGDecoder::info_callback(png_structp png_ptr, png_infop info_ptr)
if (width > MOZ_PNG_MAX_DIMENSION || height > MOZ_PNG_MAX_DIMENSION)
longjmp(png_jmpbuf(decoder->mPNG), 1);
// Set the size and notify that the container is set up
rv = decoder->mImage->SetSize(width, height);
if (NS_FAILED(rv))
longjmp(png_jmpbuf(decoder->mPNG), 5); // NS_ERROR_UNEXPECTED
if (decoder->mObserver)
decoder->mObserver->OnStartContainer(nsnull, decoder->mImage);
// Post our size to the superclass
decoder->PostSize(width, height);
if (color_type == PNG_COLOR_TYPE_PALETTE)
png_set_expand(png_ptr);

View File

@ -136,5 +136,24 @@ nsresult Decoder::WriteInternal(const char* aBuffer, PRUint32 aCount) {return NS
nsresult Decoder::FinishInternal() {return NS_OK; }
nsresult Decoder::ShutdownInternal(PRUint32 aFlags) {return NS_OK; }
/*
* Progress Notifications
*/
void
Decoder::PostSize(PRInt32 aWidth, PRInt32 aHeight)
{
// Validate
NS_ABORT_IF_FALSE(aWidth >= 0, "Width can't be negative!");
NS_ABORT_IF_FALSE(aHeight >= 0, "Height can't be negative!");
// Tell the image
mImage->SetSize(aWidth, aHeight);
// Notify the observer
if (mObserver)
mObserver->OnStartContainer(nsnull, mImage);
}
} // namespace imagelib
} // namespace mozilla

View File

@ -132,6 +132,15 @@ protected:
virtual nsresult FinishInternal();
virtual nsresult ShutdownInternal(PRUint32 aFlags);
/*
* Progress notifications.
*/
// Called by decoders when they determine the size of the image. Informs
// the image of its size and sends notifications.
void PostSize(PRInt32 aWidth, PRInt32 aHeight);
/*
* Member variables.
*