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 "SkBitmapRegionCanvas.h" | 8 #include "SkBitmapRegionCanvas.h" |
9 #include "SkBitmapRegionDecoderPriv.h" | 9 #include "SkBitmapRegionDecoderPriv.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
11 #include "SkCodecPriv.h" | 11 #include "SkCodecPriv.h" |
12 | 12 |
13 SkBitmapRegionCanvas::SkBitmapRegionCanvas(SkCodec* decoder) | 13 SkBitmapRegionCanvas::SkBitmapRegionCanvas(SkCodec* decoder) |
14 : INHERITED(decoder->getInfo().width(), decoder->getInfo().height()) | 14 : INHERITED(decoder->getInfo().width(), decoder->getInfo().height()) |
15 , fDecoder(decoder) | 15 , fDecoder(decoder) |
16 {} | 16 {} |
17 | 17 |
18 bool SkBitmapRegionCanvas::decodeRegion(SkBitmap* bitmap, SkBRDAllocator* alloca tor, | 18 bool SkBitmapRegionCanvas::decodeRegion(SkBitmap* bitmap, SkBRDAllocator* alloca tor, |
19 const SkIRect& desiredSubset, int sampleSize, SkColorType dstColorType, | 19 const SkIRect& desiredSubset, int sampleSize, SkColorType dstColorType, |
20 bool requireUnpremul) { | 20 bool requireUnpremul) { |
21 // FIXME: This class works well as a performance/quality comparison for | |
scroggo
2015/12/09 20:57:31
Maybe this should be in the header?
msarett
2015/12/10 15:19:26
Done.
| |
22 // SkBitmapRegionCodec, but it lacks several capabilities that are | |
23 // required by BitmapRegionDecoder in Android. | |
24 // (1) Decodes to kGray8 and kIndex8. | |
25 // (2) Decodes to kUnpremul. | |
26 // (3) Correcting an invalid dstColorType. For example, if the | |
27 // client requests kRGB_565 for a non-opaque image, rather than | |
28 // fail, we need to go ahead and decode to kN32. | |
29 | |
21 // Reject color types not supported by this method | 30 // Reject color types not supported by this method |
22 if (kIndex_8_SkColorType == dstColorType || kGray_8_SkColorType == dstColorT ype) { | 31 if (kIndex_8_SkColorType == dstColorType || kGray_8_SkColorType == dstColorT ype) { |
23 SkCodecPrintf("Error: Color type not supported.\n"); | 32 SkCodecPrintf("Error: Color type not supported.\n"); |
24 return false; | 33 return false; |
25 } | 34 } |
26 | 35 |
27 // Reject requests for unpremultiplied alpha | 36 // Reject requests for unpremultiplied alpha |
28 if (requireUnpremul) { | 37 if (requireUnpremul) { |
29 SkCodecPrintf("Error: Alpha type not supported.\n"); | 38 SkCodecPrintf("Error: Alpha type not supported.\n"); |
30 return false; | 39 return false; |
31 } | 40 } |
32 SkAlphaType dstAlphaType = fDecoder->getInfo().alphaType(); | 41 SkAlphaType dstAlphaType = fDecoder->getInfo().alphaType(); |
33 if (kUnpremul_SkAlphaType == dstAlphaType) { | 42 if (kUnpremul_SkAlphaType == dstAlphaType) { |
34 dstAlphaType = kPremul_SkAlphaType; | 43 dstAlphaType = kPremul_SkAlphaType; |
35 } | 44 } |
36 | 45 |
37 // FIXME: Can we add checks and support kIndex8 or unpremultiplied alpha in special cases? | |
38 | |
39 // Fix the input sampleSize if necessary. | 46 // Fix the input sampleSize if necessary. |
40 if (sampleSize < 1) { | 47 if (sampleSize < 1) { |
41 sampleSize = 1; | 48 sampleSize = 1; |
42 } | 49 } |
43 | 50 |
44 // The size of the output bitmap is determined by the size of the | 51 // The size of the output bitmap is determined by the size of the |
45 // requested subset, not by the size of the intersection of the subset | 52 // requested subset, not by the size of the intersection of the subset |
46 // and the image dimensions. | 53 // and the image dimensions. |
47 // If inputX is negative, we will need to place decoded pixels into the | 54 // If inputX is negative, we will need to place decoded pixels into the |
48 // output bitmap starting at a left offset. Call this outX. | 55 // output bitmap starting at a left offset. Call this outX. |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 // SkCanvas does not draw to these color types. | 138 // SkCanvas does not draw to these color types. |
132 if (kIndex_8_SkColorType == colorType || kGray_8_SkColorType == colorType) { | 139 if (kIndex_8_SkColorType == colorType || kGray_8_SkColorType == colorType) { |
133 return false; | 140 return false; |
134 } | 141 } |
135 | 142 |
136 // FIXME: Call virtual function when it lands. | 143 // FIXME: Call virtual function when it lands. |
137 SkImageInfo info = SkImageInfo::Make(0, 0, colorType, fDecoder->getInfo().al phaType(), | 144 SkImageInfo info = SkImageInfo::Make(0, 0, colorType, fDecoder->getInfo().al phaType(), |
138 fDecoder->getInfo().profileType()); | 145 fDecoder->getInfo().profileType()); |
139 return conversion_possible(info, fDecoder->getInfo()); | 146 return conversion_possible(info, fDecoder->getInfo()); |
140 } | 147 } |
OLD | NEW |