| 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 kStripe_Mode: { | 375 case kTile_Mode: { |
| 376 const int width = decodeInfo.width(); |
| 376 const int height = decodeInfo.height(); | 377 const int height = decodeInfo.height(); |
| 377 // This value is chosen arbitrarily. We exercise more cases by choo
sing a value that | 378 // This value is chosen arbitrarily. We exercise more cases by choo
sing a value that |
| 378 // does not align with image blocks. | 379 // does not align with image blocks. |
| 379 const int stripeHeight = 37; | 380 const int tileSize = 37; |
| 380 const int numStripes = (height + stripeHeight - 1) / stripeHeight; | 381 const int tileWidth = (width + tileSize - 1) / tileSize; |
| 382 const int tileHeight = (height + tileSize - 1) / tileSize; |
| 381 | 383 |
| 382 // Decode odd stripes | 384 SkCodec::Options opts; |
| 383 if (SkCodec::kSuccess != codec->startScanlineDecode(decodeInfo, NULL
, colorPtr, | 385 SkIRect subset; |
| 384 colorCountPtr) | 386 for (int tileX = 0; tileX < tileWidth; tileX++) { |
| 385 || SkCodec::kTopDown_SkScanlineOrder != codec->getScanlineOr
der()) { | 387 const int startX = tileX * tileSize; |
| 386 // This mode was designed to test the new skip scanlines API in
libjpeg-turbo. | 388 subset = SkIRect::MakeXYWH(startX, 0, SkTMin(tileSize, width - s
tartX), height); |
| 387 // Jpegs have kTopDown_SkScanlineOrder, and at this time, it is
not interesting | 389 opts.fSubset = ⊂ |
| 388 // to run this test for image types that do not have this scanli
ne ordering. | 390 for (int tileY = 0; tileY < tileHeight; tileY++) { |
| 389 return Error::Nonfatal("Could not start top-down scanline decode
r"); | 391 if (SkCodec::kSuccess != codec->startScanlineDecode(decodeIn
fo, &opts, |
| 390 } | 392 colorPtr, colorCountPtr) || |
| 393 SkCodec::kTopDown_SkScanlineOrder != codec->getScanl
ineOrder()) { |
| 394 if (0 == tileY && 0 == tileX) { |
| 395 return Error::Nonfatal("Could not start top-down sca
nline decoder"); |
| 396 } |
| 397 return "Could not restart scanline decoder."; |
| 398 } |
| 391 | 399 |
| 392 for (int i = 0; i < numStripes; i += 2) { | 400 const int startY = tileY * tileSize; |
| 393 // Skip a stripe | 401 codec->skipScanlines(startY); |
| 394 const int linesToSkip = SkTMin(stripeHeight, height - i * stripe
Height); | 402 const int linesToGet = SkTMin(tileSize, height - startY); |
| 395 codec->skipScanlines(linesToSkip); | 403 codec->getScanlines(bitmap.getAddr(startX, startY), linesToG
et, |
| 396 | 404 bitmap.rowBytes()); |
| 397 // Read a stripe | |
| 398 const int startY = (i + 1) * stripeHeight; | |
| 399 const int linesToRead = SkTMin(stripeHeight, height - startY); | |
| 400 if (linesToRead > 0) { | |
| 401 codec->getScanlines(bitmap.getAddr(0, startY), linesToRead,
bitmap.rowBytes()); | |
| 402 } | 405 } |
| 403 } | 406 } |
| 404 | 407 |
| 405 // Decode even stripes | |
| 406 const SkCodec::Result startResult = codec->startScanlineDecode(decod
eInfo, nullptr, | |
| 407 colorPtr, colorCountPtr); | |
| 408 if (SkCodec::kSuccess != startResult) { | |
| 409 return "Failed to restart scanline decoder with same parameters.
"; | |
| 410 } | |
| 411 for (int i = 0; i < numStripes; i += 2) { | |
| 412 // Read a stripe | |
| 413 const int startY = i * stripeHeight; | |
| 414 const int linesToRead = SkTMin(stripeHeight, height - startY); | |
| 415 codec->getScanlines(bitmap.getAddr(0, startY), linesToRead, bitm
ap.rowBytes()); | |
| 416 | |
| 417 // Skip a stripe | |
| 418 const int linesToSkip = SkTMin(stripeHeight, height - (i + 1) *
stripeHeight); | |
| 419 if (linesToSkip > 0) { | |
| 420 codec->skipScanlines(linesToSkip); | |
| 421 } | |
| 422 } | |
| 423 canvas->drawBitmap(bitmap, 0, 0); | 408 canvas->drawBitmap(bitmap, 0, 0); |
| 424 break; | 409 break; |
| 425 } | 410 } |
| 426 case kSubset_Mode: { | 411 case kSubset_Mode: { |
| 427 // Arbitrarily choose a divisor. | 412 // Arbitrarily choose a divisor. |
| 428 int divisor = 2; | 413 int divisor = 2; |
| 429 // Total width/height of the image. | 414 // Total width/height of the image. |
| 430 const int W = codec->getInfo().width(); | 415 const int W = codec->getInfo().width(); |
| 431 const int H = codec->getInfo().height(); | 416 const int H = codec->getInfo().height(); |
| 432 if (divisor > W || divisor > H) { | 417 if (divisor > W || divisor > H) { |
| (...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1264 skr.visit<void>(i, drawsAsSingletonPictures); | 1249 skr.visit<void>(i, drawsAsSingletonPictures); |
| 1265 } | 1250 } |
| 1266 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); | 1251 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); |
| 1267 | 1252 |
| 1268 canvas->drawPicture(macroPic); | 1253 canvas->drawPicture(macroPic); |
| 1269 return ""; | 1254 return ""; |
| 1270 }); | 1255 }); |
| 1271 } | 1256 } |
| 1272 | 1257 |
| 1273 } // namespace DM | 1258 } // namespace DM |
| OLD | NEW |