Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: src/codec/SkRawCodec.cpp

Issue 1820073002: Add SkEncodedInfo to report properties of encoded image data (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 } 520 }
521 521
522 bool isScalable() const { 522 bool isScalable() const {
523 return fIsScalable; 523 return fIsScalable;
524 } 524 }
525 525
526 bool isXtransImage() const { 526 bool isXtransImage() const {
527 return fIsXtransImage; 527 return fIsXtransImage;
528 } 528 }
529 529
530 private: 530 private:
531 // 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.
532 bool isTiffHeaderValid() const { 532 bool isTiffHeaderValid() const {
533 const size_t kHeaderSize = 4; 533 const size_t kHeaderSize = 4;
534 SkAutoSTMalloc<kHeaderSize, unsigned char> header(kHeaderSize); 534 SkAutoSTMalloc<kHeaderSize, unsigned char> header(kHeaderSize);
535 if (!fStream->read(header.get(), 0 /* offset */, kHeaderSize)) { 535 if (!fStream->read(header.get(), 0 /* offset */, kHeaderSize)) {
536 return false; 536 return false;
537 } 537 }
538 538
539 // 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").
540 bool littleEndian; 540 bool littleEndian;
541 if (!is_valid_endian_marker(header, &littleEndian)) { 541 if (!is_valid_endian_marker(header, &littleEndian)) {
542 return false; 542 return false;
543 } 543 }
544 544
545 return 0x2A == get_endian_short(header + 2, littleEndian); 545 return 0x2A == get_endian_short(header + 2, littleEndian);
546 } 546 }
547 547
548 void init(const int width, const int height, const dng_point& cfaPatternSize ) { 548 void init(const int width, const int height, const dng_point& cfaPatternSize ) {
549 fImageInfo = SkImageInfo::Make(width, height, kN32_SkColorType, kOpaque_ SkAlphaType); 549 fEncodedInfo = SkEncodedInfo::Make(width, height, SkEncodedInfo::kRGB_Co lor,
550 SkEncodedInfo::kOpaque_Alpha, 8);
550 551
551 // The DNG SDK scales only during demosaicing, so scaling is only possib le when 552 // The DNG SDK scales only during demosaicing, so scaling is only possib le when
552 // a mosaic info is available. 553 // a mosaic info is available.
553 fIsScalable = cfaPatternSize.v != 0 && cfaPatternSize.h != 0; 554 fIsScalable = cfaPatternSize.v != 0 && cfaPatternSize.h != 0;
554 fIsXtransImage = fIsScalable ? (cfaPatternSize.v == 6 && cfaPatternSize. h == 6) : false; 555 fIsXtransImage = fIsScalable ? (cfaPatternSize.v == 6 && cfaPatternSize. h == 6) : false;
555 } 556 }
556 557
557 bool initFromPiex() { 558 bool initFromPiex() {
558 // Does not take the ownership of rawStream. 559 // Does not take the ownership of rawStream.
559 SkPiexStream piexStream(fStream.get()); 560 SkPiexStream piexStream(fStream.get());
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 SkDngImage(SkRawStream* stream) 610 SkDngImage(SkRawStream* stream)
610 : fStream(stream) {} 611 : fStream(stream) {}
611 612
612 SkDngMemoryAllocator fAllocator; 613 SkDngMemoryAllocator fAllocator;
613 SkAutoTDelete<SkRawStream> fStream; 614 SkAutoTDelete<SkRawStream> fStream;
614 SkAutoTDelete<dng_host> fHost; 615 SkAutoTDelete<dng_host> fHost;
615 SkAutoTDelete<dng_info> fInfo; 616 SkAutoTDelete<dng_info> fInfo;
616 SkAutoTDelete<dng_negative> fNegative; 617 SkAutoTDelete<dng_negative> fNegative;
617 SkAutoTDelete<dng_stream> fDngStream; 618 SkAutoTDelete<dng_stream> fDngStream;
618 619
619 SkImageInfo fImageInfo; 620 SkEncodedInfo fEncodedInfo;
620 bool fIsScalable; 621 bool fIsScalable;
621 bool fIsXtransImage; 622 bool fIsXtransImage;
622 }; 623 };
623 624
624 /* 625 /*
625 * Tries to handle the image with PIEX. If PIEX returns kOk and finds the previe w image, create a 626 * 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, 627 * SkJpegCodec. If PIEX returns kFail, then the file is invalid, return nullptr. In other cases,
627 * fallback to create SkRawCodec for DNG images. 628 * fallback to create SkRawCodec for DNG images.
628 */ 629 */
629 SkCodec* SkRawCodec::NewFromStream(SkStream* stream) { 630 SkCodec* SkRawCodec::NewFromStream(SkStream* stream) {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 const float shortEdge = static_cast<float>(SkTMin(dim.fWidth, dim.fHeight)); 754 const float shortEdge = static_cast<float>(SkTMin(dim.fWidth, dim.fHeight));
754 755
755 SkISize sizeFloor = this->onGetScaledDimensions(1.f / std::floor(fullShortEd ge / shortEdge)); 756 SkISize sizeFloor = this->onGetScaledDimensions(1.f / std::floor(fullShortEd ge / shortEdge));
756 SkISize sizeCeil = this->onGetScaledDimensions(1.f / std::ceil(fullShortEdge / shortEdge)); 757 SkISize sizeCeil = this->onGetScaledDimensions(1.f / std::ceil(fullShortEdge / shortEdge));
757 return sizeFloor == dim || sizeCeil == dim; 758 return sizeFloor == dim || sizeCeil == dim;
758 } 759 }
759 760
760 SkRawCodec::~SkRawCodec() {} 761 SkRawCodec::~SkRawCodec() {}
761 762
762 SkRawCodec::SkRawCodec(SkDngImage* dngImage) 763 SkRawCodec::SkRawCodec(SkDngImage* dngImage)
763 : INHERITED(dngImage->getImageInfo(), nullptr) 764 : INHERITED(dngImage->getEncodedInfo(), nullptr)
764 , fDngImage(dngImage) {} 765 , fDngImage(dngImage) {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698