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

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

Issue 1390213002: Add subsetting to SkScanlineDecoder (Closed) Base URL: https://skia.googlesource.com/skia.git@fill-refactor
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 "SkBmpCodec.h" 8 #include "SkBmpCodec.h"
9 #include "SkCodec.h" 9 #include "SkCodec.h"
10 #include "SkData.h" 10 #include "SkData.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 // startScanlineDecode will need to be called before decoding scanlines. 104 // startScanlineDecode will need to be called before decoding scanlines.
105 fCurrScanline = -1; 105 fCurrScanline = -1;
106 106
107 if (!fStream->rewind()) { 107 if (!fStream->rewind()) {
108 return false; 108 return false;
109 } 109 }
110 110
111 return this->onRewind(); 111 return this->onRewind();
112 } 112 }
113 113
114 SkISize SkCodec::getScaledDimensions(float desiredScale) const {
115 // Negative and zero scales are errors.
116 SkASSERT(desiredScale > 0.0f);
117 if (desiredScale <= 0.0f) {
118 return SkISize::Make(0, 0);
119 }
120
121 // Upscaling is not supported. Return the original size if the client
122 // requests an upscale.
123 if (desiredScale >= 1.0f) {
124 return this->getInfo().dimensions();
125 }
126 return this->onGetScaledDimensions(desiredScale);
127 }
128
129 bool SkCodec::getValidSubset(SkIRect* desiredSubset) const {
130 if (!desiredSubset) {
131 return false;
132 }
133
134 SkIRect dimensions = SkIRect::MakeSize(this->getInfo().dimensions());
135 if (!dimensions.contains(*desiredSubset)) {
136 return false;
137 }
138
139 return this->onGetValidSubset(desiredSubset);
140 }
141
114 SkCodec::Result SkCodec::getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, 142 SkCodec::Result SkCodec::getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
115 const Options* options, SkPMColor ctable[], i nt* ctableCount) { 143 const Options* options, SkPMColor ctable[], i nt* ctableCount) {
116 if (kUnknown_SkColorType == info.colorType()) { 144 if (kUnknown_SkColorType == info.colorType()) {
117 return kInvalidConversion; 145 return kInvalidConversion;
118 } 146 }
119 if (nullptr == pixels) { 147 if (nullptr == pixels) {
120 return kInvalidParameters; 148 return kInvalidParameters;
121 } 149 }
122 if (rowBytes < info.minRowBytes()) { 150 if (rowBytes < info.minRowBytes()) {
123 return kInvalidParameters; 151 return kInvalidParameters;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 } 219 }
192 220
193 SkCodec::Result SkCodec::getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes) { 221 SkCodec::Result SkCodec::getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes) {
194 return this->getPixels(info, pixels, rowBytes, nullptr, nullptr, nullptr); 222 return this->getPixels(info, pixels, rowBytes, nullptr, nullptr, nullptr);
195 } 223 }
196 224
197 SkCodec::Result SkCodec::startScanlineDecode(const SkImageInfo& dstInfo, 225 SkCodec::Result SkCodec::startScanlineDecode(const SkImageInfo& dstInfo,
198 const SkCodec::Options* options, SkPMColor ctable[], int* ctableCount) { 226 const SkCodec::Options* options, SkPMColor ctable[], int* ctableCount) {
199 // Reset fCurrScanline in case of failure. 227 // Reset fCurrScanline in case of failure.
200 fCurrScanline = -1; 228 fCurrScanline = -1;
229
201 // Ensure that valid color ptrs are passed in for kIndex8 color type 230 // Ensure that valid color ptrs are passed in for kIndex8 color type
202 if (kIndex_8_SkColorType == dstInfo.colorType()) { 231 if (kIndex_8_SkColorType == dstInfo.colorType()) {
203 if (nullptr == ctable || nullptr == ctableCount) { 232 if (nullptr == ctable || nullptr == ctableCount) {
204 return SkCodec::kInvalidParameters; 233 return SkCodec::kInvalidParameters;
205 } 234 }
206 } else { 235 } else {
207 if (ctableCount) { 236 if (ctableCount) {
208 *ctableCount = 0; 237 *ctableCount = 0;
209 } 238 }
210 ctableCount = nullptr; 239 ctableCount = nullptr;
211 ctable = nullptr; 240 ctable = nullptr;
212 } 241 }
213 242
214 if (!this->rewindIfNeeded()) { 243 if (!this->rewindIfNeeded()) {
215 return kCouldNotRewind; 244 return kCouldNotRewind;
216 } 245 }
217 246
218 // Set options. 247 // Set options.
219 Options optsStorage; 248 Options optsStorage;
220 if (nullptr == options) { 249 if (nullptr == options) {
221 options = &optsStorage; 250 options = &optsStorage;
222 } else if (options->fSubset) { 251 } else if (options->fSubset) {
223 SkIRect subset(*options->fSubset); 252 SkIRect size = SkIRect::MakeSize(dstInfo.dimensions());
224 if (!this->onGetValidSubset(&subset) || subset != *options->fSubset) { 253 if (!size.contains(*options->fSubset)) {
225 // FIXME: How to differentiate between not supporting subset at all 254 return kInvalidInput;
226 // and not supporting this particular subset? 255 }
256
257 // We only support subsetting in the x-dimension for scanline decoder.
258 // Subsetting in the y-dimension can be accomplished using skipScanlines ().
259 if (options->fSubset->top() != 0 || options->fSubset->height() != dstInf o.height()) {
msarett 2015/10/07 22:15:14 Alternatively we can just ignore the y-coordinates
227 return kUnimplemented; 260 return kUnimplemented;
228 } 261 }
229 } 262 }
230 263
231 // FIXME: Support subsets somehow? 264 // FIXME: Support subsets somehow?
232 if (!this->dimensionsSupported(dstInfo.dimensions())) { 265 if (!this->dimensionsSupported(dstInfo.dimensions())) {
233 return kInvalidScale; 266 return kInvalidScale;
234 } 267 }
235 268
269 fDstInfo = dstInfo;
270 fOptions = *options;
msarett 2015/10/07 22:15:14 SkJpegCodec might need to call getSampler() in sta
scroggo 2015/10/08 20:16:07 The reason is because I did not want to update the
msarett 2015/10/09 20:03:44 Acknowledged.
236 const Result result = this->onStartScanlineDecode(dstInfo, *options, ctable, ctableCount); 271 const Result result = this->onStartScanlineDecode(dstInfo, *options, ctable, ctableCount);
237 if (result != SkCodec::kSuccess) { 272 if (result != SkCodec::kSuccess) {
238 return result; 273 return result;
239 } 274 }
240 275
241 fCurrScanline = 0; 276 fCurrScanline = 0;
242 fDstInfo = dstInfo;
243 fOptions = *options;
244 return kSuccess; 277 return kSuccess;
245 } 278 }
246 279
247 SkCodec::Result SkCodec::startScanlineDecode(const SkImageInfo& dstInfo) { 280 SkCodec::Result SkCodec::startScanlineDecode(const SkImageInfo& dstInfo) {
248 return this->startScanlineDecode(dstInfo, nullptr, nullptr, nullptr); 281 return this->startScanlineDecode(dstInfo, nullptr, nullptr, nullptr);
249 } 282 }
250 283
251 int SkCodec::getScanlines(void* dst, int countLines, size_t rowBytes) { 284 int SkCodec::getScanlines(void* dst, int countLines, size_t rowBytes) {
252 if (fCurrScanline < 0) { 285 if (fCurrScanline < 0) {
253 return 0; 286 return 0;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 SkASSERT(1 == linesRequested || this->getInfo().height() == linesReq uested); 372 SkASSERT(1 == linesRequested || this->getInfo().height() == linesReq uested);
340 const SkImageInfo fillInfo = info.makeWH(info.width(), 1); 373 const SkImageInfo fillInfo = info.makeWH(info.width(), 1);
341 for (int srcY = linesDecoded; srcY < linesRequested; srcY++) { 374 for (int srcY = linesDecoded; srcY < linesRequested; srcY++) {
342 fillDst = SkTAddOffset<void>(dst, this->outputScanline(srcY) * r owBytes); 375 fillDst = SkTAddOffset<void>(dst, this->outputScanline(srcY) * r owBytes);
343 fill_proc(sampler, fillDst, fillInfo, rowBytes, fillValue, zeroI nit); 376 fill_proc(sampler, fillDst, fillInfo, rowBytes, fillValue, zeroI nit);
344 } 377 }
345 break; 378 break;
346 } 379 }
347 } 380 }
348 } 381 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698