diff options
author | msarett <msarett@google.com> | 2015-12-11 07:38:50 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-12-11 07:38:50 -0800 |
commit | 9a0e3467da2a61ec81f676c147c21c77de91fccf (patch) | |
tree | 34f92186cea75a2af48dc76d3cb0bdf8905d2317 /src/android/SkBitmapRegionCodec.cpp | |
parent | e804292e805917002cc3d7baa7f967fb20d2c7cb (diff) |
Make BitmapRegionDecoder succeed on invalid requests
If the client requests a color type or alpha type that is
not supported, we should decode to the default/appropriate
color and alpha types to match existing behavior in Android.
BUG=skia:
Review URL: https://codereview.chromium.org/1513023002
Diffstat (limited to 'src/android/SkBitmapRegionCodec.cpp')
-rw-r--r-- | src/android/SkBitmapRegionCodec.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/android/SkBitmapRegionCodec.cpp b/src/android/SkBitmapRegionCodec.cpp index 415b60c5ab..be3d5bcce7 100644 --- a/src/android/SkBitmapRegionCodec.cpp +++ b/src/android/SkBitmapRegionCodec.cpp @@ -17,7 +17,7 @@ SkBitmapRegionCodec::SkBitmapRegionCodec(SkAndroidCodec* codec) {} bool SkBitmapRegionCodec::decodeRegion(SkBitmap* bitmap, SkBRDAllocator* allocator, - const SkIRect& desiredSubset, int sampleSize, SkColorType dstColorType, + const SkIRect& desiredSubset, int sampleSize, SkColorType prefColorType, bool requireUnpremul) { // Fix the input sampleSize if necessary. @@ -50,10 +50,8 @@ bool SkBitmapRegionCodec::decodeRegion(SkBitmap* bitmap, SkBRDAllocator* allocat SkISize scaledSize = fCodec->getSampledSubsetDimensions(sampleSize, subset); // Create the image info for the decode - SkAlphaType dstAlphaType = fCodec->getInfo().alphaType(); - if (kOpaque_SkAlphaType != dstAlphaType) { - dstAlphaType = requireUnpremul ? kUnpremul_SkAlphaType : kPremul_SkAlphaType; - } + SkColorType dstColorType = fCodec->computeOutputColorType(prefColorType); + SkAlphaType dstAlphaType = fCodec->computeOutputAlphaType(requireUnpremul); SkImageInfo decodeInfo = SkImageInfo::Make(scaledSize.width(), scaledSize.height(), dstColorType, dstAlphaType); @@ -94,6 +92,13 @@ bool SkBitmapRegionCodec::decodeRegion(SkBitmap* bitmap, SkBRDAllocator* allocat scaledOutHeight += scaledOutY + scaledExtraY; } SkImageInfo outInfo = decodeInfo.makeWH(scaledOutWidth, scaledOutHeight); + if (kGray_8_SkColorType == dstColorType) { + // The legacy implementations of BitmapFactory and BitmapRegionDecoder + // used kAlpha8 for grayscale images (before kGray8 existed). While + // the codec recognizes kGray8, we need to decode into a kAlpha8 + // bitmap in order to avoid a behavior change. + outInfo = SkImageInfo::MakeA8(scaledOutWidth, scaledOutHeight); + } bitmap->setInfo(outInfo); if (!bitmap->tryAllocPixels(allocator, colorTable.get())) { SkCodecPrintf("Error: Could not allocate pixels.\n"); |