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
8 Copyright (C) 2002, 2003, 2004
9 Gerber van der Graaf <gerber_graaf@users.sourceforge.net>
11 This file is part of gpiv.
13 Gpiv is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2, or (at your option)
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software Foundation,
25 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 ----------------------------------------------------------------------*/
31 * $Id: dac.c,v 1.5 2005-02-26 09:43:30 gerber Exp $
43 /* #include "dac_cam.h" */
44 #include <libdc1394/dc1394_control.h>
46 /* #include <sys/types.h> */
47 /* #include <sys/stat.h> */
48 /* #include <fcntl.h> */
52 * BUGFIX: Put somwhere to update on regular basis:
53 gtk_label_set_text(GTK_LABEL(gpiv->dac->label_temp),
57 static int init
, start
, stop
, error
;
59 typedef struct _ImgFrame ImgFrame
;
66 pthread_mutex_t mutex_rec
= PTHREAD_MUTEX_INITIALIZER
;
69 thread_rec_frame(void *img_frame
);
73 thread_rec_frame_serie(ImgFrame img_frame
[GPIV_NIMG_MAX
]
77 rec_frame(ImgFrame
*img_frame
81 add_buffer(GpivConsole
*gpiv
,
84 unsigned char **frameA
,
85 unsigned char **frameB
89 renew_buffer(GpivConsole
*gpiv
,
92 unsigned char **frameA
,
93 unsigned char **frameB
97 recreate_img(Display
* disp
,
98 unsigned char **frameA
,
99 unsigned char **frameB
104 open_dac_img(GpivCamVar
*cam_var
,
105 unsigned char **frameA
,
106 unsigned char **frameB
,
110 /*-----------------------------------------------------------------------------
111 * Opens an image obtained from the camera (<=> open_img from file)
116 * parameter initializing of image
118 img
->image_par
.depth_logic
= FALSE
;
119 img
->image_par
.ncolumns_logic
= FALSE
;
120 img
->image_par
.nrows_logic
= FALSE
;
121 img
->image_par
.x_corr_logic
= FALSE
;
122 img
->image_par
.s_scale_logic
= FALSE
;
123 img
->image_par
.t_scale_logic
= FALSE
;
124 img
->image_par
.z_off_logic
= FALSE
;
125 img
->image_par
.project_logic
= FALSE
;
126 img
->image_par
.creation_date_logic
= FALSE
;
127 img
->image_par
.location_logic
= FALSE
;
128 img
->image_par
.comment_logic
= FALSE
;
130 img
->image_par
.ncolumns
= cam_var
->capture
[0].frame_width
;
131 img
->image_par
.nrows
= cam_var
->capture
[0].frame_height
;
132 img
->image_par
.x_corr
= gpiv_par
.x_corr
;
133 img
->image_par
.ncolumns_logic
= TRUE
;
134 img
->image_par
.nrows_logic
= TRUE
;
135 img
->image_par
.x_corr_logic
= TRUE
;
139 gpiv_img_cp_parameters (image_par
, &img
->image_par
, FALSE
, FALSE
);
142 /* if(alloc_mem) { */
143 img
->img1
= gpiv_alloc_img(img
->image_par
);
146 for (i
= 0; i
< img
->image_par
.nrows
; i
++) {
147 for (j
= 0; j
< img
->image_par
.ncolumns
; j
++) {
149 * format 640x480 = 1:1.3
151 img
->img1
[i
][j
/* + i/3 */] = (guint16
) frameA
[i
][j
];
157 if (gpiv_par
.x_corr
) {
158 /* if(alloc_mem) { */
159 img
->img2
= gpiv_alloc_img(img
->image_par
);
161 for (i
= 0; i
< img
->image_par
.nrows
; i
++) {
162 for (j
= 0; j
< img
->image_par
.ncolumns
; j
++) {
164 * format 640x480 = 1:1.3
166 img
->img2
[i
][j
/* + i/3 */] = (guint16
) frameB
[i
][j
];
170 img
->img2
= img
->img1
;
174 img
->exist_img
= TRUE
;
180 load_dac_buffer(GpivConsole
*gpiv
,
182 gboolean second_image
,
185 unsigned char **frameA
,
186 unsigned char **frameB
,
187 enum ClistPut clist_put
)
188 /*-----------------------------------------------------------------------------
189 * create display and its (popup) menu, load image, piv data and puts
190 * buffername into clist
194 gchar
*clist_buf_txt
[MAX_BUFS
][2], cl_int
[4];
197 display
[ibuf
] = create_display(fname
, ibuf
, gpiv
);
198 display_act
= display
[ibuf
];
199 gtk_widget_show(display_act
->mwin
);
201 /* zoom_display(display_act, display_act->zoom_index); */
205 g_snprintf(display_act
->fname_base
, GPIV_MAX_CHARS
, "%s", fname
);
206 if((return_val
= open_dac_img(cam_var
, frameA
, frameB
,
207 &display_act
->img
, FALSE
)) != 0) {
208 gtk_object_destroy(GTK_OBJECT(display
[ibuf
]->mwin
));
211 display_act
= display
[ibuf
];
220 * Pop-up menu after loading data
222 display_act
->display_menu
= create_display_menu(display_act
);
223 gtk_widget_show(display_act
->display_menu
);
224 gtk_signal_connect_object(GTK_OBJECT(display_act
->mwin
),
225 "button_press_event",
226 GTK_SIGNAL_FUNC (on_my_popup_handler
),
227 GTK_OBJECT(display_act
->display_menu
));
230 zoom_display(display_act
, display_act
->zoom_index
);
235 /* display_act->img.exist_img = TRUE; */
236 create_background(display_act
);
237 create_img(display_act
);
238 if (display_act
->display_img1
) {
239 show_img1(display_act
);
241 hide_img1(display_act
);
244 if (image_par
.x_corr
) {
245 if (display_act
->display_img2
) {
246 show_img2(display_act
);
248 hide_img2(display_act
);
253 /* display_act->img.img_mean = image_mean(display_act->img.img1, */
254 /* gpiv_par.img_width, */
255 /* gpiv_par.img_height); */
258 if (gpiv_par
.display_intregs
== 1) create_all_intregs(display_act
);
263 g_snprintf(cl_int
, 4, "%d", ibuf
);
264 clist_buf_txt
[ibuf
][0] = (gchar
*) cl_int
;
265 clist_buf_txt
[ibuf
][1] = fname
;
266 if (clist_put
== PREPEND
) {
267 gtk_clist_prepend(GTK_CLIST(gpiv
->clist_buf
),
268 clist_buf_txt
[ibuf
]);
269 } else if (clist_put
== INSERT
) {
270 gtk_clist_insert(GTK_CLIST(gpiv
->clist_buf
), ibuf
,
271 clist_buf_txt
[ibuf
]);
272 } else if (clist_put
== APPEND
) {
273 gtk_clist_append(GTK_CLIST(gpiv
->clist_buf
),
274 clist_buf_txt
[ibuf
]);
276 gtk_error("non-existent CLIST enumerate");
279 gtk_clist_set_row_data(GTK_CLIST(gpiv
->clist_buf
), ibuf
,
287 rec_and_display(GpivConsole
*gpiv
288 /* , ImgFrame *img_frame */
290 /*-----------------------------------------------------------------------------
294 ImgFrame img_frame
[GPIV_NIMG_MAX
];
297 pthread_t thread_rec
;
300 pthread_attr_init(&attr
);
301 pthread_attr_setdetachstate(&attr
, PTHREAD_CREATE_JOINABLE
);
304 if (dac_par
.ttime
.mode
== GPIV_TIMER_MODE__DURATION
) {
306 * Closing existing buffer windows and cleaning up Clist
308 for (ibuf
= 0; ibuf
< nbufs
; ibuf
++) {
309 if (display
[ibuf
] != NULL
) {
310 close_buffer(gpiv
, display
[ibuf
], &ibuf
);
313 gtk_clist_clear(GTK_CLIST(gpiv
->clist_buf
));
317 * allocating image mem
319 for (ibuf
= 0; ibuf
< dac_par
.ttime
.cycles
; ibuf
++) {
321 gpiv_ucmatrix(0, cam_var
.capture
[0].frame_height
- 1,
322 0, cam_var
.capture
[0].frame_width
- 1);
323 if (gpiv_par
.x_corr
) {
324 img_frame
[ibuf
].B
= gpiv_ucmatrix(0, gpiv_par
.img_height
- 1,
325 0, gpiv_par
.img_width
- 1);
337 /* g_message("rec_and_display:: Creating thread_rec from %d", pthread_self ()); */
338 if ((return_val
= pthread_create(&thread_rec
,
340 (void *) &thread_rec_frame_serie
,
341 (void *) &img_frame
)) == TRUE
) {
343 g_error("return code from pthread_create() is %d\n", return_val
);
345 pthread_join(thread_rec
, NULL
);
346 g_message ("rec_and_display:: waited on thread_rec. Done");
351 /* for (ibuf = 0; ibuf < dac_par.ttime.cycles; ibuf++) { */
352 /* if (cancel_process) break; */
353 /* rec_frame(&img_frame[ibuf]); */
355 /* progress_value = (gfloat) (ibuf + 1.0) / */
356 /* (gfloat) dac_par.ttime.cycles; */
357 /* g_snprintf(progress_string, GPIV_MAX_CHARS, */
358 /* "recording image #%d", ibuf); */
359 /* while (g_main_iteration(FALSE)); */
360 /* gtk_progress_set_value(gnome_appbar_get_progress */
361 /* (GNOME_APPBAR(gpiv->appbar)), */
362 /* progress_value * 100.0); */
363 /* gnome_appbar_push(GNOME_APPBAR(gpiv->appbar), */
364 /* progress_string); */
368 * displaying and freeing image mem
370 for (ibuf
= 0; ibuf
< dac_par
.ttime
.cycles
; ibuf
++) {
371 add_buffer(gpiv
, gpiv_var
.fn_last
[0], ibuf
, img_frame
[ibuf
].A
,
373 gpiv_free_ucmatrix(img_frame
[ibuf
].A
, 0,
374 cam_var
.capture
[0].frame_height
- 1,
375 0, cam_var
.capture
[0].frame_width
- 1);
376 if (gpiv_par
.x_corr
) {
377 gpiv_free_ucmatrix(img_frame
[ibuf
].B
, 0,
378 cam_var
.capture
[0].frame_height
- 1,
379 0, cam_var
.capture
[0].frame_width
- 1);
384 * timing is indefinite periodic
385 * display only and continuously images in buffer 0
389 gtk_clist_select_row(GTK_CLIST(gpiv
->clist_buf
), ibuf
, 0);
390 g_message("rec_and_display:: INDEFINITE");
392 /* BUGFIX: for Gtk2 */
393 /* gtk_progress_bar_set_pulse_step (GNOME_APPBAR(gpiv->appbar), */
397 gpiv_ucmatrix(0, cam_var
.capture
[0].frame_height
- 1,
398 0, cam_var
.capture
[0].frame_width
- 1);
399 if (gpiv_par
.x_corr
) {
400 img_frame
[ibuf
].B
= gpiv_ucmatrix(0, gpiv_par
.img_height
- 1,
401 0, gpiv_par
.img_width
- 1);
404 while (!cancel_process
) {
405 rec_frame(&img_frame
[ibuf
]);
406 while (g_main_iteration(FALSE
));
407 renew_buffer(gpiv
, gpiv_var
.fn_last
[0], ibuf
, img_frame
[ibuf
].A
,
409 /* BUGFIX: for Gtk2 */
410 /* gtk_progress_bar_pulse ((GNOME_APPBAR(gpiv->appbar)) */
415 gpiv_free_ucmatrix(img_frame
[ibuf
].A
, 0,
416 cam_var
.capture
[0].frame_height
- 1,
417 0, cam_var
.capture
[0].frame_width
- 1);
418 if (gpiv_par
.x_corr
) {
419 gpiv_free_ucmatrix(img_frame
[ibuf
].B
, 0,
420 cam_var
.capture
[0].frame_height
- 1,
421 0, cam_var
.capture
[0].frame_width
- 1);
426 pthread_attr_destroy(&attr
);
438 exec_trigger_start (void
440 /*-----------------------------------------------------------------------------
443 gchar
*err_msg
= NULL
;
444 int on
= 1, param_ok
;
446 if (!gpiv_dac_openrtfs(&init
, &start
, &stop
, &error
)) {
447 err_msg
= "Fail in fifo open";
448 gtk_warning(err_msg
);
453 gpiv_dac_test_parameter(&dac_par
);
455 if((write(init
, &dac_par
.ttime
, sizeof(GpivTrigTime
))) < 0) {
456 err_msg
= "fail in setting camera and Laser timing";
457 gtk_warning(err_msg
);
461 if((read(error
, ¶m_ok
, sizeof(int))) < 0) {
462 err_msg
= "fail in receipt of confirmation";
463 gtk_warning(err_msg
);
468 g_message ("Parameters: \n\
469 cam_acq_period: %lld \n\
470 laser_trig_pw: %lld \n\
476 dac_par
.ttime
.cam_acq_period
,
477 dac_par
.ttime
.laser_trig_pw
,
478 dac_par
.ttime
.time2laser
,
481 dac_par
.ttime
.cycles
,
482 (int) dac_par
.ttime
.increment
);
484 if((write(start
, &on
, sizeof(int))) < 0) {
485 err_msg
= "fail in starting camera and Laser timing";
486 gtk_warning(err_msg
);
491 /* gpiv_par.process_dac = TRUE; */
497 exec_trigger_stop (void
499 /*-----------------------------------------------------------------------------
502 gchar
*err_msg
= NULL
;
505 if((write(stop
, &off
, sizeof(int))) < 0) {
506 err_msg
= "fail stopping camera and Laser timing";
507 gtk_warning(err_msg
);
511 /* gpiv_par.process_dac = FALSE; */
517 exec_rec_start(GpivConsole
* gpiv
519 /*-----------------------------------------------------------------------------
525 /* quadlet_t value; */
527 cancel_process
= FALSE
;
530 * report camera's feature set
531 * in: on_menu_camera_select
533 /* dc1394_print_feature_set(&cam_var.feature_set[0]); */
535 /* g_message("exec_rec_start:: mode[%d] = %s", */
536 /* cam_var.misc_info[0].mode, */
537 /* format0_desc[cam_var.misc_info[0].mode - MODE_FORMAT0_MIN]); */
538 /* g_message("exec_rec_start:: format[%d] = %s", */
539 /* cam_var.misc_info[0].format, */
540 /* format_desc[cam_var.misc_info[0].format - FORMAT_MIN]); */
542 g_warning("exec_rec_start:: fps = %d", cam_var
.misc_info
[0].framerate
/* - FRAMERATE_MIN */);
543 if (dc1394_setup_capture(cam_var
.camera
[0].handle
,
544 cam_var
.camera
[0].id
,
545 cam_var
.misc_info
[0].iso_channel
,
546 cam_var
.misc_info
[0].format
,
547 cam_var
.misc_info
[0].mode
,
550 cam_var
.misc_info
[0].framerate
,
554 /* FRAMERATE_3_75, */
558 dc1394_release_camera(cam_var
.handle
, &cam_var
.capture
[0]);
559 raw1394_destroy_handle(cam_var
.handle
);
560 gtk_warning("unable to setup camera-\n\
561 check line %d of %s to make sure\n\
562 that the video mode,framerate and format are\n\
563 supported by your camera\n",
570 * have the camera start sending us data
572 if (dc1394_start_iso_transmission(cam_var
.handle
, cam_var
.capture
[0].node
)
574 dc1394_release_camera(cam_var
.handle
, &cam_var
.capture
[0]);
575 raw1394_destroy_handle(cam_var
.handle
);
576 gtk_warning("unable to start camera iso transmission");
581 * let sending data for a while before grabbing and storing in order to stabilize
589 * set trigger mode and use triggering or just free run
592 if (gpiv_par
.trigger_cam
) {
593 g_warning("exec_rec_start:: trigger_cam");
594 /* if (dc1394_set_trigger_mode(cam_var.handle, */
595 /* cam_var.capture[0].node, */
596 /* TRIGGER_MODE_0) != DC1394_SUCCESS) */
598 /* gtk_warning("unable to set camera trigger mode"); */
600 /* exec_trigger_start(); */
602 rec_and_display(gpiv
);
604 /* exec_trigger_stop(); */
606 g_warning("exec_rec_start:: !trigger_cam");
607 rec_and_display(gpiv
);
611 /* pthread_exit(NULL); */
614 * Stop data transmission
616 g_warning("exec_rec_start:: Stop data transmission and release camera");
617 if (dc1394_stop_iso_transmission(cam_var
.handle
, cam_var
.capture
[0].node
)
619 /* && dc1394_release_camera(cam_var.handle, &cam_var.capture[0]) */
620 /* != DC1394_SUCCESS */
622 gtk_warning("couldn't stop the camera?\n");
624 /* in: exec_stop_rec dc1394_release_camera(cam_var.handle, &cam_var.capture[0]); */
625 /*in: exec_stop_rec: raw1394_destroy_handle(cam_var.handle); */
632 thread_rec_frame(void *img_frame
)
633 /*-----------------------------------------------------------------------------
636 ImgFrame
*my_frame
= NULL
;
637 unsigned char **frameA
= my_frame
->A
;
638 unsigned char **frameB
= my_frame
->B
;
640 g_warning("thread_rec_frame:: 0");
641 my_frame
= (ImgFrame
*) img_frame
;
644 /* unsigned char **frameA = gpiv_ucmatrix(0, cam_var.capture[0].frame_height - 1, */
645 /* 0, cam_var.capture[0].frame_width - 1); */
648 g_message("thread_rec_frame:: 0.1");
652 if (dc1394_single_capture(cam_var
.handle
, &cam_var
.capture
[0])
654 dc1394_release_camera(cam_var
.handle
, &cam_var
.capture
[0]);
655 raw1394_destroy_handle(cam_var
.handle
);
656 gtk_warning("unable to capture a frame");
659 g_message("thread_rec_frame:: 1");
663 * Copy buffer content to tmp buffer array
664 * block data for thread
667 pthread_mutex_lock(&mutex_rec
);
668 memcpy( frameA
[0], (const char *) cam_var
.capture
[0].capture_buffer
,
669 sizeof(char) * cam_var
.capture
[0].frame_width
*
670 cam_var
.capture
[0].frame_height
);
671 pthread_mutex_unlock(&mutex_rec
);
672 g_message("thread_rec_frame:: 2");
676 * Repeat if cross correlation; x_corr = TRUE
678 if (gpiv_par
.x_corr
) {
679 if (dc1394_single_capture(cam_var
.handle
, &cam_var
.capture
[0])
681 dc1394_release_camera(cam_var
.handle
, &cam_var
.capture
[0]);
682 raw1394_destroy_handle(cam_var
.handle
);
683 gtk_warning("unable to capture a frame");
687 pthread_mutex_lock(&mutex_rec
);
688 memcpy( frameB
[0], (const char *) cam_var
.capture
[0].capture_buffer
,
689 sizeof(char) * cam_var
.capture
[0].frame_width
*
690 cam_var
.capture
[0].frame_height
);
691 pthread_mutex_unlock(&mutex_rec
);
696 /* gpiv_free_ucmatrix(frameA, 0, cam_var.capture[0].frame_height - 1, */
697 /* 0, cam_var.capture[0].frame_width - 1); */
699 g_warning("thread_rec_frame:: 3/3");
707 thread_rec_frame_serie(ImgFrame img_frame
[GPIV_NIMG_MAX
]
709 /*-----------------------------------------------------------------------------
714 /* g_message("rec_frame_series:: 0 with id = %d", (int) pthread_self ()); */
715 for (ibuf
= 0; ibuf
< dac_par
.ttime
.cycles
; ibuf
++) {
716 if (cancel_process
) break;
717 rec_frame(&img_frame
[ibuf
]);
719 /* g_message("rec_frame_series:: 1/1"); */
725 rec_frame(ImgFrame
*img_frame
727 /*-----------------------------------------------------------------------------
733 /* g_message("rec_frame:: 0"); */
734 if (dc1394_single_capture(cam_var
.handle
, &cam_var
.capture
[0])
736 dc1394_release_camera(cam_var
.handle
, &cam_var
.capture
[0]);
737 raw1394_destroy_handle(cam_var
.handle
);
738 g_warning("unable to capture a frame");
743 * Copy buffer content to tmp buffer array
745 memcpy( img_frame
->A
[0],
746 (const char *) cam_var
.capture
[0].capture_buffer
,
747 sizeof(char) * cam_var
.capture
[0].frame_width
*
748 cam_var
.capture
[0].frame_height
);
750 if (gpiv_par
.x_corr
) {
752 * capture second frame
754 if (dc1394_single_capture(cam_var
.handle
, &cam_var
.capture
[0])
756 dc1394_release_camera(cam_var
.handle
, &cam_var
.capture
[0]);
757 raw1394_destroy_handle(cam_var
.handle
);
758 g_warning("unable to capture a frame");
762 memcpy( img_frame
->B
[0],
763 (const char *) cam_var
.capture
[0].capture_buffer
,
764 sizeof(char) * cam_var
.capture
[0].frame_width
*
765 cam_var
.capture
[0].frame_height
);
768 /* g_message("rec_frame:: 3/3"); */
774 add_buffer(GpivConsole
*gpiv
,
777 unsigned char **frameA
,
778 unsigned char **frameB
780 /*-----------------------------------------------------------------------------
783 gchar cbuf
[4], cdate
[GPIV_MAX_CHARS
], ctime
[GPIV_MAX_CHARS
];
784 GDate
*date
= g_date_new ();
785 GTimeVal
*my_gtime
= NULL
;
789 * use numbers or timing to concanate after buffer names
793 my_time
= time(&my_time
);
794 my_ltime
= localtime(&my_time
);
795 g_snprintf(ctime
, sizeof(gint
) * 3 + 2,
802 g_date_set_time(date
, time(NULL
));
803 my_gtime
= g_malloc(sizeof(GTimeVal
));
804 g_get_current_time(my_gtime
);
805 g_snprintf(cdate
, sizeof(gint
) * 3 + 2,
812 g_snprintf(cbuf
, 4, "%d", ibuf
);
815 if (gpiv_var
.fname_date
816 && gpiv_var
.fname_time
) {
817 fname_base
= g_strdup(g_strconcat(gpiv_var
.fn_last
[0],
822 } else if (gpiv_var
.fname_date
) {
823 fname_base
= g_strdup(g_strconcat(gpiv_var
.fn_last
[0],
827 } else if (gpiv_var
.fname_time
) {
828 fname_base
= g_strdup(g_strconcat(gpiv_var
.fn_last
[0],
833 fname_base
= g_strdup(g_strconcat(gpiv_var
.fn_last
[0],
838 load_dac_buffer(gpiv
, &cam_var
, FALSE
, fname_base
, ibuf
, frameA
, frameB
,
840 /* exist_buf = TRUE; */
852 renew_buffer(GpivConsole
*gpiv
,
855 unsigned char **frameA
,
856 unsigned char **frameB
858 /*-----------------------------------------------------------------------------
859 * updates image of buffer
863 * Open buffer 0 if not exist
866 if (display
[ibuf
] == NULL
) {
867 add_buffer(gpiv
, fname_base
, ibuf
, frameA
, frameB
);
869 display_act
= display
[ibuf
];
871 recreate_img(display_act
, frameA
, frameB
);
872 if (display_act
->display_img1
) {
873 show_img1(display_act
);
875 hide_img1(display_act
);
878 if (image_par
.x_corr
) {
879 if (display_act
->display_img2
) {
880 show_img2(display_act
);
882 hide_img2(display_act
);
894 recreate_img(Display
* disp
,
895 unsigned char **frameA
,
896 unsigned char **frameB
898 /* ----------------------------------------------------------------------------
899 * Re-creates image in gnome canvas; without memallocating of rgbbuf_img1 and
901 * row stride; each row is a 4-byte buffer array
905 GpivImagePar image_par
= disp
->img
.image_par
;
907 /* guchar *pos2 = NULL; */
909 GdkPixbuf
*pixbuf1
= NULL
;
910 /* GdkPixbuf *pixbuf2 = NULL; */
914 assert (disp
!= NULL
);
915 assert (disp
->img
.img1
!= NULL
);
916 assert (disp
->img
.rgbbuf_img1
!= NULL
);
917 if(image_par
.x_corr
) {
918 assert (disp
->img
.img2
!= NULL
);
919 assert (disp
->img
.rgbbuf_img2
!= NULL
);
921 assert (disp
->img
.exist_img
);
924 fact
= fact
<< (image_par
.depth
- depth
);
925 disp
->img
.rgb_img_width
= gpiv_par
.img_width
* 3;
926 while ((disp
->img
.rgb_img_width
) % 4 != 0) {
927 disp
->img
.rgb_img_width
++;
930 pixbuf1
= gdk_pixbuf_new_from_data(disp
->img
.rgbbuf_img1
,
932 FALSE
, /* gboolean has_alpha */
933 depth
, /* image_par.depth */
936 disp
->img
.rgb_img_width
, /* rowstride */
942 pos1
= disp
->img
.rgbbuf_img1
;
943 for (i
= 0; i
< gpiv_par
.img_height
; i
++) {
944 for (j
= 0; j
< gpiv_par
.img_width
; j
++) {
945 *pos1
++ = (guchar
) (frameA
[i
][j
] / fact
);
946 *pos1
++ = (guchar
) (frameA
[i
][j
] / fact
);
947 *pos1
++ = (guchar
) (frameA
[i
][j
] / fact
);
952 gnome_canvas_item_set(GNOME_CANVAS_ITEM (disp
->img
.gci_img1
),
955 /* gnome_canvas_item_raise_to_top (GNOME_CANVAS_ITEM (disp->img.gci_img1)); */
956 /* gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (disp->img.gci_img1)); */
958 /* gtk_widget_pop_visual(); */
959 /* gtk_widget_pop_colormap(); */
962 gdk_pixbuf_unref (pixbuf1
);
966 /* if(image_par.x_corr) { */
969 /* disp->img.rgbbuf_img2 = g_malloc(disp->img.rgb_img_width * 3 * */
970 /* gpiv_par.img_height); */
972 /* pixbuf2 = gdk_pixbuf_new_from_data(disp->img.rgbbuf_img2, */
973 /* GDK_COLORSPACE_RGB, */
976 /* gpiv_par.img_width, */
977 /* gpiv_par.img_height, */
978 /* disp->img.rgb_img_width, */
982 /* if (disp->img.gci_img2 != NULL) { */
983 /* destroy_img(disp); */
986 /* disp->img.gci_img2 = */
987 /* gnome_canvas_item_new( gnome_canvas_root( GNOME_CANVAS */
988 /* (disp->canvas)), */
989 /* gnome_canvas_pixbuf_get_type (), */
990 /* "pixbuf", pixbuf2, */
994 /* pos2 = disp->img.rgbbuf_img2; */
995 /* for (i = 0; i < gpiv_par.img_height; i++) { */
996 /* for (j = 0; j < gpiv_par.img_width; j++) { */
997 /* *pos2++ = (guchar) (frameB[i][j] / fact); */
998 /* *pos2++ = (guchar) (frameB[i][j] / fact); */
999 /* *pos2++ = (guchar) (frameB[i][j] / fact); */
1003 /* gdk_pixbuf_unref (pixbuf2); */
1006 disp
->img
.gci_img2
= disp
->img
.gci_img2
;
1016 /*-----------------------------------------------------------------------------
1019 cancel_process
= TRUE
;
1020 /* if (dc1394_stop_iso_transmission(cam_var.handle, cam_var.capture[0].node) != DC1394_SUCCESS */
1021 /* != DC1394_SUCCESS) */
1023 /* gtk_warning("couldn't stop the camera?\n"); */
1026 /* pthread_exit(NULL); */
1027 /* dc1394_release_camera(cam_var.handle, &cam_var.capture[0]); */
1028 /* raw1394_destroy_handle(cam_var.handle); */
1034 * Callback functions
1038 on_entry_dac_fname(GtkSpinButton
*widget
,
1041 /*-----------------------------------------------------------------------------
1045 Dac
* dac
= gtk_object_get_data(GTK_OBJECT(widget
), "dac");
1047 push_list_lastfnames(gtk_entry_get_text(GTK_ENTRY(dac
->entry_fname
)));
1048 dac
->combo_fname_items
= NULL
;
1049 for (i
= 0; i
< gpiv_var
.number_fnames_last
; i
++) {
1050 dac
->combo_fname_items
= g_list_append (dac
->combo_fname_items
,
1051 gpiv_var
.fn_last
[i
]);
1053 gtk_combo_set_popdown_strings (GTK_COMBO (dac
->combo_fname
),
1054 dac
->combo_fname_items
);
1055 g_list_free (dac
->combo_fname_items
);
1059 * dac_par.fname_logic = TRUE;
1065 on_checkbutton_fname_date_enter(GtkWidget
*widget
,
1068 /* ----------------------------------------------------------------------------
1071 GpivConsole
* gpiv
= gtk_object_get_data(GTK_OBJECT(widget
), "gpiv");
1072 gchar
*msg
= _("Extends the name with current date");
1073 gnome_appbar_set_status(GNOME_APPBAR(gpiv
->appbar
), msg
);
1079 on_checkbutton_fname_date(GtkWidget
*widget
,
1082 /* ----------------------------------------------------------------------------
1085 if (GTK_TOGGLE_BUTTON(widget
)->active
) {
1086 gpiv_var
.fname_date
= TRUE
;
1088 gpiv_var
.fname_date
= FALSE
;
1090 gnome_config_set_bool("fname_date", gpiv_var
.fname_date
);
1091 gnome_config_sync();
1097 on_checkbutton_fname_time_enter(GtkWidget
*widget
,
1100 /* ----------------------------------------------------------------------------
1103 GpivConsole
* gpiv
= gtk_object_get_data(GTK_OBJECT(widget
), "gpiv");
1104 gchar
*msg
= _("Extends the name with current time");
1105 gnome_appbar_set_status(GNOME_APPBAR(gpiv
->appbar
), msg
);
1111 on_checkbutton_fname_time(GtkWidget
*widget
,
1114 /* ----------------------------------------------------------------------------
1117 if (GTK_TOGGLE_BUTTON(widget
)->active
) {
1118 gpiv_var
.fname_time
= TRUE
;
1120 gpiv_var
.fname_time
= FALSE
;
1122 gnome_config_set_bool("fname_time", gpiv_var
.fname_time
);
1123 gnome_config_sync();
1129 on_radiobutton_dac_mouse_1_enter(GtkWidget
* widget
,
1132 /*-----------------------------------------------------------------------------
1135 GpivConsole
*gpiv
= gtk_object_get_data(GTK_OBJECT(widget
), "gpiv");
1136 gchar
*msg
= _("indefinite periodic recording");
1137 gnome_appbar_set_status(GNOME_APPBAR(gpiv
->appbar
), msg
);
1143 on_radiobutton_dac_mouse_2_enter(GtkWidget
* widget
,
1146 /*-----------------------------------------------------------------------------
1149 GpivConsole
*gpiv
= gtk_object_get_data(GTK_OBJECT(widget
), "gpiv");
1150 gchar
*msg
= _("with pre-defined number of images");
1151 gnome_appbar_set_status(GNOME_APPBAR(gpiv
->appbar
), msg
);
1157 on_radiobutton_dac_mouse_3_enter(GtkWidget
* widget
,
1160 /*-----------------------------------------------------------------------------
1163 GpivConsole
*gpiv
= gtk_object_get_data(GTK_OBJECT(widget
), "gpiv");
1164 gchar
*msg
= _("one shot with interrupd");
1165 gnome_appbar_set_status(GNOME_APPBAR(gpiv
->appbar
), msg
);
1171 on_radiobutton_dac_mouse_4_enter(GtkWidget
* widget
,
1174 /*-----------------------------------------------------------------------------
1177 GpivConsole
*gpiv
= gtk_object_get_data(GTK_OBJECT(widget
), "gpiv");
1178 gchar
*msg
= _("periodic with interrupt");
1179 gnome_appbar_set_status(GNOME_APPBAR(gpiv
->appbar
), msg
);
1185 on_radiobutton_dac_mouse_5_enter(GtkWidget
* widget
,
1188 /*-----------------------------------------------------------------------------
1191 GpivConsole
*gpiv
= gtk_object_get_data(GTK_OBJECT(widget
), "gpiv");
1192 gchar
*msg
= _("with incremental separation time dt");
1193 gnome_appbar_set_status(GNOME_APPBAR(gpiv
->appbar
), msg
);
1199 on_radiobutton_dac_mouse_6_enter(GtkWidget
* widget
,
1202 /*-----------------------------------------------------------------------------
1205 GpivConsole
*gpiv
= gtk_object_get_data(GTK_OBJECT(widget
), "gpiv");
1206 gchar
*msg
= _("double exposure");
1207 gnome_appbar_set_status(GNOME_APPBAR(gpiv
->appbar
), msg
);
1213 on_radiobutton_dac_mouse(GtkWidget
* widget
,
1216 /*-----------------------------------------------------------------------------
1219 gint mouse_select
= atoi(gtk_object_get_data(GTK_OBJECT(widget
),
1221 dac_par
.ttime
.mode
= mouse_select
;
1222 /* g_warning("on_radiobutton_dac_mouse:: ttime.mode = %d", */
1223 /* dac_par.ttime.mode); */
1225 if (mouse_select
== GPIV_TIMER_MODE__PERIODIC
) {}
1226 if (mouse_select
== GPIV_TIMER_MODE__DURATION
) {}
1227 if (mouse_select
== GPIV_TIMER_MODE__ONE_SHOT_IRQ
) {}
1228 if (mouse_select
== GPIV_TIMER_MODE__TRIGGER_IRQ
) {}
1229 if (mouse_select
== GPIV_TIMER_MODE__INCREMENT
) {}
1230 if (mouse_select
== GPIV_TIMER_MODE__DOUBLE
) {}
1237 on_spinbutton_dac_trigger_dt(GtkSpinButton
* widget
,
1240 /*-----------------------------------------------------------------------------
1243 gfloat val
= gtk_spin_button_get_value_as_float(widget
);
1244 dac_par
.ttime
.dt
= (RTIME
) (GPIV_MILI2NANO
* val
);
1250 on_spinbutton_dac_trigger_incrdt(GtkSpinButton
* widget
,
1253 /*-----------------------------------------------------------------------------
1256 gfloat val
= gtk_spin_button_get_value_as_float(widget
);
1257 dac_par
.ttime
.increment
= (RTIME
) (GPIV_MILI2NANO
* val
);
1263 on_spinbutton_dac_trigger_cap(GtkSpinButton
* widget
,
1266 /*-----------------------------------------------------------------------------
1269 gfloat val
= gtk_spin_button_get_value_as_float(widget
);
1270 dac_par
.ttime
.cam_acq_period
= (RTIME
) (GPIV_MILI2NANO
* val
);
1276 on_spinbutton_dac_trigger_nf(GtkSpinButton
* widget
,
1279 /*-----------------------------------------------------------------------------
1282 dac_par
.ttime
.cycles
= gtk_spin_button_get_value_as_int(widget
);
1288 on_button_dac_triggerstart_enter(GtkWidget
*widget
,
1291 /*-----------------------------------------------------------------------------
1294 GpivConsole
* gpiv
= gtk_object_get_data(GTK_OBJECT(widget
), "gpiv");
1295 gchar
*msg
= _("Uploads and Starts timings to kernel module");
1296 gnome_appbar_set_status(GNOME_APPBAR(gpiv
->appbar
), msg
);
1302 on_button_dac_triggerstart(GtkWidget
* widget
,
1305 /* ----------------------------------------------------------------------------
1309 /* gtk_warning(msg); */
1310 exec_trigger_start();
1316 on_button_dac_triggerstop_enter(GtkWidget
*widget
,
1319 /*-----------------------------------------------------------------------------
1322 GpivConsole
* gpiv
= gtk_object_get_data(GTK_OBJECT(widget
), "gpiv");
1323 gchar
*msg
= _("Stops timings");
1324 gnome_appbar_set_status(GNOME_APPBAR(gpiv
->appbar
), msg
);
1330 on_button_dac_triggerstop(GtkWidget
* widget
,
1333 /* ----------------------------------------------------------------------------
1337 /* gtk_warning(msg); */
1338 exec_trigger_stop();
1344 on_menu_camera_select(GtkWidget
*widget
,
1346 /* ----------------------------------------------------------------------------
1354 on_menu_format(GtkWidget
*widget
,
1356 /* ----------------------------------------------------------------------------
1359 GpivConsole
* gpiv
= gtk_object_get_data(GTK_OBJECT(widget
), "gpiv");
1360 gint mode
= (int) data
;
1363 /* change_mode_and_format(format, FORMAT_VGA_NONCOMPRESSED); */
1364 /* IsoFlowCheck(state); */
1366 g_message("on_menu_format:: ");
1367 if (!dc1394_get_iso_status(cam_var
.camera
[0].handle
, cam_var
.camera
[0].id
,
1368 &cam_var
.misc_info
[0].is_iso_on
)) {
1369 g_warning("Could not get ISO status");
1371 if (cam_var
.misc_info
[0].is_iso_on
> 0) {
1372 cancel_process
= TRUE
;
1375 was_iso_on
= cam_var
.misc_info
[0].is_iso_on
;
1376 /* g_message("on_menu_format:: is_iso_on = %d", was_iso_on); */
1379 if (mode
>= MODE_FORMAT0_MIN
&& mode
<= MODE_FORMAT0_MAX
) {
1380 format
= FORMAT_VGA_NONCOMPRESSED
;
1382 /* g_message("on_menu_format:: mode[%d] = %s", */
1383 /* mode, format0_desc[mode - MODE_FORMAT0_MIN]); */
1385 /* g_message(":n_menu_format: format[%d] = %s", */
1387 /* format_desc[format - FORMAT_MIN]); */
1388 } else if (mode
>= MODE_FORMAT1_MIN
&& mode
<= MODE_FORMAT1_MAX
) {
1389 format
= FORMAT_SVGA_NONCOMPRESSED_1
;
1390 } else if (mode
>= MODE_FORMAT2_MIN
&& mode
<= MODE_FORMAT2_MAX
) {
1391 format
= FORMAT_SVGA_NONCOMPRESSED_2
;
1392 } else if (mode
>= MODE_FORMAT6_MIN
&& mode
<= MODE_FORMAT6_MAX
) {
1393 format
= FORMAT_STILL_IMAGE
;
1394 } else if (mode
>= MODE_FORMAT7_MIN
&& mode
<= MODE_FORMAT7_MAX
) {
1395 format
= FORMAT_SCALABLE_IMAGE_SIZE
;
1396 /* } else if (mode >= COLOR_FORMAT7_MIN && mode <= COLOR_FORMAT7_MAX) { */
1397 /* format = FORMAT_SCALABLE_IMAGE_SIZE; */
1399 gtk_warning("on_menu_format: non valid format");
1402 if (!dc1394_set_video_format(cam_var
.camera
[0].handle
,
1403 cam_var
.camera
[0].id
,
1405 g_warning("on_menu_format:: Could not set video format");
1407 cam_var
.misc_info
[0].format
= format
;
1410 if (!dc1394_set_video_mode(cam_var
.camera
[0].handle
,
1411 cam_var
.camera
[0].id
,
1413 g_warning("on_menu_format:: Could not set video format");
1415 cam_var
.misc_info
[0].mode
= mode
;
1420 if (was_iso_on
> 0) {
1421 exec_rec_start(gpiv
);
1424 /* BuildFpsMenu(); */
1427 /* UpdateTriggerFrame(); */
1429 /* IsoFlowResume(state); */
1432 /* MODE_320x240_YUV422, */
1433 /* MODE_640x480_YUV411, */
1434 /* MODE_640x480_YUV422, */
1435 /* MODE_640x480_RGB, */
1436 /* MODE_640x480_MONO, */
1437 /* MODE_640x480_MONO16 */
1443 on_menu_fps(GtkWidget
*widget
,
1445 /* ----------------------------------------------------------------------------
1448 cam_var
.misc_info
[0].framerate
= (int) data
/* - FRAMERATE_MIN */;
1449 /* cam_var.misc_info[0].framerat */
1450 g_warning("on_menu_fps:: fps = %d", cam_var
.misc_info
[0].framerate
);
1455 * BUGFIX: include in trigger callbacks?
1458 on_trigger_polarity_toggled (GtkToggleButton
*togglebutton
,
1461 if (!dc1394_set_trigger_polarity(cam_var
.camera
[0].handle
,
1462 cam_var
.camera
[0].id
,
1463 togglebutton
->active
)) {
1464 gtk_warning("Cannot set trigger polarity");
1466 cam_var
.feature_set
[0].feature
[FEATURE_TRIGGER
-FEATURE_MIN
].
1467 trigger_polarity
= (int) togglebutton
->active
;
1474 on_trigger_external_toggled (GtkToggleButton
*togglebutton
,
1477 if (!dc1394_feature_on_off(cam_var
.camera
[0].handle
,
1478 cam_var
.camera
[0].id
,
1480 togglebutton
->active
)) {
1481 gtk_warning("Could not set external trigger source");
1483 cam_var
.feature_set
[0].feature
[FEATURE_TRIGGER
- FEATURE_MIN
].is_on
=
1484 togglebutton
->active
;
1486 /* UpdateTriggerFrame(); */
1492 on_trigger_mode_activate(GtkWidget
*widget
,
1494 /* ----------------------------------------------------------------------------
1497 if (!dc1394_set_trigger_mode(cam_var
.camera
[0].handle
, cam_var
.camera
[0].id
,
1499 gtk_warning("Could not set trigger mode");
1501 cam_var
.feature_set
[0].feature
[FEATURE_TRIGGER
-FEATURE_MIN
].
1502 trigger_mode
= (int) user_data
;
1505 /* UpdateTriggerFrame(); */
1511 /* on_trigger_value_changed (GtkAdjustment *adj, */
1512 /* gpointer user_data) */
1514 /* if (!dc1394_set_feature_value(cam_var.camera[0].handle, cam_var.camera[0].id, */
1515 /* FEATURE_TRIGGER, adj->value)) */
1516 /* gtk_warning("Could not set external trigger count"); */
1518 /* cam_var.feature_set[0].feature[FEATURE_TRIGGER-FEATURE_MIN].value = */
1524 on_checkbutton_camera_trigger_enter(GtkWidget
*widget
,
1526 /* ----------------------------------------------------------------------------
1529 GpivConsole
* gpiv
= gtk_object_get_data(GTK_OBJECT(widget
), "gpiv");
1530 gchar
*msg
= _("Enables triggering of the camera");
1531 gnome_appbar_set_status(GNOME_APPBAR(gpiv
->appbar
), msg
);
1537 on_checkbutton_camera_trigger(GtkWidget
*widget
,
1539 /* ----------------------------------------------------------------------------
1542 if (GTK_TOGGLE_BUTTON(widget
)->active
) {
1543 gpiv_par
.trigger_cam
= TRUE
;
1545 gpiv_par
.trigger_cam
= FALSE
;
1552 on_man_auto_menu(GtkWidget
*widget
,
1554 /* ----------------------------------------------------------------------------
1557 GtkWidget
*scale
= gtk_object_get_data(GTK_OBJECT(widget
), "scale");
1558 int feature
= (int) data
;
1564 var_type
= atoi(gtk_object_get_data(GTK_OBJECT(widget
), "var_type"));
1565 if (!dc1394_auto_on_off(cam_var
.camera
[0].handle
,
1566 cam_var
.camera
[0].id
,
1567 feature
, var_type
)) {
1568 gtk_warning("on_man_auto_menu: Could not set auto / manual");
1571 if (var_type
== MAN
) {
1572 gtk_widget_set_sensitive (GTK_WIDGET(scale
), TRUE
);
1573 } else if (var_type
== AUTO
) {
1574 gtk_widget_set_sensitive (GTK_WIDGET(scale
), FALSE
);
1582 on_scale_changed(GtkAdjustment
*adj
,
1584 /* ----------------------------------------------------------------------------
1587 switch((int)user_data
) {
1588 case FEATURE_TEMPERATURE
:
1589 if (!dc1394_set_temperature(cam_var
.camera
[0].handle
,
1590 cam_var
.camera
[0].id
,
1592 gtk_warning("on_scale_changed:Could not set temperature");
1594 cam_var
.feature_set
[0].feature
[FEATURE_TEMPERATURE
-FEATURE_MIN
].
1599 /* g_message("on_scale_changed:: feature = %d value = %f", */
1600 /* (gint) user_data, adj->value); */
1601 if (!dc1394_set_feature_value(cam_var
.camera
[0].handle
,
1602 cam_var
.camera
[0].id
,
1605 gtk_warning("on_scale_changed: Could not set feature");
1607 cam_var
.feature_set
[0].feature
[(gint
) user_data
- FEATURE_MIN
].
1618 on_button_dac_recstart_enter(GtkWidget
*widget
,
1621 /*-----------------------------------------------------------------------------
1624 GpivConsole
* gpiv
= gtk_object_get_data(GTK_OBJECT(widget
), "gpiv");
1625 gchar
*msg
= _("Records PIV images");
1626 gnome_appbar_set_status(GNOME_APPBAR(gpiv
->appbar
), msg
);
1632 on_button_dac_recstart(GtkWidget
* widget
,
1635 /* ----------------------------------------------------------------------------
1636 * The actual calculation of particle image displacements
1639 GpivConsole
* gpiv
= gtk_object_get_data(GTK_OBJECT(widget
), "gpiv");
1641 /*in exec_rec_start: exec_trigger_start(); */
1642 exec_rec_start(gpiv
);
1649 on_button_dac_recstop_enter(GtkWidget
*widget
,
1652 /*-----------------------------------------------------------------------------
1655 GpivConsole
* gpiv
= gtk_object_get_data(GTK_OBJECT(widget
), "gpiv");
1656 gchar
*msg
= _("Stops recording PIV images");
1657 gnome_appbar_set_status(GNOME_APPBAR(gpiv
->appbar
), msg
);
1663 on_button_dac_recstop(GtkWidget
* widget
,
1666 /* ----------------------------------------------------------------------------
1667 * The actual calculation of particle image displacements
1670 exec_trigger_stop();
1676 #endif /* DISABLE_DAC */