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 "DMSrcSink.h" | 8 #include "DMSrcSink.h" |
9 #include "SamplePipeControllers.h" | 9 #include "SamplePipeControllers.h" |
10 #include "SkCodec.h" | 10 #include "SkCodec.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 // We consider incomplete to be valid, since we should still decode what is | 134 // We consider incomplete to be valid, since we should still decode what is |
135 // available. | 135 // available. |
136 case SkImageGenerator::kIncompleteInput: | 136 case SkImageGenerator::kIncompleteInput: |
137 break; | 137 break; |
138 case SkImageGenerator::kInvalidConversion: | 138 case SkImageGenerator::kInvalidConversion: |
139 return Error::Nonfatal("Incompatible colortype conversion"); | 139 return Error::Nonfatal("Incompatible colortype conversion"); |
140 default: | 140 default: |
141 // Everything else is considered a failure. | 141 // Everything else is considered a failure. |
142 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str( )); | 142 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str( )); |
143 } | 143 } |
144 canvas->drawBitmap(bitmap, 0, 0); | |
144 break; | 145 break; |
145 case kScanline_Mode: { | 146 case kScanline_Mode: { |
146 SkScanlineDecoder* scanlineDecoder = codec->getScanlineDecoder(decod eInfo, NULL, | 147 SkScanlineDecoder* scanlineDecoder = codec->getScanlineDecoder(decod eInfo, NULL, |
147 colorPtr, colorCountPtr); | 148 colorPtr, colorCountPtr); |
148 if (NULL == scanlineDecoder) { | 149 if (NULL == scanlineDecoder) { |
149 return Error::Nonfatal("Cannot use scanline decoder for all imag es"); | 150 return Error::Nonfatal("Cannot use scanline decoder for all imag es"); |
150 } | 151 } |
151 for (int y = 0; y < decodeInfo.height(); ++y) { | 152 for (int y = 0; y < decodeInfo.height(); ++y) { |
152 const SkImageGenerator::Result result = scanlineDecoder->getScan lines( | 153 const SkImageGenerator::Result result = scanlineDecoder->getScan lines( |
153 bitmap.getAddr(0, y), 1, 0); | 154 bitmap.getAddr(0, y), 1, 0); |
154 switch (result) { | 155 switch (result) { |
155 case SkImageGenerator::kSuccess: | 156 case SkImageGenerator::kSuccess: |
156 case SkImageGenerator::kIncompleteInput: | 157 case SkImageGenerator::kIncompleteInput: |
157 break; | 158 break; |
158 default: | 159 default: |
159 return SkStringPrintf("%s failed after %d scanlines with error message %d", | 160 return SkStringPrintf("%s failed after %d scanlines with error message %d", |
160 fPath.c_str(), y-1, (int) result); | 161 fPath.c_str(), y-1, (int) result); |
161 } | 162 } |
162 } | 163 } |
164 canvas->drawBitmap(bitmap, 0, 0); | |
165 break; | |
166 } | |
167 case kSubset_Mode: { | |
168 //this mode decodes the image in 4 subsets, using a scanline decoder | |
169 int fDivisor = 2; | |
scroggo
2015/05/18 14:03:58
style nit: Skia adds an 'f' to the beginning of va
emmaleeroach
2015/05/18 20:04:27
On 2015/05/18 14:03:58, scroggo wrote:
> style nit
| |
170 SkScanlineDecoder* subsetScanlineDecoder = codec->getScanlineDecoder (decodeInfo, NULL, | |
171 colorPtr, colorCountPtr); | |
172 if (NULL == subsetScanlineDecoder) { | |
173 return Error::Nonfatal("Cannot use scanline decoder for all imag es"); | |
174 } | |
175 SkImageInfo subsetDecodeInfo = decodeInfo.makeWH(decodeInfo.width()/ fDivisor, | |
176 decodeInfo.height()/fDivisor); | |
177 SkBitmap subsetBm; | |
178 if (!subsetBm.tryAllocPixels(subsetDecodeInfo, NULL, colorTable.get( ))) { | |
179 return SkStringPrintf("Image(%s) is too large (%d x %d)\n", fPat h.c_str(), | |
180 subsetDecodeInfo.width(), subsetDecodeInfo.height()); | |
181 } | |
182 char* line = new char[decodeInfo.width()*decodeInfo.bytesPerPixel()] ; | |
scroggo
2015/05/18 14:03:58
This will leak. You can solve this a few different
emmaleeroach
2015/05/18 20:04:27
On 2015/05/18 14:03:58, scroggo wrote:
> This will
scroggo
2015/05/18 20:43:18
Yes.
| |
183 for (int subset = 0; subset < fDivisor*2; subset++) { | |
scroggo
2015/05/18 14:03:58
subset < fDivisor*2
Shouldn't this be subset < fD
emmaleeroach
2015/05/18 20:04:27
On 2015/05/18 14:03:58, scroggo wrote:
> subset <
| |
184 //reset scanline decoder for right half of image | |
185 if (subset == 2) { | |
scroggo
2015/05/18 14:03:59
Again, this supposes that fDivisor is 2. The nice
emmaleeroach
2015/05/18 20:04:27
On 2015/05/18 14:03:59, scroggo wrote:
> Again, th
| |
186 subsetScanlineDecoder = codec->getScanlineDecoder(decodeInfo , NULL, | |
187 colorPtr, colorCountPtr); | |
188 if (NULL == subsetScanlineDecoder) { | |
189 return Error::Nonfatal("Cannot use scanline decoder for all images"); | |
scroggo
2015/05/18 14:03:59
I think in this case we have an actual error. If t
emmaleeroach
2015/05/18 20:04:27
On 2015/05/18 14:03:59, scroggo wrote:
> I think i
scroggo
2015/05/18 20:43:18
Oh, no, the check is necessary; the behavior if su
emmaleeroach
2015/05/18 22:35:14
On 2015/05/18 20:43:18, scroggo wrote:
> On 2015/0
scroggo
2015/05/18 23:02:17
Yes. Both the message itself and "Error::Nonfatal"
| |
190 } | |
191 } | |
192 for (int y = 0; y < subsetDecodeInfo.height(); ++y) { | |
193 const SkImageGenerator::Result subsetResult = | |
194 subsetScanlineDecoder->getScanlines(line, 1, 0); | |
195 if (subset == 0 || subset == 1) { | |
196 //if subset is on left copy left half of line | |
197 memcpy(subsetBm.getAddr(0, y), line, | |
198 subsetDecodeInfo.width()*subsetDecodeInfo.bytesP erPixel()); | |
199 } else { | |
200 //if subset if on right copy right half of line | |
scroggo
2015/05/18 14:03:58
is*
emmaleeroach
2015/05/18 20:04:27
Acknowledged.
| |
201 memcpy(subsetBm.getAddr(0,y), | |
scroggo
2015/05/18 14:03:58
Won't this copy to the beginning of this row?
emmaleeroach
2015/05/18 20:04:27
On 2015/05/18 14:03:58, scroggo wrote:
> Won't thi
scroggo
2015/05/18 20:43:18
Oh, of course!
| |
202 line + subsetDecodeInfo.width()*subsetDecodeInfo .bytesPerPixel(), | |
203 subsetDecodeInfo.width()*subsetDecodeInfo.bytesP erPixel()); | |
scroggo
2015/05/18 14:03:58
Won't this copy too much?
emmaleeroach
2015/05/18 20:04:27
On 2015/05/18 14:03:58, scroggo wrote:
> Won't thi
scroggo
2015/05/18 20:43:17
Got it. My eyes must have glazed over when I read
| |
204 } | |
205 switch (subsetResult) { | |
206 case SkImageGenerator::kSuccess: | |
207 case SkImageGenerator::kIncompleteInput: | |
208 break; | |
209 default: | |
210 return SkStringPrintf("%s failed after %d scanlines with error" | |
211 "message %d", fPath.c_str(), y-1, (int) subs etResult); | |
212 } | |
213 } | |
214 int w; | |
215 int h; | |
scroggo
2015/05/18 14:03:58
nit: These variables look like width and height, b
emmaleeroach
2015/05/18 20:04:27
On 2015/05/18 14:03:58, scroggo wrote:
> nit: Thes
| |
216 //set drawing position based on subset number | |
217 switch (subset) { | |
scroggo
2015/05/18 14:03:58
nit: This works with a divisor of 2, but I think i
emmaleeroach
2015/05/18 20:04:27
On 2015/05/18 14:03:58, scroggo wrote:
> nit: This
scroggo
2015/05/18 20:43:18
https://skia.googlesource.com/skia/+/7be0ce0ab123b
emmaleeroach
2015/05/18 22:35:14
On 2015/05/18 20:43:18, scroggo wrote:
> On 2015/0
| |
218 case 0: | |
219 w = 0; | |
220 h = 0; | |
221 break; | |
222 case 1: | |
223 w = 0; | |
224 h = subsetDecodeInfo.height(); | |
225 break; | |
226 case 2: | |
227 w = subsetDecodeInfo.width(); | |
228 h = 0; | |
229 break; | |
230 case 3: | |
231 w = subsetDecodeInfo.width(); | |
232 h = subsetDecodeInfo.height(); | |
233 break; | |
234 } | |
235 canvas->drawBitmap(subsetBm, w, h); | |
236 } | |
163 break; | 237 break; |
164 } | 238 } |
165 } | 239 } |
166 canvas->drawBitmap(bitmap, 0, 0); | |
167 return ""; | 240 return ""; |
168 } | 241 } |
169 | 242 |
170 SkISize CodecSrc::size() const { | 243 SkISize CodecSrc::size() const { |
171 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 244 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
172 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); | 245 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
173 if (NULL != codec) { | 246 if (NULL != codec) { |
174 return codec->getInfo().dimensions(); | 247 return codec->getInfo().dimensions(); |
175 } else { | 248 } else { |
176 return SkISize::Make(0, 0); | 249 return SkISize::Make(0, 0); |
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
780 skr.visit<void>(i, drawsAsSingletonPictures); | 853 skr.visit<void>(i, drawsAsSingletonPictures); |
781 } | 854 } |
782 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); | 855 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); |
783 | 856 |
784 canvas->drawPicture(macroPic); | 857 canvas->drawPicture(macroPic); |
785 return ""; | 858 return ""; |
786 }); | 859 }); |
787 } | 860 } |
788 | 861 |
789 } // namespace DM | 862 } // namespace DM |
OLD | NEW |