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

Side by Side Diff: tools/SkBitmapRegionSampler.cpp

Issue 1288963002: Provides multiple implementations of Android's SkBitmapRegionDecoder (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Disable png subsets for SkImageDecoder 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
« no previous file with comments | « tools/SkBitmapRegionSampler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SkBitmapRegionSampler.h"
9
10 SkBitmapRegionSampler::SkBitmapRegionSampler(SkImageDecoder* decoder, int width,
11 int height)
12 : INHERITED(width, height)
13 , fDecoder(decoder)
14 {}
15
16 /*
17 * Three differences from the Android version:
18 * Returns a Skia bitmap instead of an Android bitmap.
19 * Android version attempts to reuse a recycled bitmap.
20 * Removed the options object and used parameters for color type and
21 * sample size.
22 */
23 SkBitmap* SkBitmapRegionSampler::decodeRegion(int start_x, int start_y,
24 int width, int height,
25 int sampleSize,
26 SkColorType prefColorType) {
27 // Match Android's default settings
28 fDecoder->setDitherImage(true);
29 fDecoder->setPreferQualityOverSpeed(false);
30 fDecoder->setRequireUnpremultipliedColors(false);
31 fDecoder->setSampleSize(sampleSize);
32
33 // kAlpha8 is the legacy representation of kGray8 used by SkImageDecoder
34 if (kGray_8_SkColorType == prefColorType) {
35 prefColorType = kAlpha_8_SkColorType;
36 }
37
38 SkIRect region;
39 region.fLeft = start_x;
40 region.fTop = start_y;
41 region.fRight = start_x + width;
42 region.fBottom = start_y + height;
43
44 SkAutoTDelete<SkBitmap> bitmap(new SkBitmap());
45 if (!fDecoder->decodeSubset(bitmap.get(), region, prefColorType)) {
46 SkDebugf("Error: decodeRegion failed.\n");
47 return nullptr;
48 }
49 return bitmap.detach();
50 }
OLDNEW
« no previous file with comments | « tools/SkBitmapRegionSampler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698