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 "SkAndroidCodec.h" | 8 #include "SkAndroidCodec.h" |
9 #include "SkBitmapRegionCodec.h" | 9 #include "SkBitmapRegionCodec.h" |
10 #include "SkBitmapRegionDecoderPriv.h" | 10 #include "SkBitmapRegionDecoderPriv.h" |
11 #include "SkCodecPriv.h" | 11 #include "SkCodecPriv.h" |
12 #include "SkPixelRef.h" | 12 #include "SkPixelRef.h" |
13 | 13 |
14 SkBitmapRegionCodec::SkBitmapRegionCodec(SkAndroidCodec* codec) | 14 SkBitmapRegionCodec::SkBitmapRegionCodec(SkAndroidCodec* codec) |
15 : INHERITED(codec->getInfo().width(), codec->getInfo().height()) | 15 : INHERITED(codec->getInfo().width(), codec->getInfo().height()) |
16 , fCodec(codec) | 16 , fCodec(codec) |
17 {} | 17 {} |
18 | 18 |
19 bool SkBitmapRegionCodec::decodeRegion(SkBitmap* bitmap, SkBitmap::Allocator* al
locator, | 19 bool SkBitmapRegionCodec::decodeRegion(SkBitmap* bitmap, SkBRDAllocator* allocat
or, |
20 const SkIRect& desiredSubset, int sampleSize, SkColorType dstColorType, | 20 const SkIRect& desiredSubset, int sampleSize, SkColorType dstColorType, |
21 bool requireUnpremul) { | 21 bool requireUnpremul) { |
22 | 22 |
23 // Fix the input sampleSize if necessary. | 23 // Fix the input sampleSize if necessary. |
24 if (sampleSize < 1) { | 24 if (sampleSize < 1) { |
25 sampleSize = 1; | 25 sampleSize = 1; |
26 } | 26 } |
27 | 27 |
28 // The size of the output bitmap is determined by the size of the | 28 // The size of the output bitmap is determined by the size of the |
29 // requested subset, not by the size of the intersection of the subset | 29 // requested subset, not by the size of the intersection of the subset |
(...skipping 67 matching lines...) Loading... |
97 bitmap->setInfo(outInfo); | 97 bitmap->setInfo(outInfo); |
98 if (!bitmap->tryAllocPixels(allocator, colorTable.get())) { | 98 if (!bitmap->tryAllocPixels(allocator, colorTable.get())) { |
99 SkCodecPrintf("Error: Could not allocate pixels.\n"); | 99 SkCodecPrintf("Error: Could not allocate pixels.\n"); |
100 return false; | 100 return false; |
101 } | 101 } |
102 | 102 |
103 // Zero the bitmap if the region is not completely within the image. | 103 // Zero the bitmap if the region is not completely within the image. |
104 // TODO (msarett): Can we make this faster by implementing it to only | 104 // TODO (msarett): Can we make this faster by implementing it to only |
105 // zero parts of the image that we won't overwrite with | 105 // zero parts of the image that we won't overwrite with |
106 // pixels? | 106 // pixels? |
107 // TODO (msarett): This could be skipped if memory is zero initialized. | 107 SkCodec::ZeroInitialized zeroInit = allocator ? allocator->zeroInit() : |
108 // This would matter if this code is moved to Android and | 108 SkCodec::kNo_ZeroInitialized; |
109 // uses Android bitmaps. | 109 if (SubsetType::kPartiallyInside_SubsetType == type && |
110 if (SubsetType::kPartiallyInside_SubsetType == type) { | 110 SkCodec::kNo_ZeroInitialized == zeroInit) { |
111 void* pixels = bitmap->getPixels(); | 111 void* pixels = bitmap->getPixels(); |
112 size_t bytes = outInfo.getSafeSize(bitmap->rowBytes()); | 112 size_t bytes = outInfo.getSafeSize(bitmap->rowBytes()); |
113 memset(pixels, 0, bytes); | 113 memset(pixels, 0, bytes); |
114 } | 114 } |
115 | 115 |
116 // Decode into the destination bitmap | 116 // Decode into the destination bitmap |
117 SkAndroidCodec::AndroidOptions options; | 117 SkAndroidCodec::AndroidOptions options; |
118 options.fSampleSize = sampleSize; | 118 options.fSampleSize = sampleSize; |
119 options.fSubset = ⊂ | 119 options.fSubset = ⊂ |
120 options.fColorPtr = colorPtr; | 120 options.fColorPtr = colorPtr; |
121 options.fColorCount = colorCountPtr; | 121 options.fColorCount = colorCountPtr; |
| 122 options.fZeroInitialized = zeroInit; |
122 void* dst = bitmap->getAddr(scaledOutX, scaledOutY); | 123 void* dst = bitmap->getAddr(scaledOutX, scaledOutY); |
123 | 124 |
124 // FIXME: skbug.com/4538 | 125 // FIXME: skbug.com/4538 |
125 // It is important that we use the rowBytes on the pixelRef. They may not b
e | 126 // It is important that we use the rowBytes on the pixelRef. They may not b
e |
126 // set properly on the bitmap. | 127 // set properly on the bitmap. |
127 SkPixelRef* pr = SkRef(bitmap->pixelRef()); | 128 SkPixelRef* pr = SkRef(bitmap->pixelRef()); |
128 size_t rowBytes = pr->rowBytes(); | 129 size_t rowBytes = pr->rowBytes(); |
129 bitmap->setInfo(outInfo, rowBytes); | 130 bitmap->setInfo(outInfo, rowBytes); |
130 bitmap->setPixelRef(pr)->unref(); | 131 bitmap->setPixelRef(pr)->unref(); |
131 SkCodec::Result result = fCodec->getAndroidPixels(decodeInfo, dst, rowBytes,
&options); | 132 SkCodec::Result result = fCodec->getAndroidPixels(decodeInfo, dst, rowBytes,
&options); |
132 if (SkCodec::kSuccess != result && SkCodec::kIncompleteInput != result) { | 133 if (SkCodec::kSuccess != result && SkCodec::kIncompleteInput != result) { |
133 SkCodecPrintf("Error: Could not get pixels.\n"); | 134 SkCodecPrintf("Error: Could not get pixels.\n"); |
134 return false; | 135 return false; |
135 } | 136 } |
136 | 137 |
137 return true; | 138 return true; |
138 } | 139 } |
139 | 140 |
140 bool SkBitmapRegionCodec::conversionSupported(SkColorType colorType) { | 141 bool SkBitmapRegionCodec::conversionSupported(SkColorType colorType) { |
141 // FIXME: Call virtual function when it lands. | 142 // FIXME: Call virtual function when it lands. |
142 SkImageInfo info = SkImageInfo::Make(0, 0, colorType, fCodec->getInfo().alph
aType(), | 143 SkImageInfo info = SkImageInfo::Make(0, 0, colorType, fCodec->getInfo().alph
aType(), |
143 fCodec->getInfo().profileType()); | 144 fCodec->getInfo().profileType()); |
144 return conversion_possible(info, fCodec->getInfo()); | 145 return conversion_possible(info, fCodec->getInfo()); |
145 } | 146 } |
OLD | NEW |