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

Side by Side Diff: src/codec/SkCodec_wbmp.cpp

Issue 1321433002: Add subsetting to SkScaledCodec (Closed) Base URL: https://skia.googlesource.com/skia.git@gif-scan
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 "SkCodec.h" 8 #include "SkCodec.h"
9 #include "SkCodecPriv.h" 9 #include "SkCodecPriv.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 if (size) { 64 if (size) {
65 *size = SkISize::Make(SkToS32(width), SkToS32(height)); 65 *size = SkISize::Make(SkToS32(width), SkToS32(height));
66 } 66 }
67 return true; 67 return true;
68 } 68 }
69 69
70 bool SkWbmpCodec::onRewind() { 70 bool SkWbmpCodec::onRewind() {
71 return read_header(this->stream(), nullptr); 71 return read_header(this->stream(), nullptr);
72 } 72 }
73 73
74 SkSwizzler* SkWbmpCodec::initializeSwizzler(const SkImageInfo& info, 74 SkSwizzler* SkWbmpCodec::initializeSwizzler(const SkImageInfo& info, const SkPMC olor* ctable,
75 const SkPMColor* ctable, const Options& opts) { 75 const Options& opts, int subsetLeft, int subsetWidth) {
76 // Create the swizzler based on the desired color type 76 // Create the swizzler based on the desired color type
77 switch (info.colorType()) { 77 switch (info.colorType()) {
78 case kIndex_8_SkColorType: 78 case kIndex_8_SkColorType:
79 case kN32_SkColorType: 79 case kN32_SkColorType:
80 case kRGB_565_SkColorType: 80 case kRGB_565_SkColorType:
81 case kGray_8_SkColorType: 81 case kGray_8_SkColorType:
82 return SkSwizzler::CreateSwizzler(SkSwizzler::kBit, ctable, info, op ts.fZeroInitialized, 82 return SkSwizzler::CreateSwizzler(SkSwizzler::kBit, ctable, info, op ts.fZeroInitialized,
83 this->getInfo()); 83 this->getInfo(), subsetLeft, subsetWidth);
84 default: 84 default:
85 return nullptr; 85 return nullptr;
86 } 86 }
87 } 87 }
88 88
89 bool SkWbmpCodec::readRow(uint8_t* row) { 89 bool SkWbmpCodec::readRow(uint8_t* row) {
90 return this->stream()->read(row, fSrcRowBytes) == fSrcRowBytes; 90 return this->stream()->read(row, fSrcRowBytes) == fSrcRowBytes;
91 } 91 }
92 92
93 SkWbmpCodec::SkWbmpCodec(const SkImageInfo& info, SkStream* stream) 93 SkWbmpCodec::SkWbmpCodec(const SkImageInfo& info, SkStream* stream)
(...skipping 24 matching lines...) Expand all
118 118
119 if (!valid_alpha(info.alphaType(), this->getInfo().alphaType())) { 119 if (!valid_alpha(info.alphaType(), this->getInfo().alphaType())) {
120 return kInvalidConversion; 120 return kInvalidConversion;
121 } 121 }
122 122
123 // Prepare a color table if necessary 123 // Prepare a color table if necessary
124 setup_color_table(info.colorType(), ctable, ctableCount); 124 setup_color_table(info.colorType(), ctable, ctableCount);
125 125
126 126
127 // Initialize the swizzler 127 // Initialize the swizzler
128 SkAutoTDelete<SkSwizzler> swizzler(this->initializeSwizzler(info, ctable, op tions)); 128 SkAutoTDelete<SkSwizzler> swizzler(this->initializeSwizzler(info, ctable, op tions, 0,
129 if (nullptr == swizzler.get()) { 129 info.width()));
130 if (NULL == swizzler.get()) {
130 return kInvalidConversion; 131 return kInvalidConversion;
131 } 132 }
132 133
133 // Perform the decode 134 // Perform the decode
134 SkISize size = info.dimensions(); 135 SkISize size = info.dimensions();
135 SkAutoTMalloc<uint8_t> src(fSrcRowBytes); 136 SkAutoTMalloc<uint8_t> src(fSrcRowBytes);
136 void* dstRow = dst; 137 void* dstRow = dst;
137 for (int y = 0; y < size.height(); ++y) { 138 for (int y = 0; y < size.height(); ++y) {
138 if (!this->readRow(src.get())) { 139 if (!this->readRow(src.get())) {
139 *rowsDecoded = y; 140 *rowsDecoded = y;
(...skipping 26 matching lines...) Expand all
166 if (!this->readRow(fSrcBuffer.get())) { 167 if (!this->readRow(fSrcBuffer.get())) {
167 return y; 168 return y;
168 } 169 }
169 fSwizzler->swizzle(dstRow, fSrcBuffer.get()); 170 fSwizzler->swizzle(dstRow, fSrcBuffer.get());
170 dstRow = SkTAddOffset<void>(dstRow, dstRowBytes); 171 dstRow = SkTAddOffset<void>(dstRow, dstRowBytes);
171 } 172 }
172 return count; 173 return count;
173 } 174 }
174 175
175 SkCodec::Result SkWbmpCodec::onStartScanlineDecode(const SkImageInfo& dstInfo, 176 SkCodec::Result SkWbmpCodec::onStartScanlineDecode(const SkImageInfo& dstInfo,
176 const Options& options, SkPMColor inputColorTable[], int* inputColorCoun t) { 177 const Options& options, SkPMColor inputColorTable[], int* inputColorCoun t, int subsetLeft,
178 int subsetWidth) {
177 if (options.fSubset) { 179 if (options.fSubset) {
178 // Subsets are not supported. 180 // Subsets are not supported.
179 return kUnimplemented; 181 return kUnimplemented;
180 } 182 }
181 if (dstInfo.dimensions() != this->getInfo().dimensions()) { 183 if (dstInfo.dimensions() != this->getInfo().dimensions()) {
182 if (!SkScaledCodec::DimensionsSupportedForSampling(this->getInfo(), dstI nfo)) { 184 if (!SkScaledCodec::DimensionsSupportedForSampling(this->getInfo(), dstI nfo)) {
183 return kInvalidScale; 185 return kInvalidScale;
184 } 186 }
185 } 187 }
186 188
187 if (!valid_alpha(dstInfo.alphaType(), this->getInfo().alphaType())) { 189 if (!valid_alpha(dstInfo.alphaType(), this->getInfo().alphaType())) {
188 return kInvalidConversion; 190 return kInvalidConversion;
189 } 191 }
190 192
191 // Fill in the color table 193 // Fill in the color table
192 setup_color_table(dstInfo.colorType(), inputColorTable, inputColorCount); 194 setup_color_table(dstInfo.colorType(), inputColorTable, inputColorCount);
193 195
194 // Copy the color table to a pointer that can be owned by the scanline decod er 196 // Copy the color table to a pointer that can be owned by the scanline decod er
195 if (kIndex_8_SkColorType == dstInfo.colorType()) { 197 if (kIndex_8_SkColorType == dstInfo.colorType()) {
196 fColorTable.reset(new SkColorTable(inputColorTable, 2)); 198 fColorTable.reset(new SkColorTable(inputColorTable, 2));
197 } 199 }
198 200
199 // Initialize the swizzler 201 // Initialize the swizzler
200 fSwizzler.reset(this->initializeSwizzler(dstInfo, 202 fSwizzler.reset(this->initializeSwizzler(dstInfo, get_color_ptr(fColorTable. get()), options,
201 get_color_ptr(fColorTable.get()), options)); 203 subsetLeft, subsetWidth));
202 if (nullptr == fSwizzler.get()) { 204 if (nullptr == fSwizzler.get()) {
203 return kInvalidConversion; 205 return kInvalidConversion;
204 } 206 }
205 207
206 fSrcBuffer.reset(fSrcRowBytes); 208 fSrcBuffer.reset(fSrcRowBytes);
207 209
208 return kSuccess; 210 return kSuccess;
209 } 211 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698