OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 | 508 |
509 dng_point stage3_size = negative->Stage3Image()->Size(); | 509 dng_point stage3_size = negative->Stage3Image()->Size(); |
510 render.SetMaximumSize(SkTMax(stage3_size.h, stage3_size.v)); | 510 render.SetMaximumSize(SkTMax(stage3_size.h, stage3_size.v)); |
511 | 511 |
512 return render.Render(); | 512 return render.Render(); |
513 } catch (...) { | 513 } catch (...) { |
514 return nullptr; | 514 return nullptr; |
515 } | 515 } |
516 } | 516 } |
517 | 517 |
518 const SkImageInfo& getImageInfo() const { | 518 const SkEncodedInfo& getEncodedInfo() const { |
519 return fImageInfo; | 519 return fEncodedInfo; |
| 520 } |
| 521 |
| 522 int width() const { |
| 523 return fWidth; |
| 524 } |
| 525 |
| 526 int height() const { |
| 527 return fHeight; |
520 } | 528 } |
521 | 529 |
522 bool isScalable() const { | 530 bool isScalable() const { |
523 return fIsScalable; | 531 return fIsScalable; |
524 } | 532 } |
525 | 533 |
526 bool isXtransImage() const { | 534 bool isXtransImage() const { |
527 return fIsXtransImage; | 535 return fIsXtransImage; |
528 } | 536 } |
529 | 537 |
530 private: | 538 private: |
531 // Quick check if the image contains a valid TIFF header as requested by DNG
format. | 539 // Quick check if the image contains a valid TIFF header as requested by DNG
format. |
532 bool isTiffHeaderValid() const { | 540 bool isTiffHeaderValid() const { |
533 const size_t kHeaderSize = 4; | 541 const size_t kHeaderSize = 4; |
534 SkAutoSTMalloc<kHeaderSize, unsigned char> header(kHeaderSize); | 542 SkAutoSTMalloc<kHeaderSize, unsigned char> header(kHeaderSize); |
535 if (!fStream->read(header.get(), 0 /* offset */, kHeaderSize)) { | 543 if (!fStream->read(header.get(), 0 /* offset */, kHeaderSize)) { |
536 return false; | 544 return false; |
537 } | 545 } |
538 | 546 |
539 // Check if the header is valid (endian info and magic number "42"). | 547 // Check if the header is valid (endian info and magic number "42"). |
540 bool littleEndian; | 548 bool littleEndian; |
541 if (!is_valid_endian_marker(header, &littleEndian)) { | 549 if (!is_valid_endian_marker(header, &littleEndian)) { |
542 return false; | 550 return false; |
543 } | 551 } |
544 | 552 |
545 return 0x2A == get_endian_short(header + 2, littleEndian); | 553 return 0x2A == get_endian_short(header + 2, littleEndian); |
546 } | 554 } |
547 | 555 |
548 void init(const int width, const int height, const dng_point& cfaPatternSize
) { | 556 void init(int width, int height, const dng_point& cfaPatternSize) { |
549 fImageInfo = SkImageInfo::Make(width, height, kN32_SkColorType, kOpaque_
SkAlphaType); | 557 fWidth = width; |
| 558 fHeight = height; |
| 559 fEncodedInfo = SkEncodedInfo::Make(SkEncodedInfo::kRGB_Color, |
| 560 SkEncodedInfo::kOpaque_Alpha, 8); |
550 | 561 |
551 // The DNG SDK scales only during demosaicing, so scaling is only possib
le when | 562 // The DNG SDK scales only during demosaicing, so scaling is only possib
le when |
552 // a mosaic info is available. | 563 // a mosaic info is available. |
553 fIsScalable = cfaPatternSize.v != 0 && cfaPatternSize.h != 0; | 564 fIsScalable = cfaPatternSize.v != 0 && cfaPatternSize.h != 0; |
554 fIsXtransImage = fIsScalable ? (cfaPatternSize.v == 6 && cfaPatternSize.
h == 6) : false; | 565 fIsXtransImage = fIsScalable ? (cfaPatternSize.v == 6 && cfaPatternSize.
h == 6) : false; |
555 } | 566 } |
556 | 567 |
557 bool initFromPiex() { | 568 bool initFromPiex() { |
558 // Does not take the ownership of rawStream. | 569 // Does not take the ownership of rawStream. |
559 SkPiexStream piexStream(fStream.get()); | 570 SkPiexStream piexStream(fStream.get()); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 SkDngImage(SkRawStream* stream) | 620 SkDngImage(SkRawStream* stream) |
610 : fStream(stream) {} | 621 : fStream(stream) {} |
611 | 622 |
612 SkDngMemoryAllocator fAllocator; | 623 SkDngMemoryAllocator fAllocator; |
613 SkAutoTDelete<SkRawStream> fStream; | 624 SkAutoTDelete<SkRawStream> fStream; |
614 SkAutoTDelete<dng_host> fHost; | 625 SkAutoTDelete<dng_host> fHost; |
615 SkAutoTDelete<dng_info> fInfo; | 626 SkAutoTDelete<dng_info> fInfo; |
616 SkAutoTDelete<dng_negative> fNegative; | 627 SkAutoTDelete<dng_negative> fNegative; |
617 SkAutoTDelete<dng_stream> fDngStream; | 628 SkAutoTDelete<dng_stream> fDngStream; |
618 | 629 |
619 SkImageInfo fImageInfo; | 630 int fWidth; |
| 631 int fHeight; |
| 632 SkEncodedInfo fEncodedInfo; |
620 bool fIsScalable; | 633 bool fIsScalable; |
621 bool fIsXtransImage; | 634 bool fIsXtransImage; |
622 }; | 635 }; |
623 | 636 |
624 /* | 637 /* |
625 * Tries to handle the image with PIEX. If PIEX returns kOk and finds the previe
w image, create a | 638 * Tries to handle the image with PIEX. If PIEX returns kOk and finds the previe
w image, create a |
626 * SkJpegCodec. If PIEX returns kFail, then the file is invalid, return nullptr.
In other cases, | 639 * SkJpegCodec. If PIEX returns kFail, then the file is invalid, return nullptr.
In other cases, |
627 * fallback to create SkRawCodec for DNG images. | 640 * fallback to create SkRawCodec for DNG images. |
628 */ | 641 */ |
629 SkCodec* SkRawCodec::NewFromStream(SkStream* stream) { | 642 SkCodec* SkRawCodec::NewFromStream(SkStream* stream) { |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 const float shortEdge = static_cast<float>(SkTMin(dim.fWidth, dim.fHeight)); | 770 const float shortEdge = static_cast<float>(SkTMin(dim.fWidth, dim.fHeight)); |
758 | 771 |
759 SkISize sizeFloor = this->onGetScaledDimensions(1.f / std::floor(fullShortEd
ge / shortEdge)); | 772 SkISize sizeFloor = this->onGetScaledDimensions(1.f / std::floor(fullShortEd
ge / shortEdge)); |
760 SkISize sizeCeil = this->onGetScaledDimensions(1.f / std::ceil(fullShortEdge
/ shortEdge)); | 773 SkISize sizeCeil = this->onGetScaledDimensions(1.f / std::ceil(fullShortEdge
/ shortEdge)); |
761 return sizeFloor == dim || sizeCeil == dim; | 774 return sizeFloor == dim || sizeCeil == dim; |
762 } | 775 } |
763 | 776 |
764 SkRawCodec::~SkRawCodec() {} | 777 SkRawCodec::~SkRawCodec() {} |
765 | 778 |
766 SkRawCodec::SkRawCodec(SkDngImage* dngImage) | 779 SkRawCodec::SkRawCodec(SkDngImage* dngImage) |
767 : INHERITED(dngImage->getImageInfo(), nullptr) | 780 : INHERITED(dngImage->width(), dngImage->height(), dngImage->getEncodedInfo(
), nullptr) |
768 , fDngImage(dngImage) {} | 781 , fDngImage(dngImage) {} |
OLD | NEW |