| 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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
| 9 #include "SkCodecPriv.h" | 9 #include "SkCodecPriv.h" |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 this->allocateStorage(); | 413 this->allocateStorage(); |
| 414 return kSuccess; | 414 return kSuccess; |
| 415 } | 415 } |
| 416 | 416 |
| 417 int readRows(const SkImageInfo& dstInfo, void* dst, size_t rowBytes, int cou
nt, int startRow) | 417 int readRows(const SkImageInfo& dstInfo, void* dst, size_t rowBytes, int cou
nt, int startRow) |
| 418 override { | 418 override { |
| 419 SkASSERT(0 == startRow); | 419 SkASSERT(0 == startRow); |
| 420 | 420 |
| 421 // Assume that an error in libpng indicates an incomplete input. | 421 // Assume that an error in libpng indicates an incomplete input. |
| 422 int y = 0; | 422 int y = 0; |
| 423 if (setjmp(png_jmpbuf(fPng_ptr))) { | 423 if (setjmp(png_jmpbuf((png_struct*)fPng_ptr))) { |
| 424 SkCodecPrintf("Failed to read row.\n"); | 424 SkCodecPrintf("Failed to read row.\n"); |
| 425 return y; | 425 return y; |
| 426 } | 426 } |
| 427 | 427 |
| 428 void* swizzlerDstRow = dst; | 428 void* swizzlerDstRow = dst; |
| 429 size_t swizzlerDstRowBytes = rowBytes; | 429 size_t swizzlerDstRowBytes = rowBytes; |
| 430 | 430 |
| 431 bool colorXform = fColorXform && | 431 bool colorXform = fColorXform && |
| 432 apply_xform_on_decode(dstInfo.colorType(), this->getEncodedInfo(
).color()); | 432 apply_xform_on_decode(dstInfo.colorType(), this->getEncodedInfo(
).color()); |
| 433 if (colorXform) { | 433 if (colorXform) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 451 } | 451 } |
| 452 | 452 |
| 453 return y; | 453 return y; |
| 454 } | 454 } |
| 455 | 455 |
| 456 int onGetScanlines(void* dst, int count, size_t rowBytes) override { | 456 int onGetScanlines(void* dst, int count, size_t rowBytes) override { |
| 457 return this->readRows(this->dstInfo(), dst, rowBytes, count, 0); | 457 return this->readRows(this->dstInfo(), dst, rowBytes, count, 0); |
| 458 } | 458 } |
| 459 | 459 |
| 460 bool onSkipScanlines(int count) override { | 460 bool onSkipScanlines(int count) override { |
| 461 if (setjmp(png_jmpbuf(fPng_ptr))) { | 461 if (setjmp(png_jmpbuf((png_struct*)fPng_ptr))) { |
| 462 SkCodecPrintf("Failed to skip row.\n"); | 462 SkCodecPrintf("Failed to skip row.\n"); |
| 463 return false; | 463 return false; |
| 464 } | 464 } |
| 465 | 465 |
| 466 for (int row = 0; row < count; row++) { | 466 for (int row = 0; row < count; row++) { |
| 467 png_read_row(fPng_ptr, fSwizzlerSrcRow, nullptr); | 467 png_read_row(fPng_ptr, fSwizzlerSrcRow, nullptr); |
| 468 } | 468 } |
| 469 return true; | 469 return true; |
| 470 } | 470 } |
| 471 | 471 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 492 return kInvalidConversion; | 492 return kInvalidConversion; |
| 493 } | 493 } |
| 494 | 494 |
| 495 this->allocateStorage(); | 495 this->allocateStorage(); |
| 496 fCanSkipRewind = true; | 496 fCanSkipRewind = true; |
| 497 return SkCodec::kSuccess; | 497 return SkCodec::kSuccess; |
| 498 } | 498 } |
| 499 | 499 |
| 500 int readRows(const SkImageInfo& dstInfo, void* dst, size_t rowBytes, int cou
nt, int startRow) | 500 int readRows(const SkImageInfo& dstInfo, void* dst, size_t rowBytes, int cou
nt, int startRow) |
| 501 override { | 501 override { |
| 502 if (setjmp(png_jmpbuf(fPng_ptr))) { | 502 if (setjmp(png_jmpbuf((png_struct*)fPng_ptr))) { |
| 503 SkCodecPrintf("Failed to get scanlines.\n"); | 503 SkCodecPrintf("Failed to get scanlines.\n"); |
| 504 // FIXME (msarett): Returning 0 is pessimistic. If we can complete
a single pass, | 504 // FIXME (msarett): Returning 0 is pessimistic. If we can complete
a single pass, |
| 505 // we may be able to report that all of the memory has been initiali
zed. Even if we | 505 // we may be able to report that all of the memory has been initiali
zed. Even if we |
| 506 // fail on the first pass, we can still report than some scanlines a
re initialized. | 506 // fail on the first pass, we can still report than some scanlines a
re initialized. |
| 507 return 0; | 507 return 0; |
| 508 } | 508 } |
| 509 | 509 |
| 510 SkAutoTMalloc<uint8_t> storage(count * fSrcRowBytes); | 510 SkAutoTMalloc<uint8_t> storage(count * fSrcRowBytes); |
| 511 uint8_t* srcRow; | 511 uint8_t* srcRow; |
| 512 for (int i = 0; i < fNumberPasses; i++) { | 512 for (int i = 0; i < fNumberPasses; i++) { |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 fInfo_ptr = nullptr; | 803 fInfo_ptr = nullptr; |
| 804 } | 804 } |
| 805 } | 805 } |
| 806 | 806 |
| 807 /////////////////////////////////////////////////////////////////////////////// | 807 /////////////////////////////////////////////////////////////////////////////// |
| 808 // Getting the pixels | 808 // Getting the pixels |
| 809 /////////////////////////////////////////////////////////////////////////////// | 809 /////////////////////////////////////////////////////////////////////////////// |
| 810 | 810 |
| 811 bool SkPngCodec::initializeXforms(const SkImageInfo& dstInfo, const Options& opt
ions, | 811 bool SkPngCodec::initializeXforms(const SkImageInfo& dstInfo, const Options& opt
ions, |
| 812 SkPMColor ctable[], int* ctableCount) { | 812 SkPMColor ctable[], int* ctableCount) { |
| 813 if (setjmp(png_jmpbuf(fPng_ptr))) { | 813 if (setjmp(png_jmpbuf((png_struct*)fPng_ptr))) { |
| 814 SkCodecPrintf("Failed on png_read_update_info.\n"); | 814 SkCodecPrintf("Failed on png_read_update_info.\n"); |
| 815 return false; | 815 return false; |
| 816 } | 816 } |
| 817 png_read_update_info(fPng_ptr, fInfo_ptr); | 817 png_read_update_info(fPng_ptr, fInfo_ptr); |
| 818 | 818 |
| 819 // It's important to reset fColorXform to nullptr. We don't do this on rewi
nding | 819 // It's important to reset fColorXform to nullptr. We don't do this on rewi
nding |
| 820 // because the interlaced scanline decoder may need to rewind. | 820 // because the interlaced scanline decoder may need to rewind. |
| 821 fColorXform = nullptr; | 821 fColorXform = nullptr; |
| 822 SkImageInfo swizzlerInfo = dstInfo; | 822 SkImageInfo swizzlerInfo = dstInfo; |
| 823 Options swizzlerOptions = options; | 823 Options swizzlerOptions = options; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 926 SkCodec* outCodec; | 926 SkCodec* outCodec; |
| 927 if (read_header(stream, chunkReader, &outCodec, nullptr, nullptr)) { | 927 if (read_header(stream, chunkReader, &outCodec, nullptr, nullptr)) { |
| 928 // Codec has taken ownership of the stream. | 928 // Codec has taken ownership of the stream. |
| 929 SkASSERT(outCodec); | 929 SkASSERT(outCodec); |
| 930 streamDeleter.release(); | 930 streamDeleter.release(); |
| 931 return outCodec; | 931 return outCodec; |
| 932 } | 932 } |
| 933 | 933 |
| 934 return nullptr; | 934 return nullptr; |
| 935 } | 935 } |
| OLD | NEW |