~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina6/tina-tools/tinatool/gphx/gdk2/gphxGdk_mask.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**********
  2  * 
  3  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  4  * University of Manchester, UK.  All rights reserved.
  5  * 
  6  * Redistribution and use in source and binary forms, with or without modification, 
  7  * are permitted provided that the following conditions are met:
  8  * 
  9  *   . Redistributions of source code must retain the above copyright notice, 
 10  *     this list of conditions and the following disclaimer.
 11  *    
 12  *   . Redistributions in binary form must reproduce the above copyright notice,
 13  *     this list of conditions and the following disclaimer in the documentation 
 14  *     and/or other materials provided with the distribution.
 15  * 
 16  *   . Neither the name of the University of Manchester nor the names of its
 17  *     contributors may be used to endorse or promote products derived from this 
 18  *     software without specific prior written permission.
 19  * 
 20  * 
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  *
 33  **********
 34  * 
 35  * Program :  TINA
 36  * File    :  $Source: /home/tina/cvs/tina-tools/tinatool/gphx/gdk2/gphxGdk_mask.c,v $
 37  * Date    :  $Date: 2007/02/15 01:55:50 $
 38  * Version :  $Revision: 1.2 $
 39  * CVS Id  :  $Id: gphxGdk_mask.c,v 1.2 2007/02/15 01:55:50 paul Exp $
 40  *
 41  * Author  :  giob@man.ac.uk, paul.bromiley@manchester.ac.uk
 42  *
 43  *********
 44 */
 45 /** 
 46  *  @file  gphxGdk_mask.c
 47  *  @brief Use a clip mask for plotting.
 48  *
 49  *  I've had some intermittent problems with this.  However, it now seems to work.
 50  *  Let me know if it doesn't.  
 51  *
 52  *  GAB 9 Jan 2004.  giob@man.ac.uk
 53  *
 54  *  Note: the functions in this file are duplicated for each graphics lib (x11, GDK, etc ...).
 55  *
 56  */
 57 
 58 
 59 #include "gphxGdk_mask.h"
 60 
 61 #if HAVE_CONFIG_H
 62   #include <config.h>
 63 #endif
 64 
 65 #include <gtk/gtk.h>
 66 #include <tinatool/gphx/gdk2/gphx_GdkDef.h>
 67 #include <tinatool/gphx/gdk2/gphxGdk_color.h>
 68 
 69 
 70 /**
 71  * @brief  Get a mask from the specified Tv_screen.  
 72  * @param  screen  Pointer to Tv_screen from which to take mask.
 73  * @param  lx      Screen x-co-ordinate of ROI top-left for mask definition.
 74  * @param  ly      Screen y-co-ordinate of ROI top-left for mask definition.
 75  * @param  ux      Screen x-co-ordinate of ROI bottom-right for mask definition.
 76  * @param  uy      Screen y-co-ordinate of ROI bottom-right for mask definition.
 77  * @return void *  Void pointer to GdkBitmap mask.
 78  */
 79 void   *tv_screen_mask_get(Tv_screen *screen, int lx, int ly, int ux, int uy)
 80 {
 81     Tv_mask *mask = ts_ralloc(Tv_mask);
 82 
 83     mask->lx = lx;
 84     mask->ly = ly;
 85     mask->ux = ux;
 86     mask->uy = uy;
 87 
 88     mask->bitmap = (GdkBitmap *) gdk_pixmap_new(NULL,
 89                                                 ux - lx, uy - ly,
 90                                                 1);
 91     mask->gc = gdk_gc_new(mask->bitmap);
 92     gdk_rgb_gc_set_background(mask->gc, (guint32) 0);
 93     gdk_rgb_gc_set_foreground(mask->gc, (guint32) 0);
 94     gdk_draw_rectangle(mask->bitmap, mask->gc, TRUE,
 95                        0, 0, 
 96                        ux - lx, uy - ly);
 97 
 98     return ((void *) mask);
 99 }
100 
101 /**
102  * @brief  Set clip mask for the given Tv_screen from the given Tv_mask.  
103  * @param  screen  Pointer to Tv_screen for which to set mask.
104  * @param  mask    Pointer to Tv_mask to be set.
105  */
106 void   tv_screen_mask_use(Tv_screen *screen, Tv_mask *mask)
107 {
108     if (mask == NULL)
109         gdk_gc_set_clip_mask(screen->gc, NULL);
110     else
111     {
112         gdk_gc_set_clip_mask(screen->gc, mask->bitmap);
113         gdk_gc_set_clip_origin(screen->gc, (gint) mask->lx, (gint) mask->ly);
114     }
115 }
116 
117 /**
118  * @brief  Set a point on a Tv_mask.  
119  * @param  screen  Pointer to Tv_screen for which to set mask point.
120  * @param  mask    Pointer to Tv_mask for which mask point will be set.
121  * @param  pos     Co-ordinates of point to be set.
122  * @param  bit     Zero if point not set; non-zero otherwise.
123  *
124  * Notes: something is badly wrong here; this function will segfault if 
125  * tv->screen in NULL (i.e. the tv has been created but has not been 
126  * installed onto a tv_tool).  This can occur when this function is 
127  * used to plot a graph on the Imcalc graph tv, which is created as soon as
128  * the Imcalc tool is started.  Therefore, whenever you use a graph plotting
129  * function you have to check both the Tv and the Tv->screen.
130  *
131  */
132 void   tv_screen_mask_point(Tv_screen *screen, Tv_mask *mask, Ipos pos, int bit)
133 {
134     int       x = ipos_x(pos) - mask->lx;
135     int       y = ipos_y(pos) - mask->ly;
136     guint32  *rgb = g_malloc(sizeof(guint32));
137     unsigned long int color;
138 
139     if(bit)
140     {
141       color = screen->tv->cmap_data_visible->std_lut[white];
142       (void) rgb_from_long_uint(screen, color, rgb);
143     }
144 
145     gdk_rgb_gc_set_foreground(mask->gc, *rgb);
146     gdk_draw_point(mask->bitmap, mask->gc, x, y);
147 
148     g_free(rgb);
149 }
150 
151 /**
152  * @brief  Free clip mask.  
153  * @param  screen  Pointer to Tv_screen for which to free mask.
154  * @param  mask    Pointer to Tv_mask to be freed.
155  */
156 void   tv_screen_mask_free(Tv_screen *screen, Tv_mask *mask)
157 {
158     gdk_gc_set_clip_mask(screen->gc, NULL);
159     gdk_gc_unref(mask->gc);
160     gdk_bitmap_unref(mask->bitmap);
161     rfree((void *) mask);
162 }
163 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.