Project

General

Profile

Bug #11706

wrong colors in DNG import

Added by Heiko Bauke over 1 year ago. Updated over 1 year ago.

Status:
Fixed
Priority:
Low
Assignee:
Category:
-
Target version:
Start date:
08/22/2017
Due date:
% Done:

100%

Affected Version:
git master branch
System:
all
bitness:
64-bit
hardware architecture:
amd64/x86

Description

Hi,

I usually do not work with DNG images. Recently, however, I tried to import a DNG file, which darktable could not read properly. Importing the image from http://calvinize.d.pr/xwA7u4 yields an image with wrong colors. Only different shades of magenta are shown in darktable. The expected interpretation of the raw image can be seen in the video https://www.youtube.com/watch?v=77Cj-3L8L0k

Associated revisions

Revision c97cd3b5
Added by Roman Lebedev over 1 year ago

RawSpeed submodule update: fuzzing, DNG CFA fix.

Fixes #11706. Huge thanks to <reyalp> from CHDK!

History

#1 Updated by Roman Lebedev over 1 year ago

  • Status changed from New to Incomplete
  • % Done changed from 0 to 20

Heiko Bauke wrote:

Hi,

I usually do not work with DNG images. Recently, however, I tried to import a DNG file, which darktable could not read properly. Importing the image from http://calvinize.d.pr/xwA7u4 yields an image with wrong colors. Only different shades of magenta are shown in darktable. The expected interpretation of the raw image can be seen in the video https://www.youtube.com/watch?v=77Cj-3L8L0k

Please directly attach the sample.

#2 Updated by Roman Lebedev over 1 year ago

And, how (and why, i guess) was that dng created? canon camera's don't produce dng.

#3 Updated by Roman Lebedev over 1 year ago

Good news bad news:
This fixes the particular sample:

diff --git a/src/librawspeed/decoders/DngDecoder.cpp b/src/librawspeed/decoders/DngDecoder.cpp
index 1075db7a..9d9de057 100644
--- a/src/librawspeed/decoders/DngDecoder.cpp
+++ b/src/librawspeed/decoders/DngDecoder.cpp
@@ -181,6 +181,18 @@ void DngDecoder::parseCFA(const TiffIFD* raw) {
       mRaw->cfa.setColorAt(iPoint2D(x, y), c2);
     }
   }
+
+  // the cfa is specified relative to the main image data.
+  // we want it relative to the (0,0), so if there is a crop
+  // then do shift the cfa.
+
+  if (!raw->hasEntry(DEFAULTCROPORIGIN))
+    return;
+
+  TiffEntry* origin_entry = raw->getEntry(DEFAULTCROPORIGIN);
+  auto tl = origin_entry->getFloatArray(2);
+  mRaw->cfa.shiftLeft(tl[0]);
+  mRaw->cfa.shiftDown(tl[1]);
 }

 void DngDecoder::decodeData(const TiffIFD* raw, uint32 sample_format) {```

Bad news: it clearly breaks several other dng samples:

WARNING: the following 4 tests have failed:
./Canon/Canon PowerShot ELPH 130 IS/CANON_IXUS140_ELPH130_CHDK_CRW_5645.DNG failed: hash/metadata mismatch
./Canon/PowerShot S100/CRW_1369.DNG failed: hash/metadata mismatch
./Canon/PowerShot SX100 IS/CRW_0854.DNG failed: hash/metadata mismatch
./Pentax/645D/20170311_CCSG_on_Pentax_645D-2102.DNG failed: hash/metadata mismatch

(from https://raw.pixls.us/)

So while it is pretty clear that the cfa is the problem, can't think of a proper fix.
Perhaps adobe has f-d up that raw.

#4 Updated by Heiko Bauke over 1 year ago

Roman Lebedev wrote:

Please directly attach the sample.

The image was created by Calvin Hollywood, a German Photoshop artist, not by me. He explicitly does not allow to upload the file elsewhere.

And, how (and why, i guess) was that dng created? canon camera's don't produce dng.

I assume that it was created by some software by Adobe.

So while it is pretty clear that the cfa is the problem, can't think of a proper fix.
Perhaps adobe has f-d up that raw.

I can not judge if the particular DNG is well-formed or not. It can, however, be read by Lightroom as well as by RawTherapee without problems.

#5 Updated by Roman Lebedev over 1 year ago

  • Status changed from Incomplete to In Progress
  • System changed from Ubuntu to all
  • % Done changed from 20 to 50
  • Assignee set to Roman Lebedev
  • Category deleted (Darkroom)

#6 Updated by Roman Lebedev over 1 year ago

  • Status changed from In Progress to Fixed
  • % Done changed from 50 to 100

#7 Updated by Roman Lebedev over 1 year ago

  • Target version changed from Candidate for next patch release to 2.4.0

Also available in: Atom PDF