diff options
author | ebrauer <ebrauer@google.com> | 2016-02-17 08:04:00 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-02-17 08:04:00 -0800 |
commit | 46d2aa824c0a0ee8218d90e821786bd51a63be1e (patch) | |
tree | 9eae930c89062b19ee53e87de8ca214f830cdaa7 | |
parent | 0cf795fd1135babe0ee0b3585f3ad49a02fe1387 (diff) |
Updates Piex and uses it to obtain the DNG dimensions.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1659873002
Review URL: https://codereview.chromium.org/1659873002
-rw-r--r-- | resources/sample_1mp_rotated.dng | bin | 0 -> 87460 bytes | |||
-rw-r--r-- | src/codec/SkRawCodec.cpp | 58 | ||||
-rw-r--r-- | tests/CodexTest.cpp | 2 |
3 files changed, 43 insertions, 17 deletions
diff --git a/resources/sample_1mp_rotated.dng b/resources/sample_1mp_rotated.dng Binary files differnew file mode 100644 index 0000000000..e0270abae1 --- /dev/null +++ b/resources/sample_1mp_rotated.dng diff --git a/src/codec/SkRawCodec.cpp b/src/codec/SkRawCodec.cpp index f9a1488e98..4cd44a4df1 100644 --- a/src/codec/SkRawCodec.cpp +++ b/src/codec/SkRawCodec.cpp @@ -398,14 +398,20 @@ private: class SkDngImage { public: - // Will take the ownership of the stream. + /* + * Initializes the object with the information from Piex in a first attempt. This way it can + * save time and storage to obtain the DNG dimensions and color filter array (CFA) pattern + * which is essential for the demosaicing of the sensor image. + * Note: this will take the ownership of the stream. + */ static SkDngImage* NewFromStream(SkRawStream* stream) { SkAutoTDelete<SkDngImage> dngImage(new SkDngImage(stream)); - if (!dngImage->readDng()) { - return nullptr; + if (!dngImage->initFromPiex()) { + if (!dngImage->readDng()) { + return nullptr; + } } - SkASSERT(dngImage->fNegative); return dngImage.release(); } @@ -477,6 +483,30 @@ public: } private: + void init(const int width, const int height, const dng_point& cfaPatternSize) { + fImageInfo = SkImageInfo::Make(width, height, kN32_SkColorType, kOpaque_SkAlphaType); + + // The DNG SDK scales only during demosaicing, so scaling is only possible when + // a mosaic info is available. + fIsScalable = cfaPatternSize.v != 0 && cfaPatternSize.h != 0; + fIsXtransImage = fIsScalable ? (cfaPatternSize.v == 6 && cfaPatternSize.h == 6) : false; + } + + bool initFromPiex() { + // Does not take the ownership of rawStream. + SkPiexStream piexStream(fStream.get()); + ::piex::PreviewImageData imageData; + if (::piex::IsRaw(&piexStream) + && ::piex::GetPreviewImageData(&piexStream, &imageData) == ::piex::Error::kOk) + { + dng_point cfaPatternSize(imageData.cfa_pattern_dim[1], imageData.cfa_pattern_dim[0]); + this->init(static_cast<int>(imageData.full_width), + static_cast<int>(imageData.full_height), cfaPatternSize); + return true; + } + return false; + } + bool readDng() { // Due to the limit of DNG SDK, we need to reset host and info. fHost.reset(new SkDngHost(&fAllocator)); @@ -495,21 +525,15 @@ private: fNegative->PostParse(*fHost, *fDngStream, *fInfo); fNegative->SynchronizeMetadata(); - fImageInfo = SkImageInfo::Make( - static_cast<int>(fNegative->DefaultCropSizeH().As_real64()), - static_cast<int>(fNegative->DefaultCropSizeV().As_real64()), - kN32_SkColorType, kOpaque_SkAlphaType); - - // The DNG SDK scales only for at demosaicing, so only when a mosaic info - // is available also scale is available. - fIsScalable = fNegative->GetMosaicInfo() != nullptr; - fIsXtransImage = fIsScalable - ? (fNegative->GetMosaicInfo()->fCFAPatternSize.v == 6 - && fNegative->GetMosaicInfo()->fCFAPatternSize.h == 6) - : false; + dng_point cfaPatternSize(0, 0); + if (fNegative->GetMosaicInfo() != nullptr) { + cfaPatternSize = fNegative->GetMosaicInfo()->fCFAPatternSize; + } + this->init(static_cast<int>(fNegative->DefaultCropSizeH().As_real64()), + static_cast<int>(fNegative->DefaultCropSizeV().As_real64()), + cfaPatternSize); return true; } catch (...) { - fNegative.reset(nullptr); return false; } } diff --git a/tests/CodexTest.cpp b/tests/CodexTest.cpp index 0bd58935da..c5651ac0af 100644 --- a/tests/CodexTest.cpp +++ b/tests/CodexTest.cpp @@ -388,6 +388,7 @@ DEF_TEST(Codec, r) { // RAW #if defined(SK_CODEC_DECODES_RAW) check(r, "sample_1mp.dng", SkISize::Make(600, 338), false, false, false); + check(r, "sample_1mp_rotated.dng", SkISize::Make(600, 338), false, false, false); check(r, "dng_with_preview.dng", SkISize::Make(600, 338), true, false, false); #endif } @@ -586,6 +587,7 @@ DEF_TEST(Codec_Dimensions, r) { // RAW #if defined(SK_CODEC_DECODES_RAW) test_dimensions(r, "sample_1mp.dng"); + test_dimensions(r, "sample_1mp_rotated.dng"); test_dimensions(r, "dng_with_preview.dng"); #endif } |