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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 case SkCodec::kInvalidConversion: | 151 case SkCodec::kInvalidConversion: |
152 return Error::Nonfatal("Incompatible colortype conversion"); | 152 return Error::Nonfatal("Incompatible colortype conversion"); |
153 default: | 153 default: |
154 // Everything else is considered a failure. | 154 // Everything else is considered a failure. |
155 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str(
)); | 155 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str(
)); |
156 } | 156 } |
157 canvas->drawBitmap(bitmap, 0, 0); | 157 canvas->drawBitmap(bitmap, 0, 0); |
158 break; | 158 break; |
159 } | 159 } |
160 case kScanline_Mode: { | 160 case kScanline_Mode: { |
161 SkScanlineDecoder* scanlineDecoder = codec->getScanlineDecoder(decod
eInfo, NULL, | 161 SkAutoTDelete<SkScanlineDecoder> scanlineDecoder(codec->getScanlineD
ecoder( |
162 colorPtr, colorCountPtr); | 162 decodeInfo, NULL, colorPtr, colorCountPtr)); |
163 if (NULL == scanlineDecoder) { | 163 if (NULL == scanlineDecoder) { |
164 return Error::Nonfatal("Cannot use scanline decoder for all imag
es"); | 164 return Error::Nonfatal("Cannot use scanline decoder for all imag
es"); |
165 } | 165 } |
166 const SkCodec::Result result = scanlineDecoder->getScanlines( | 166 const SkCodec::Result result = scanlineDecoder->getScanlines( |
167 bitmap.getAddr(0, 0), decodeInfo.height(), bitmap.rowBytes()
); | 167 bitmap.getAddr(0, 0), decodeInfo.height(), bitmap.rowBytes()
); |
168 switch (result) { | 168 switch (result) { |
169 case SkCodec::kSuccess: | 169 case SkCodec::kSuccess: |
170 case SkCodec::kIncompleteInput: | 170 case SkCodec::kIncompleteInput: |
171 break; | 171 break; |
172 default: | 172 default: |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 //currentSubsetWidth may be larger than subsetWidth for rightmos
t subsets | 213 //currentSubsetWidth may be larger than subsetWidth for rightmos
t subsets |
214 const int currentSubsetWidth = (col + 1 == divisor) ? | 214 const int currentSubsetWidth = (col + 1 == divisor) ? |
215 subsetWidth + extraX : subsetWidth; | 215 subsetWidth + extraX : subsetWidth; |
216 const int x = col * subsetWidth; | 216 const int x = col * subsetWidth; |
217 for (int row = 0; row < divisor; row++) { | 217 for (int row = 0; row < divisor; row++) { |
218 //currentSubsetHeight may be larger than subsetHeight for bo
ttom subsets | 218 //currentSubsetHeight may be larger than subsetHeight for bo
ttom subsets |
219 const int currentSubsetHeight = (row + 1 == divisor) ? | 219 const int currentSubsetHeight = (row + 1 == divisor) ? |
220 subsetHeight + extraY : subsetHeight; | 220 subsetHeight + extraY : subsetHeight; |
221 const int y = row * subsetHeight; | 221 const int y = row * subsetHeight; |
222 //create scanline decoder for each subset | 222 //create scanline decoder for each subset |
223 SkScanlineDecoder* subsetScanlineDecoder = codec->getScanlin
eDecoder(decodeInfo, | 223 SkAutoTDelete<SkScanlineDecoder> subsetScanlineDecoder( |
224 NULL, colorPtr, colorCountPtr); | 224 codec->getScanlineDecoder(decodeInfo, NULL, colorPtr
, colorCountPtr)); |
225 if (NULL == subsetScanlineDecoder) { | 225 if (NULL == subsetScanlineDecoder) { |
226 if (x == 0 && y == 0) { | 226 if (x == 0 && y == 0) { |
227 //first try, image may not be compatible | 227 //first try, image may not be compatible |
228 return Error::Nonfatal("Cannot use scanline decoder
for all images"); | 228 return Error::Nonfatal("Cannot use scanline decoder
for all images"); |
229 } else { | 229 } else { |
230 return "Error scanline decoder is NULL"; | 230 return "Error scanline decoder is NULL"; |
231 } | 231 } |
232 } | 232 } |
233 //skip to first line of subset | 233 //skip to first line of subset |
234 const SkCodec::Result skipResult = | 234 const SkCodec::Result skipResult = |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 break; | 280 break; |
281 } | 281 } |
282 case kStripe_Mode: { | 282 case kStripe_Mode: { |
283 const int height = decodeInfo.height(); | 283 const int height = decodeInfo.height(); |
284 // This value is chosen arbitrarily. We exercise more cases by choo
sing a value that | 284 // This value is chosen arbitrarily. We exercise more cases by choo
sing a value that |
285 // does not align with image blocks. | 285 // does not align with image blocks. |
286 const int stripeHeight = 37; | 286 const int stripeHeight = 37; |
287 const int numStripes = (height + stripeHeight - 1) / stripeHeight; | 287 const int numStripes = (height + stripeHeight - 1) / stripeHeight; |
288 | 288 |
289 // Decode odd stripes | 289 // Decode odd stripes |
290 SkScanlineDecoder* decoder = codec->getScanlineDecoder(decodeInfo, N
ULL, colorPtr, | 290 SkAutoTDelete<SkScanlineDecoder> decoder( |
291 colorCountPtr); | 291 codec->getScanlineDecoder(decodeInfo, NULL, colorPtr, colorC
ountPtr)); |
292 if (NULL == decoder) { | 292 if (NULL == decoder) { |
293 return Error::Nonfatal("Cannot use scanline decoder for all imag
es"); | 293 return Error::Nonfatal("Cannot use scanline decoder for all imag
es"); |
294 } | 294 } |
295 for (int i = 0; i < numStripes; i += 2) { | 295 for (int i = 0; i < numStripes; i += 2) { |
296 // Skip a stripe | 296 // Skip a stripe |
297 const int linesToSkip = SkTMin(stripeHeight, height - i * stripe
Height); | 297 const int linesToSkip = SkTMin(stripeHeight, height - i * stripe
Height); |
298 SkCodec::Result result = decoder->skipScanlines(linesToSkip); | 298 SkCodec::Result result = decoder->skipScanlines(linesToSkip); |
299 switch (result) { | 299 switch (result) { |
300 case SkCodec::kSuccess: | 300 case SkCodec::kSuccess: |
301 case SkCodec::kIncompleteInput: | 301 case SkCodec::kIncompleteInput: |
(...skipping 12 matching lines...) Expand all Loading... |
314 case SkCodec::kSuccess: | 314 case SkCodec::kSuccess: |
315 case SkCodec::kIncompleteInput: | 315 case SkCodec::kIncompleteInput: |
316 break; | 316 break; |
317 default: | 317 default: |
318 return SkStringPrintf("Cannot get scanlines for %s."
, fPath.c_str()); | 318 return SkStringPrintf("Cannot get scanlines for %s."
, fPath.c_str()); |
319 } | 319 } |
320 } | 320 } |
321 } | 321 } |
322 | 322 |
323 // Decode even stripes | 323 // Decode even stripes |
324 decoder = codec->getScanlineDecoder(decodeInfo, NULL, colorPtr, colo
rCountPtr); | 324 decoder.reset(codec->getScanlineDecoder(decodeInfo, NULL, colorPtr,
colorCountPtr)); |
325 if (NULL == decoder) { | 325 if (NULL == decoder) { |
326 return "Failed to create second scanline decoder."; | 326 return "Failed to create second scanline decoder."; |
327 } | 327 } |
328 for (int i = 0; i < numStripes; i += 2) { | 328 for (int i = 0; i < numStripes; i += 2) { |
329 // Read a stripe | 329 // Read a stripe |
330 const int startY = i * stripeHeight; | 330 const int startY = i * stripeHeight; |
331 const int linesToRead = SkTMin(stripeHeight, height - startY); | 331 const int linesToRead = SkTMin(stripeHeight, height - startY); |
332 SkCodec::Result result = decoder->getScanlines(bitmap.getAddr(0,
startY), | 332 SkCodec::Result result = decoder->getScanlines(bitmap.getAddr(0,
startY), |
333 linesToRead, bitmap.rowBytes()); | 333 linesToRead, bitmap.rowBytes()); |
334 switch (result) { | 334 switch (result) { |
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
989 skr.visit<void>(i, drawsAsSingletonPictures); | 989 skr.visit<void>(i, drawsAsSingletonPictures); |
990 } | 990 } |
991 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); | 991 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); |
992 | 992 |
993 canvas->drawPicture(macroPic); | 993 canvas->drawPicture(macroPic); |
994 return ""; | 994 return ""; |
995 }); | 995 }); |
996 } | 996 } |
997 | 997 |
998 } // namespace DM | 998 } // namespace DM |
OLD | NEW |