00001
00002
00003
00004
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
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
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
00057
00058 #define MAP_XY(x,wx,wn) (((wn)*(x))/(wx))
00059
00060
00061
00062
00063
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
00079
00080 typedef struct {
00081 int classKRH ;
00082 int depth ;
00083
00084 int ncolors , nblack,nwhite ;
00085 byte * rr , * gg , * bb ;
00086
00087 unsigned long rrmask , ggmask , bbmask ;
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
00099
00100 #define MAX_COLORS 256
00101
00102
00103
00104 typedef struct {
00105 int ncol_ov ;
00106 XColor xcol_ov[MAX_COLORS] ;
00107 Pixel pix_ov[MAX_COLORS] ;
00108 char * name_ov[MAX_COLORS] ;
00109 char * label_ov[MAX_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] ;
00115
00116 byte r_ov[MAX_COLORS] ;
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 ;
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 ;
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 ;
00145
00146 int ncol_im ;
00147 double gamma , gamma_init ;
00148 int use_xcol_im ;
00149
00150 XColor xgry_im[MAX_COLORS] ,
00151 xcol_im[MAX_COLORS] ;
00152
00153 Pixel pix_im[MAX_COLORS] ;
00154 int pix_im_ready ;
00155 int byper , bypad ;
00156
00157 MCW_DCOV * ovc ;
00158
00159 int xint_im[MAX_COLORS] ;
00160
00161 XFontStruct * myFontStruct ;
00162
00163 Widget parent_widget ;
00164
00165 XtPointer parent , aux ;
00166
00167 DC_colordef * cdef ;
00168
00169 int does_backingstore ;
00170 int does_saveunders ;
00171
00172 byte r_im[MAX_COLORS] ;
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 ;
00181
00182 #define DC_REDBYTE(dc,i) ((dc)->r_im[i])
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
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
00200
00201 #define DC_text_width(dc,str) XTextWidth((dc)->myFontStruct,(str),strlen((str)))
00202
00203
00204
00205 extern void DC_yokify( Widget , MCW_DC * ) ;
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 ) ;
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 * ) ;
00260
00261 extern void reload_DC_colordef( MCW_DC * ) ;
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 ) ;
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 *) ;
00269
00270 extern rgbyte DC_spectrum_AJJ( double, double ) ;
00271 extern rgbyte DC_spectrum_ZSS( double, double ) ;
00272
00273 #endif