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
diff --git a/resources/sample_1mp_rotated.dng b/resources/sample_1mp_rotated.dng
new file mode 100644
index 0000000..e0270ab
--- /dev/null
+++ b/resources/sample_1mp_rotated.dng
Binary files differ
diff --git a/src/codec/SkRawCodec.cpp b/src/codec/SkRawCodec.cpp
index f9a1488..4cd44a4 100644
--- a/src/codec/SkRawCodec.cpp
+++ b/src/codec/SkRawCodec.cpp
@@ -398,14 +398,20 @@
 
 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 @@
     }
 
 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 @@
             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 0bd5893..c5651ac 100644
--- a/tests/CodexTest.cpp
+++ b/tests/CodexTest.cpp
@@ -388,6 +388,7 @@
     // 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 @@
     // 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
 }