| 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 "SkCodec.h" | 8 #include "SkCodec.h" |
| 9 #include "SkMSAN.h" | 9 #include "SkMSAN.h" |
| 10 #include "SkJpegCodec.h" | 10 #include "SkJpegCodec.h" |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 // Try the next scale | 471 // Try the next scale |
| 472 num -= 1; | 472 num -= 1; |
| 473 calc_output_dimensions(&dinfo, num, denom); | 473 calc_output_dimensions(&dinfo, num, denom); |
| 474 } | 474 } |
| 475 | 475 |
| 476 fDecoderMgr->dinfo()->scale_num = num; | 476 fDecoderMgr->dinfo()->scale_num = num; |
| 477 fDecoderMgr->dinfo()->scale_denom = denom; | 477 fDecoderMgr->dinfo()->scale_denom = denom; |
| 478 return true; | 478 return true; |
| 479 } | 479 } |
| 480 | 480 |
| 481 static bool needs_color_xform(const SkImageInfo& dstInfo, const SkImageInfo& src
Info) { | |
| 482 return (kRGBA_F16_SkColorType == dstInfo.colorType()) || | |
| 483 (dstInfo.colorSpace() && !SkColorSpace::Equals(srcInfo.colorSpace(), | |
| 484 dstInfo.colorSpace()))
; | |
| 485 } | |
| 486 | |
| 487 int SkJpegCodec::readRows(const SkImageInfo& dstInfo, void* dst, size_t rowBytes
, int count) { | 481 int SkJpegCodec::readRows(const SkImageInfo& dstInfo, void* dst, size_t rowBytes
, int count) { |
| 488 // Set the jump location for libjpeg-turbo errors | 482 // Set the jump location for libjpeg-turbo errors |
| 489 if (setjmp(fDecoderMgr->getJmpBuf())) { | 483 if (setjmp(fDecoderMgr->getJmpBuf())) { |
| 490 return 0; | 484 return 0; |
| 491 } | 485 } |
| 492 | 486 |
| 493 // When fSwizzleSrcRow is non-null, it means that we need to swizzle. In th
is case, | 487 // When fSwizzleSrcRow is non-null, it means that we need to swizzle. In th
is case, |
| 494 // we will always decode into fSwizzlerSrcRow before swizzling into the next
buffer. | 488 // we will always decode into fSwizzlerSrcRow before swizzling into the next
buffer. |
| 495 // We can never swizzle "in place" because the swizzler may perform sampling
and/or | 489 // We can never swizzle "in place" because the swizzler may perform sampling
and/or |
| 496 // subsetting. | 490 // subsetting. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 522 sk_msan_mark_initialized(decodeDst, decodeDst + srcRowBytes, "skbug.com/
4550"); | 516 sk_msan_mark_initialized(decodeDst, decodeDst + srcRowBytes, "skbug.com/
4550"); |
| 523 if (0 == lines) { | 517 if (0 == lines) { |
| 524 return y; | 518 return y; |
| 525 } | 519 } |
| 526 | 520 |
| 527 if (fSwizzler) { | 521 if (fSwizzler) { |
| 528 fSwizzler->swizzle(swizzleDst, decodeDst); | 522 fSwizzler->swizzle(swizzleDst, decodeDst); |
| 529 } | 523 } |
| 530 | 524 |
| 531 if (fColorXform) { | 525 if (fColorXform) { |
| 532 int width = dstInfo.width(); | 526 fColorXform->apply(dst, swizzleDst, dstInfo.width(), dstInfo.colorTy
pe(), |
| 533 switch (dstInfo.colorType()) { | 527 kOpaque_SkAlphaType); |
| 534 case kRGBA_8888_SkColorType: | |
| 535 fColorXform->applyToRGBA((uint32_t*) dst, swizzleDst, width)
; | |
| 536 break; | |
| 537 case kBGRA_8888_SkColorType: | |
| 538 fColorXform->applyToBGRA((uint32_t*) dst, swizzleDst, width)
; | |
| 539 break; | |
| 540 case kRGBA_F16_SkColorType: | |
| 541 fColorXform->applyToF16((uint64_t*) dst, swizzleDst, width); | |
| 542 break; | |
| 543 default: | |
| 544 SkASSERT(false); | |
| 545 break; | |
| 546 } | |
| 547 | |
| 548 dst = SkTAddOffset<void>(dst, rowBytes); | 528 dst = SkTAddOffset<void>(dst, rowBytes); |
| 549 } | 529 } |
| 550 | 530 |
| 551 decodeDst = SkTAddOffset<JSAMPLE>(decodeDst, decodeDstRowBytes); | 531 decodeDst = SkTAddOffset<JSAMPLE>(decodeDst, decodeDstRowBytes); |
| 552 swizzleDst = SkTAddOffset<uint32_t>(swizzleDst, swizzleDstRowBytes); | 532 swizzleDst = SkTAddOffset<uint32_t>(swizzleDst, swizzleDstRowBytes); |
| 553 } | 533 } |
| 554 | 534 |
| 555 return count; | 535 return count; |
| 556 } | 536 } |
| 557 | 537 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 void SkJpegCodec::allocateStorage(const SkImageInfo& dstInfo) { | 592 void SkJpegCodec::allocateStorage(const SkImageInfo& dstInfo) { |
| 613 size_t swizzleBytes = 0; | 593 size_t swizzleBytes = 0; |
| 614 if (fSwizzler) { | 594 if (fSwizzler) { |
| 615 swizzleBytes = get_row_bytes(fDecoderMgr->dinfo()); | 595 swizzleBytes = get_row_bytes(fDecoderMgr->dinfo()); |
| 616 SkASSERT(!fColorXform || SkIsAlign4(swizzleBytes)); | 596 SkASSERT(!fColorXform || SkIsAlign4(swizzleBytes)); |
| 617 } | 597 } |
| 618 | 598 |
| 619 size_t xformBytes = 0; | 599 size_t xformBytes = 0; |
| 620 if (kRGBA_F16_SkColorType == dstInfo.colorType()) { | 600 if (kRGBA_F16_SkColorType == dstInfo.colorType()) { |
| 621 SkASSERT(fColorXform); | 601 SkASSERT(fColorXform); |
| 622 xformBytes = dstInfo.width() * sizeof(SkColorSpaceXform::RGBA32); | 602 xformBytes = dstInfo.width() * sizeof(uint32_t); |
| 623 } | 603 } |
| 624 | 604 |
| 625 size_t totalBytes = swizzleBytes + xformBytes; | 605 size_t totalBytes = swizzleBytes + xformBytes; |
| 626 if (totalBytes > 0) { | 606 if (totalBytes > 0) { |
| 627 fStorage.reset(totalBytes); | 607 fStorage.reset(totalBytes); |
| 628 fSwizzleSrcRow = (swizzleBytes > 0) ? fStorage.get() : nullptr; | 608 fSwizzleSrcRow = (swizzleBytes > 0) ? fStorage.get() : nullptr; |
| 629 fColorXformSrcRow = (xformBytes > 0) ? | 609 fColorXformSrcRow = (xformBytes > 0) ? |
| 630 SkTAddOffset<uint32_t>(fStorage.get(), swizzleBytes) : nullptr; | 610 SkTAddOffset<uint32_t>(fStorage.get(), swizzleBytes) : nullptr; |
| 631 } | 611 } |
| 632 } | 612 } |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 997 | 977 |
| 998 JDIMENSION linesRead = jpeg_read_raw_data(dinfo, yuv, numRowsPerBlock); | 978 JDIMENSION linesRead = jpeg_read_raw_data(dinfo, yuv, numRowsPerBlock); |
| 999 if (linesRead < remainingRows) { | 979 if (linesRead < remainingRows) { |
| 1000 // FIXME: Handle incomplete YUV decodes without signalling an error. | 980 // FIXME: Handle incomplete YUV decodes without signalling an error. |
| 1001 return kInvalidInput; | 981 return kInvalidInput; |
| 1002 } | 982 } |
| 1003 } | 983 } |
| 1004 | 984 |
| 1005 return kSuccess; | 985 return kSuccess; |
| 1006 } | 986 } |
| OLD | NEW |