Fixes for decoding to A8.

src/images/SkImageDecoder_libpng.cpp:
A8 images are not opaque, so do not set the opaque flag.
This fixes a bug where copyTo does not work as expected (when
copying an A8 decoded image to ARGB_8888), leading to
a bitmap hash that does not represent the image correctly
(in skimage).

tools/skimage_main.cpp:
In write_bitmap, which is creating the image for visual comparison,
copy A8 to 8888, since A8 cannot be encoded.

In the section that tests reencoding, do not test reencoding A8,
which is known to not work.

R=mtklein@google.com, djsollen@google.com

Author: scroggo@google.com

Review URL: https://codereview.chromium.org/25726004

git-svn-id: http://skia.googlecode.com/svn/trunk@11589 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
commit-bot@chromium.org 2013-10-03 17:13:38 +00:00
parent 3390b9ac9a
commit 546f70c823
2 changed files with 21 additions and 2 deletions

View File

@ -435,6 +435,9 @@ bool SkPNGImageDecoder::onDecode(SkStream* sk_stream, SkBitmap* decodedBitmap,
// return false, since the result will have premultiplied colors.
return false;
}
if (SkBitmap::kA8_Config == decodedBitmap->config()) {
reallyHasAlpha = true;
}
decodedBitmap->setIsOpaque(!reallyHasAlpha);
return true;
}
@ -888,6 +891,9 @@ bool SkPNGImageDecoder::onDecodeSubset(SkBitmap* bm, const SkIRect& region) {
if (0 != theTranspColor) {
reallyHasAlpha |= substituteTranspColor(&decodedBitmap, theTranspColor);
}
if (SkBitmap::kA8_Config == decodedBitmap.config()) {
reallyHasAlpha = true;
}
decodedBitmap.setIsOpaque(!reallyHasAlpha);
if (swapOnly) {

View File

@ -111,7 +111,19 @@ static SkBitmap::Config gPrefConfig(SkBitmap::kNo_Config);
SkAutoTUnref<skiagm::JsonExpectationsSource> gJsonExpectations;
static bool write_bitmap(const char outName[], const SkBitmap& bm) {
return SkImageEncoder::EncodeFile(outName, bm, SkImageEncoder::kPNG_Type, 100);
const SkBitmap* bmPtr;
SkBitmap bm8888;
if (bm.config() == SkBitmap::kA8_Config) {
// Copy A8 into ARGB_8888, since our image encoders do not currently
// support A8.
if (!bm.copyTo(&bm8888, SkBitmap::kARGB_8888_Config)) {
return false;
}
bmPtr = &bm8888;
} else {
bmPtr = &bm;
}
return SkImageEncoder::EncodeFile(outName, *bmPtr, SkImageEncoder::kPNG_Type, 100);
}
/**
@ -495,7 +507,8 @@ static void decodeFileAndWrite(const char srcPath[], const SkString* writePath)
}
}
if (FLAGS_reencode) {
// Do not attempt to re-encode A8, since our image encoders do not support encoding to A8.
if (FLAGS_reencode && bitmap.config() != SkBitmap::kA8_Config) {
// Encode to the format the file was originally in, or PNG if the encoder for the same
// format is unavailable.
SkImageDecoder::Format format = codec->getFormat();