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, 2007, 2008
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 ----------------------------------------------------------------------*/
30 #include "display_image.h"
34 create_img (Display
*disp
36 /* ----------------------------------------------------------------------------
37 * Creates pixbuf image in gnome canvas
38 * row stride; each row is a 4-byte buffer array
42 /* GpivImagePar image_par = disp->img->image->header; */
43 guchar
*pos1
= NULL
, *pos2
= NULL
;
45 /* GdkPixbuf *pixbuf1 = NULL, *pixbuf2 = NULL; */
50 assert (disp
!= NULL
);
51 assert (disp
->img
->image
->frame1
[0] != NULL
);
52 assert (disp
->img
->exist_img
);
54 disp
->img
->pixbuf1
= NULL
;
55 disp
->img
->pixbuf2
= NULL
;
57 fact
= fact
<< (disp
->img
->image
->header
->depth
- depth
);
58 /* g_message ("create_img:: fact = %d", fact); */
61 * BUGFIX: this works for rowstride
63 disp
->img
->rgb_img_width
= disp
->img
->image
->header
->ncolumns
* 3;
64 while ((disp
->img
->rgb_img_width
) % 4 != 0) {
65 disp
->img
->rgb_img_width
++;
69 * this is a more formal way to do it
71 px
= gdk_pixbuf_new (GDK_COLORSPACE_RGB
,
74 disp
->img
->image
->header
->ncolumns
,
75 disp
->img
->image
->header
->nrows
);
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_ref (disp
->img
->pixbuf2
);
163 disp
->img
->gci_img2
= disp
->img
->gci_img1
;
166 gdk_pixbuf_unref (px
);
172 hide_img1 (Display
*disp
174 /*-----------------------------------------------------------------------------
177 assert (disp
!= NULL
);
179 if (disp
->img
->exist_img
&& disp
->img
->gci_img1
!= NULL
) {
180 gnome_canvas_item_hide (GNOME_CANVAS_ITEM (disp
->img
->gci_img1
));
181 disp
->display_backgrnd
= SHOW_BG_DARKBLUE
;
188 show_img1 (Display
*disp
190 /*-----------------------------------------------------------------------------
193 assert (disp
!= NULL
);
195 if (disp
->img
->exist_img
&& disp
->img
->gci_img1
!= NULL
) {
196 gnome_canvas_item_show (GNOME_CANVAS_ITEM (disp
->img
->gci_img1
));
197 disp
->display_backgrnd
= SHOW_BG_IMG1
;
204 hide_img2 (Display
*disp
206 /*-----------------------------------------------------------------------------
209 assert (disp
!= NULL
);
211 if (disp
->img
->exist_img
&& disp
->img
->gci_img2
!= NULL
) {
212 gnome_canvas_item_hide (GNOME_CANVAS_ITEM (disp
->img
->gci_img2
));
213 disp
->display_backgrnd
= SHOW_BG_DARKBLUE
;
219 show_img2 (Display
*disp
221 /*-----------------------------------------------------------------------------
224 assert (disp
!= NULL
);
226 if (disp
->img
->exist_img
&& disp
->img
->gci_img2
!= NULL
) {
227 gnome_canvas_item_show (GNOME_CANVAS_ITEM (disp
->img
->gci_img2
));
228 disp
->display_backgrnd
= SHOW_BG_IMG2
;
235 destroy_img (Display
*disp
237 /*-----------------------------------------------------------------------------
240 assert (disp
->img
->gci_img1
!= NULL
);
241 gtk_object_destroy(GTK_OBJECT
242 (disp
->img
->gci_img1
));
243 /* g_free(disp->img->gci_img1); */
244 disp
->img
->gci_img1
= NULL
;
246 if(display_act
->img
->image
->header
->x_corr
) {
247 gtk_object_destroy(GTK_OBJECT
248 (disp
->img
->gci_img2
));
249 disp
->img
->gci_img2
= NULL
;
256 create_background (Display
*disp
258 /* ----------------------------------------------------------------------------
259 * Displays backgroundcolor
262 GnomeCanvasItem
*bg
= NULL
;
266 if (gpiv_par
->display__backgrnd
== SHOW_BG_DARKBLUE
) {
268 } else if (gpiv_par
->display__backgrnd
== SHOW_BG_BLACK
) {
273 gnome_canvas_item_new(gnome_canvas_root(GNOME_CANVAS(disp
->canvas
)),
274 gnome_canvas_rect_get_type(),
277 "x2", (double) disp
->img
->image
->header
->ncolumns
,
278 "y2", (double) disp
->img
->image
->header
->nrows
,
290 destroy_background (GnomeCanvasItem
*gci
292 /*-----------------------------------------------------------------------------
295 assert (gci
!= NULL
);
296 gtk_object_destroy(GTK_OBJECT