# HG changeset patch # User alex@thinkpad # Date 1367418351 -10800 # Node ID 5189313644e7a57552c5fe64e98ba459eefe98b6 # Parent ab68b0fa190193b7c1bfcd2119352ae779428a3e Highlight fix for strong colors when using profile matrix (well, more like a hack, but works for me) diff -r ab68b0fa1901 -r 5189313644e7 ufraw_developer.c --- a/ufraw_developer.c Thu Dec 12 20:24:57 2013 +0200 +++ b/ufraw_developer.c Wed May 01 17:25:51 2013 +0300 @@ -617,8 +617,29 @@ for (c = 0; c < d->colors; c++) tmp[cc] += in[c] * d->colorMatrix[cc][c]; } + /** + * When color matrix is enabled, there is a bug in highlight recovery and clipping routines + * that causes color artifacts (looks like some sort of overflow, not sure). + * + * Without color matrix, the image looks perfect even if the RAWs are overexposed. + * + * Since I don't understand the highlight recovery algorithm, I'll just apply the color matrix + * for midtones and shadows only, and I'll blend it towards the identity matrix as it gets close + * to the clipping point. + */ + + int maxin = MAX(MAX(in[0], in[1]), in[2]); + + /** + * at saturation level (65535), it will use identity matrix + * at -1EV under saturation level, it will use a 50% blend between color matrix and identity matrix + * at -2EV, it will use 75% color matrix and 25% identity + * at low EV values (almost the entire luma range), the color matrix will be predominant + */ + double k = MIN(maxin / 65536.0, 1.0); + for (cc = 0; cc < 3; cc++) - out[cc] = MAX(tmp[cc] / 0x10000, 0); + out[cc] = MAX((tmp[cc] / 0x10000 * (1-k) + in[cc] * k), 0); } static void cond_apply_matrix(const developer_data *d,