added imgproc routines
[gpiv.git] / src / imgproc.c
blobc42797fd34e4da7a4f8a4d735114e8d22743f3a7
1 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 c-style: "K&R" -*- */
3 /*----------------------------------------------------------------------
5 gpiv - Graphic program for Particle Image Velocimetry, based on gtk/gnome
6 libraries.
8 Copyright (C) 2007 Gerber van der Graaf
10 This file is part of gpiv.
12 Gpiv is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2, or (at your option)
15 any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 ----------------------------------------------------------------------*/
29 * Image processing window/tabulator callbacks
30 * $Log: imgproc.c,v $
31 * Revision 1.1 2008-09-16 11:04:47 gerber
32 * added imgproc routines
36 #include "gpiv_gui.h"
37 #include "imgproc.h"
38 /* #include "imgproc_interface.h" */
41 * Prototyping
43 gchar *
44 exec_imgproc_smooth (void);
46 gchar *
47 exec_imgproc_hilo (void);
49 gchar *
50 exec_imgproc_clip (void);
53 * Callback functions
55 void
56 on_button_filter_enter(GtkWidget *widget,
57 gpointer data
59 /*-----------------------------------------------------------------------------
62 GpivConsole * gpiv = gtk_object_get_data (GTK_OBJECT (widget), "gpiv");
64 gnome_appbar_set_status (GNOME_APPBAR (gpiv->appbar), data);
68 void
69 on_button_filter(GtkWidget *widget,
70 gpointer data
72 /*-----------------------------------------------------------------------------
73 Adjust/ sets variables for a image processing button, its relatives and
74 variables of other imgproc buttons if adeqaute.
76 imf_inf: current widget which is calling the callback function
77 imgproc->imf_inf[]: (element of) array widgets belonging to imgproc
80 Imgprocess *imgproc = gtk_object_get_data (GTK_OBJECT (widget), "imgproc");
81 ImgfilterInterface *imf_inf = gtk_object_get_data (GTK_OBJECT (widget),
82 "imf_inf");
83 ImgfilterVar *ivar = gtk_object_get_data (GTK_OBJECT (widget), "ivar");
84 /* gint filter_id = (int) data; */
85 gchar label[GPIV_MAX_CHARS];
86 gint i;
88 if (GTK_TOGGLE_BUTTON(widget)->active == TRUE) {
89 gpiv_var->imgproc_count++;
90 g_snprintf (label, GPIV_MAX_CHARS,
91 "Step #: %d", gpiv_var->imgproc_count);
92 ivar->label_step_filter_label = label;
93 gtk_label_set_text (GTK_LABEL (imf_inf->label_step_filter),
94 (char *) ivar->label_step_filter_label);
95 ivar->count_nr = gpiv_var->imgproc_count;
97 } else {
98 for (i = 0; i < IMG_FILTERS; i++) {
99 if (imgproc->ivar[i]->count_nr > ivar->count_nr) {
100 imgproc->ivar[i]->count_nr--;
101 g_snprintf(label, GPIV_MAX_CHARS, "Step #: %d",
102 imgproc->ivar[i]->count_nr);
103 imgproc->ivar[i]->label_step_filter_label = label;
104 gtk_label_set_text (GTK_LABEL (imgproc->imf_inf[i]->label_step_filter),
105 (char *) imgproc->ivar[i]->label_step_filter_label);
109 gpiv_var->imgproc_count--;
110 ivar->count_nr = 0;
111 g_snprintf(label, GPIV_MAX_CHARS, "Step #: %d", ivar->count_nr);
112 ivar->label_step_filter_label = label;
113 gtk_label_set_text (GTK_LABEL (imf_inf->label_step_filter),
114 (char *) ivar->label_step_filter_label);
120 void
121 on_spinbutton_filtervar (GtkSpinButton *widget,
122 GtkWidget *entry
124 /* ----------------------------------------------------------------------------
127 ImgfilterVar *ivar = gtk_object_get_data (GTK_OBJECT (widget), "ivar");
129 ivar->value = gtk_spin_button_get_value_as_int (widget);
131 if (ivar->filter_id == GPIV_IMGFI_SUBACK) {
132 /* gpiv_var->imgproc_smooth_window = gtk_spin_button_get_value_as_int (widget);*/
133 /* g_message ("on_spinbutton_filtervar:: GPIV_IMGFI_SUBACK val = %d", */
134 /* ivar->value); */
135 } else if (ivar->filter_id == GPIV_IMGFI_HILO) {
136 /* g_message ("on_spinbutton_filtervar:: GPIV_IMGFI_HILO val = %d", */
137 /* ivar->value); */
138 } else if (ivar->filter_id == GPIV_IMGFI_SMOOTH) {
139 /* g_message ("on_spinbutton_filtervar:: GPIV_IMGFI_SMOOTH val = %d", */
140 /* ivar->value); */
141 } else if (ivar->filter_id == GPIV_IMGFI_CLIP) {
142 /* g_message ("on_spinbutton_filtervar:: GPIV_IMGFI_CLIP val = %d", */
143 /* ivar->value); */
144 } else if (ivar->filter_id == GPIV_IMGFI_HIGHPASS) {
145 /* g_message ("on_spinbutton_filtervar:: GPIV_IMGFI_HIGHPASS val = %d", */
146 /* ivar->value); */
151 void
152 on_button_imgproc_enter (GtkWidget *widget,
153 gpointer data
155 /*-----------------------------------------------------------------------------
158 GpivConsole *gpiv = gtk_object_get_data (GTK_OBJECT (widget), "gpiv");
159 gchar *msg = _("Processes image");
160 gnome_appbar_set_status (GNOME_APPBAR (gpiv->appbar), msg);
164 void
165 on_button_imgproc (GtkWidget *widget,
166 gpointer data
168 /* ----------------------------------------------------------------------------
171 /* Imgprocess *imgproc = gtk_object_get_data (GTK_OBJECT (widget), "imgproc"); */
172 GpivConsole *gpiv = gtk_object_get_data (GTK_OBJECT (widget), "gpiv");
174 cancel_process = FALSE;
175 exec_imgproc (gpiv);
179 * Local functions
181 gchar *
182 set_imgproc_filtervar (GpivConsole *gpiv,
183 gint id,
184 gint value)
185 /* ----------------------------------------------------------------------------
188 gchar *err_msg = NULL;
189 gint i;
192 for (i = 0; i < IMG_FILTERS; i++) {
193 if (gpiv->imgproc->ivar[i]->filter_id == id /* GPIV_IMGFI_SUBACK */ ) {
194 gpiv->imgproc->ivar[i]->value = value;
195 gtk_spin_button_set_value
196 (GTK_SPIN_BUTTON (gpiv->imgproc->imf_inf[i]->spinbutton_filtervar),
197 (gdouble) value);
198 if (gpiv_par->verbose) g_message ("set_imgproc_filtervar:: i = %d id = %d value = %d",
199 i, id, value);
204 return err_msg;
208 gchar *
209 exec_imgproc_subtract (ImgfilterVar *ivar)
210 /*-----------------------------------------------------------------------------
213 gchar *err_msg = NULL;
215 if (gpiv_par->verbose) g_message ("exec_imgproc_subtract:: value = %d", ivar->value);
216 if (ivar->value > nbufs - 1) {
217 err_msg = "exec_imgproc_subtract: unvalid value: larger than number of buffers";
218 warning_gpiv ("%s", err_msg);
219 return err_msg;
222 if (ivar->value == display_act->id) {
223 err_msg = "exec_imgproc_subtract: subtracting intensities from own buffer image";
224 return err_msg;
227 if ((err_msg =
228 gpiv_imgproc_subtractimg (display[ivar->value]->img->image,
229 display_act->img->image
231 != NULL) {
232 g_message("exec_imgproc_subtract: %s", err_msg);
233 return err_msg;
237 return err_msg;
242 gchar *
243 exec_imgproc_hilo (void)
244 /*-----------------------------------------------------------------------------
247 gchar *err_msg = NULL;
250 /* BUGFIX: there is an error in the procedure? */
251 if (gpiv_par->verbose) g_message ("exec_imgproc_hilo:: 0");
252 if ((err_msg =
253 gpiv_imgproc_highlow (display_act->img->image, gl_imgproc_par))
254 != NULL) gpiv_warning ("exec_imgproc_hilo: %s", err_msg);
255 if (gpiv_par->verbose) g_message ("exec_imgproc_hilo:: 1");
258 if (gpiv_par->verbose) g_message ("exec_imgproc_hilo:: 2/2");
259 return (err_msg);
264 gchar *
265 exec_imgproc_clip (void)
266 /*-----------------------------------------------------------------------------
269 gchar *err_msg = NULL;
272 if ((err_msg =
273 gpiv_imgproc_clip (display_act->img->image, gl_imgproc_par))
274 != NULL) gpiv_warning ("exec_imgproc_clip: %s", err_msg);
277 return (err_msg);
282 gchar *
283 exec_imgproc_smooth (void)
284 /*-----------------------------------------------------------------------------
287 gchar *err_msg = NULL;
290 if ((err_msg =
291 gpiv_imgproc_smooth (display_act->img->image, gl_imgproc_par))
292 != NULL) gpiv_warning ("exec_imgproc_smooth: %s", err_msg);
295 return (err_msg);
300 gchar *
301 exec_imgproc_highpass (void)
302 /*-----------------------------------------------------------------------------
305 gchar *err_msg = NULL;
308 if ((err_msg =
309 gpiv_imgproc_highpass (display_act->img->image, gl_imgproc_par))
310 != NULL) gpiv_warning ("exec_imgproc_highpass: %s", err_msg);
313 return (err_msg);
318 void
319 exec_imgproc (GpivConsole * gpiv
320 /* Imgprocess *imgproc */
322 /*-----------------------------------------------------------------------------
325 gchar *err_msg = NULL;
326 gint i, j;
328 for (i = 1; i <= gpiv_var->imgproc_count; i++) {
329 for (j = 0; j < IMG_FILTERS; j++) {
330 if (gpiv->imgproc->ivar[j]->count_nr == i) {
331 if (gpiv->imgproc->ivar[j]->filter_id == GPIV_IMGFI_SUBACK) {
332 if ((err_msg = exec_imgproc_subtract (gpiv->imgproc->ivar[j]))
333 != NULL) {
334 g_warning ("exec_imgproc: %s", err_msg);
336 } else if (gpiv->imgproc->ivar[j]->filter_id == GPIV_IMGFI_HILO) {
337 gl_imgproc_par->window = gpiv->imgproc->ivar[j]->value;
338 exec_imgproc_hilo ();
339 } else if (gpiv->imgproc->ivar[j]->filter_id == GPIV_IMGFI_CLIP) {
340 gl_imgproc_par->threshold = gpiv->imgproc->ivar[j]->value;
341 exec_imgproc_clip ();
342 } else if (gpiv->imgproc->ivar[j]->filter_id == GPIV_IMGFI_SMOOTH) {
343 exec_imgproc_smooth ();
344 } else if (gpiv->imgproc->ivar[j]->filter_id == GPIV_IMGFI_HIGHPASS) {
345 gl_imgproc_par->window = gpiv->imgproc->ivar[j]->value;
346 exec_imgproc_highpass ();
353 /* #ifdef IMGPROC_SAVE_IMG */
354 if (display_act != NULL) {
355 destroy_img (display_act);
356 create_img (display_act);
357 if (gpiv_par->verbose) g_message ("EXEC_IMGPROC:: img.saved_img = FALSE");
358 display_act->img->saved_img = FALSE;
360 /* #endif */