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) 2006 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)
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 #include "display_image.h"
33 create_img (Display
*disp
35 /* ----------------------------------------------------------------------------
36 * Creates pixbuf image in gnome canvas
37 * row stride; each row is a 4-byte buffer array
41 /* GpivImagePar image_par = disp->img->image->header; */
42 guchar
*pos1
= NULL
, *pos2
= NULL
;
44 /* GdkPixbuf *pixbuf1 = NULL, *pixbuf2 = NULL; */
49 assert (disp
!= NULL
);
50 assert (disp
->img
->image
->frame1
[0] != NULL
);
51 assert (disp
->img
->exist_img
);
53 disp
->img
->pixbuf1
= NULL
;
54 disp
->img
->pixbuf2
= NULL
;
56 fact
= fact
<< (disp
->img
->image
->header
->depth
- depth
);
57 /* g_message ("create_img:: fact = %d", fact); */
60 * BUGFIX: this works for rowstride
62 disp
->img
->rgb_img_width
= disp
->img
->image
->header
->ncolumns
* 3;
63 while ((disp
->img
->rgb_img_width
) % 4 != 0) {
64 disp
->img
->rgb_img_width
++;
68 * this is a more formal way to do it
70 px
= gdk_pixbuf_new (GDK_COLORSPACE_RGB
,
73 disp
->img
->image
->header
->ncolumns
,
74 disp
->img
->image
->header
->nrows
);
76 gdk_pixbuf_unref (px
);
79 g_message("create_img:: rowstride = %d, rgb_img_width = %d",
80 gdk_pixbuf_get_rowstride(px
),
81 disp
->img
->rgb_img_width
);
84 disp
->img
->rgbbuf_img1
= g_malloc (gdk_pixbuf_get_rowstride(px
) *
85 disp
->img
->image
->header
->nrows
);
87 disp
->img
->pixbuf1
= gdk_pixbuf_new_from_data (disp
->img
->rgbbuf_img1
,
89 FALSE
, /* gboolean has_alpha */
90 depth
, /* image_par->depth */
91 disp
->img
->image
->header
->ncolumns
,
92 disp
->img
->image
->header
->nrows
,
93 disp
->img
->rgb_img_width
, /* rowstride */
97 if (disp
->img
->gci_img1
!= NULL
) {
101 disp
->img
->gci_img1
=
102 gnome_canvas_item_new( gnome_canvas_root( GNOME_CANVAS
104 gnome_canvas_pixbuf_get_type (),
105 "pixbuf", disp
->img
->pixbuf1
,
108 pos1
= disp
->img
->rgbbuf_img1
;
111 for (i
= 0; i
< disp
->img
->image
->header
->nrows
; i
++) {
112 for (j
= 0; j
< disp
->img
->image
->header
->ncolumns
; j
++) {
113 *pos1
++ = (guchar
) (disp
->img
->image
->frame1
[i
][j
] / fact
);
114 *pos1
++ = (guchar
) (disp
->img
->image
->frame1
[i
][j
] / fact
);
115 *pos1
++ = (guchar
) (disp
->img
->image
->frame1
[i
][j
] / fact
);
119 gdk_pixbuf_ref (disp
->img
->pixbuf1
);
122 if (disp
->img
->image
->header
->x_corr
) {
125 disp
->img
->rgbbuf_img2
= g_malloc(gdk_pixbuf_get_rowstride(px
) *
126 disp
->img
->image
->header
->nrows
);
128 /* disp->img->rgbbuf_img2 = g_malloc(disp->img->rgb_img_width * */
129 /* disp->img->image->header->nrows); */
131 disp
->img
->pixbuf2
= gdk_pixbuf_new_from_data (disp
->img
->rgbbuf_img2
,
135 disp
->img
->image
->header
->ncolumns
,
136 disp
->img
->image
->header
->nrows
,
137 disp
->img
->rgb_img_width
,
140 if (disp
->img
->gci_img2
!= NULL
) {
144 disp
->img
->gci_img2
=
145 gnome_canvas_item_new( gnome_canvas_root( GNOME_CANVAS
147 gnome_canvas_pixbuf_get_type (),
148 "pixbuf", disp
->img
->pixbuf2
,
151 pos2
= disp
->img
->rgbbuf_img2
;
152 for (i
= 0; i
< disp
->img
->image
->header
->nrows
; i
++) {
153 for (j
= 0; j
< disp
->img
->image
->header
->ncolumns
; j
++) {
154 *pos2
++ = (guchar
) (disp
->img
->image
->frame2
[i
][j
] / fact
);
155 *pos2
++ = (guchar
) (disp
->img
->image
->frame2
[i
][j
] / fact
);
156 *pos2
++ = (guchar
) (disp
->img
->image
->frame2
[i
][j
] / fact
);
160 /* gdk_pixbuf_unref (pixbuf2); */
161 gdk_pixbuf_ref (disp
->img
->pixbuf2
);
164 disp
->img
->gci_img2
= disp
->img
->gci_img1
;
167 /* g_message(":: freeing rgbbuf_img1/2"); */
168 /* g_free(disp->img->rgbbuf_img1); */
169 /* disp->img->rgbbuf_img1 = NULL; */
170 /* g_free(disp->img->rgbbuf_img2); */
171 /* disp->img->rgbbuf_img2 = NULL; */
172 /* g_message(":: rgbbuf_img1/2 freed SUCCESSFULL"); */
178 hide_img1 (Display
*disp
180 /*-----------------------------------------------------------------------------
183 assert (disp
!= NULL
);
185 if (disp
->img
->exist_img
&& disp
->img
->gci_img1
!= NULL
) {
186 gnome_canvas_item_hide (GNOME_CANVAS_ITEM (disp
->img
->gci_img1
));
187 disp
->display_backgrnd
= SHOW_BG_DARKBLUE
;
194 show_img1 (Display
*disp
196 /*-----------------------------------------------------------------------------
199 assert (disp
!= NULL
);
201 if (disp
->img
->exist_img
&& disp
->img
->gci_img1
!= NULL
) {
202 gnome_canvas_item_show (GNOME_CANVAS_ITEM (disp
->img
->gci_img1
));
203 disp
->display_backgrnd
= SHOW_BG_IMG1
;
210 hide_img2 (Display
*disp
212 /*-----------------------------------------------------------------------------
215 assert (disp
!= NULL
);
217 if (disp
->img
->exist_img
&& disp
->img
->gci_img2
!= NULL
) {
218 gnome_canvas_item_hide (GNOME_CANVAS_ITEM (disp
->img
->gci_img2
));
219 disp
->display_backgrnd
= SHOW_BG_DARKBLUE
;
225 show_img2 (Display
*disp
227 /*-----------------------------------------------------------------------------
230 assert (disp
!= NULL
);
232 if (disp
->img
->exist_img
&& disp
->img
->gci_img2
!= NULL
) {
233 gnome_canvas_item_show (GNOME_CANVAS_ITEM (disp
->img
->gci_img2
));
234 disp
->display_backgrnd
= SHOW_BG_IMG2
;
241 destroy_img (Display
*disp
243 /*-----------------------------------------------------------------------------
246 assert (disp
->img
->gci_img1
!= NULL
);
247 gtk_object_destroy(GTK_OBJECT
248 (disp
->img
->gci_img1
));
249 /* g_free(disp->img->gci_img1); */
250 disp
->img
->gci_img1
= NULL
;
252 if(display_act
->img
->image
->header
->x_corr
) {
253 gtk_object_destroy(GTK_OBJECT
254 (disp
->img
->gci_img2
));
255 disp
->img
->gci_img2
= NULL
;
262 create_background (Display
*disp
264 /* ----------------------------------------------------------------------------
265 * Displays backgroundcolor
268 GnomeCanvasItem
*bg
= NULL
;
272 if (gpiv_par
->display__backgrnd
== SHOW_BG_DARKBLUE
) {
274 } else if (gpiv_par
->display__backgrnd
== SHOW_BG_BLACK
) {
279 gnome_canvas_item_new(gnome_canvas_root(GNOME_CANVAS(disp
->canvas
)),
280 gnome_canvas_rect_get_type(),
283 "x2", (double) disp
->img
->image
->header
->ncolumns
,
284 "y2", (double) disp
->img
->image
->header
->nrows
,
296 destroy_background (GnomeCanvasItem
*gci
298 /*-----------------------------------------------------------------------------
301 assert (gci
!= NULL
);
302 gtk_object_destroy(GTK_OBJECT