Index: ufraw_developer.c =================================================================== RCS file: /cvsroot/ufraw/ufraw/ufraw_developer.c,v retrieving revision 1.26 diff -u -p -r1.26 ufraw_developer.c --- ufraw_developer.c 13 Nov 2006 00:30:40 -0000 1.26 +++ ufraw_developer.c 13 Nov 2006 06:20:34 -0000 @@ -191,7 +191,7 @@ void developer_prepare(developer_data *d int clipHighlights = conf->clipHighlights; unsigned exposure = pow(2, conf->exposure) * 0x10000; if ( exposure>=0x10000 ) d->restoreDetails = clip_details; - if ( exposure<=0x10000 ) clipHighlights = digital_highlights; + if ( 0 && exposure<=0x10000 ) clipHighlights = digital_highlights; /* Check if gamma curve data has changed. */ if ( in->gamma!=d->gamma || in->linear!=d->linear || exposure!=d->exposure || clipHighlights!=d->clipHighlights || @@ -212,7 +212,7 @@ void developer_prepare(developer_data *d d->exposure = exposure; d->clipHighlights = clipHighlights; guint16 FilmCurve[0x10000]; - if ( d->clipHighlights==film_highlights ) { + if ( 0 && d->clipHighlights==film_highlights ) { /* Exposure is set by FilmCurve[]. * Set initial slope to d->exposuse/0x10000 */ double a = findExpCoeff((double)d->exposure/0x10000); @@ -413,6 +413,7 @@ inline void develope(void *po, guint16 p int i; gboolean clipped; for (i=0; icolors; c++) { /* Set WB, normalizing tmppix[c]<0x10000 */ @@ -518,6 +519,82 @@ inline void develope(void *po, guint16 p } for (c=0; c<3; c++) buf[i*3+c] = d->gammaCurve[MIN(MAX(tmppix[c], 0), 0xFFFF)]; +#else + guint16 *p = buf + (i * 3); + gint64 unclippix[3], exppix[3], clippix[3]; + int maxc, midc, minc; + + clipped = FALSE; + for (c=0; ccolors; c++) { + tmppix[c] = (guint64)pix[i*4+c] * d->rgbWB[c] / 0x10000; + if (d->restoreDetails!=clip_details && tmppix[c] > d->max) + clipped = TRUE; + } + + if ( d->useMatrix ) { + for (cc=0; cc<3; cc++) { + for (c=0, tmp=0; ccolors; c++) { + tmp += tmppix[c] * d->colorMatrix[cc][c]; + } + unclippix[cc] = MAX(tmp / 0x10000, 0); + } + + for (c=0; c<3; c++) { + tmppix[c] = tmppix[c] * d->exposure / d->max; + exppix[c] = unclippix[c] * d->exposure / d->max; + tmppix[c] = MIN(tmppix[c], d->exposure); + } + + for (cc=0; cc<3; cc++) { + for (c=0, tmp=0; ccolors; c++) + tmp += tmppix[c] * d->colorMatrix[cc][c]; + clippix[cc] = MAX(tmp / 0x10000, 0); + } + } else { + for (c=0; c<3; c++) { + unclippix[c] = tmppix[c]; + tmppix[c] = tmppix[c] * d->exposure / d->max; + exppix[c] = tmppix[c]; + tmppix[c] = MIN(tmppix[c], d->exposure); + clippix[c] = tmppix[c]; + } + } + + if (clipped) { + float lch[3], clippedLch[3], unclippedLch[3]; + + rgb_to_cielch(exppix, unclippedLch); + rgb_to_cielch(clippix, clippedLch); + lch[0] = unclippedLch[0]; + lch[1] = clippedLch[1]; + lch[2] = clippedLch[2]; + cielch_to_rgb(lch, clippix); + } + + for (c=0; c<3; c++) { + unclippix[c] = d->gammaCurve[MIN(unclippix[c], 0xFFFF)]; + clippix[c] = d->gammaCurve[MIN(clippix[c], 0xFFFF)]; + } + + MaxMidMin(unclippix, &maxc, &midc, &minc); + + if (unclippix[maxc]!=unclippix[minc]) { + p[minc] = clippix[minc]; + p[maxc] = clippix[maxc]; + if (d->clipHighlights==film_highlights) { + /* + * Apply hue from the un-exposure-clipped pixel + */ + p[midc] = (clippix[maxc] * (unclippix[midc]-unclippix[minc]) + + clippix[minc] * (unclippix[maxc]-unclippix[midc])) / + (unclippix[maxc]-unclippix[minc]); + } else + p[midc] = clippix[midc]; + } else { + for (c=0; c<3; c++) + p[c] = clippix[c]; + } +#endif } if (d->colorTransform!=NULL) cmsDoTransform(d->colorTransform, buf, buf, count);