Chromium Code Reviews| 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::prepareRegion(const SkIRect& desiredSubset, |
| 18 * Three differences from the Android version: | 18 int sampleSize, |
| 19 * Returns a Skia bitmap instead of an Android bitmap. | 19 SkColorType dstColorType, |
| 20 * Android version attempts to reuse a recycled bitmap. | 20 bool requireUnpremul, |
| 21 * Removed the options object and used parameters for color type and | 21 SkImageInfo* outInfo) { |
| 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); | 22 fDecoder->setDitherImage(true); |
| 30 fDecoder->setPreferQualityOverSpeed(false); | 23 fDecoder->setPreferQualityOverSpeed(false); |
| 31 fDecoder->setRequireUnpremultipliedColors(false); | 24 fDecoder->setRequireUnpremultipliedColors(requireUnpremul); |
| 32 fDecoder->setSampleSize(sampleSize); | 25 fDecoder->setSampleSize(sampleSize); |
| 33 | 26 |
| 27 fSubset = desiredSubset; | |
| 28 | |
| 34 // kAlpha8 is the legacy representation of kGray8 used by SkImageDecoder | 29 // kAlpha8 is the legacy representation of kGray8 used by SkImageDecoder |
| 35 if (kGray_8_SkColorType == prefColorType) { | 30 if (kGray_8_SkColorType == dstColorType) { |
| 36 prefColorType = kAlpha_8_SkColorType; | 31 dstColorType = kAlpha_8_SkColorType; |
|
scroggo
2015/10/27 15:00:51
note that we'll need to update the glue code in An
| |
| 32 } | |
| 33 fColorType = dstColorType; | |
| 34 return true; | |
| 35 } | |
| 36 | |
| 37 bool SkBitmapRegionSampler::decodeRegion(SkBitmap& bitmap) { | |
| 38 if (fSubset.isEmpty()) { | |
| 39 SkCodecPrintf("Error: Call prepareRegion() first."); | |
| 40 return false; | |
| 37 } | 41 } |
| 38 | 42 |
| 39 SkIRect region; | 43 if (!fDecoder->decodeSubset(&bitmap, fSubset, fColorType)) { |
| 40 region.fLeft = start_x; | 44 SkCodecPrintf("Error: decodeRegion failed.\n"); |
| 41 region.fTop = start_y; | 45 return false; |
| 42 region.fRight = start_x + width; | 46 } |
| 43 region.fBottom = start_y + height; | |
| 44 | 47 |
| 45 SkAutoTDelete<SkBitmap> bitmap(new SkBitmap()); | 48 return true; |
| 46 if (!fDecoder->decodeSubset(bitmap.get(), region, prefColorType)) { | |
| 47 SkCodecPrintf("Error: decodeRegion failed.\n"); | |
| 48 return nullptr; | |
| 49 } | |
| 50 return bitmap.detach(); | |
| 51 } | 49 } |
| OLD | NEW |