Update of /cvsroot/ufraw/ufraw
In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv24374

Modified Files:
        dcraw_api.cc dcraw_api.h ufraw_preview.c ufraw_ufraw.c 
Log Message:
Make sure that FreezeDialog is set while the non-tiled part of the image
is being rendered. This requires making all ufraw_*_image functions
returning images, not do any rendering.


Index: dcraw_api.h
===================================================================
RCS file: /cvsroot/ufraw/ufraw/dcraw_api.h,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- dcraw_api.h 25 Nov 2009 16:15:45 -0000      1.37
+++ dcraw_api.h 28 Nov 2009 05:56:51 -0000      1.38
@@ -73,7 +73,8 @@
 int dcraw_finalize_interpolate(dcraw_image_data *f, dcraw_data *h,
        int interpolation, int smoothing);
 void dcraw_close(dcraw_data *h);
-int dcraw_image_dimensions(dcraw_data *raw, int flip, int *height, int *width);
+void dcraw_image_dimensions(dcraw_data *raw, int flip, int shrink,
+       int *height, int *width);
 
 #define DCRAW_SUCCESS 0
 #define DCRAW_ERROR 1

Index: dcraw_api.cc
===================================================================
RCS file: /cvsroot/ufraw/ufraw/dcraw_api.cc,v
retrieving revision 1.61
retrieving revision 1.62
diff -u -d -r1.61 -r1.62
--- dcraw_api.cc        25 Nov 2009 16:15:45 -0000      1.61
+++ dcraw_api.cc        28 Nov 2009 05:56:51 -0000      1.62
@@ -153,28 +153,30 @@
     return d->lastStatus;
 }
 
-int dcraw_image_dimensions(dcraw_data *raw, int flip, int *height, int *width)
+void dcraw_image_dimensions(dcraw_data *raw, int flip, int shrink,
+       int *height, int *width)
 {
+    // Effect of dcraw_finilize_shrink()
+    *width = raw->width / shrink;
+    *height = raw->height / shrink;
+    // Effect of fuji_rotate_INDI() */
     if (raw->fuji_width) {
-       /* Copied from DCRaw's fuji_rotate() */
-       *width = (raw->fuji_width - 1) / raw->fuji_step;
-       *height = (raw->height - raw->fuji_width + 1) / raw->fuji_step;
-    } else {
-       if (raw->pixel_aspect < 1)
-           *height = raw->height / raw->pixel_aspect + 0.5;
-       else
-           *height = raw->height;
-       if (raw->pixel_aspect > 1)
-           *width = raw->width * raw->pixel_aspect + 0.5;
-       else
-           *width = raw->width;
+       int fuji_width = raw->fuji_width / shrink - 1;
+       *width = fuji_width / raw->fuji_step;
+       *height = (*height - fuji_width) / raw->fuji_step;
     }
+    // Effect of dcraw_image_stretch()
+    if (raw->pixel_aspect < 1)
+        *height = *height / raw->pixel_aspect + 0.5;
+    if (raw->pixel_aspect > 1)
+        *width = *width * raw->pixel_aspect + 0.5;
+
+    // Effect of dcraw_flip_image()
     if (flip & 4) {
        int tmp = *height;
        *height = *width;
        *width = tmp;
     }
-    return DCRAW_SUCCESS;
 }
 
 int dcraw_load_raw(dcraw_data *h)

Index: ufraw_ufraw.c
===================================================================
RCS file: /cvsroot/ufraw/ufraw/ufraw_ufraw.c,v
retrieving revision 1.221
retrieving revision 1.222
diff -u -d -r1.221 -r1.222
--- ufraw_ufraw.c       27 Nov 2009 07:18:23 -0000      1.221
+++ ufraw_ufraw.c       28 Nov 2009 05:56:51 -0000      1.222
@@ -48,6 +48,8 @@
 static void ufraw_convert_image_transform(ufraw_data *uf, ufraw_image_data 
*img,
        ufraw_image_data *outimg, UFRectangle *area);
 static void ufraw_prepare_transform(ufraw_data *uf);
+static void ufraw_convert_prepare_first_buffer(ufraw_data *uf,
+       ufraw_image_data *img);
 static void ufraw_convert_prepare_transform_buffer(ufraw_data *uf,
        ufraw_image_data *img, int width, int height);
 static void ufraw_convert_reverse_wb(ufraw_data *uf, UFRawPhase phase);
@@ -342,9 +344,11 @@
     return UFRAW_SUCCESS;
 }
 
+// Get the dimensions of the unshrunk, rotated image.
+// The crop coordinates are calculated based on these dimensions.
 void ufraw_get_image_dimensions(ufraw_data *uf)
 {
-    dcraw_image_dimensions(uf->raw, uf->conf->orientation,
+    dcraw_image_dimensions(uf->raw, uf->conf->orientation, 1,
            &uf->initialHeight, &uf->initialWidth);
 
     // update rotated dimensions
@@ -752,8 +756,11 @@
     uf->mark_hotpixels = FALSE;
     ufraw_developer_prepare(uf, file_developer);
     ufraw_convert_image_raw(uf, ufraw_raw_phase);
-    ufraw_convert_image_first(uf, ufraw_first_phase);
+
     ufraw_image_data *img = &uf->Images[ufraw_first_phase];
+    ufraw_convert_prepare_first_buffer(uf, img);
+    ufraw_convert_image_first(uf, ufraw_first_phase);
+
     UFRectangle area = { 0, 0, img->width, img->height };
 #ifdef HAVE_LENSFUN
     ufraw_prepare_transform(uf);
@@ -1121,8 +1128,9 @@
     return active;
 }
 
-static void ufraw_convertshrink(ufraw_data *uf, dcraw_image_data *final, 
dcraw_data *raw)
+static int ufraw_calculate_scale(ufraw_data *uf)
 {
+    dcraw_data *raw = uf->raw;
     int scale = 1;
 
     /* We can do a simple interpolation in the following cases:
@@ -1141,6 +1149,15 @@
        if (cropSize/uf->conf->size >= 2)
            scale = cropSize / uf->conf->size;
     }
+    return scale;
+}
+
+// Any change to ufraw_convertshrink() that might change the final image
+// dimensions should also be applied to ufraw_convert_prepare_first_buffer().
+static void ufraw_convertshrink(ufraw_data *uf, dcraw_image_data *final)
+{
+    dcraw_data *raw = uf->raw;
+    int scale = ufraw_calculate_scale(uf);
 
     if (uf->HaveFilters && scale == 1)
        dcraw_finalize_interpolate(final, raw, uf->conf->interpolation,
@@ -1204,21 +1221,28 @@
     ufraw_image_data *in = &uf->Images[phase - 1];
     ufraw_image_data *out = &uf->Images[phase];
     dcraw_data *raw = uf->raw;
-    dcraw_image_type *rawimage;
-    dcraw_image_data final;
 
+    dcraw_image_data final;
     final.image = (ufraw_image_type *)out->buffer;
-    final.width = out->width;
-    final.height = out->height;
 
-    rawimage = raw->raw.image;
+    dcraw_image_type *rawimage = raw->raw.image;
     raw->raw.image = (dcraw_image_type *)in->buffer;
-    ufraw_convertshrink(uf, &final, raw);
+    ufraw_convertshrink(uf, &final);
     raw->raw.image = rawimage;
     dcraw_flip_image(&final, uf->conf->orientation);
 
-    out->height = final.height;
-    out->width = final.width;
+    // The 'out' image contains the predictated image dimensions.
+    // We want to be sure that our predictions were correct.
+    if (out->height != final.height) {
+       g_warning("ufraw_convert_image_first: height mismatch %d!=%d",
+               out->height, final.height);
+       out->height = final.height;
+    }
+    if (out->width != final.width) {
+       g_warning("ufraw_convert_image_first: width mismatch %d!=%d",
+               out->width, final.width);
+       out->width = final.width;
+    }
     out->depth = sizeof (dcraw_image_type);
     out->rowstride = out->width * out->depth;
     out->buffer = (guint8 *)final.image;
@@ -1320,6 +1344,40 @@
     img->buffer = g_realloc(img->buffer, img->height * img->rowstride);
 }
 
+static void ufraw_convert_prepare_first_buffer(ufraw_data *uf,
+       ufraw_image_data *img)
+{
+    // The actual buffer allocation is done in ufraw_convertshrink().
+    int scale = ufraw_calculate_scale(uf);
+    dcraw_image_dimensions(uf->raw, uf->conf->orientation, scale,
+           &img->height, &img->width);
+    // The final resizing in ufraw_convertshrink() is calculate here:
+    if (uf->conf->size==0 && uf->conf->shrink>1) {
+       // This is the effect of first call to dcraw_image_resize().
+       // It only relevant when raw->pixel_aspect != 1.
+       img->width = img->width * scale / uf->conf->shrink;
+       img->height = img->height * scale / uf->conf->shrink;
+    }
+    if (uf->conf->size>0) {
+       int cropHeight = uf->conf->CropY2 - uf->conf->CropY1;
+       int cropWidth = uf->conf->CropX2 - uf->conf->CropX1;
+       int cropSize = MAX(cropHeight, cropWidth);
+       if ( uf->conf->size > cropSize ) {
+           ufraw_message(UFRAW_ERROR, _("Can not downsize from %d to %d."),
+                   cropSize, uf->conf->size);
+       } else {
+           /* uf->conf->size holds the size of the cropped image.
+            * We need to calculate from it the desired size of
+            * the uncropped image. */
+           int finalSize = scale * MAX(img->height, img->width);
+           int mul = uf->conf->size * finalSize / cropSize;
+           int div = MAX(img->height, img->width);
+           img->height = img->height * mul / div;
+           img->width = img->width * mul / div;
+       }
+    }
+}
+ 
 static void ufraw_convert_prepare_transform_buffer(ufraw_data *uf,
        ufraw_image_data *img, int width, int height)
 {
@@ -1353,12 +1411,9 @@
 void ufraw_convert_prepare_buffers(ufraw_data *uf)
 {
     ufraw_image_data *img = &uf->Images[ufraw_first_phase];
-    // Buffers can be prepared only after first image is generated.
-    // If first image is not valid we can easily skip the buffer
-    // preparation since it will be prepared after first image generation.
-    if (img->valid != 0xffffffff)
-       return;
-
+    if (img->valid == 0) {
+       ufraw_convert_prepare_first_buffer(uf, img);
+    }
     int width = img->width;
     int height = img->height;
 
@@ -1488,15 +1543,17 @@
 #endif /* HAVE_LENSFUN */
     int i;
 
-    if (dbg && uf->Images[phase].valid != 0xffffffff)
-       g_warning("%s->%s: conversion necessary (suboptimal).\n", dbg,
+    if (bufferok) {
+       if (dbg && uf->Images[phase].valid != 0xffffffff) {
+           g_warning("%s->%s: conversion necessary (suboptimal).\n", dbg,
                G_STRFUNC);
-    for (i = 0; i < 32; ++i) {
-       ufraw_convert_image_area(uf, i, phase);
-       if (!bufferok) {
-           /* the first tile should yield the image dimensions already */
-           break;
+           for (i = 0; i < 32; ++i) {
+               ufraw_convert_image_area(uf, i, phase);
+           }
        }
+    } else {
+       if (uf->Images[phase].valid == 0)
+           ufraw_convert_prepare_buffers(uf);
     }
     return &uf->Images[phase];
 }
@@ -1520,12 +1577,8 @@
                ufraw_convert_image_area(uf, i, phase);
        }
     } else {
-       if (uf->Images[phase].valid == 0) {
-           // TODO: this warning should be avoided
-           //g_warning("%s: starting conversion.\n", G_STRFUNC);
-           /* this will update all buffer sizes (e.g. due to rotate) */
-           ufraw_convert_image_area(uf, 0, ufraw_first_phase);
-       }
+       if (uf->Images[phase].valid == 0)
+           ufraw_convert_prepare_buffers(uf);
     }
     return &uf->Images[phase];
 }
@@ -1550,12 +1603,8 @@
                ufraw_convert_image_area(uf, i, phase);
        }
     } else {
-       if (uf->Images[phase].valid == 0) {
-           // TODO: this warning should be avoided
-           //g_warning("%s: starting conversion.\n", G_STRFUNC);
-           /* this will update all buffer sizes (e.g. due to rotate) */
-           ufraw_convert_image_area(uf, 0, ufraw_first_phase);
-       }
+       if (uf->Images[phase].valid == 0)
+           ufraw_convert_prepare_buffers(uf);
     }
     return &uf->Images[phase];
 }
@@ -1599,7 +1648,6 @@
            if (out->valid != 0xffffffff) {
                ufraw_convert_image_first(uf, phase);
                out->valid = 0xffffffff;
-               ufraw_convert_prepare_buffers(uf);
 #ifdef HAVE_LENSFUN
                UFRectangle area = { 0, 0, out->width, out->height };
                ufraw_convert_image_vignetting(uf, out, &area);

Index: ufraw_preview.c
===================================================================
RCS file: /cvsroot/ufraw/ufraw/ufraw_preview.c,v
retrieving revision 1.316
retrieving revision 1.317
diff -u -d -r1.316 -r1.317
--- ufraw_preview.c     27 Nov 2009 15:00:16 -0000      1.316
+++ ufraw_preview.c     28 Nov 2009 05:56:51 -0000      1.317
@@ -944,27 +944,27 @@
     }
     ufraw_developer_prepare(data->UF, display_developer);
     ufraw_convert_prepare_buffers(data->UF);
-
+    if (ufraw_invalidate_layer_event(data->UF, ufraw_transform_phase)) {
+       render_init(data);
+    }
     /* This will trigger the untiled phases if necessary. The progress bar
      * updates require gtk_main_iteration() calls which can only be
      * done when there are no pending idle tasks which could recurse
      * into ufraw_convert_image_area(). */
     preview_progress_enable(data);
-    gboolean again = render_preview_image(data);
+    data->FreezeDialog = TRUE;
+    ufraw_convert_image_area(data->UF, 0, ufraw_first_phase);
+    data->FreezeDialog = FALSE;
+
+    preview_progress(PROGRESS_RENDER, -32);
+    g_idle_add_full(G_PRIORITY_DEFAULT_IDLE,
+           (GSourceFunc)(render_preview_image), data, NULL);
 
-    if (again) {
-       preview_progress(PROGRESS_RENDER, -32);
-       g_idle_add_full(G_PRIORITY_DEFAULT_IDLE,
-               (GSourceFunc)(render_preview_image), data, NULL);
-    }
     return FALSE;
 }
 
 void render_preview(preview_data *data)
 {
-    if (is_rendering(data))
-       return;
-
     while (g_idle_remove_by_data(data))
        ;
     g_idle_add_full(G_PRIORITY_DEFAULT_IDLE,
@@ -1131,13 +1131,9 @@
 }
 
 /*
- * OpenMP notes:
+ * render_preview_image() is called after all non-tiled phases are rendered.
  *
- * render_init() resizes the pixbuf and calls ufraw_final_image() for obtaining
- * image dimensions. That one calls ufraw_convert_image_area() with a subarea
- * index for ufraw_first_phase. After this all non-tiled phases are done and
- * all buffers have been resized so ufraw_convert_image_area() should then be
- * OpenMP safe.
+ * OpenMP notes:
  *
  * Unfortunately ufraw_convert_image_area() still has some OpenMP awareness
  * which is related to OpenMP here. That should not be necessary.
@@ -1148,10 +1144,6 @@
     int chosen = 0;
 
     if (data->FreezeDialog) return FALSE;
-
-    if (ufraw_invalidate_layer_event(data->UF, ufraw_transform_phase)) {
-       render_init(data);
-    }
 #ifdef _OPENMP
 #pragma omp parallel shared(chosen,data) reduction(||:again)
     {
@@ -1594,7 +1586,7 @@
 
     data->FreezeDialog = FALSE;
     update_shrink_ranges(data);
-    render_preview_now(data);
+    render_preview(data);
 }
 
 static void curve_update(GtkWidget *widget, long curveType)
@@ -3000,7 +2992,6 @@
 static void adjustment_update(GtkAdjustment *adj, double *valuep)
 {
     preview_data *data = get_preview_data(adj);
-    if (data->FreezeDialog) return;
 
     if (valuep==&CFG->profile[0][0].gamma)
        valuep = (void *)&CFG->profile[0][CFG->profileIndex[0]].gamma;
@@ -5869,6 +5860,7 @@
 
     /* This will start the conversion and enqueue rendering functions */
     update_scales(data);
+    render_preview_now(data);
     update_crop_ranges(data, FALSE);   // calls ufraw_final_image(uf, FALSE)
 
     /* Collect raw histogram data */


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
ufraw-cvs mailing list
ufraw-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ufraw-cvs

Reply via email to