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

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: 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(new uint8_t[info.minRowBytes()]);
66 codec->startScanlineDecode(info, nullptr, colors, &colorCount);
67 66
68 const int centerX = info.width() / 2; 67 const int centerX = info.width() / 2;
69 const int centerY = info.height() / 2; 68 const int centerY = info.height() / 2;
70 int w = fSubsetWidth; 69 int w = fSubsetWidth;
71 int h = fSubsetHeight; 70 int h = fSubsetHeight;
72 do { 71 do {
73 const int subsetStartX = SkTMax(0, centerX - w / 2); 72 const int subsetStartX = SkTMax(0, centerX - w / 2);
74 const int subsetStartY = SkTMax(0, centerY - h / 2); 73 const int subsetStartY = SkTMax(0, centerY - h / 2);
75 const int subsetWidth = SkTMin(w, info.width() - subsetStartX); 74 const int subsetWidth = SkTMin(w, info.width() - subsetStartX);
76 const int subsetHeight = SkTMin(h, info.height() - subsetStartY) ; 75 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 76 // 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. 77 // same bitmap - as is often done in actual use cases.
79 SkBitmap bitmap; 78 SkBitmap bitmap;
80 SkImageInfo subsetInfo = info.makeWH(subsetWidth, subsetHeight); 79 SkImageInfo subsetInfo = info.makeWH(subsetWidth, subsetHeight);
81 alloc_pixels(&bitmap, subsetInfo, colors, colorCount); 80 alloc_pixels(&bitmap, subsetInfo, colors, colorCount);
82 81
83 uint32_t bpp = info.bytesPerPixel(); 82 uint32_t bpp = info.bytesPerPixel();
83
84 codec->startScanlineDecode(info, nullptr, colors, &colorCount);
84 codec->skipScanlines(subsetStartY); 85 codec->skipScanlines(subsetStartY);
85 for (int y = 0; y < subsetHeight; y++) { 86
86 codec->getScanlines(row.get(), 1, 0); 87 switch (codec->getScanlineOrder()) {
87 memcpy(bitmap.getAddr(0, y), row.get() + subsetStartX * bpp, 88 case SkCodec::kTopDown_SkScanlineOrder:
88 subsetWidth * bpp); 89 for (int y = 0; y < subsetHeight; y++) {
scroggo 2015/10/06 20:36:04 loop should be unchanged
msarett 2015/10/06 21:58:52 Acknowledged.
90 codec->getScanlines(row.get(), 1, 0);
91 memcpy(bitmap.getAddr(0, y), row.get() + subsetStart X * bpp,
92 subsetWidth * bpp);
93 }
94 break;
95 case SkCodec::kNone_SkScanlineOrder: {
96 // decode all scanlines that intersect the subset, and c opy the subset
97 // into the output.
98 SkImageInfo stripeInfo = info.makeWH(info.width(), subse tHeight);
99 SkBitmap stripeBm;
100 alloc_pixels(&stripeBm, stripeInfo, colors, colorCount);
101
102 codec->getScanlines(stripeBm.getPixels(), subsetHeight,
103 stripeBm.rowBytes());
104 for (int y = 0; y < subsetHeight; y++) {
105 memcpy(bitmap.getAddr(0, y),
106 stripeBm.getAddr(subsetStartX, y),
107 subsetWidth * bpp);
108 }
109 break;
110 }
111 default:
112 // We currently are only testing kTopDown and kNone, whi ch are the only
113 // two used by the subsets we care about. skbug.com/4428
114 SkASSERT(false);
89 } 115 }
116
90 w <<= 1; 117 w <<= 1;
91 h <<= 1; 118 h <<= 1;
92 } while (w < 2 * info.width() || h < 2 * info.height()); 119 } while (w < 2 * info.width() || h < 2 * info.height());
93 } 120 }
94 } else { 121 } else {
95 for (int count = 0; count < n; count++) { 122 for (int count = 0; count < n; count++) {
96 int width, height; 123 int width, height;
97 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStrea m)); 124 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStrea m));
98 decoder->buildTileIndex(fStream->duplicate(), &width, &height); 125 decoder->buildTileIndex(fStream->duplicate(), &width, &height);
99 126
100 const int centerX = width / 2; 127 const int centerX = width / 2;
101 const int centerY = height / 2; 128 const int centerY = height / 2;
102 int w = fSubsetWidth; 129 int w = fSubsetWidth;
103 int h = fSubsetHeight; 130 int h = fSubsetHeight;
104 do { 131 do {
105 const int subsetStartX = SkTMax(0, centerX - w / 2); 132 const int subsetStartX = SkTMax(0, centerX - w / 2);
106 const int subsetStartY = SkTMax(0, centerY - h / 2); 133 const int subsetStartY = SkTMax(0, centerY - h / 2);
107 const int subsetWidth = SkTMin(w, width - subsetStartX); 134 const int subsetWidth = SkTMin(w, width - subsetStartX);
108 const int subsetHeight = SkTMin(h, height - subsetStartY); 135 const int subsetHeight = SkTMin(h, height - subsetStartY);
109 SkBitmap bitmap; 136 SkBitmap bitmap;
110 SkIRect rect = SkIRect::MakeXYWH(subsetStartX, subsetStartY, sub setWidth, 137 SkIRect rect = SkIRect::MakeXYWH(subsetStartX, subsetStartY, sub setWidth,
111 subsetHeight); 138 subsetHeight);
112 decoder->decodeSubset(&bitmap, rect, fColorType); 139 decoder->decodeSubset(&bitmap, rect, fColorType);
113 w <<= 1; 140 w <<= 1;
114 h <<= 1; 141 h <<= 1;
115 } while (w < 2 * width || h < 2 * height); 142 } while (w < 2 * width || h < 2 * height);
116 } 143 }
117 } 144 }
118 } 145 }
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