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