added gpiv_logo.xpm
[gpiv.git] / src / display_image.c
blobdcec661b55fe693639bdc56e010292712e5ececa
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) 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)
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 ----------------------------------------------------------------------*/
28 #include "gpiv_gui.h"
29 #include "display_image.h"
32 void
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;
43 gint i, j;
44 /* GdkPixbuf *pixbuf1 = NULL, *pixbuf2 = NULL; */
45 GdkPixbuf *px;
46 guint16 fact = 1;
47 gint depth = 8;
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,
71 FALSE,
72 depth,
73 disp->img->image->header->ncolumns,
74 disp->img->image->header->nrows);
76 gdk_pixbuf_unref (px);
78 #ifdef DEBUG
79 g_message("create_img:: rowstride = %d, rgb_img_width = %d",
80 gdk_pixbuf_get_rowstride(px),
81 disp->img->rgb_img_width);
82 #endif
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,
88 GDK_COLORSPACE_RGB,
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 */
94 NULL,
95 NULL);
97 if (disp->img->gci_img1 != NULL) {
98 destroy_img(disp);
101 disp->img->gci_img1 =
102 gnome_canvas_item_new( gnome_canvas_root( GNOME_CANVAS
103 (disp->canvas)),
104 gnome_canvas_pixbuf_get_type (),
105 "pixbuf", disp->img->pixbuf1,
106 NULL);
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) {
123 pos2 = NULL;
124 /* NEW */
125 disp->img->rgbbuf_img2 = g_malloc(gdk_pixbuf_get_rowstride(px) *
126 disp->img->image->header->nrows);
127 /* OLD */
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,
132 GDK_COLORSPACE_RGB,
133 FALSE,
134 depth,
135 disp->img->image->header->ncolumns,
136 disp->img->image->header->nrows,
137 disp->img->rgb_img_width,
138 NULL,
139 NULL);
140 if (disp->img->gci_img2 != NULL) {
141 destroy_img(disp);
144 disp->img->gci_img2 =
145 gnome_canvas_item_new( gnome_canvas_root( GNOME_CANVAS
146 (disp->canvas)),
147 gnome_canvas_pixbuf_get_type (),
148 "pixbuf", disp->img->pixbuf2,
149 NULL);
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);
163 } else {
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"); */
177 void
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;
193 void
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;
209 void
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;
224 void
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;
240 void
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;
261 GnomeCanvasItem *
262 create_background (Display *disp
264 /* ----------------------------------------------------------------------------
265 * Displays backgroundcolor
268 GnomeCanvasItem *bg = NULL;
269 gchar *color = NULL;
272 if (gpiv_par->display__backgrnd == SHOW_BG_DARKBLUE) {
273 color = "darkblue";
274 } else if (gpiv_par->display__backgrnd == SHOW_BG_BLACK) {
275 color = "black";
278 bg =
279 gnome_canvas_item_new(gnome_canvas_root(GNOME_CANVAS(disp->canvas)),
280 gnome_canvas_rect_get_type(),
281 "x1", (double) 0,
282 "y1", (double) 0,
283 "x2", (double) disp->img->image->header->ncolumns,
284 "y2", (double) disp->img->image->header->nrows,
285 "fill_color", color,
286 "width_units", 1.0,
287 NULL);
290 return bg;
295 void
296 destroy_background (GnomeCanvasItem *gci
298 /*-----------------------------------------------------------------------------
301 assert (gci != NULL);
302 gtk_object_destroy(GTK_OBJECT
303 (gci));
304 gci = NULL;