Hi. Attached is a patch to add support for OpenMP parallelism to the preview redraw routine. Instead of redrawing a single tile each time the render_preview_image background routine is called, it redraws one tile for each thread, speeding up redraws on multi-core systems.
The extra "omp critical" markers are necessary to guard resources that would otherwise have race conditions. The critical guard around image_draw_area in particular was due to a seg fault in gtk_widget_queue_draw_area. -- Bruce Guenter <[email protected]> http://untroubled.org/
diff --git a/ufraw_preview.c b/ufraw_preview.c
index 4c5a7e7..40ee07f 100644
--- a/ufraw_preview.c
+++ b/ufraw_preview.c
@@ -682,6 +682,9 @@ static void preview_draw_img_area(preview_data *data,
ufraw_image_data *img,
}
}
}
+#ifdef _OPENMP
+#pragma omp critical
+#endif
/* Redraw the changed areas */
image_draw_area(data, x, y, width, height);
}
@@ -1002,12 +1005,9 @@ static gboolean render_raw_histogram(preview_data *data)
static gboolean render_preview_image(preview_data *data)
{
-#ifdef HAVE_GTKIMAGEVIEW
- int i;
-#endif
- int x, y, w, h;
ufraw_image_data *img;
- int subarea;
+ gboolean again = TRUE;
+ int i = -1;
if (data->FreezeDialog) return FALSE;
@@ -1025,10 +1025,18 @@ static gboolean render_preview_image(preview_data *data)
gtk_image_view_get_viewport (
GTK_IMAGE_VIEW (data->PreviewWidget), &viewport);
+#ifdef _OPENMP
+#pragma omp parallel shared(i) reduction(||:again)
+#endif
+ {
int max_area = -1;
- subarea = -1;
+ int subarea = -1;
+ int x, y, w, h;
- for (i = 0; i < 32; i++)
+#ifdef _OPENMP
+#pragma omp critical
+#endif
+ for (i++; i < 32; i++)
{
/* Skip valid subareas */
if (img->valid & (1 << i))
@@ -1073,34 +1081,36 @@ static gboolean render_preview_image(preview_data *data)
}
}
- if (subarea < 0)
- {
- data->RenderSubArea = -1;
- redraw_navigation_image(data);
- return FALSE;
- }
#else
+#ifdef _OPENMP
+#pragma omp critical
+#endif
subarea = data->RenderSubArea++;
- gboolean last_subimage = (data->RenderSubArea > 31);
+ if (subarea > 31)
+ subarea = -1;
#endif
- img = ufraw_convert_image_area (data->UF, subarea, ufraw_phases_num - 1);
- if (!img)
- return FALSE;
-
- ufraw_img_get_subarea_coord (img, subarea, &x, &y, &w, &h);
- preview_draw_img_area (data, img, x, y, w, h);
-
-#ifndef HAVE_GTKIMAGEVIEW
- if (last_subimage)
+ if (subarea < 0)
{
data->RenderSubArea = -1;
redraw_navigation_image(data);
- return FALSE;
+ again = FALSE;
}
-#endif
+ else {
+ ufraw_image_data *img1 = ufraw_convert_image_area (
+ data->UF, subarea, ufraw_phases_num - 1);
+ if (!img1)
+ again = FALSE;
- return TRUE;
+ else {
+ ufraw_img_get_subarea_coord (img1, subarea, &x, &y, &w, &h);
+ preview_draw_img_area (data, img1, x, y, w, h);
+ }
+ }
+
+ }
+
+ return again;
}
static gboolean render_live_histogram(preview_data *data)
diff --git a/ufraw_ufraw.c b/ufraw_ufraw.c
index 8027e0b..ab651d8 100644
--- a/ufraw_ufraw.c
+++ b/ufraw_ufraw.c
@@ -1294,6 +1294,9 @@ ufraw_image_data *ufraw_convert_image_area (
return in;
}
+#ifdef _OPENMP
+#pragma omp critical
+#endif
// Mark the subarea as valid
out->valid |= (1 << saidx);
pgpcw5pp3MhcT.pgp
Description: PGP signature
------------------------------------------------------------------------------ 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-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ufraw-devel
