Index: dm/DMSrcSink.cpp |
diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp |
index 9a61b020e8f7eb4a5f330b0cc38ccc4581dcdb57..4e072ebeaf976587e9e95c8da53eeb6f08064db1 100644 |
--- a/dm/DMSrcSink.cpp |
+++ b/dm/DMSrcSink.cpp |
@@ -108,15 +108,18 @@ Error BRDSrc::draw(SkCanvas* canvas) const { |
break; |
} |
+ // Construct a color table for the decode if necessary |
+ SkAutoTUnref<SkColorTable> colorTable(nullptr); |
+ if (kIndex_8_SkColorType == colorType) { |
+ SkPMColor colors[256]; |
+ colorTable.reset(new SkColorTable(colors, 256)); |
+ } |
+ |
SkAutoTDelete<SkBitmapRegionDecoderInterface> brd(create_brd(fPath, fStrategy)); |
if (nullptr == brd.get()) { |
return Error::Nonfatal(SkStringPrintf("Could not create brd for %s.", fPath.c_str())); |
} |
- if (!brd->conversionSupported(colorType)) { |
- return Error::Nonfatal("Cannot convert to color type.\n"); |
- } |
- |
const uint32_t width = brd->width(); |
const uint32_t height = brd->height(); |
// Visually inspecting very small output images is not necessary. |
@@ -125,12 +128,25 @@ Error BRDSrc::draw(SkCanvas* canvas) const { |
} |
switch (fMode) { |
case kFullImage_Mode: { |
- SkAutoTDelete<SkBitmap> bitmap(brd->decodeRegion(0, 0, width, height, fSampleSize, |
- colorType)); |
- if (nullptr == bitmap.get() || colorType != bitmap->colorType()) { |
+ SkImageInfo info; |
+ SkIRect subset = SkIRect::MakeXYWH(0, 0, width, height); |
+ if (!brd->prepareRegion(subset, fSampleSize, colorType, false, &info)) { |
+ return Error::Nonfatal("Cannot set up for subset decode.\n"); |
+ } |
+ |
+ SkBitmap bitmap; |
+ if (SkBitmapRegionDecoderInterface::kOriginal_Strategy != fStrategy) { |
+ if (!bitmap.tryAllocPixels(info, nullptr, colorTable)) { |
+ return "Could not allocate pixels."; |
+ } |
+ } |
+ if (!brd->decodeRegion(bitmap)) { |
+ return "Failed to decode subset"; |
+ } |
+ if (colorType != bitmap.colorType()) { |
return Error::Nonfatal("Cannot convert to color type.\n"); |
} |
- canvas->drawBitmap(*bitmap, 0, 0); |
+ canvas->drawBitmap(bitmap, 0, 0); |
return ""; |
} |
case kDivisor_Mode: { |
@@ -178,13 +194,28 @@ Error BRDSrc::draw(SkCanvas* canvas) const { |
const int decodeTop = top - unscaledBorder; |
const uint32_t decodeWidth = subsetWidth + unscaledBorder * 2; |
const uint32_t decodeHeight = subsetHeight + unscaledBorder * 2; |
- SkAutoTDelete<SkBitmap> bitmap(brd->decodeRegion(decodeLeft, |
- decodeTop, decodeWidth, decodeHeight, fSampleSize, colorType)); |
- if (nullptr == bitmap.get() || colorType != bitmap->colorType()) { |
+ |
+ SkImageInfo info; |
+ SkIRect subset = SkIRect::MakeXYWH(decodeLeft, decodeTop, decodeWidth, |
+ decodeHeight); |
+ if (!brd->prepareRegion(subset, fSampleSize, colorType, false, &info)) { |
+ return Error::Nonfatal("Cannot set up for subset decode.\n"); |
+ } |
+ |
+ SkBitmap bitmap; |
+ if (SkBitmapRegionDecoderInterface::kOriginal_Strategy != fStrategy) { |
+ if (!bitmap.tryAllocPixels(info, nullptr, colorTable)) { |
+ return "Could not allocate pixels."; |
+ } |
+ } |
+ if (!brd->decodeRegion(bitmap)) { |
+ return "Failed to decode subset"; |
+ } |
+ if (colorType != bitmap.colorType()) { |
return Error::Nonfatal("Cannot convert to color type.\n"); |
} |
- canvas->drawBitmapRect(*bitmap, |
+ canvas->drawBitmapRect(bitmap, |
SkRect::MakeXYWH((SkScalar) scaledBorder, (SkScalar) scaledBorder, |
(SkScalar) (subsetWidth / fSampleSize), |
(SkScalar) (subsetHeight / fSampleSize)), |