From 8ed93b0163968a225f5deff3d4563831be81896c Mon Sep 17 00:00:00 2001 From: Lawrence Lee <45837045+Lawrence37@users.noreply.github.com> Date: Sat, 26 Apr 2025 18:37:39 -0700 Subject: [PATCH] Fix blown images when using LibRaw dcraw code only normalizes the pre-multipliers for the number of colors in the raw image. LibRaw can set the pre-multipliers for a greater number of colors. For example, it can set the 4th multiplier for a 3-color raw. This causes the dcraw code to produce incorrect multipliers. Remove the 4th multiplier if the number of colors is less than 4 and the multiplier is equal to the 2nd multiplier. This lets the multiplier be set equal to the 2nd one after normalization. For images where the multipliers are not equal, print a warning. --- rtengine/rawimage.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/rtengine/rawimage.cc b/rtengine/rawimage.cc index 1663b9811..d853c568d 100644 --- a/rtengine/rawimage.cc +++ b/rtengine/rawimage.cc @@ -859,6 +859,16 @@ int RawImage::loadRaw(bool loadData, unsigned int imageNum, bool closeFile, Prog RT_blacklevel_from_constant = ThreeValBool::F; RT_whitelevel_from_constant = ThreeValBool::F; + if (get_colors() < 4 && get_pre_mul(3) > 0.f) { + if (get_pre_mul(1) != get_pre_mul(3)) { + printf("Warning: Number of colors is less than 4, but pre-multiplier for color 4 is set and different from pre-multiplier for color 1\n"); + } else { + // This will be calculated later. adobe_coeff() does not + // handle pre-multipliers beyond the number of colors. + pre_mul[3] = 0; + } + } + adobe_coeff(make, model); RT_blacklevel_from_constant = bl;