Chromium Code Reviews| Index: src/utils/SkBitmapRegionSampler.cpp |
| diff --git a/src/utils/SkBitmapRegionSampler.cpp b/src/utils/SkBitmapRegionSampler.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2306ccd2ad76cb604b69299e12939f9c287087c4 |
| --- /dev/null |
| +++ b/src/utils/SkBitmapRegionSampler.cpp |
| @@ -0,0 +1,53 @@ |
| +/* |
| + * Copyright (C) 2010 The Android Open Source Project |
| + * |
| + * Licensed under the Apache License, Version 2.0 (the "License"); |
| + * you may not use this file except in compliance with the License. |
| + * You may obtain a copy of the License at |
| + * |
| + * http://www.apache.org/licenses/LICENSE-2.0 |
| + * |
| + * Unless required by applicable law or agreed to in writing, software |
| + * distributed under the License is distributed on an "AS IS" BASIS, |
| + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| + * See the License for the specific language governing permissions and |
| + * limitations under the License. |
| + */ |
| + |
| +#include "SkBitmapRegionSampler.h" |
| + |
| +SkBitmapRegionSampler::SkBitmapRegionSampler(SkImageDecoder* decoder, int width, |
| + int height) |
| + : INHERITED(width, height) |
| + , fDecoder(decoder) |
| +{} |
| + |
| +/* |
| + * This has several key 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) { |
| + |
| + fDecoder->setDitherImage(true); |
|
scroggo
2015/08/13 16:53:07
Why did you choose these settings?
msarett
2015/08/13 18:10:23
These are Android's default settings. Adding a co
|
| + fDecoder->setPreferQualityOverSpeed(false); |
| + fDecoder->setRequireUnpremultipliedColors(false); |
| + fDecoder->setSampleSize(sampleSize); |
| + SkIRect region; |
|
scroggo
2015/08/13 16:53:07
nit: a blank line before this line would be helpfu
msarett
2015/08/13 18:10:23
Done.
|
| + region.fLeft = start_x; |
| + region.fTop = start_y; |
| + region.fRight = start_x + width; |
| + region.fBottom = start_y + height; |
| + |
| + SkAutoTDelete<SkBitmap> bitmap(new SkBitmap()); |
| + if (!fDecoder->decodeSubset(bitmap.get(), region, prefColorType)) { |
| + SkDebugf("Error: decodeRegion failed.\n"); |
| + return NULL; |
| + } |
| + return bitmap.detach(); |
| +} |