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

Side by Side Diff: bench/subset/SubsetSingleBench.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 | « no previous file | bench/subset/SubsetTranslateBench.cpp » ('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 "CodecBenchPriv.h" 8 #include "CodecBenchPriv.h"
9 #include "SubsetSingleBench.h" 9 #include "SubsetSingleBench.h"
10 #include "SubsetBenchPriv.h" 10 #include "SubsetBenchPriv.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 } 58 }
59 59
60 void SubsetSingleBench::onDraw(int n, SkCanvas* canvas) { 60 void SubsetSingleBench::onDraw(int n, SkCanvas* canvas) {
61 // When the color type is kIndex8, we will need to store the color table. I f it is 61 // When the color type is kIndex8, we will need to store the color table. I f it is
62 // used, it will be initialized by the codec. 62 // used, it will be initialized by the codec.
63 int colorCount; 63 int colorCount;
64 SkPMColor colors[256]; 64 SkPMColor colors[256];
65 if (fUseCodec) { 65 if (fUseCodec) {
66 for (int count = 0; count < n; count++) { 66 for (int count = 0; count < n; count++) {
67 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplica te())); 67 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplica te()));
68 SkASSERT(SkCodec::kOutOfOrder_SkScanlineOrder != codec->getScanlineO rder());
68 const SkImageInfo info = codec->getInfo().makeColorType(fColorType); 69 const SkImageInfo info = codec->getInfo().makeColorType(fColorType);
69 70
71 // The scanline decoder will handle subsetting in the x-dimension.
72 SkIRect subset = SkIRect::MakeXYWH(fOffsetLeft, 0, fSubsetWidth,
73 codec->getInfo().height());
74 SkCodec::Options options;
75 options.fSubset = &subset;
76
70 SkDEBUGCODE(SkCodec::Result result =) 77 SkDEBUGCODE(SkCodec::Result result =)
71 codec->startScanlineDecode(info, nullptr, colors, &colorCount); 78 codec->startScanlineDecode(info, &options, colors, &colorCount);
72 SkASSERT(result == SkCodec::kSuccess); 79 SkASSERT(result == SkCodec::kSuccess);
73 80
74 SkBitmap bitmap; 81 SkBitmap bitmap;
75 SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight); 82 SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight);
76 alloc_pixels(&bitmap, subsetInfo, colors, colorCount); 83 alloc_pixels(&bitmap, subsetInfo, colors, colorCount);
77 84
78 SkDEBUGCODE(int lines = ) codec->skipScanlines(fOffsetTop); 85 SkDEBUGCODE(bool success = ) codec->skipScanlines(fOffsetTop);
79 SkASSERT((uint32_t) lines == fOffsetTop); 86 SkASSERT(success);
80 87
81 const uint32_t bpp = info.bytesPerPixel(); 88 SkDEBUGCODE(uint32_t lines = ) codec->getScanlines(bitmap.getPixels( ), fSubsetHeight,
82 89 bitmap.rowBytes());
83 switch (codec->getScanlineOrder()) { 90 SkASSERT(lines == fSubsetHeight);
84 case SkCodec::kTopDown_SkScanlineOrder: {
85 SkAutoTDeleteArray<uint8_t> row(new uint8_t[info.minRowBytes ()]);
86 for (uint32_t y = 0; y < fSubsetHeight; y++) {
87 SkDEBUGCODE(lines = ) codec->getScanlines(row.get(), 1, 0);
88 SkASSERT(lines == 1);
89
90 memcpy(bitmap.getAddr(0, y), row.get() + fOffsetLeft * b pp,
91 fSubsetWidth * bpp);
92 }
93 break;
94 }
95 case SkCodec::kNone_SkScanlineOrder: {
96 // decode all scanlines that intersect the subset, and copy the subset
97 // into the output.
98 SkImageInfo stripeInfo = info.makeWH(info.width(), fSubsetHe ight);
99 SkBitmap stripeBm;
100 alloc_pixels(&stripeBm, stripeInfo, colors, colorCount);
101
102 SkDEBUGCODE(lines = ) codec->getScanlines(stripeBm.getPixels (), fSubsetHeight,
103 stripeBm.rowBytes ());
104 SkASSERT((uint32_t) lines == fSubsetHeight);
105
106 for (uint32_t y = 0; y < fSubsetHeight; y++) {
107 memcpy(bitmap.getAddr(0, y), stripeBm.getAddr(fOffsetLef t, y),
108 fSubsetWidth * bpp);
109 }
110 break;
111 }
112 default:
113 // We currently are only testing kTopDown and kNone, which a re the only
114 // two used by the subsets we care about. skbug.com/4428
115 SkASSERT(false);
116
117 }
118 } 91 }
119 } else { 92 } else {
120 for (int count = 0; count < n; count++) { 93 for (int count = 0; count < n; count++) {
121 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStrea m)); 94 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStrea m));
122 int width, height; 95 int width, height;
123 SkAssertResult(decoder->buildTileIndex(fStream->duplicate(), &width, &height)); 96 SkAssertResult(decoder->buildTileIndex(fStream->duplicate(), &width, &height));
124 SkBitmap bitmap; 97 SkBitmap bitmap;
125 SkIRect rect = SkIRect::MakeXYWH(fOffsetLeft, fOffsetTop, fSubsetWid th, 98 SkIRect rect = SkIRect::MakeXYWH(fOffsetLeft, fOffsetTop, fSubsetWid th,
126 fSubsetHeight); 99 fSubsetHeight);
127 SkAssertResult(decoder->decodeSubset(&bitmap, rect, fColorType)); 100 SkAssertResult(decoder->decodeSubset(&bitmap, rect, fColorType));
128 } 101 }
129 } 102 }
130 } 103 }
OLDNEW
« no previous file with comments | « no previous file | bench/subset/SubsetTranslateBench.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698