| Index: src/utils/SkBitmapRegionSampler.cpp
|
| diff --git a/src/utils/SkBitmapRegionSampler.cpp b/src/utils/SkBitmapRegionSampler.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..c505431fcaadf8d55052edf0cd12c4e2309a3dbf
|
| --- /dev/null
|
| +++ b/src/utils/SkBitmapRegionSampler.cpp
|
| @@ -0,0 +1,54 @@
|
| +/*
|
| + * 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) {
|
| + // Match Android's default settings
|
| + fDecoder->setDitherImage(true);
|
| + fDecoder->setPreferQualityOverSpeed(false);
|
| + fDecoder->setRequireUnpremultipliedColors(false);
|
| + fDecoder->setSampleSize(sampleSize);
|
| +
|
| + SkIRect region;
|
| + 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 nullptr;
|
| + }
|
| + return bitmap.detach();
|
| +}
|
|
|