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.
This commit is contained in:
Lawrence Lee 2025-04-26 18:37:39 -07:00
parent b8d094dd78
commit 8ed93b0163
No known key found for this signature in database
GPG Key ID: 048FF2B76A63895F

View File

@ -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;