| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkBitmapRegionSampler.h" | 8 #include "SkBitmapRegionSampler.h" |
| 9 #include "SkCodecPriv.h" | 9 #include "SkCodecPriv.h" |
| 10 | 10 |
| 11 SkBitmapRegionSampler::SkBitmapRegionSampler(SkImageDecoder* decoder, int width,
| 11 SkBitmapRegionSampler::SkBitmapRegionSampler(SkImageDecoder* decoder, int width,
|
| 12 int height) | 12 int height) |
| 13 : INHERITED(width, height) | 13 : INHERITED(width, height) |
| 14 , fDecoder(decoder) | 14 , fDecoder(decoder) |
| 15 {} | 15 {} |
| 16 | 16 |
| 17 /* | 17 bool SkBitmapRegionSampler::decodeRegion(SkBitmap* bitmap, SkBitmap::Allocator*
allocator, |
| 18 * Three differences from the Android version: | 18 const SkIRect& desiredSubset, int sampleSize, SkColorType colorType, boo
l requireUnpremul) { |
| 19 * Returns a Skia bitmap instead of an Android bitmap. | |
| 20 * Android version attempts to reuse a recycled bitmap. | |
| 21 * Removed the options object and used parameters for color type and | |
| 22 * sample size. | |
| 23 */ | |
| 24 SkBitmap* SkBitmapRegionSampler::decodeRegion(int start_x, int start_y, | |
| 25 int width, int height, | |
| 26 int sampleSize, | |
| 27 SkColorType prefColorType) { | |
| 28 // Match Android's default settings | |
| 29 fDecoder->setDitherImage(true); | 19 fDecoder->setDitherImage(true); |
| 30 fDecoder->setPreferQualityOverSpeed(false); | 20 fDecoder->setPreferQualityOverSpeed(false); |
| 31 fDecoder->setRequireUnpremultipliedColors(false); | 21 fDecoder->setRequireUnpremultipliedColors(false); |
| 32 fDecoder->setSampleSize(sampleSize); | 22 fDecoder->setSampleSize(sampleSize); |
| 23 fDecoder->setAllocator(allocator); |
| 33 | 24 |
| 34 // kAlpha8 is the legacy representation of kGray8 used by SkImageDecoder | 25 // kAlpha8 is the legacy representation of kGray8 used by SkImageDecoder |
| 35 if (kGray_8_SkColorType == prefColorType) { | 26 if (kGray_8_SkColorType == colorType) { |
| 36 prefColorType = kAlpha_8_SkColorType; | 27 colorType = kAlpha_8_SkColorType; |
| 37 } | 28 } |
| 38 | 29 |
| 39 SkIRect region; | 30 bool result = fDecoder->decodeSubset(bitmap, desiredSubset, colorType); |
| 40 region.fLeft = start_x; | 31 fDecoder->setAllocator(nullptr); |
| 41 region.fTop = start_y; | 32 return result; |
| 42 region.fRight = start_x + width; | |
| 43 region.fBottom = start_y + height; | |
| 44 | |
| 45 SkAutoTDelete<SkBitmap> bitmap(new SkBitmap()); | |
| 46 if (!fDecoder->decodeSubset(bitmap.get(), region, prefColorType)) { | |
| 47 SkCodecPrintf("Error: decodeRegion failed.\n"); | |
| 48 return nullptr; | |
| 49 } | |
| 50 return bitmap.detach(); | |
| 51 } | 33 } |
| OLD | NEW |