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

Unified Diff: tools/SkBitmapRegionSampler.cpp

Issue 1418093006: Refactor SkBitmapRegionDecoderInterface for Android (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 2 months 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
Index: tools/SkBitmapRegionSampler.cpp
diff --git a/tools/SkBitmapRegionSampler.cpp b/tools/SkBitmapRegionSampler.cpp
index 514af108593ffa6113233fe9cf807e376d8169fe..47472b678a4ef4ec14fff88caa73f4f4012259ac 100644
--- a/tools/SkBitmapRegionSampler.cpp
+++ b/tools/SkBitmapRegionSampler.cpp
@@ -14,38 +14,36 @@ SkBitmapRegionSampler::SkBitmapRegionSampler(SkImageDecoder* decoder, int width,
, fDecoder(decoder)
{}
-/*
- * Three differences from the Android version:
- * Returns a Skia bitmap instead of an Android bitmap.
- * Android version attempts to reuse a recycled bitmap.
- * Removed the options object and used parameters for color type and
- * sample size.
- */
-SkBitmap* SkBitmapRegionSampler::decodeRegion(int start_x, int start_y,
- int width, int height,
- int sampleSize,
- SkColorType prefColorType) {
- // Match Android's default settings
+bool SkBitmapRegionSampler::prepareRegion(const SkIRect& desiredSubset,
+ int sampleSize,
+ SkColorType dstColorType,
+ bool requireUnpremul,
+ SkImageInfo* outInfo) {
fDecoder->setDitherImage(true);
fDecoder->setPreferQualityOverSpeed(false);
- fDecoder->setRequireUnpremultipliedColors(false);
+ fDecoder->setRequireUnpremultipliedColors(requireUnpremul);
fDecoder->setSampleSize(sampleSize);
+ fSubset = desiredSubset;
+
// kAlpha8 is the legacy representation of kGray8 used by SkImageDecoder
- if (kGray_8_SkColorType == prefColorType) {
- prefColorType = kAlpha_8_SkColorType;
+ if (kGray_8_SkColorType == dstColorType) {
+ dstColorType = kAlpha_8_SkColorType;
scroggo 2015/10/27 15:00:51 note that we'll need to update the glue code in An
}
+ fColorType = dstColorType;
+ return true;
+}
- SkIRect region;
- region.fLeft = start_x;
- region.fTop = start_y;
- region.fRight = start_x + width;
- region.fBottom = start_y + height;
+bool SkBitmapRegionSampler::decodeRegion(SkBitmap& bitmap) {
+ if (fSubset.isEmpty()) {
+ SkCodecPrintf("Error: Call prepareRegion() first.");
+ return false;
+ }
- SkAutoTDelete<SkBitmap> bitmap(new SkBitmap());
- if (!fDecoder->decodeSubset(bitmap.get(), region, prefColorType)) {
+ if (!fDecoder->decodeSubset(&bitmap, fSubset, fColorType)) {
SkCodecPrintf("Error: decodeRegion failed.\n");
- return nullptr;
+ return false;
}
- return bitmap.detach();
+
+ return true;
}

Powered by Google App Engine
This is Rietveld 408576698