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 @@
-
-
-
-
-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.
-
-
-
- Type: |
- image/png |
- image/jpeg |
- image/bmp (24 bpp) |
- image/bmp (32 bpp) |
-
-
- rgba(128, 255, 128, 0.5) |
- |
- |
- |
- |
-
-
- rgba(255, 128, 128, 0.75) |
- |
- |
- |
- |
-
-
- rgba(128, 128, 255, 0.25) |
- |
- |
- |
- |
-
-
- rgba(255, 255, 255, 1.0) |
- |
- |
- |
- |
-
-
- rgba(255, 255, 255, 0) |
- |
- |
- |
- |
-
-
- rgba(0, 0, 0, 1.0) |
- |
- |
- |
- |
-
-
- rgba(0, 0, 0, 0) |
- |
- |
- |
- |
-
-
-
-
-
-
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;
+ }
}
}