On Thu, Sep 17, 2009 at 02:47:10PM -0500, Udi Fuchs wrote:
> > Here's take two. The white balancing has been removed from
> > dcraw_finalize_interpolate(), together with the hack to compensate
> > for that again. This consolidates the path for WB because
> > dcraw_finalize_shrink() doesn't do that either.
> 
> White balance has to be applied before interpolation, otherwise you
> get interpolation artifacts.
> 
> A compromise for the preview could be to apply WB once in
> create_base_image() and then apply changes in WB relative to the
> original one. Of course this would only make the WB logic more
> complicated. For now, disabling WB during 100% zoom would be enough.

Disabling any GUI controls for 100% zoom is a bit poor IMO. Converting the
image in the dcraw_finalize_shrink() path [in case of a WB adjustment]
is slow. So, I decided to keep the two WB paths and cleanup the code in
ufraw_convert_image_first_phase() instead.

> 
> Another issue is that changing to 100% zoom freezes the UI for a few
> seconds, it can be around 20 seconds on older machines. A progress bar
> might be needed.

There's a progress bar now for that. The progress itself still needs to
be implemented but that's a separate issue. At least the user is informed
about what is happening.

diff --git a/ufraw.h b/ufraw.h
index ac5804d..5c71a9e 100644
--- a/ufraw.h
+++ b/ufraw.h
@@ -93,7 +93,7 @@ typedef struct {
     DeveloperMode mode;
     unsigned rgbMax, max, exposure, colors, useMatrix;
     int restoreDetails, clipHighlights;
-    int rgbWB[4], colorMatrix[3][4];
+    int doWB, rgbWB[4], colorMatrix[3][4];
     double gamma, linear;
     char profileFile[profile_types][max_path];
     void *profile[profile_types];
@@ -291,6 +291,7 @@ typedef struct ufraw_struct {
     int postproc_ops; /* postprocessing operations (LF_MODIFY_XXX) */
     lfModifier *modifier;
 #endif /* HAVE_LENSFUN */
+    int WBrequest;
 } ufraw_data;
 
 extern const conf_data conf_default;
diff --git a/ufraw_developer.c b/ufraw_developer.c
index 67840eb..c4c5c82 100644
--- a/ufraw_developer.c
+++ b/ufraw_developer.c
@@ -41,6 +41,7 @@ developer_data *developer_init()
     int i;
     developer_data *d = g_new(developer_data,1);
     d->mode = -1;
+    d->doWB = 1;
     d->gamma = -1;
     d->linear = -1;
     d->saturation = -1;
@@ -739,8 +740,13 @@ void uf_raw_to_cielch(const developer_data *d,
     cmsCIELCh LCh;
     unsigned int c;
 
-    for (c = 0; c < d->colors; ++c)
-       tmp[c] = (guint64)raw[c] * d->rgbWB[c] / 0x10000;
+    for (c = 0; c < d->colors; ++c) {
+       tmp[c] = raw[c];
+       if (d->doWB) {
+           tmp[c] *= d->rgbWB[c];
+           tmp[c] /= 0x10000;
+       }
+    }
     cond_apply_matrix(d, tmp, tmp);
     for (c = 0; c < 3; ++c)
        rgbpixel[c] = tmp[c];
@@ -872,8 +878,11 @@ void develop_linear(guint16 in[4], guint16 out[3], 
developer_data *d)
     gint64 tmppix[4];
     gboolean clipped = FALSE;
     for (c=0; c<d->colors; c++) {
-       /* Set WB, normalizing tmppix[c]<0x10000 */
-       tmppix[c] = (guint64)in[c] * d->rgbWB[c] / 0x10000;
+       tmppix[c] = in[c];
+       if (d->doWB) {
+          tmppix[c] *= d->rgbWB[c];
+          tmppix[c] /= 0x10000;
+       }
        if ( d->restoreDetails!=clip_details &&
            tmppix[c] > d->max ) {
            clipped = TRUE;
diff --git a/ufraw_preview.c b/ufraw_preview.c
index 34b0697..be20089 100644
--- a/ufraw_preview.c
+++ b/ufraw_preview.c
@@ -39,6 +39,7 @@
 void ufraw_chooser_toggle(GtkToggleButton *button, GtkFileChooser 
*filechooser);
 #endif
 
+static void create_base_image(preview_data *data);
 static void adjustment_update(GtkAdjustment *adj, double *valuep);
 static void button_update(GtkWidget *button, gpointer user_data);
 
@@ -830,6 +831,8 @@ void preview_invalidate_layer (preview_data *data, 
UFRawPhase phase)
 {
     for (; phase < ufraw_phases_num; phase++)
        data->UF->Images [phase].valid = 0;
+    if (data->UF->WBrequest && !data->UF->developer->doWB)
+       create_base_image(data);
 }
 
 void render_preview(preview_data *data)
@@ -873,9 +876,6 @@ static gboolean render_prepare(preview_data *data)
            CFG->curve[CFG->curveIndex].m_anchors[0].x);
     gtk_label_set_text(GTK_LABEL(data->BlackLabel), text);
 
-    if ( Developer==NULL )
-            Developer = developer_init();
-
     if ( CFG->profileIndex[display_profile]==0 ) {
        guint8 *displayProfile;
        gint profileSize;
@@ -939,6 +939,8 @@ static gboolean render_raw_histogram(preview_data *data)
        }
        raw_his_max = MAX(raw_his_max, y);
     }
+    /* we use the developer for our own purpose so enable WB */
+    ++data->UF->developer->doWB;
     /* Prepare pen color, which is not effected by exposure.
      * Use a small value to avoid highlights and then normalize. */
     for (c=0; c<colors; c++) {
@@ -972,6 +974,7 @@ static gboolean render_raw_histogram(preview_data *data)
                    (hisHeight-1) / MAXOUT;
        }
     }
+    --data->UF->developer->doWB;
     for (x=0; x<raw_his_size; x++) {
        /* draw the raw histogram */
        for (c=0, y0=0; c<colors; c++) {
@@ -1868,6 +1871,11 @@ static void create_base_image(preview_data *data)
 {
     int shrinkSave = CFG->shrink;
     int sizeSave = CFG->size;
+    UFRawPhase phase;
+
+    data->UF->WBrequest = 0;
+    for (phase = 0; phase < ufraw_phases_num; phase++)
+       data->UF->Images [phase].valid = 0;
     if (CFG->Scale==0) {
        int cropHeight = data->UF->conf->CropY2 - data->UF->conf->CropY1;
        int cropWidth = data->UF->conf->CropX2 - data->UF->conf->CropX1;
@@ -1878,9 +1886,11 @@ static void create_base_image(preview_data *data)
        CFG->size = 0;
        CFG->shrink = CFG->Scale;
     }
-    preview_invalidate_layer (data, ufraw_denoise_phase);
+    preview_progress(data->UF->widget, _("Converting image"), 0.01);
+    ufraw_developer_prepare(data->UF, display_developer);
     ufraw_convert_image_init(data->UF);
     ufraw_convert_image_first_phase(data->UF, FALSE);
+    preview_progress(data->UF->widget, _("Developing image"), 0.99);
     ufraw_rotate_image_buffer(&data->UF->Images[ufraw_first_phase], 
data->UF->conf->rotationAngle);
     CFG->shrink = shrinkSave;
     CFG->size = sizeSave;
@@ -2592,6 +2602,7 @@ static void button_update(GtkWidget *button, gpointer 
user_data)
        CFG->temperature = data->initialTemperature;
        CFG->green = data->initialGreen;
        for (c=0; c<4; c++) CFG->chanMul[c] = data->initialChanMul[c];
+        ++data->UF->WBrequest;
     }
     if (button==data->ResetGammaButton) {
        CFG->profile[0][CFG->profileIndex[0]].gamma =
@@ -4260,7 +4271,7 @@ static void whitebalance_fill_interface(preview_data 
*data,
 
     // Zoom percentage spin button:
     data->ZoomAdjustment = GTK_ADJUSTMENT(gtk_adjustment_new(
-               CFG->Zoom, 5, 50, 1, 1, 0));
+               CFG->Zoom, 5, 100, 1, 1, 0));
     g_object_set_data(G_OBJECT(data->ZoomAdjustment),
                "Adjustment-Accuracy", (gpointer)0);
     button = gtk_spin_button_new(data->ZoomAdjustment, 1, 0);
@@ -5152,7 +5163,7 @@ int ufraw_preview(ufraw_data *uf, conf_data *rc, int 
plugin,
     max_preview_height = MIN(def_preview_height, screen.height-152);
     CFG->Scale = MAX((uf->rotatedWidth-1)/max_preview_width,
            (uf->rotatedHeight-1)/max_preview_height)+1;
-    CFG->Scale = MAX(2, CFG->Scale);
+    CFG->Scale = MAX(min_scale, CFG->Scale);
     CFG->Zoom = 100.0 / CFG->Scale;
     // Make preview size a tiny bit larger to prevent rounding errors
     // that will cause the scrollbars to appear.
@@ -5370,7 +5381,7 @@ int ufraw_preview(ufraw_data *uf, conf_data *rc, int 
plugin,
 
     // Zoom percentage spin button:
     data->ZoomAdjustment = GTK_ADJUSTMENT(gtk_adjustment_new(
-               CFG->Zoom, 5, 50, 1, 1, 0));
+               CFG->Zoom, 5, 100, 1, 1, 0));
     g_object_set_data(G_OBJECT(data->ZoomAdjustment),
                "Adjustment-Accuracy", (gpointer)0);
     button = gtk_spin_button_new(data->ZoomAdjustment, 1, 0);
diff --git a/ufraw_ufraw.c b/ufraw_ufraw.c
index 91b74f5..ba0c376 100644
--- a/ufraw_ufraw.c
+++ b/ufraw_ufraw.c
@@ -936,7 +936,7 @@ no_distortion:
  * ufraw_convert_image_area() */
 int ufraw_convert_image_first_phase(ufraw_data *uf, gboolean lensfix)
 {
-    int status, c;
+    int status;
     dcraw_data *raw = uf->raw;
     // final->image memory will be realloc'd as needed
     dcraw_image_data final;
@@ -947,15 +947,14 @@ int ufraw_convert_image_first_phase(ufraw_data *uf, 
gboolean lensfix)
 
     if ( uf->ConvertShrink>1 || !uf->HaveFilters ) {
        dcraw_finalize_shrink(&final, raw, dark, uf->ConvertShrink);
+       uf->developer->doWB = 1;
     } else {
        if ( (status=dcraw_wavelet_denoise(raw,
                uf->conf->threshold))!=DCRAW_SUCCESS )
            return status;
        dcraw_finalize_interpolate(&final, raw, dark, uf->conf->interpolation,
                uf->conf->smoothing, uf->developer->rgbWB);
-       uf->developer->rgbMax = uf->developer->max;
-       for (c=0; c<4; c++)
-           uf->developer->rgbWB[c] = 0x10000;
+       uf->developer->doWB = 0;
     }
 
     dcraw_image_stretch(&final, raw->pixel_aspect);
@@ -1386,6 +1385,7 @@ int ufraw_set_wb(ufraw_data *uf)
     double rgbWB[3];
     int status, c, cc, i;
 
+    ++uf->WBrequest;
     /* For manual_wb we calculate chanMul from the temperature/green. */
     /* For all other it is the other way around. */
     if (!strcmp(uf->conf->wb, manual_wb)) {
diff --git a/ufraw_ui.h b/ufraw_ui.h
index 2c67ba4..3b6016b 100644
--- a/ufraw_ui.h
+++ b/ufraw_ui.h
@@ -15,7 +15,7 @@
 
 #define raw_his_size 320
 #define live_his_size 256
-#define min_scale 2
+#define min_scale 1
 #define max_scale 20
 
 typedef struct {

-- 
Frank

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
ufraw-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ufraw-devel

Reply via email to