Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(429)

Unified Diff: src/android/SkBitmapRegionCodec.cpp

Issue 1513023002: Make BitmapRegionDecoder succeed on invalid requests (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Update comments Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/android/SkBitmapRegionCanvas.cpp ('k') | src/codec/SkAndroidCodec.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/android/SkBitmapRegionCodec.cpp
diff --git a/src/android/SkBitmapRegionCodec.cpp b/src/android/SkBitmapRegionCodec.cpp
index 415b60c5ab354e9ddeac605585e02b4e68244c30..be3d5bcce7179dd7e29871ad72f1d602c2d22bd0 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");
« no previous file with comments | « src/android/SkBitmapRegionCanvas.cpp ('k') | src/codec/SkAndroidCodec.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698