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, SkBitmap::Allocator* a llocator, | 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 // Reject color types not supported by this method | 21 // Reject color types not supported by this method |
22 if (kIndex_8_SkColorType == dstColorType || kGray_8_SkColorType == dstColorT ype) { | 22 if (kIndex_8_SkColorType == dstColorType || kGray_8_SkColorType == dstColorT ype) { |
23 SkCodecPrintf("Error: Color type not supported.\n"); | 23 SkCodecPrintf("Error: Color type not supported.\n"); |
24 return false; | 24 return false; |
25 } | 25 } |
26 | 26 |
27 // Reject requests for unpremultiplied alpha | 27 // Reject requests for unpremultiplied alpha |
28 if (requireUnpremul) { | 28 if (requireUnpremul) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 bitmap->setInfo(dstInfo, dstInfo.minRowBytes()); | 95 bitmap->setInfo(dstInfo, dstInfo.minRowBytes()); |
96 if (!bitmap->tryAllocPixels(allocator, nullptr)) { | 96 if (!bitmap->tryAllocPixels(allocator, nullptr)) { |
97 SkCodecPrintf("Error: Could not allocate pixels.\n"); | 97 SkCodecPrintf("Error: Could not allocate pixels.\n"); |
98 return false; | 98 return false; |
99 } | 99 } |
100 | 100 |
101 // Zero the bitmap if the region is not completely within the image. | 101 // Zero the bitmap if the region is not completely within the image. |
102 // TODO (msarett): Can we make this faster by implementing it to only | 102 // TODO (msarett): Can we make this faster by implementing it to only |
103 // zero parts of the image that we won't overwrite with | 103 // zero parts of the image that we won't overwrite with |
104 // pixels? | 104 // pixels? |
105 // TODO (msarett): This could be skipped if memory is zero initialized. | 105 SkCodec::ZeroInitialized zeroInit = allocator ? allocator->zeroInit() : |
scroggo
2015/11/10 22:31:14
It looks like we only care about the variable zero
msarett
2015/11/10 22:49:59
Done.
| |
106 // This would matter if this code is moved to Android and | 106 SkCodec::kNo_ZeroInitialized; |
107 // uses Android bitmaps. | 107 if (SubsetType::kPartiallyInside_SubsetType == type && |
108 if (SubsetType::kPartiallyInside_SubsetType == type) { | 108 SkCodec::kNo_ZeroInitialized == zeroInit) { |
109 bitmap->eraseColor(0); | 109 bitmap->eraseColor(0); |
110 } | 110 } |
111 | 111 |
112 // Use a canvas to crop and scale to the destination bitmap | 112 // Use a canvas to crop and scale to the destination bitmap |
113 SkCanvas canvas(*bitmap); | 113 SkCanvas canvas(*bitmap); |
114 // TODO (msarett): Maybe we can take advantage of the fact that SkRect uses floats? | 114 // TODO (msarett): Maybe we can take advantage of the fact that SkRect uses floats? |
115 SkRect src = SkRect::MakeXYWH((SkScalar) subset.x(), (SkScalar) 0, | 115 SkRect src = SkRect::MakeXYWH((SkScalar) subset.x(), (SkScalar) 0, |
116 (SkScalar) subset.width(), (SkScalar) subset.height()); | 116 (SkScalar) subset.width(), (SkScalar) subset.height()); |
117 SkRect dst = SkRect::MakeXYWH((SkScalar) (outX / sampleSize), (SkScalar) (ou tY / sampleSize), | 117 SkRect dst = SkRect::MakeXYWH((SkScalar) (outX / sampleSize), (SkScalar) (ou tY / sampleSize), |
118 (SkScalar) get_scaled_dimension(subset.width(), sampleSize), | 118 (SkScalar) get_scaled_dimension(subset.width(), sampleSize), |
(...skipping 11 matching lines...) Expand all Loading... | |
130 // SkCanvas does not draw to these color types. | 130 // SkCanvas does not draw to these color types. |
131 if (kIndex_8_SkColorType == colorType || kGray_8_SkColorType == colorType) { | 131 if (kIndex_8_SkColorType == colorType || kGray_8_SkColorType == colorType) { |
132 return false; | 132 return false; |
133 } | 133 } |
134 | 134 |
135 // FIXME: Call virtual function when it lands. | 135 // FIXME: Call virtual function when it lands. |
136 SkImageInfo info = SkImageInfo::Make(0, 0, colorType, fDecoder->getInfo().al phaType(), | 136 SkImageInfo info = SkImageInfo::Make(0, 0, colorType, fDecoder->getInfo().al phaType(), |
137 fDecoder->getInfo().profileType()); | 137 fDecoder->getInfo().profileType()); |
138 return conversion_possible(info, fDecoder->getInfo()); | 138 return conversion_possible(info, fDecoder->getInfo()); |
139 } | 139 } |
OLD | NEW |