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

Side by Side Diff: bench/subset/SubsetZoomBench.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/SubsetTranslateBench.cpp ('k') | dm/DMSrcSink.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 "SubsetZoomBench.h" 9 #include "SubsetZoomBench.h"
10 #include "SubsetBenchPriv.h" 10 #include "SubsetBenchPriv.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 } 54 }
55 55
56 void SubsetZoomBench::onDraw(int n, SkCanvas* canvas) { 56 void SubsetZoomBench::onDraw(int n, SkCanvas* canvas) {
57 // When the color type is kIndex8, we will need to store the color table. I f it is 57 // When the color type is kIndex8, we will need to store the color table. I f it is
58 // used, it will be initialized by the codec. 58 // used, it will be initialized by the codec.
59 int colorCount; 59 int colorCount;
60 SkPMColor colors[256]; 60 SkPMColor colors[256];
61 if (fUseCodec) { 61 if (fUseCodec) {
62 for (int count = 0; count < n; count++) { 62 for (int count = 0; count < n; count++) {
63 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplica te())); 63 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplica te()));
64 SkASSERT(SkCodec::kOutOfOrder_SkScanlineOrder != codec->getScanlineO rder());
64 const SkImageInfo info = codec->getInfo().makeColorType(fColorType); 65 const SkImageInfo info = codec->getInfo().makeColorType(fColorType);
65 SkAutoTDeleteArray<uint8_t> row(nullptr);
66 if (codec->getScanlineOrder() == SkCodec::kTopDown_SkScanlineOrder) {
67 row.reset(new uint8_t[info.minRowBytes()]);
68 }
69 66
70 const int centerX = info.width() / 2; 67 const int centerX = info.width() / 2;
71 const int centerY = info.height() / 2; 68 const int centerY = info.height() / 2;
72 int w = fSubsetWidth; 69 int w = fSubsetWidth;
73 int h = fSubsetHeight; 70 int h = fSubsetHeight;
74 do { 71 do {
75 SkDEBUGCODE(SkCodec::Result result = )
76 codec->startScanlineDecode(info, nullptr, colors, &colorCount);
77 SkASSERT(SkCodec::kSuccess == result);
78
79 const int subsetStartX = SkTMax(0, centerX - w / 2); 72 const int subsetStartX = SkTMax(0, centerX - w / 2);
80 const int subsetStartY = SkTMax(0, centerY - h / 2); 73 const int subsetStartY = SkTMax(0, centerY - h / 2);
81 const int subsetWidth = SkTMin(w, info.width() - subsetStartX); 74 const int subsetWidth = SkTMin(w, info.width() - subsetStartX);
82 const int subsetHeight = SkTMin(h, info.height() - subsetStartY) ; 75 const int subsetHeight = SkTMin(h, info.height() - subsetStartY) ;
76
77 // The scanline decoder will handle subsetting in the x-dimensio n.
78 SkIRect subset = SkIRect::MakeXYWH(subsetStartX, 0, subsetWidth,
79 codec->getInfo().height());
80 SkCodec::Options options;
81 options.fSubset = &subset;
82
83 SkDEBUGCODE(SkCodec::Result result = )
84 codec->startScanlineDecode(info, &options, colors, &colorCount);
85 SkASSERT(SkCodec::kSuccess == result);
86
83 // Note that if we subsetted and scaled in a single step, we cou ld use the 87 // Note that if we subsetted and scaled in a single step, we cou ld use the
84 // same bitmap - as is often done in actual use cases. 88 // same bitmap - as is often done in actual use cases.
85 SkBitmap bitmap; 89 SkBitmap bitmap;
86 SkImageInfo subsetInfo = info.makeWH(subsetWidth, subsetHeight); 90 SkImageInfo subsetInfo = info.makeWH(subsetWidth, subsetHeight);
87 alloc_pixels(&bitmap, subsetInfo, colors, colorCount); 91 alloc_pixels(&bitmap, subsetInfo, colors, colorCount);
88 92
89 uint32_t bpp = info.bytesPerPixel(); 93 SkDEBUGCODE(bool success = ) codec->skipScanlines(subsetStartY);
94 SkASSERT(success);
90 95
91 SkDEBUGCODE(int lines = ) codec->skipScanlines(subsetStartY); 96 SkDEBUGCODE(int lines = ) codec->getScanlines(bitmap.getPixels() ,
92 SkASSERT(subsetStartY == lines); 97 subsetHeight, bitmap.rowBytes());
93 98 SkASSERT(subsetHeight == lines);
94 switch (codec->getScanlineOrder()) {
95 case SkCodec::kTopDown_SkScanlineOrder:
96 for (int y = 0; y < subsetHeight; y++) {
97 SkDEBUGCODE(lines = ) codec->getScanlines(row.get(), 1, 0);
98 SkASSERT(1 == lines);
99
100 memcpy(bitmap.getAddr(0, y), row.get() + subsetStart X * bpp,
101 subsetWidth * bpp);
102 }
103 break;
104 case SkCodec::kNone_SkScanlineOrder: {
105 // decode all scanlines that intersect the subset, and c opy the subset
106 // into the output.
107 SkImageInfo stripeInfo = info.makeWH(info.width(), subse tHeight);
108 SkBitmap stripeBm;
109 alloc_pixels(&stripeBm, stripeInfo, colors, colorCount);
110
111 SkDEBUGCODE(lines = ) codec->getScanlines(stripeBm.getPi xels(),
112 subsetHeight, stripeBm.rowBytes());
113 SkASSERT(subsetHeight == lines);
114
115 for (int y = 0; y < subsetHeight; y++) {
116 memcpy(bitmap.getAddr(0, y),
117 stripeBm.getAddr(subsetStartX, y),
118 subsetWidth * bpp);
119 }
120 break;
121 }
122 default:
123 // We currently are only testing kTopDown and kNone, whi ch are the only
124 // two used by the subsets we care about. skbug.com/4428
125 SkASSERT(false);
126 }
127 99
128 w <<= 1; 100 w <<= 1;
129 h <<= 1; 101 h <<= 1;
130 } while (w < 2 * info.width() || h < 2 * info.height()); 102 } while (w < 2 * info.width() || h < 2 * info.height());
131 } 103 }
132 } else { 104 } else {
133 for (int count = 0; count < n; count++) { 105 for (int count = 0; count < n; count++) {
134 int width, height; 106 int width, height;
135 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStrea m)); 107 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStrea m));
136 SkAssertResult(decoder->buildTileIndex(fStream->duplicate(), &width, &height)); 108 SkAssertResult(decoder->buildTileIndex(fStream->duplicate(), &width, &height));
(...skipping 10 matching lines...) Expand all
147 SkBitmap bitmap; 119 SkBitmap bitmap;
148 SkIRect rect = SkIRect::MakeXYWH(subsetStartX, subsetStartY, sub setWidth, 120 SkIRect rect = SkIRect::MakeXYWH(subsetStartX, subsetStartY, sub setWidth,
149 subsetHeight); 121 subsetHeight);
150 SkAssertResult(decoder->decodeSubset(&bitmap, rect, fColorType)) ; 122 SkAssertResult(decoder->decodeSubset(&bitmap, rect, fColorType)) ;
151 w <<= 1; 123 w <<= 1;
152 h <<= 1; 124 h <<= 1;
153 } while (w < 2 * width || h < 2 * height); 125 } while (w < 2 * width || h < 2 * height);
154 } 126 }
155 } 127 }
156 } 128 }
OLDNEW
« no previous file with comments | « bench/subset/SubsetTranslateBench.cpp ('k') | dm/DMSrcSink.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698