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 "SkAndroidCodec.h" | 10 #include "SkAndroidCodec.h" |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 // memory will be filled with the proper value. | 365 // memory will be filled with the proper value. |
366 codec->getScanlines(dstPtr, 1, bitmap.rowBytes()); | 366 codec->getScanlines(dstPtr, 1, bitmap.rowBytes()); |
367 } | 367 } |
368 break; | 368 break; |
369 } | 369 } |
370 } | 370 } |
371 | 371 |
372 canvas->drawBitmap(bitmap, 0, 0); | 372 canvas->drawBitmap(bitmap, 0, 0); |
373 break; | 373 break; |
374 } | 374 } |
375 case kScanline_Subset_Mode: { | |
376 //this mode decodes the image in divisor*divisor subsets, using a sc
anline decoder | |
377 const int divisor = 2; | |
378 const int w = decodeInfo.width(); | |
379 const int h = decodeInfo.height(); | |
380 if (divisor > w || divisor > h) { | |
381 return Error::Nonfatal(SkStringPrintf("Cannot decode subset: div
isor %d is too big" | |
382 "for %s with dimensions (%d x %d)", divisor, fPath.c_str
(), w, h)); | |
383 } | |
384 const int subsetWidth = w/divisor; | |
385 const int subsetHeight = h/divisor; | |
386 // One of our subsets will be larger to contain any pixels that do n
ot divide evenly. | |
387 const int extraX = w % divisor; | |
388 const int extraY = h % divisor; | |
389 /* | |
390 * if w or h are not evenly divided by divisor need to adjust width a
nd height of end | |
391 * subsets to cover entire image. | |
392 * Add extraX and extraY to largestSubsetBm's width and height to adj
ust width | |
393 * and height of end subsets. | |
394 * subsetBm is extracted from largestSubsetBm. | |
395 * subsetBm's size is determined based on the current subset and may
be larger for end | |
396 * subsets. | |
397 */ | |
398 SkImageInfo largestSubsetDecodeInfo = | |
399 decodeInfo.makeWH(subsetWidth + extraX, subsetHeight + extra
Y); | |
400 SkBitmap largestSubsetBm; | |
401 if (!largestSubsetBm.tryAllocPixels(largestSubsetDecodeInfo, nullptr
, | |
402 colorTable.get())) { | |
403 return SkStringPrintf("Image(%s) is too large (%d x %d)\n", fPat
h.c_str(), | |
404 largestSubsetDecodeInfo.width(), largestSubsetDecodeInfo
.height()); | |
405 } | |
406 for (int col = 0; col < divisor; col++) { | |
407 //currentSubsetWidth may be larger than subsetWidth for rightmos
t subsets | |
408 const int currentSubsetWidth = (col + 1 == divisor) ? | |
409 subsetWidth + extraX : subsetWidth; | |
410 const int x = col * subsetWidth; | |
411 for (int row = 0; row < divisor; row++) { | |
412 //currentSubsetHeight may be larger than subsetHeight for bo
ttom subsets | |
413 const int currentSubsetHeight = (row + 1 == divisor) ? | |
414 subsetHeight + extraY : subsetHeight; | |
415 const int y = row * subsetHeight; | |
416 //create scanline decoder for each subset | |
417 SkCodec::Options options; | |
418 SkIRect subset = SkIRect::MakeXYWH(x, 0, currentSubsetWidth,
h); | |
419 options.fSubset = ⊂ | |
420 // TODO (msarett): Support this mode for all scanline orderi
ngs. | |
421 if (SkCodec::kSuccess != codec->startScanlineDecode(decodeIn
fo, &options, | |
422 colorPtr, colorCountPtr) || | |
423 SkCodec::kTopDown_SkScanlineOrder != codec->getScanl
ineOrder()) { | |
424 if (x == 0 && y == 0) { | |
425 //first try, image may not be compatible | |
426 return Error::Nonfatal("Could not start top-down sca
nline decoder"); | |
427 } else { | |
428 return "Error scanline decoder is nullptr"; | |
429 } | |
430 } | |
431 // Skip to the first line of subset. We ignore the result v
alue here. | |
432 // If the skip value fails, this will indicate an incomplete
image. | |
433 // This means that the call to getScanlines() will also fail
, but it | |
434 // will fill the buffer with a default value, so we can stil
l draw the | |
435 // image. | |
436 codec->skipScanlines(y); | |
437 | |
438 //create and set size of subsetBm | |
439 SkBitmap subsetBm; | |
440 SkIRect bounds = SkIRect::MakeWH(currentSubsetWidth, current
SubsetHeight); | |
441 SkAssertResult(largestSubsetBm.extractSubset(&subsetBm, boun
ds)); | |
442 SkAutoLockPixels autolock(subsetBm, true); | |
443 codec->getScanlines(subsetBm.getAddr(0, 0), currentSubsetHei
ght, | |
444 subsetBm.rowBytes()); | |
445 subsetBm.notifyPixelsChanged(); | |
446 canvas->drawBitmap(subsetBm, SkIntToScalar(x), SkIntToScalar
(y)); | |
447 } | |
448 } | |
449 break; | |
450 } | |
451 case kStripe_Mode: { | 375 case kStripe_Mode: { |
452 const int height = decodeInfo.height(); | 376 const int height = decodeInfo.height(); |
453 // This value is chosen arbitrarily. We exercise more cases by choo
sing a value that | 377 // This value is chosen arbitrarily. We exercise more cases by choo
sing a value that |
454 // does not align with image blocks. | 378 // does not align with image blocks. |
455 const int stripeHeight = 37; | 379 const int stripeHeight = 37; |
456 const int numStripes = (height + stripeHeight - 1) / stripeHeight; | 380 const int numStripes = (height + stripeHeight - 1) / stripeHeight; |
457 | 381 |
458 // Decode odd stripes | 382 // Decode odd stripes |
459 if (SkCodec::kSuccess != codec->startScanlineDecode(decodeInfo, NULL
, colorPtr, | 383 if (SkCodec::kSuccess != codec->startScanlineDecode(decodeInfo, NULL
, colorPtr, |
460 colorCountPtr) | 384 colorCountPtr) |
(...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1332 skr.visit<void>(i, drawsAsSingletonPictures); | 1256 skr.visit<void>(i, drawsAsSingletonPictures); |
1333 } | 1257 } |
1334 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); | 1258 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); |
1335 | 1259 |
1336 canvas->drawPicture(macroPic); | 1260 canvas->drawPicture(macroPic); |
1337 return ""; | 1261 return ""; |
1338 }); | 1262 }); |
1339 } | 1263 } |
1340 | 1264 |
1341 } // namespace DM | 1265 } // namespace DM |
OLD | NEW |