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

Side by Side Diff: src/utils/SkBitmapRegionSampler.cpp

Issue 1288963002: Provides multiple implementations of Android's SkBitmapRegionDecoder (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Use nullptr instead of NULL Created 5 years, 3 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 unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "SkBitmapRegionSampler.h"
18
19 SkBitmapRegionSampler::SkBitmapRegionSampler(SkImageDecoder* decoder, int width,
20 int height)
21 : INHERITED(width, height)
22 , fDecoder(decoder)
23 {}
24
25 /*
26 * This has several key differences from the Android version:
27 * Returns a Skia bitmap instead of an Android bitmap.
28 * Android version attempts to reuse a recycled bitmap.
29 * Removed the options object and used parameters for color type and
30 * sample size.
31 */
32 SkBitmap* SkBitmapRegionSampler::decodeRegion(int start_x, int start_y,
33 int width, int height,
34 int sampleSize,
35 SkColorType prefColorType) {
36 // Match Android's default settings
37 fDecoder->setDitherImage(true);
38 fDecoder->setPreferQualityOverSpeed(false);
39 fDecoder->setRequireUnpremultipliedColors(false);
40 fDecoder->setSampleSize(sampleSize);
41
42 SkIRect region;
43 region.fLeft = start_x;
44 region.fTop = start_y;
45 region.fRight = start_x + width;
46 region.fBottom = start_y + height;
47
48 SkAutoTDelete<SkBitmap> bitmap(new SkBitmap());
49 if (!fDecoder->decodeSubset(bitmap.get(), region, prefColorType)) {
50 SkDebugf("Error: decodeRegion failed.\n");
51 return nullptr;
52 }
53 return bitmap.detach();
54 }
OLDNEW
« src/utils/SkBitmapRegionCanvas.cpp ('K') | « src/utils/SkBitmapRegionSampler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698