From 971fb9f9364851f735e3cb262ca358b3de7ce65b Mon Sep 17 00:00:00 2001 From: "dtownsend%oxymoronical.com" Date: Fri, 21 Dec 2007 09:19:27 +0000 Subject: [PATCH] Bug 405982: Improve error handling and consistency with image encoders. r=dolse, r+sr=pavlov, a=beltzner --- .../canvas/src/nsCanvasRenderingContext2D.cpp | 19 ++++++----- content/canvas/test/Makefile.in | 1 + content/canvas/test/test_bug405982.html | 34 +++++++++++++++++++ .../libpr0n/encoders/jpeg/nsJPEGEncoder.cpp | 3 ++ 4 files changed, 49 insertions(+), 8 deletions(-) create mode 100644 content/canvas/test/test_bug405982.html diff --git a/content/canvas/src/nsCanvasRenderingContext2D.cpp b/content/canvas/src/nsCanvasRenderingContext2D.cpp index 75212988806..3983dcf699d 100644 --- a/content/canvas/src/nsCanvasRenderingContext2D.cpp +++ b/content/canvas/src/nsCanvasRenderingContext2D.cpp @@ -736,6 +736,7 @@ nsCanvasRenderingContext2D::GetInputStream(const char *aMimeType, cairo_surface_status(mSurface) != CAIRO_STATUS_SUCCESS) return NS_ERROR_FAILURE; + nsresult rv; const char encoderPrefix[] = "@mozilla.org/image/encoder;2?type="; nsAutoArrayPtr conid(new (std::nothrow) char[strlen(encoderPrefix) + strlen(aMimeType) + 1]); strcpy(conid, encoderPrefix); @@ -746,10 +747,11 @@ nsCanvasRenderingContext2D::GetInputStream(const char *aMimeType, return NS_ERROR_FAILURE; if (mImageSurfaceData) { - encoder->InitFromData(mImageSurfaceData, - mWidth * mHeight * 4, mWidth, mHeight, mWidth * 4, - imgIEncoder::INPUT_FORMAT_HOSTARGB, - nsDependentString(aEncoderOptions)); + rv = encoder->InitFromData(mImageSurfaceData, + mWidth * mHeight * 4, mWidth, mHeight, mWidth * 4, + imgIEncoder::INPUT_FORMAT_HOSTARGB, + nsDependentString(aEncoderOptions)); + NS_ENSURE_SUCCESS(rv, rv); } else { nsAutoArrayPtr imageBuffer(new (std::nothrow) PRUint8[mWidth * mHeight * 4]); if (!imageBuffer) @@ -769,10 +771,11 @@ nsCanvasRenderingContext2D::GetInputStream(const char *aMimeType, cairo_paint (cr); cairo_destroy (cr); - encoder->InitFromData(imageBuffer.get(), - mWidth * mHeight * 4, mWidth, mHeight, mWidth * 4, - imgIEncoder::INPUT_FORMAT_HOSTARGB, - nsDependentString(aEncoderOptions)); + rv = encoder->InitFromData(imageBuffer.get(), + mWidth * mHeight * 4, mWidth, mHeight, mWidth * 4, + imgIEncoder::INPUT_FORMAT_HOSTARGB, + nsDependentString(aEncoderOptions)); + NS_ENSURE_SUCCESS(rv, rv); } return CallQueryInterface(encoder, aStream); diff --git a/content/canvas/test/Makefile.in b/content/canvas/test/Makefile.in index 84a6bd4eed8..ea421067b18 100644 --- a/content/canvas/test/Makefile.in +++ b/content/canvas/test/Makefile.in @@ -488,6 +488,7 @@ _TEST_FILES_E = \ test_2d.imageData.put.unchanged.html \ test_2d.imageData.put.unaffected.html \ test_2d.imageData.put.path.html \ + test_bug405982.html \ image_transparent50.png \ image_redtransparent.png \ image_yellow.png \ diff --git a/content/canvas/test/test_bug405982.html b/content/canvas/test/test_bug405982.html new file mode 100644 index 00000000000..4f6d4cc376b --- /dev/null +++ b/content/canvas/test/test_bug405982.html @@ -0,0 +1,34 @@ + +Canvas test: toDataURL.png + + + + +

FAIL (fallback content)

+ diff --git a/modules/libpr0n/encoders/jpeg/nsJPEGEncoder.cpp b/modules/libpr0n/encoders/jpeg/nsJPEGEncoder.cpp index 7903b1890fe..71c89999141 100644 --- a/modules/libpr0n/encoders/jpeg/nsJPEGEncoder.cpp +++ b/modules/libpr0n/encoders/jpeg/nsJPEGEncoder.cpp @@ -126,6 +126,9 @@ NS_IMETHODIMP nsJPEGEncoder::InitFromData(const PRUint8* aData, NS_WARNING("Quality value invalid, should be integer 0-100, using default"); } } + else { + return NS_ERROR_INVALID_ARG; + } } jpeg_compress_struct cinfo;