| 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 |
| 21 // Reject color types not supported by this method | 22 // Reject color types not supported by this method |
| 22 if (kIndex_8_SkColorType == dstColorType || kGray_8_SkColorType == dstColorT
ype) { | 23 if (kIndex_8_SkColorType == dstColorType || kGray_8_SkColorType == dstColorT
ype) { |
| 23 SkCodecPrintf("Error: Color type not supported.\n"); | 24 SkCodecPrintf("Error: Color type not supported.\n"); |
| 24 return false; | 25 return false; |
| 25 } | 26 } |
| 26 | 27 |
| 27 // Reject requests for unpremultiplied alpha | 28 // Reject requests for unpremultiplied alpha |
| 28 if (requireUnpremul) { | 29 if (requireUnpremul) { |
| 29 SkCodecPrintf("Error: Alpha type not supported.\n"); | 30 SkCodecPrintf("Error: Alpha type not supported.\n"); |
| 30 return false; | 31 return false; |
| 31 } | 32 } |
| 32 SkAlphaType dstAlphaType = fDecoder->getInfo().alphaType(); | 33 SkAlphaType dstAlphaType = fDecoder->getInfo().alphaType(); |
| 33 if (kUnpremul_SkAlphaType == dstAlphaType) { | 34 if (kUnpremul_SkAlphaType == dstAlphaType) { |
| 34 dstAlphaType = kPremul_SkAlphaType; | 35 dstAlphaType = kPremul_SkAlphaType; |
| 35 } | 36 } |
| 36 | 37 |
| 37 // FIXME: Can we add checks and support kIndex8 or unpremultiplied alpha in
special cases? | |
| 38 | |
| 39 // Fix the input sampleSize if necessary. | 38 // Fix the input sampleSize if necessary. |
| 40 if (sampleSize < 1) { | 39 if (sampleSize < 1) { |
| 41 sampleSize = 1; | 40 sampleSize = 1; |
| 42 } | 41 } |
| 43 | 42 |
| 44 // The size of the output bitmap is determined by the size of the | 43 // 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 | 44 // requested subset, not by the size of the intersection of the subset |
| 46 // and the image dimensions. | 45 // and the image dimensions. |
| 47 // If inputX is negative, we will need to place decoded pixels into the | 46 // If inputX is negative, we will need to place decoded pixels into the |
| 48 // output bitmap starting at a left offset. Call this outX. | 47 // 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. | 130 // SkCanvas does not draw to these color types. |
| 132 if (kIndex_8_SkColorType == colorType || kGray_8_SkColorType == colorType) { | 131 if (kIndex_8_SkColorType == colorType || kGray_8_SkColorType == colorType) { |
| 133 return false; | 132 return false; |
| 134 } | 133 } |
| 135 | 134 |
| 136 // FIXME: Call virtual function when it lands. | 135 // FIXME: Call virtual function when it lands. |
| 137 SkImageInfo info = SkImageInfo::Make(0, 0, colorType, fDecoder->getInfo().al
phaType(), | 136 SkImageInfo info = SkImageInfo::Make(0, 0, colorType, fDecoder->getInfo().al
phaType(), |
| 138 fDecoder->getInfo().profileType()); | 137 fDecoder->getInfo().profileType()); |
| 139 return conversion_possible(info, fDecoder->getInfo()); | 138 return conversion_possible(info, fDecoder->getInfo()); |
| 140 } | 139 } |
| OLD | NEW |