diff --git a/content/canvas/test/Makefile.in b/content/canvas/test/Makefile.in index 96b3aae9a96..1404414d537 100644 --- a/content/canvas/test/Makefile.in +++ b/content/canvas/test/Makefile.in @@ -81,7 +81,6 @@ _TEST_FILES_0 = \ test_2d.composite.uncovered.image.source-in.html \ test_2d.composite.uncovered.image.source-out.html \ test_2d.drawImage.zerocanvas.html \ - test_toDataURL_alpha.html \ test_toDataURL_lowercase_ascii.html \ test_toDataURL_parameters.html \ test_mozGetAsFile.html \ diff --git a/content/canvas/test/test_toDataURL_alpha.html b/content/canvas/test/test_toDataURL_alpha.html deleted file mode 100644 index 3fcece8e2ac..00000000000 --- a/content/canvas/test/test_toDataURL_alpha.html +++ /dev/null @@ -1,206 +0,0 @@ - - - -Canvas test: toDataURL parameters (Bug 564388) - - - - - -

-For image types that do not support an alpha channel, the image must be -composited onto a solid black background using the source-over operator, -and the resulting image must be the one used to create the data: URL. -

-

See: - -http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#dom-canvas-todataurl - -

-

Mozilla - Bug 650720 -

-

Output:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Type:image/pngimage/jpegimage/bmp
(24 bpp)
image/bmp
(32 bpp)
rgba(128, 255, 128, 0.5) -

FAIL (fallback content)

-

FAIL (fallback content)

-

FAIL (fallback content)

-

FAIL (fallback content)

rgba(255, 128, 128, 0.75) -

FAIL (fallback content)

-

FAIL (fallback content)

-

FAIL (fallback content)

-

FAIL (fallback content)

rgba(128, 128, 255, 0.25) -

FAIL (fallback content)

-

FAIL (fallback content)

-

FAIL (fallback content)

-

FAIL (fallback content)

rgba(255, 255, 255, 1.0) -

FAIL (fallback content)

-

FAIL (fallback content)

-

FAIL (fallback content)

-

FAIL (fallback content)

rgba(255, 255, 255, 0) -

FAIL (fallback content)

-

FAIL (fallback content)

-

FAIL (fallback content)

-

FAIL (fallback content)

rgba(0, 0, 0, 1.0) -

FAIL (fallback content)

-

FAIL (fallback content)

-

FAIL (fallback content)

-

FAIL (fallback content)

rgba(0, 0, 0, 0) -

FAIL (fallback content)

-

FAIL (fallback content)

-

FAIL (fallback content)

-

FAIL (fallback content)

- - - - diff --git a/image/encoders/bmp/nsBMPEncoder.cpp b/image/encoders/bmp/nsBMPEncoder.cpp index ccc077567d1..64fc2e2c82e 100644 --- a/image/encoders/bmp/nsBMPEncoder.cpp +++ b/image/encoders/bmp/nsBMPEncoder.cpp @@ -441,12 +441,15 @@ nsBMPEncoder::ConvertHostARGBRow(const PRUint8* aSrc, PRUint8* aDest, PRUint8 *pixelOut = &aDest[x * BytesPerPixel(mBMPInfoHeader.bpp)]; PRUint8 alpha = (pixelIn & 0xff000000) >> 24; - pixelOut[0] = (((pixelIn & 0xff0000) >> 16)); - pixelOut[1] = (((pixelIn & 0x00ff00) >> 8)); - pixelOut[2] = (((pixelIn & 0x0000ff) >> 0)); - - if (mBMPInfoHeader.bpp == 32) { - pixelOut[3] = alpha; + if (alpha == 0) { + pixelOut[0] = pixelOut[1] = pixelOut[2] = 0; + } else { + pixelOut[0] = (((pixelIn & 0xff0000) >> 16) * 255 + alpha / 2) / alpha; + pixelOut[1] = (((pixelIn & 0x00ff00) >> 8) * 255 + alpha / 2) / alpha; + pixelOut[2] = (((pixelIn & 0x0000ff) >> 0) * 255 + alpha / 2) / alpha; + if(mBMPInfoHeader.bpp == 32) { + pixelOut[3] = alpha; + } } } } diff --git a/image/encoders/jpeg/nsJPEGEncoder.cpp b/image/encoders/jpeg/nsJPEGEncoder.cpp index 5744572dd86..4d199dad3be 100644 --- a/image/encoders/jpeg/nsJPEGEncoder.cpp +++ b/image/encoders/jpeg/nsJPEGEncoder.cpp @@ -365,9 +365,14 @@ nsJPEGEncoder::ConvertHostARGBRow(const PRUint8* aSrc, PRUint8* aDest, const PRUint32& pixelIn = ((const PRUint32*)(aSrc))[x]; PRUint8 *pixelOut = &aDest[x * 3]; - pixelOut[0] = (((pixelIn & 0xff0000) >> 16)); - pixelOut[1] = (((pixelIn & 0x00ff00) >> 8)); - pixelOut[2] = (((pixelIn & 0x0000ff) >> 0)); + PRUint8 alpha = (pixelIn & 0xff000000) >> 24; + if (alpha == 0) { + pixelOut[0] = pixelOut[1] = pixelOut[2] = 0; + } else { + pixelOut[0] = (((pixelIn & 0xff0000) >> 16) * 255 + alpha / 2) / alpha; + pixelOut[1] = (((pixelIn & 0x00ff00) >> 8) * 255 + alpha / 2) / alpha; + pixelOut[2] = (((pixelIn & 0x0000ff) >> 0) * 255 + alpha / 2) / alpha; + } } }