Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

display.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002    Major portions of this software are copyrighted by the Medical College
00003    of Wisconsin, 1994-2000, and are released under the Gnu General Public
00004    License, Version 2.  See the file README.Copyright for details.
00005 ******************************************************************************/
00006 
00007 #ifndef _MCW_DISPLAY_HEADER_
00008 #define _MCW_DISPLAY_HEADER_
00009 
00010 #include <math.h>
00011 #include <stdio.h>
00012 #include <stdlib.h>
00013 #include <string.h>
00014 
00015 #include <X11/X.h>
00016 #include <X11/Intrinsic.h>
00017 #include <X11/Shell.h>
00018 #include <X11/cursorfont.h>
00019 
00020 #include <Xm/Xm.h>
00021 #include <Xm/MwmUtil.h>
00022 #include <Xm/DialogS.h>
00023 #include <Xm/PushB.h>
00024 
00025 #include "mrilib.h"
00026 
00027 /*** Macros ***/
00028 
00029 #ifndef MAX
00030 #   define MAX(a,b) (((a)<(b)) ? (b) : (a))
00031 #   define MIN(a,b) (((a)>(b)) ? (b) : (a))
00032 #endif
00033 
00034 #ifndef myXtFree
00035 # define myXtFree(xp) (XtFree((char *)(xp)) , (xp)=NULL)
00036 #endif
00037 
00038 #ifndef myXtNew
00039 # define myXtNew(type) ((type *) XtCalloc(1,(unsigned) sizeof(type)))
00040 #endif
00041 
00042 /* these macros are to produce RGB intensities (unsigned shorts) */
00043 
00044 #define CLIP_INTEN(i)    (((i)<256) ? (256) : ((i)>65280) ? (65280) : (i))
00045 #define BYTE_TO_INTEN(b) (CLIP_INTEN((b)<<8))
00046 #define INTEN_TO_BYTE(i) ((i)>>8)
00047 
00048 #define BRIGHTNESS(r,g,b)   (0.299*(r)+0.587*(g)+0.114*(b))
00049 #define XCOL_BRIGHTNESS(xc) BRIGHTNESS((xc).red,(xc).green,(xc).blue)
00050 
00051 #define XCOL_REDNESS(xc)    (0.299*(xc).red   - MAX(0.587*(xc).green,0.114*(xc).blue ))
00052 #define XCOL_GREENNESS(xc)  (0.587*(xc).green - MAX(0.299*(xc).red  ,0.114*(xc).blue ))
00053 #define XCOL_BLUENESS(xc)   (0.114*(xc).blue  - MAX(0.299*(xc).red  ,0.587*(xc).green))
00054 #define XCOL_YELLOWNESS(xc) (0.299*(xc).red+0.587*(xc).green-0.114*(xc).blue)
00055 
00056 /* given x in [0..wx-1], map proportionally to [0..wn-1] */
00057 
00058 #define MAP_XY(x,wx,wn) (((wn)*(x))/(wx))
00059 
00060 /* 07 Aug 1998:
00061    Macro to produce TrueColor pixel values from
00062    an RGB triple, by appropriately shifting and masking.
00063    This can only be used if dc->visual_class == TrueColor! */
00064 
00065 #define RGB_TO_TCINT(dc,r,g,b)                                       \
00066  ( ((((dc)->visual_redshift  <0)                                     \
00067       ? ((r)<<(-(dc)->visual_redshift)  )                            \
00068       : ((r)>>  (dc)->visual_redshift)  ) & (dc)->visual_redmask  )  \
00069   |                                                                  \
00070    ((((dc)->visual_greenshift<0)                                     \
00071       ? ((g)<<(-(dc)->visual_greenshift))                            \
00072       : ((g)>>  (dc)->visual_greenshift)) & (dc)->visual_greenmask)  \
00073   |                                                                  \
00074    ((((dc)->visual_blueshift <0)                                     \
00075       ? ((b)<<(-(dc)->visual_blueshift) )                            \
00076       : ((b)>>  (dc)->visual_blueshift) ) & (dc)->visual_bluemask ) )
00077 
00078 /*--- 11 Feb 1999: stuff for mapping colors to pixels ------------------*/
00079 
00080 typedef struct {
00081    int classKRH ;    /* type of colormap: PseudoColor and TrueColor are OK */
00082    int depth ;
00083 
00084    int ncolors , nblack,nwhite ;  /* This stuff for PseudoColor */
00085    byte * rr , * gg , * bb ;
00086 
00087    unsigned long rrmask , ggmask , bbmask ;   /* This stuff for TrueColor */
00088    int           rrshift, ggshift, bbshift;
00089    Pixel         whpix ;
00090 } DC_colordef ;
00091 
00092 #define FREE_DC_colordef(cd)                                     \
00093   do{ if( (cd) != NULL ){                                        \
00094          if( (cd)->rr != NULL ){                                 \
00095             free((cd)->rr) ; free((cd)->gg) ; free((cd)->bb) ; } \
00096          free((cd)) ; (cd) = NULL ; } } while(0)
00097 
00098 /***---------------------------- typedefs ----------------------------***/
00099 
00100 #define MAX_COLORS 256
00101 
00102 /** Dec 1997: split overlay stuff into a separate struct **/
00103 
00104 typedef struct {
00105    int    ncol_ov ;              /* number of overlay colors defined */
00106    XColor xcol_ov[MAX_COLORS] ;  /* definitions of overlay colors */
00107    Pixel  pix_ov[MAX_COLORS]  ;  /* Pixels for overlay */
00108    char * name_ov[MAX_COLORS] ;  /* names of overlay colors */
00109    char * label_ov[MAX_COLORS] ; /* labels for overlay colors */
00110 
00111    Pixel  pixov_brightest,pixov_darkest,pixov_reddest,pixov_greenest,pixov_bluest,pixov_yellowest;
00112    int    ov_brightest   ,   ov_darkest,   ov_reddest,   ov_greenest,   ov_bluest,   ov_yellowest;
00113 
00114    float  bright_ov[MAX_COLORS] ; /* brightness of overlay colors [20 Dec 1999] */
00115 
00116    byte r_ov[MAX_COLORS] ;  /* 06 Mar 2001 */
00117    byte g_ov[MAX_COLORS] ;
00118    byte b_ov[MAX_COLORS] ;
00119 } MCW_DCOV ;
00120 
00121 #define DCOV_REDBYTE(dc,i)   ((dc)->ovc->r_ov[i])
00122 #define DCOV_GREENBYTE(dc,i) ((dc)->ovc->g_ov[i])
00123 #define DCOV_BLUEBYTE(dc,i)  ((dc)->ovc->b_ov[i])
00124 
00125 #define DCOV_BRIGHTNESS(dc,i) ((dc)->ovc->bright_ov[i])
00126 
00127 typedef struct {
00128       XtAppContext appcontext ;    /* X and Xt stuff */
00129       Display *    display ;
00130       Screen *     screen ;
00131       int          screen_num ;
00132       Visual *     visual ;
00133       Colormap     colormap , default_colormap ;
00134       GC           myGC , origGC ;
00135       int          planes ;
00136       int          depth ;
00137 
00138       VisualID      visual_id ;     /* 07 Aug 1998: added visual_* stuff */
00139       XVisualInfo * visual_info ;
00140       unsigned long visual_redmask  , visual_greenmask  , visual_bluemask ;
00141       int           visual_redshift , visual_greenshift , visual_blueshift ;
00142       int           visual_class ;
00143 
00144       int          width , height ;       /* of the screen */
00145 
00146       int          ncol_im ;              /* # colors we use */
00147       double       gamma , gamma_init ;   /* gamma factor */
00148       int          use_xcol_im ;          /* color in use? */
00149 
00150       XColor       xgry_im[MAX_COLORS] ,  /* for images */
00151                    xcol_im[MAX_COLORS]  ;
00152 
00153       Pixel        pix_im[MAX_COLORS] ;
00154       int          pix_im_ready ;         /* 22 Aug 1998 */
00155       int          byper , bypad ;        /* 23 Aug 1998 */
00156 
00157       MCW_DCOV *   ovc ;                  /* Dec 1997 */
00158 
00159       int          xint_im[MAX_COLORS] ;  /* intensity levels for xgry_im */
00160 
00161       XFontStruct * myFontStruct ;
00162 
00163       Widget       parent_widget ;
00164 
00165       XtPointer    parent , aux ;
00166 
00167       DC_colordef * cdef ;    /* 11 Feb 1999 */
00168 
00169       int does_backingstore ; /* 27 Feb 2001 */
00170       int does_saveunders ;
00171 
00172       byte r_im[MAX_COLORS] ; /* 06 Mar 2001 */
00173       byte g_im[MAX_COLORS] ;
00174       byte b_im[MAX_COLORS] ;
00175 #if 0
00176       byte gray_im[MAX_COLORS] ;
00177 #endif
00178 } MCW_DC ;
00179 
00180 extern MCW_DC *first_dc ;                     /* 26 Jun 2003 */
00181 
00182 #define DC_REDBYTE(dc,i)     ((dc)->r_im[i])  /* 06 Mar 2001 */
00183 #define DC_GREENBYTE(dc,i)   ((dc)->g_im[i])
00184 #define DC_BLUEBYTE(dc,i)    ((dc)->b_im[i])
00185 
00186 #if 0
00187 #define DC_GRAYBYTE(dc,i)    ((dc)->gray_im[i])
00188 #endif
00189 
00190 /* fonts to try if the defaults fail */
00191 
00192 static char * tfont_hopefuls[] = {
00193                  "-adobe-courier-medium-r-normal--12-120-75-75-m-70-iso8859-1" ,
00194                  "-misc-fixed-medium-r-normal--13-100-100-100-c-70-iso8859-1" ,
00195                  "lucidasanstypewriter-10" ,
00196                  "7x14" , "6x13" , "fixed" ,
00197               NULL } ;
00198 
00199 /*** Macro for text widths ***/
00200 
00201 #define DC_text_width(dc,str) XTextWidth((dc)->myFontStruct,(str),strlen((str)))
00202 
00203 /*** prototypes ***/
00204 
00205 extern void DC_yokify( Widget , MCW_DC * ) ; /* 14 Sep 1998 */
00206 
00207 extern MCW_DC * MCW_new_DC( Widget, int, int, char * c[], char * l[], double, int ) ;
00208 
00209 extern void DC_init_im_gry( MCW_DC * ) ;
00210 extern void DC_init_im_col( MCW_DC * ) ;
00211 extern void DC_init_ov_col( MCW_DC * ) ;
00212 
00213 #if 0
00214 extern Pixel RGB_byte_to_color( MCW_DC *, int,int,int ) ;
00215 extern Pixel Name_to_color( MCW_DC * , char * ) ;
00216 #endif
00217 
00218 extern int DC_add_overlay_color( MCW_DC * , char * , char * ) ;
00219 extern int DC_find_overlay_color( MCW_DC * , char * ) ;
00220 extern int DC_find_closest_overlay_color( MCW_DC * , char * ) ;
00221 
00222 extern void load_tmp_colors( int , XColor c[] ) ;
00223 
00224 extern void DC_palette_rotate( MCW_DC * , int ) ;
00225 extern void DC_palette_swap( MCW_DC * ) ;
00226 
00227 extern void DC_palette_bright( MCW_DC * , int ) ;
00228 extern void DC_palette_squeeze( MCW_DC * , int ) ;
00229 
00230 extern void DC_palette_restore( MCW_DC * , double ) ;
00231 
00232 extern void DC_gray_change( MCW_DC * , int ) ;
00233 extern void DC_color_bright( MCW_DC * , int ) ;
00234 
00235 extern void DC_gray_contrast( MCW_DC * , int ) ;
00236 extern void DC_color_squeeze( MCW_DC * , int ) ;
00237 
00238 extern void DC_gray_conbrio( MCW_DC * , int ) ;  /* 23 Oct 2003 */
00239 
00240 extern void DC_palette_setgray( MCW_DC * ) ;
00241 extern void DC_palette_setcolor( MCW_DC * ) ;
00242 
00243 extern Boolean MCW_check_iconsize( int,int,MCW_DC * ) ;
00244 
00245 extern XColor * DCpix_to_XColor( MCW_DC * , Pixel , int ) ;
00246 
00247 extern void DC_fg_color( MCW_DC * , int ) ;
00248 extern void DC_bg_color( MCW_DC * , int ) ;
00249 extern void DC_fg_colortext( MCW_DC * , char * ) ;
00250 extern void DC_linewidth( MCW_DC * , int ) ;
00251 extern void DC_fg_colorpix( MCW_DC * , Pixel ) ;
00252 
00253 extern void DC_linestyle( MCW_DC * , int ) ;
00254 #define DC_solid_line(ddcc)  DC_linestyle((ddcc),LineSolid)
00255 #define DC_dashed_line(ddcc) DC_linestyle((ddcc),LineOnOffDash)
00256 
00257 extern void OVC_mostest( MCW_DCOV * ) ;
00258 
00259 extern void DC_set_image_colors( MCW_DC * ) ;  /* 22 Aug 1998 */
00260 
00261 extern void reload_DC_colordef( MCW_DC * ) ;   /* 11 Feb 1999 */
00262 extern Pixel DC_rgb_to_pixel( MCW_DC *, byte,byte,byte ) ;
00263 extern void DC_pixel_to_rgb( MCW_DC *, Pixel, byte *,byte *,byte * ) ;
00264 
00265 extern Pixel DC_rgb_to_ovpix( MCW_DC *, byte,byte,byte ) ; /* 20 Dec 1999 */
00266 extern void DC_rgb_to_ovrgb( MCW_DC *, int,int *,int,byte *, byte *, byte *) ;
00267 
00268 extern int DC_parse_color( MCW_DC *, char *, float *,float *,float *) ; /* 21 Sep 2001 */
00269 
00270 extern rgbyte DC_spectrum_AJJ( double, double ) ;
00271 extern rgbyte DC_spectrum_ZSS( double, double ) ;
00272 
00273 #endif /* _MCW_DISPLAY_HEADER_ */
 

Powered by Plone

This site conforms to the following standards: