Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: dm/DMSrcSink.cpp

Issue 1390213002: Add subsetting to SkScanlineDecoder (Closed) Base URL: https://skia.googlesource.com/skia.git@fill-refactor
Patch Set: Response to comments Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « bench/subset/SubsetZoomBench.cpp ('k') | include/codec/SkCodec.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 * subsets. 393 * subsets.
394 */ 394 */
395 SkImageInfo largestSubsetDecodeInfo = 395 SkImageInfo largestSubsetDecodeInfo =
396 decodeInfo.makeWH(subsetWidth + extraX, subsetHeight + extra Y); 396 decodeInfo.makeWH(subsetWidth + extraX, subsetHeight + extra Y);
397 SkBitmap largestSubsetBm; 397 SkBitmap largestSubsetBm;
398 if (!largestSubsetBm.tryAllocPixels(largestSubsetDecodeInfo, nullptr , 398 if (!largestSubsetBm.tryAllocPixels(largestSubsetDecodeInfo, nullptr ,
399 colorTable.get())) { 399 colorTable.get())) {
400 return SkStringPrintf("Image(%s) is too large (%d x %d)\n", fPat h.c_str(), 400 return SkStringPrintf("Image(%s) is too large (%d x %d)\n", fPat h.c_str(),
401 largestSubsetDecodeInfo.width(), largestSubsetDecodeInfo .height()); 401 largestSubsetDecodeInfo.width(), largestSubsetDecodeInfo .height());
402 } 402 }
403 const size_t rowBytes = decodeInfo.minRowBytes();
404 char* buffer = new char[largestSubsetDecodeInfo.height() * rowBytes] ;
405 SkAutoTDeleteArray<char> lineDeleter(buffer);
406 for (int col = 0; col < divisor; col++) { 403 for (int col = 0; col < divisor; col++) {
407 //currentSubsetWidth may be larger than subsetWidth for rightmos t subsets 404 //currentSubsetWidth may be larger than subsetWidth for rightmos t subsets
408 const int currentSubsetWidth = (col + 1 == divisor) ? 405 const int currentSubsetWidth = (col + 1 == divisor) ?
409 subsetWidth + extraX : subsetWidth; 406 subsetWidth + extraX : subsetWidth;
410 const int x = col * subsetWidth; 407 const int x = col * subsetWidth;
411 for (int row = 0; row < divisor; row++) { 408 for (int row = 0; row < divisor; row++) {
412 //currentSubsetHeight may be larger than subsetHeight for bo ttom subsets 409 //currentSubsetHeight may be larger than subsetHeight for bo ttom subsets
413 const int currentSubsetHeight = (row + 1 == divisor) ? 410 const int currentSubsetHeight = (row + 1 == divisor) ?
414 subsetHeight + extraY : subsetHeight; 411 subsetHeight + extraY : subsetHeight;
415 const int y = row * subsetHeight; 412 const int y = row * subsetHeight;
416 //create scanline decoder for each subset 413 //create scanline decoder for each subset
417 if (SkCodec::kSuccess != codec->startScanlineDecode(decodeIn fo, NULL, colorPtr, 414 SkCodec::Options options;
418 colorCou ntPtr) 415 SkIRect subset = SkIRect::MakeXYWH(x, 0, currentSubsetWidth, h);
419 // TODO (msarett): Support this mode for all scanlin e orderings. 416 options.fSubset = &subset;
420 || SkCodec::kTopDown_SkScanlineOrder != codec->getSc anlineOrder()) { 417 // TODO (msarett): Support this mode for all scanline orderi ngs.
418 if (SkCodec::kSuccess != codec->startScanlineDecode(decodeIn fo, &options,
419 colorPtr, colorCountPtr) ||
420 SkCodec::kTopDown_SkScanlineOrder != codec->getScanl ineOrder()) {
421 if (x == 0 && y == 0) { 421 if (x == 0 && y == 0) {
422 //first try, image may not be compatible 422 //first try, image may not be compatible
423 return Error::Nonfatal("Could not start top-down sca nline decoder"); 423 return Error::Nonfatal("Could not start top-down sca nline decoder");
424 } else { 424 } else {
425 return "Error scanline decoder is nullptr"; 425 return "Error scanline decoder is nullptr";
426 } 426 }
427 } 427 }
428 // Skip to the first line of subset. We ignore the result v alue here. 428 // Skip to the first line of subset. We ignore the result v alue here.
429 // If the skip value fails, this will indicate an incomplete image. 429 // If the skip value fails, this will indicate an incomplete image.
430 // This means that the call to getScanlines() will also fail , but it 430 // This means that the call to getScanlines() will also fail , but it
431 // will fill the buffer with a default value, so we can stil l draw the 431 // will fill the buffer with a default value, so we can stil l draw the
432 // image. 432 // image.
433 codec->skipScanlines(y); 433 codec->skipScanlines(y);
434 434
435 //create and set size of subsetBm 435 //create and set size of subsetBm
436 SkBitmap subsetBm; 436 SkBitmap subsetBm;
437 SkIRect bounds = SkIRect::MakeWH(currentSubsetWidth, current SubsetHeight); 437 SkIRect bounds = SkIRect::MakeWH(currentSubsetWidth, current SubsetHeight);
438 SkAssertResult(largestSubsetBm.extractSubset(&subsetBm, boun ds)); 438 SkAssertResult(largestSubsetBm.extractSubset(&subsetBm, boun ds));
439 SkAutoLockPixels autlockSubsetBm(subsetBm, true); 439 SkAutoLockPixels autolock(subsetBm, true);
440 codec->getScanlines(buffer, currentSubsetHeight, rowBytes); 440 codec->getScanlines(subsetBm.getAddr(0, 0), currentSubsetHei ght,
441 441 subsetBm.rowBytes());
442 const size_t bpp = decodeInfo.bytesPerPixel();
443 char* bufferRow = buffer;
444 for (int subsetY = 0; subsetY < currentSubsetHeight; ++subse tY) {
445 memcpy(subsetBm.getAddr(0, subsetY), bufferRow + x*bpp,
446 currentSubsetWidth*bpp);
447 bufferRow += rowBytes;
448 }
449
450 subsetBm.notifyPixelsChanged(); 442 subsetBm.notifyPixelsChanged();
451 canvas->drawBitmap(subsetBm, SkIntToScalar(x), SkIntToScalar (y)); 443 canvas->drawBitmap(subsetBm, SkIntToScalar(x), SkIntToScalar (y));
452 } 444 }
453 } 445 }
454 break; 446 break;
455 } 447 }
456 case kStripe_Mode: { 448 case kStripe_Mode: {
457 const int height = decodeInfo.height(); 449 const int height = decodeInfo.height();
458 // This value is chosen arbitrarily. We exercise more cases by choo sing a value that 450 // This value is chosen arbitrarily. We exercise more cases by choo sing a value that
459 // does not align with image blocks. 451 // does not align with image blocks.
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 skr.visit<void>(i, drawsAsSingletonPictures); 1196 skr.visit<void>(i, drawsAsSingletonPictures);
1205 } 1197 }
1206 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); 1198 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture());
1207 1199
1208 canvas->drawPicture(macroPic); 1200 canvas->drawPicture(macroPic);
1209 return ""; 1201 return "";
1210 }); 1202 });
1211 } 1203 }
1212 1204
1213 } // namespace DM 1205 } // namespace DM
OLDNEW
« no previous file with comments | « bench/subset/SubsetZoomBench.cpp ('k') | include/codec/SkCodec.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698