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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkBitmapRegionDecoderInterface.h" | 9 #include "SkBitmapRegionDecoderInterface.h" |
10 #include "SkImageDecoder.h" | 10 #include "SkImageDecoder.h" |
11 #include "SkTemplates.h" | 11 #include "SkTemplates.h" |
12 | 12 |
13 /* | 13 /* |
14 * This class aims to duplicate the current implementation of | 14 * This class aims to duplicate the current implementation of |
15 * SkBitmapRegionDecoder in Android. | 15 * SkBitmapRegionDecoder in Android. |
16 */ | 16 */ |
17 class SkBitmapRegionSampler : public SkBitmapRegionDecoderInterface { | 17 class SkBitmapRegionSampler : public SkBitmapRegionDecoderInterface { |
18 public: | 18 public: |
19 | 19 |
20 /* | 20 /* |
21 * Takes ownership of pointer to decoder | 21 * Takes ownership of pointer to decoder |
22 */ | 22 */ |
23 SkBitmapRegionSampler(SkImageDecoder* decoder, int width, int height); | 23 SkBitmapRegionSampler(SkImageDecoder* decoder, int width, int height); |
24 | 24 |
25 /* | 25 bool prepareRegion(const SkIRect& desiredSubset, int sampleSize, |
26 * Three differences from the Android version: | 26 SkColorType colorType, bool requireUnpremul, SkImageInfo* outSize) o
verride; |
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* decodeRegion(int start_x, int start_y, int width, int height, | |
33 int sampleSize, SkColorType prefColorType) override; | |
34 | 27 |
35 bool conversionSupported(SkColorType colorType) override { | 28 bool decodeRegion(SkBitmap& bitmap) override; |
36 // SkBitmapRegionSampler does not allow the client to check if the conve
rsion | |
37 // is supported. We will return true as a default. If the conversion i
s in | |
38 // fact not supported, decodeRegion() will ignore the prefColorType and
choose | |
39 // its own color type. We catch this and fail non-fatally in our test c
ode. | |
40 return true; | |
41 } | |
42 | 29 |
43 private: | 30 private: |
44 | 31 |
45 SkAutoTDelete<SkImageDecoder> fDecoder; | 32 SkAutoTDelete<SkImageDecoder> fDecoder; |
46 | 33 |
| 34 |
| 35 // Fields set by prepareRegion() |
| 36 SkIRect fSubset; // Subset of the original image to decode |
| 37 SkColorType fColorType; // Color type to decode to |
| 38 |
47 typedef SkBitmapRegionDecoderInterface INHERITED; | 39 typedef SkBitmapRegionDecoderInterface INHERITED; |
48 | 40 |
49 }; | 41 }; |
OLD | NEW |