Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "SkCodecPriv.h" | 10 #include "SkCodecPriv.h" |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 221 rowsDecoded); | 221 rowsDecoded); |
| 222 } | 222 } |
| 223 | 223 |
| 224 return result; | 224 return result; |
| 225 } | 225 } |
| 226 | 226 |
| 227 SkCodec::Result SkCodec::getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes) { | 227 SkCodec::Result SkCodec::getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes) { |
| 228 return this->getPixels(info, pixels, rowBytes, nullptr, nullptr, nullptr); | 228 return this->getPixels(info, pixels, rowBytes, nullptr, nullptr, nullptr); |
| 229 } | 229 } |
| 230 | 230 |
| 231 SkCodec::Result SkCodec::startIncrementalDecode(const SkImageInfo& dstInfo, | |
| 232 const SkCodec::Options* options, SkPMColor* ctable, int* ctableCount) { | |
| 233 fStartedIncrementalDecode = false; | |
| 234 | |
| 235 // FIXME: Share more code with getPixels/startScanlineDecode? | |
|
msarett
2016/05/20 15:04:40
I think this would be a good chance to share the c
scroggo_chromium
2016/05/20 16:51:59
I moved the checks for index8, colortables, etc in
| |
| 236 // Ensure that valid color ptrs are passed in for kIndex8 color type | |
| 237 if (kIndex_8_SkColorType == dstInfo.colorType()) { | |
| 238 if (nullptr == ctable || nullptr == ctableCount) { | |
| 239 return kInvalidParameters; | |
| 240 } | |
| 241 } else { | |
| 242 if (ctableCount) { | |
| 243 *ctableCount = 0; | |
| 244 } | |
| 245 ctableCount = nullptr; | |
| 246 ctable = nullptr; | |
| 247 } | |
| 248 | |
| 249 // FIXME: If the rows come after the rows of a previous incremental decode, | |
| 250 // we might be able to skip the rewind, but only the implementation knows | |
| 251 // that. (e.g. PNG will always need to rewind, since we called longjmp, but | |
| 252 // a bottom-up BMP could skip rewinding if the new rows are above the old | |
| 253 // rows.) | |
| 254 if (!this->rewindIfNeeded()) { | |
| 255 return kCouldNotRewind; | |
| 256 } | |
| 257 | |
| 258 // Set options. | |
| 259 Options optsStorage; | |
| 260 if (nullptr == options) { | |
| 261 options = &optsStorage; | |
| 262 } else if (options->fSubset) { | |
| 263 SkIRect size = SkIRect::MakeSize(dstInfo.dimensions()); | |
| 264 if (!size.contains(*options->fSubset)) { | |
| 265 return kInvalidParameters; | |
| 266 } | |
| 267 | |
| 268 const int top = options->fSubset->top(); | |
| 269 const int bottom = options->fSubset->bottom(); | |
| 270 if (top < 0 || top >= dstInfo.height() || top >= bottom || bottom > dstI nfo.height()) { | |
| 271 return kInvalidParameters; | |
| 272 } | |
| 273 } | |
| 274 | |
| 275 if (!this->dimensionsSupported(dstInfo.dimensions())) { | |
| 276 return kInvalidScale; | |
| 277 } | |
| 278 | |
| 279 fDstInfo = dstInfo; | |
| 280 fOptions = *options; | |
| 281 | |
| 282 const Result result = this->onStartIncrementalDecode(dstInfo, fOptions, ctab le, | |
| 283 ctableCount); | |
| 284 if (kSuccess == result) { | |
| 285 fStartedIncrementalDecode = true; | |
| 286 } | |
| 287 return result; | |
| 288 } | |
| 289 | |
| 290 | |
| 231 SkCodec::Result SkCodec::startScanlineDecode(const SkImageInfo& dstInfo, | 291 SkCodec::Result SkCodec::startScanlineDecode(const SkImageInfo& dstInfo, |
| 232 const SkCodec::Options* options, SkPMColor ctable[], int* ctableCount) { | 292 const SkCodec::Options* options, SkPMColor ctable[], int* ctableCount) { |
| 233 // Reset fCurrScanline in case of failure. | 293 // Reset fCurrScanline in case of failure. |
| 234 fCurrScanline = -1; | 294 fCurrScanline = -1; |
| 235 // Ensure that valid color ptrs are passed in for kIndex8 color type | 295 // Ensure that valid color ptrs are passed in for kIndex8 color type |
| 236 if (kIndex_8_SkColorType == dstInfo.colorType()) { | 296 if (kIndex_8_SkColorType == dstInfo.colorType()) { |
| 237 if (nullptr == ctable || nullptr == ctableCount) { | 297 if (nullptr == ctable || nullptr == ctableCount) { |
| 238 return SkCodec::kInvalidParameters; | 298 return SkCodec::kInvalidParameters; |
| 239 } | 299 } |
| 240 } else { | 300 } else { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 324 } | 384 } |
| 325 | 385 |
| 326 int SkCodec::outputScanline(int inputScanline) const { | 386 int SkCodec::outputScanline(int inputScanline) const { |
| 327 SkASSERT(0 <= inputScanline && inputScanline < this->getInfo().height()); | 387 SkASSERT(0 <= inputScanline && inputScanline < this->getInfo().height()); |
| 328 return this->onOutputScanline(inputScanline); | 388 return this->onOutputScanline(inputScanline); |
| 329 } | 389 } |
| 330 | 390 |
| 331 int SkCodec::onOutputScanline(int inputScanline) const { | 391 int SkCodec::onOutputScanline(int inputScanline) const { |
| 332 switch (this->getScanlineOrder()) { | 392 switch (this->getScanlineOrder()) { |
| 333 case kTopDown_SkScanlineOrder: | 393 case kTopDown_SkScanlineOrder: |
| 334 case kNone_SkScanlineOrder: | |
| 335 return inputScanline; | 394 return inputScanline; |
| 336 case kBottomUp_SkScanlineOrder: | 395 case kBottomUp_SkScanlineOrder: |
| 337 return this->getInfo().height() - inputScanline - 1; | 396 return this->getInfo().height() - inputScanline - 1; |
| 338 default: | 397 default: |
| 339 // This case indicates an interlaced gif and is implemented by SkGif Codec. | 398 // This case indicates an interlaced gif and is implemented by SkGif Codec. |
| 340 SkASSERT(false); | 399 SkASSERT(false); |
| 341 return 0; | 400 return 0; |
| 342 } | 401 } |
| 343 } | 402 } |
| 344 | 403 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 358 const uint32_t fillValue = this->getFillValue(info.colorType()); | 417 const uint32_t fillValue = this->getFillValue(info.colorType()); |
| 359 const int linesRemaining = linesRequested - linesDecoded; | 418 const int linesRemaining = linesRequested - linesDecoded; |
| 360 SkSampler* sampler = this->getSampler(false); | 419 SkSampler* sampler = this->getSampler(false); |
| 361 | 420 |
| 362 int fillWidth = info.width(); | 421 int fillWidth = info.width(); |
| 363 if (fOptions.fSubset) { | 422 if (fOptions.fSubset) { |
| 364 fillWidth = fOptions.fSubset->width(); | 423 fillWidth = fOptions.fSubset->width(); |
| 365 } | 424 } |
| 366 | 425 |
| 367 switch (this->getScanlineOrder()) { | 426 switch (this->getScanlineOrder()) { |
| 368 case kTopDown_SkScanlineOrder: | 427 case kTopDown_SkScanlineOrder: { |
| 369 case kNone_SkScanlineOrder: { | |
| 370 const SkImageInfo fillInfo = info.makeWH(fillWidth, linesRemaining); | 428 const SkImageInfo fillInfo = info.makeWH(fillWidth, linesRemaining); |
| 371 fillDst = SkTAddOffset<void>(dst, linesDecoded * rowBytes); | 429 fillDst = SkTAddOffset<void>(dst, linesDecoded * rowBytes); |
| 372 fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, sampler) ; | 430 fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, sampler) ; |
| 373 break; | 431 break; |
| 374 } | 432 } |
| 375 case kBottomUp_SkScanlineOrder: { | 433 case kBottomUp_SkScanlineOrder: { |
| 376 fillDst = dst; | 434 fillDst = dst; |
| 377 const SkImageInfo fillInfo = info.makeWH(fillWidth, linesRemaining); | 435 const SkImageInfo fillInfo = info.makeWH(fillWidth, linesRemaining); |
| 378 fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, sampler) ; | 436 fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, sampler) ; |
| 379 break; | 437 break; |
| 380 } | 438 } |
| 381 case kOutOfOrder_SkScanlineOrder: { | 439 case kOutOfOrder_SkScanlineOrder: { |
| 382 SkASSERT(1 == linesRequested || this->getInfo().height() == linesReq uested); | 440 SkASSERT(1 == linesRequested || this->getInfo().height() == linesReq uested); |
| 383 const SkImageInfo fillInfo = info.makeWH(fillWidth, 1); | 441 const SkImageInfo fillInfo = info.makeWH(fillWidth, 1); |
| 384 for (int srcY = linesDecoded; srcY < linesRequested; srcY++) { | 442 for (int srcY = linesDecoded; srcY < linesRequested; srcY++) { |
| 385 fillDst = SkTAddOffset<void>(dst, this->outputScanline(srcY) * r owBytes); | 443 fillDst = SkTAddOffset<void>(dst, this->outputScanline(srcY) * r owBytes); |
| 386 fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, samp ler); | 444 fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, samp ler); |
| 387 } | 445 } |
| 388 break; | 446 break; |
| 389 } | 447 } |
| 390 } | 448 } |
| 391 } | 449 } |
| OLD | NEW |