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

Side by Side Diff: bench/subset/SubsetSingleBench.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 "SubsetSingleBench.h" 9 #include "SubsetSingleBench.h"
10 #include "SubsetBenchPriv.h" 10 #include "SubsetBenchPriv.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 const SkImageInfo info = codec->getInfo().makeColorType(fColorType); 68 const SkImageInfo info = codec->getInfo().makeColorType(fColorType);
69 SkAutoTDeleteArray<uint8_t> row(new uint8_t[info.minRowBytes()]); 69
70 SkDEBUGCODE(SkCodec::Result result =)
70 codec->startScanlineDecode(info, nullptr, colors, &colorCount); 71 codec->startScanlineDecode(info, nullptr, colors, &colorCount);
72 SkASSERT(result == SkCodec::kSuccess);
71 73
72 SkBitmap bitmap; 74 SkBitmap bitmap;
73 SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight); 75 SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight);
74 alloc_pixels(&bitmap, subsetInfo, colors, colorCount); 76 alloc_pixels(&bitmap, subsetInfo, colors, colorCount);
75 77
76 codec->skipScanlines(fOffsetTop); 78 SkDEBUGCODE(result = ) codec->skipScanlines(fOffsetTop);
77 uint32_t bpp = info.bytesPerPixel(); 79 SkASSERT(result == SkCodec::kSuccess);
78 for (uint32_t y = 0; y < fSubsetHeight; y++) { 80
79 codec->getScanlines(row.get(), 1, 0); 81 const uint32_t bpp = info.bytesPerPixel();
80 memcpy(bitmap.getAddr(0, y), row.get() + fOffsetLeft * bpp, 82
81 fSubsetWidth * bpp); 83 switch (codec->getScanlineOrder()) {
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(result = ) codec->getScanlines(row.get(), 1, 0);
88 SkASSERT(result == SkCodec::kSuccess);
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(result = ) codec->getScanlines(stripeBm.getPixel s(), fSubsetHeight,
103 stripeBm.rowBytes ());
104 SkASSERT(result == SkCodec::kSuccess);
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
82 } 117 }
83 } 118 }
84 } else { 119 } else {
85 for (int count = 0; count < n; count++) { 120 for (int count = 0; count < n; count++) {
86 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStrea m)); 121 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStrea m));
87 int width, height; 122 int width, height;
88 decoder->buildTileIndex(fStream->duplicate(), &width, &height); 123 SkAssertResult(decoder->buildTileIndex(fStream->duplicate(), &width, &height));
89 SkBitmap bitmap; 124 SkBitmap bitmap;
90 SkIRect rect = SkIRect::MakeXYWH(fOffsetLeft, fOffsetTop, fSubsetWid th, 125 SkIRect rect = SkIRect::MakeXYWH(fOffsetLeft, fOffsetTop, fSubsetWid th,
91 fSubsetHeight); 126 fSubsetHeight);
92 decoder->decodeSubset(&bitmap, rect, fColorType); 127 SkAssertResult(decoder->decodeSubset(&bitmap, rect, fColorType));
93 } 128 }
94 } 129 }
95 } 130 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698