| 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 SkAutoTDelete<SkScanlineDecoder> scanlineDecoder(codec->getScanlineD
ecoder( | 161 SkAutoTDelete<SkScanlineDecoder> scanlineDecoder( |
| 162 decodeInfo, NULL, colorPtr, colorCountPtr)); | 162 SkScanlineDecoder::NewFromData(encoded)); |
| 163 if (NULL == scanlineDecoder) { | 163 if (NULL == scanlineDecoder || SkCodec::kSuccess != |
| 164 scanlineDecoder->reset(decodeInfo, NULL, colorPtr, colorCoun
tPtr)) { |
| 164 return Error::Nonfatal("Cannot use scanline decoder for all imag
es"); | 165 return Error::Nonfatal("Cannot use scanline decoder for all imag
es"); |
| 165 } | 166 } |
| 167 |
| 166 const SkCodec::Result result = scanlineDecoder->getScanlines( | 168 const SkCodec::Result result = scanlineDecoder->getScanlines( |
| 167 bitmap.getAddr(0, 0), decodeInfo.height(), bitmap.rowBytes()
); | 169 bitmap.getAddr(0, 0), decodeInfo.height(), bitmap.rowBytes()
); |
| 168 switch (result) { | 170 switch (result) { |
| 169 case SkCodec::kSuccess: | 171 case SkCodec::kSuccess: |
| 170 case SkCodec::kIncompleteInput: | 172 case SkCodec::kIncompleteInput: |
| 171 break; | 173 break; |
| 172 default: | 174 default: |
| 173 return SkStringPrintf("%s failed with error message %d", | 175 return SkStringPrintf("%s failed with error message %d", |
| 174 fPath.c_str(), (int) result); | 176 fPath.c_str(), (int) result); |
| 175 } | 177 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 const int currentSubsetWidth = (col + 1 == divisor) ? | 216 const int currentSubsetWidth = (col + 1 == divisor) ? |
| 215 subsetWidth + extraX : subsetWidth; | 217 subsetWidth + extraX : subsetWidth; |
| 216 const int x = col * subsetWidth; | 218 const int x = col * subsetWidth; |
| 217 for (int row = 0; row < divisor; row++) { | 219 for (int row = 0; row < divisor; row++) { |
| 218 //currentSubsetHeight may be larger than subsetHeight for bo
ttom subsets | 220 //currentSubsetHeight may be larger than subsetHeight for bo
ttom subsets |
| 219 const int currentSubsetHeight = (row + 1 == divisor) ? | 221 const int currentSubsetHeight = (row + 1 == divisor) ? |
| 220 subsetHeight + extraY : subsetHeight; | 222 subsetHeight + extraY : subsetHeight; |
| 221 const int y = row * subsetHeight; | 223 const int y = row * subsetHeight; |
| 222 //create scanline decoder for each subset | 224 //create scanline decoder for each subset |
| 223 SkAutoTDelete<SkScanlineDecoder> subsetScanlineDecoder( | 225 SkAutoTDelete<SkScanlineDecoder> subsetScanlineDecoder( |
| 224 codec->getScanlineDecoder(decodeInfo, NULL, colorPtr
, colorCountPtr)); | 226 SkScanlineDecoder::NewFromData(encoded)); |
| 225 if (NULL == subsetScanlineDecoder) { | 227 if (NULL == subsetScanlineDecoder || SkCodec::kSuccess != |
| 228 subsetScanlineDecoder->reset( |
| 229 decodeInfo, NULL, colorPtr, colorCountPtr)) |
| 230 { |
| 226 if (x == 0 && y == 0) { | 231 if (x == 0 && y == 0) { |
| 227 //first try, image may not be compatible | 232 //first try, image may not be compatible |
| 228 return Error::Nonfatal("Cannot use scanline decoder
for all images"); | 233 return Error::Nonfatal("Cannot use scanline decoder
for all images"); |
| 229 } else { | 234 } else { |
| 230 return "Error scanline decoder is NULL"; | 235 return "Error scanline decoder is NULL"; |
| 231 } | 236 } |
| 232 } | 237 } |
| 233 //skip to first line of subset | 238 //skip to first line of subset |
| 234 const SkCodec::Result skipResult = | 239 const SkCodec::Result skipResult = |
| 235 subsetScanlineDecoder->skipScanlines(y); | 240 subsetScanlineDecoder->skipScanlines(y); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 break; | 285 break; |
| 281 } | 286 } |
| 282 case kStripe_Mode: { | 287 case kStripe_Mode: { |
| 283 const int height = decodeInfo.height(); | 288 const int height = decodeInfo.height(); |
| 284 // This value is chosen arbitrarily. We exercise more cases by choo
sing a value that | 289 // This value is chosen arbitrarily. We exercise more cases by choo
sing a value that |
| 285 // does not align with image blocks. | 290 // does not align with image blocks. |
| 286 const int stripeHeight = 37; | 291 const int stripeHeight = 37; |
| 287 const int numStripes = (height + stripeHeight - 1) / stripeHeight; | 292 const int numStripes = (height + stripeHeight - 1) / stripeHeight; |
| 288 | 293 |
| 289 // Decode odd stripes | 294 // Decode odd stripes |
| 290 SkAutoTDelete<SkScanlineDecoder> decoder( | 295 SkAutoTDelete<SkScanlineDecoder> decoder(SkScanlineDecoder::NewFromD
ata(encoded)); |
| 291 codec->getScanlineDecoder(decodeInfo, NULL, colorPtr, colorC
ountPtr)); | 296 if (NULL == decoder || SkCodec::kSuccess != |
| 292 if (NULL == decoder) { | 297 decoder->reset(decodeInfo, NULL, colorPtr, colorCountPtr)) { |
| 293 return Error::Nonfatal("Cannot use scanline decoder for all imag
es"); | 298 return Error::Nonfatal("Cannot use scanline decoder for all imag
es"); |
| 294 } | 299 } |
| 295 for (int i = 0; i < numStripes; i += 2) { | 300 for (int i = 0; i < numStripes; i += 2) { |
| 296 // Skip a stripe | 301 // Skip a stripe |
| 297 const int linesToSkip = SkTMin(stripeHeight, height - i * stripe
Height); | 302 const int linesToSkip = SkTMin(stripeHeight, height - i * stripe
Height); |
| 298 SkCodec::Result result = decoder->skipScanlines(linesToSkip); | 303 SkCodec::Result result = decoder->skipScanlines(linesToSkip); |
| 299 switch (result) { | 304 switch (result) { |
| 300 case SkCodec::kSuccess: | 305 case SkCodec::kSuccess: |
| 301 case SkCodec::kIncompleteInput: | 306 case SkCodec::kIncompleteInput: |
| 302 break; | 307 break; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 314 case SkCodec::kSuccess: | 319 case SkCodec::kSuccess: |
| 315 case SkCodec::kIncompleteInput: | 320 case SkCodec::kIncompleteInput: |
| 316 break; | 321 break; |
| 317 default: | 322 default: |
| 318 return SkStringPrintf("Cannot get scanlines for %s."
, fPath.c_str()); | 323 return SkStringPrintf("Cannot get scanlines for %s."
, fPath.c_str()); |
| 319 } | 324 } |
| 320 } | 325 } |
| 321 } | 326 } |
| 322 | 327 |
| 323 // Decode even stripes | 328 // Decode even stripes |
| 324 decoder.reset(codec->getScanlineDecoder(decodeInfo, NULL, colorPtr,
colorCountPtr)); | 329 const SkCodec::Result resetResult = decoder->reset(decodeInfo, NULL,
colorPtr, |
| 325 if (NULL == decoder) { | 330 colorCountPtr); |
| 326 return "Failed to create second scanline decoder."; | 331 if (SkCodec::kSuccess != resetResult) { |
| 332 return "Failed to reset scanline decoder with same parameters."; |
| 327 } | 333 } |
| 328 for (int i = 0; i < numStripes; i += 2) { | 334 for (int i = 0; i < numStripes; i += 2) { |
| 329 // Read a stripe | 335 // Read a stripe |
| 330 const int startY = i * stripeHeight; | 336 const int startY = i * stripeHeight; |
| 331 const int linesToRead = SkTMin(stripeHeight, height - startY); | 337 const int linesToRead = SkTMin(stripeHeight, height - startY); |
| 332 SkCodec::Result result = decoder->getScanlines(bitmap.getAddr(0,
startY), | 338 SkCodec::Result result = decoder->getScanlines(bitmap.getAddr(0,
startY), |
| 333 linesToRead, bitmap.rowBytes()); | 339 linesToRead, bitmap.rowBytes()); |
| 334 switch (result) { | 340 switch (result) { |
| 335 case SkCodec::kSuccess: | 341 case SkCodec::kSuccess: |
| 336 case SkCodec::kIncompleteInput: | 342 case SkCodec::kIncompleteInput: |
| (...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1066 skr.visit<void>(i, drawsAsSingletonPictures); | 1072 skr.visit<void>(i, drawsAsSingletonPictures); |
| 1067 } | 1073 } |
| 1068 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); | 1074 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); |
| 1069 | 1075 |
| 1070 canvas->drawPicture(macroPic); | 1076 canvas->drawPicture(macroPic); |
| 1071 return ""; | 1077 return ""; |
| 1072 }); | 1078 }); |
| 1073 } | 1079 } |
| 1074 | 1080 |
| 1075 } // namespace DM | 1081 } // namespace DM |
| OLD | NEW |