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

Side by Side Diff: bench/subset/SubsetZoomBench.cpp

Issue 1387233002: Update Subset benches to support interlacing and fix bugs (Closed) Base URL: https://skia.googlesource.com/skia.git@limitScaled
Patch Set: Initialize colorCount before reading from it. 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
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 const SkImageInfo info = codec->getInfo().makeColorType(fColorType); 64 const SkImageInfo info = codec->getInfo().makeColorType(fColorType);
65 SkAutoTDeleteArray<uint8_t> row(new uint8_t[info.minRowBytes()]); 65 SkAutoTDeleteArray<uint8_t> row(nullptr);
66 codec->startScanlineDecode(info, nullptr, colors, &colorCount); 66 if (codec->getScanlineOrder() == SkCodec::kTopDown_SkScanlineOrder) {
67 row.reset(new uint8_t[info.minRowBytes()]);
68 }
67 69
68 const int centerX = info.width() / 2; 70 const int centerX = info.width() / 2;
69 const int centerY = info.height() / 2; 71 const int centerY = info.height() / 2;
70 int w = fSubsetWidth; 72 int w = fSubsetWidth;
71 int h = fSubsetHeight; 73 int h = fSubsetHeight;
72 do { 74 do {
75 SkDEBUGCODE(SkCodec::Result result = )
76 codec->startScanlineDecode(info, nullptr, colors, &colorCount);
77 SkASSERT(SkCodec::kSuccess == result);
78
73 const int subsetStartX = SkTMax(0, centerX - w / 2); 79 const int subsetStartX = SkTMax(0, centerX - w / 2);
74 const int subsetStartY = SkTMax(0, centerY - h / 2); 80 const int subsetStartY = SkTMax(0, centerY - h / 2);
75 const int subsetWidth = SkTMin(w, info.width() - subsetStartX); 81 const int subsetWidth = SkTMin(w, info.width() - subsetStartX);
76 const int subsetHeight = SkTMin(h, info.height() - subsetStartY) ; 82 const int subsetHeight = SkTMin(h, info.height() - subsetStartY) ;
77 // Note that if we subsetted and scaled in a single step, we cou ld use the 83 // Note that if we subsetted and scaled in a single step, we cou ld use the
78 // same bitmap - as is often done in actual use cases. 84 // same bitmap - as is often done in actual use cases.
79 SkBitmap bitmap; 85 SkBitmap bitmap;
80 SkImageInfo subsetInfo = info.makeWH(subsetWidth, subsetHeight); 86 SkImageInfo subsetInfo = info.makeWH(subsetWidth, subsetHeight);
81 alloc_pixels(&bitmap, subsetInfo, colors, colorCount); 87 alloc_pixels(&bitmap, subsetInfo, colors, colorCount);
scroggo 2015/10/08 18:29:08 Since we do a new allocation each time, we can alw
msarett 2015/10/08 18:52:42 Acknowledged.
82 88
83 uint32_t bpp = info.bytesPerPixel(); 89 uint32_t bpp = info.bytesPerPixel();
84 codec->skipScanlines(subsetStartY); 90
85 for (int y = 0; y < subsetHeight; y++) { 91 SkDEBUGCODE(result = ) codec->skipScanlines(subsetStartY);
86 codec->getScanlines(row.get(), 1, 0); 92 SkASSERT(SkCodec::kSuccess == result);
87 memcpy(bitmap.getAddr(0, y), row.get() + subsetStartX * bpp, 93
88 subsetWidth * bpp); 94 switch (codec->getScanlineOrder()) {
95 case SkCodec::kTopDown_SkScanlineOrder:
96 for (int y = 0; y < subsetHeight; y++) {
97 SkDEBUGCODE(result = ) codec->getScanlines(row.get() , 1, 0);
98 SkASSERT(SkCodec::kSuccess == result);
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);
scroggo 2015/10/08 18:29:08 Here and in SubsetTranslateBench, we're doing some
msarett 2015/10/08 18:52:41 This is probably the right decision. In general,
110
111 SkDEBUGCODE(result = ) codec->getScanlines(stripeBm.getP ixels(),
112 subsetHeight, stripeBm.rowBytes());
113 SkASSERT(SkCodec::kSuccess == result);
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);
89 } 126 }
127
90 w <<= 1; 128 w <<= 1;
91 h <<= 1; 129 h <<= 1;
92 } while (w < 2 * info.width() || h < 2 * info.height()); 130 } while (w < 2 * info.width() || h < 2 * info.height());
93 } 131 }
94 } else { 132 } else {
95 for (int count = 0; count < n; count++) { 133 for (int count = 0; count < n; count++) {
96 int width, height; 134 int width, height;
97 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStrea m)); 135 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStrea m));
98 decoder->buildTileIndex(fStream->duplicate(), &width, &height); 136 SkAssertResult(decoder->buildTileIndex(fStream->duplicate(), &width, &height));
99 137
100 const int centerX = width / 2; 138 const int centerX = width / 2;
101 const int centerY = height / 2; 139 const int centerY = height / 2;
102 int w = fSubsetWidth; 140 int w = fSubsetWidth;
103 int h = fSubsetHeight; 141 int h = fSubsetHeight;
104 do { 142 do {
105 const int subsetStartX = SkTMax(0, centerX - w / 2); 143 const int subsetStartX = SkTMax(0, centerX - w / 2);
106 const int subsetStartY = SkTMax(0, centerY - h / 2); 144 const int subsetStartY = SkTMax(0, centerY - h / 2);
107 const int subsetWidth = SkTMin(w, width - subsetStartX); 145 const int subsetWidth = SkTMin(w, width - subsetStartX);
108 const int subsetHeight = SkTMin(h, height - subsetStartY); 146 const int subsetHeight = SkTMin(h, height - subsetStartY);
109 SkBitmap bitmap; 147 SkBitmap bitmap;
110 SkIRect rect = SkIRect::MakeXYWH(subsetStartX, subsetStartY, sub setWidth, 148 SkIRect rect = SkIRect::MakeXYWH(subsetStartX, subsetStartY, sub setWidth,
111 subsetHeight); 149 subsetHeight);
112 decoder->decodeSubset(&bitmap, rect, fColorType); 150 SkAssertResult(decoder->decodeSubset(&bitmap, rect, fColorType)) ;
113 w <<= 1; 151 w <<= 1;
114 h <<= 1; 152 h <<= 1;
115 } while (w < 2 * width || h < 2 * height); 153 } while (w < 2 * width || h < 2 * height);
116 } 154 }
117 } 155 }
118 } 156 }
OLDNEW
« bench/subset/SubsetTranslateBench.cpp ('K') | « bench/subset/SubsetTranslateBench.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698