skia: fix a regression in decoding DNG
Since PIEX can now return an uncompressed RGB thumbnail, check the type
of the image before treating it as a JPEG.
this commit was already reviewed and cherry-picked from skia project,
https://codereview.chromium.org/1883783002/
Bug: 28119810, Bug: 26894354
Change-Id: Ib30d6f73518c77034b23573ac9ac018df2efac66
diff --git a/DEPS b/DEPS
index a723d8d..bf5c591 100644
--- a/DEPS
+++ b/DEPS
@@ -22,7 +22,7 @@
"third_party/externals/giflib" : "https://android.googlesource.com/platform/external/giflib.git@ab10e256df4f684260ca239905b1cec727181f6c",
"third_party/externals/dng_sdk" : "https://android.googlesource.com/platform/external/dng_sdk.git@6579353b8ee5d8aa1f1a96ae22798de9b41e19b8",
- "third_party/externals/piex" : "https://android.googlesource.com/platform/external/piex.git@883a1e5419990f51b8e928969e9c5a09869bce0e",
+ "third_party/externals/piex" : "https://android.googlesource.com/platform/external/piex.git@be908191d0a6883a95333bdc0bca749c9b830969",
"third_party/externals/libjpeg-turbo" : "https://skia.googlesource.com/third_party/libjpeg-turbo.git@7bf1a3c9b06bede89cec37cec0b5085c0d6d6c13",
# libjpeg-turbo depends on yasm to compile .asm files
diff --git a/src/codec/SkRawCodec.cpp b/src/codec/SkRawCodec.cpp
index 208bd89..ab2c55d 100644
--- a/src/codec/SkRawCodec.cpp
+++ b/src/codec/SkRawCodec.cpp
@@ -637,7 +637,11 @@
if (::piex::IsRaw(&piexStream)) {
::piex::Error error = ::piex::GetPreviewImageData(&piexStream, &imageData);
- if (error == ::piex::Error::kOk && imageData.preview.length > 0) {
+ // Theoretically PIEX can return JPEG compressed image or uncompressed RGB image. We only
+ // handle the JPEG compressed preview image here.
+ if (error == ::piex::Error::kOk && imageData.preview.length > 0 &&
+ imageData.preview.format == ::piex::Image::kJpegCompressed)
+ {
// transferBuffer() is destructive to the rawStream. Abandon the rawStream after this
// function call.
// FIXME: one may avoid the copy of memoryStream and use the buffered rawStream.