00001 
00002 
00003 
00004 
00005 #include "win.h"
00006 #include <string.h>
00007 
00008 #define  ColormapFromDefault    0       
00009 #define  ColormapFromDefaultC   1       
00010 #define  ColormapFromStandard   2       
00011 #define  ColormapFromFile       3
00012 #define  ImmutableColormap      4       
00013 
00014 extern Display           *display;
00015 extern Visual            *visual;
00016 extern int                screen;
00017 extern XStandardColormap  map_info;
00018 extern Colormap           colormap;
00019 extern int                colormap_size;
00020 extern char              *colorfile;
00021 extern lux_wins          *get_currentwin();
00022 unsigned   long           BLACK_COLOR,WHITE_COLOR;
00023 
00024 XColor colors[256];              
00025 
00026 
00027 extern int    lux_colors;
00028 extern int    lux_colormap;
00029 
00030 lux_setup_colorfile(name)
00031 char *name;
00032 {
00033     if (colorfile != NULL) free(colorfile);
00034     colorfile = (char *) malloc((strlen(name)+1)*sizeof(char));
00035     colorfile[0] = 0;
00036     strcat(colorfile,name);
00037 }
00038 
00039 int lux_get_colormap_name(n)
00040 char *n;
00041 {
00042     if (n == (char *)NULL) return(ColormapFromDefault);
00043     if (!strcmp(n,"ColormapFromDefault"))  return(ColormapFromDefault);
00044     if (!strcmp(n,"ColormapFromDefaultC")) return(ColormapFromDefaultC);
00045     if (!strcmp(n,"ColormapFromStandard")) return(ColormapFromStandard);
00046     return(ColormapFromFile);
00047 }
00048 
00049 Colormap lux_setup_colormap(display, screen, visual)
00050 Display *display;
00051 int      screen;
00052 Visual **visual;
00053 {
00054     Colormap            colormap;
00055     Visual             *vis;
00056     XVisualInfo         visual_info, *vlist, vinfo_template, *v;
00057     int                 num_vis=0;
00058     unsigned int        default_depth;
00059 
00060     vlist = XGetVisualInfo(display, VisualNoMask, &vinfo_template, &num_vis);
00061 
00062     for (v = vlist; v < vlist + num_vis; v++) 
00063       if (v->visual == DefaultVisual(display,screen)) break;
00064     
00065     default_depth = DefaultDepth(display, screen);
00066 
00067     if (default_depth == 1) { 
00068         lux_colormap = ImmutableColormap;
00069         colormap_size = 2;
00070         BLACK_COLOR = BlackPixel(display,screen);
00071         WHITE_COLOR = WhitePixel(display,screen);
00072         *visual = v->visual;
00073         return(DefaultColormap(display, screen));         
00074     }
00075 
00076     if (!XMatchVisualInfo(display, screen, default_depth, 
00077                           PseudoColor, &visual_info)) {
00078         if (!XMatchVisualInfo(display, screen, default_depth, 
00079                               DirectColor, &visual_info)) {
00080             
00081             lux_colormap = ImmutableColormap;
00082             colormap_size = v->colormap_size;
00083             BLACK_COLOR = BlackPixel(display,screen);
00084             WHITE_COLOR = WhitePixel(display,screen);
00085             *visual = v->visual;
00086             return(DefaultColormap(display, screen));
00087         }
00088     }
00089     if (visual_info.visual != DefaultVisual(display,screen)) 
00090       for (v = vlist; v < vlist + num_vis; v++) 
00091         if (v->visual == visual_info.visual) break;
00092 
00093     colormap_size = v->colormap_size;
00094     *visual = v->visual;
00095 
00096     if (colormap_size>256) colormap_size = 256;
00097 
00098     lux_setup_map_info();
00099 
00100     BLACK_COLOR = BlackPixel(display,screen);
00101     WHITE_COLOR = WhitePixel(display,screen);
00102 
00103 
00104 
00105     switch(lux_colormap = lux_get_colormap_name(colorfile)) {
00106 
00107         case ColormapFromDefault:
00108         case ColormapFromDefaultC:
00109 
00110           return(DefaultColormap(display, screen)); break;
00111         case ColormapFromStandard:
00112           colormap = XCreateColormap(display, RootWindow(display, screen), 
00113                                      *visual, AllocAll);
00114 
00115           if (colormap == DefaultColormap(display, screen)) {
00116               fprintf(stderr,"lux_msg: hardware colormap is immutable: cannot create new colormap. Using default colormap\n");
00117               lux_colormap = ColormapFromDefault;
00118               return(DefaultColormap(display, screen));
00119           }
00120           lux_store_default_color(display,colormap,screen);
00121 
00122           return(colormap);
00123           break;
00124         case ColormapFromFile:
00125           colormap = XCreateColormap(display, RootWindow(display, screen), 
00126                                      *visual, AllocAll);
00127 
00128           if (colormap == DefaultColormap(display, screen)) {
00129               fprintf(stderr,"lux_msg: hardware colormap is immutable: cannot create new colormap. Using default colormap\n");
00130               lux_colormap = ColormapFromDefault;
00131               return(DefaultColormap(display, screen));
00132           }
00133           if(lux_store_colorfromfile(display, colormap, screen, colorfile)) {
00134 
00135               return(colormap);
00136           }
00137           else {
00138               lux_colormap = ColormapFromDefault;
00139 
00140               return(DefaultColormap(display, screen));
00141           }               
00142           break;
00143         default:
00144           fprintf(stderr,"lux_msg: Unknown case in lux_setup_colormap\n");
00145 
00146       }
00147 }
00148 
00149 lux_store_colorfromfile(display, colormap, screen, filename)
00150 Display            *display;
00151 Colormap colormap;
00152 int screen;
00153 char *filename;
00154 {
00155   int     ncells, i, j, k, l;
00156   XColor *exact_defs;
00157   unsigned char red[256],green[256],blue[256];
00158   FILE   *input;
00159 
00160   input = fopen(filename,"rb");
00161 
00162   if (input == (FILE *)NULL) return(0);
00163   ncells = colormap_size;
00164   exact_defs = (XColor *) calloc(sizeof(XColor), ncells); 
00165 
00166   fread(red,  1,256,input);
00167   fread(green,1,256,input);
00168   fread(blue, 1,256,input);
00169 
00170   for(i=0;i<ncells;i++) {
00171     exact_defs[i].red   = red[i]*256;
00172     exact_defs[i].green = green[i]*256;
00173     exact_defs[i].blue  = blue[i]*256;
00174     exact_defs[i].pixel = (unsigned long)i;
00175     exact_defs[i].flags = DoRed | DoGreen | DoBlue;
00176   }
00177 
00178   exact_defs[WhitePixel(display,screen)].red   = 65535;
00179   exact_defs[WhitePixel(display,screen)].green = 65535;
00180   exact_defs[WhitePixel(display,screen)].blue  = 65535;
00181 
00182   exact_defs[BlackPixel(display,screen)].red   = 0;
00183   exact_defs[BlackPixel(display,screen)].green = 0;
00184   exact_defs[BlackPixel(display,screen)].blue  = 0;
00185 
00186 
00187 
00188 
00189   XStoreColors (display, colormap, exact_defs, ncells);
00190   fclose(input);
00191   return(1);
00192 }
00193 
00194 lux_store_default_color(display,colormap,screen)
00195 Display     *display;
00196 Colormap     colormap;
00197 int          screen;
00198 {
00199   int     ncells, i, j, k, l;
00200   XColor *exact_defs;
00201 
00202   ncells = colormap_size;
00203 
00204   exact_defs = (XColor *)calloc(sizeof(XColor), ncells); 
00205 
00206   
00207   l = map_info.base_pixel;
00208   for (k = 0; k <= map_info.red_max; k++) {
00209     for (j = 0; j <= map_info.green_max; j++) {
00210       for (i = 0; i <= map_info.blue_max; i++) {
00211         exact_defs[l].blue  = 65535 * i / map_info.blue_max;
00212         exact_defs[l].green = 65535 * j / map_info.green_max;
00213         exact_defs[l].red   = 65535 * k / map_info.red_max;
00214         exact_defs[l].pixel = (unsigned long)l;
00215         exact_defs[l].flags = DoRed | DoGreen | DoBlue;
00216         l++;
00217       }
00218     }
00219   }
00220 
00221   exact_defs[WhitePixel(display,screen)].red   = 65535;
00222   exact_defs[WhitePixel(display,screen)].green = 65535;
00223   exact_defs[WhitePixel(display,screen)].blue  = 65535;
00224 
00225   exact_defs[BlackPixel(display,screen)].red   = 0;
00226   exact_defs[BlackPixel(display,screen)].green = 0;
00227   exact_defs[BlackPixel(display,screen)].blue  = 0;
00228 
00229 
00230 
00231 
00232   XStoreColors(display, colormap, exact_defs, ncells);
00233   free(exact_defs);
00234 }
00235 
00236 lux_setup_map_info()
00237 {
00238         if (colormap_size == 256) {
00239           map_info.red_max   = (unsigned long)7;
00240           map_info.green_max = (unsigned long)7;
00241           map_info.blue_max  = (unsigned long)3;
00242  
00243           map_info.red_mult   = (unsigned long)32;
00244           map_info.green_mult = (unsigned long)4;
00245           map_info.blue_mult  = (unsigned long)1;
00246         }
00247         else if (colormap_size == 128) {
00248           map_info.red_max   = (unsigned long)7;
00249           map_info.green_max = (unsigned long)3;
00250           map_info.blue_max  = (unsigned long)3;
00251  
00252           map_info.red_mult   = (unsigned long)16;
00253           map_info.green_mult = (unsigned long)4;
00254           map_info.blue_mult  = (unsigned long)1;
00255         }
00256         else if (colormap_size == 16) {
00257           map_info.red_max   = (unsigned long)3;
00258           map_info.green_max = (unsigned long)1;
00259           map_info.blue_max  = (unsigned long)1;
00260  
00261           map_info.red_mult   = (unsigned long)4;
00262           map_info.green_mult = (unsigned long)2;
00263           map_info.blue_mult  = (unsigned long)1;
00264         }
00265         else if (colormap_size == 4) {
00266           map_info.red_max   = (unsigned long)3;
00267           map_info.green_max = (unsigned long)3;
00268           map_info.blue_max  = (unsigned long)3;
00269  
00270           map_info.red_mult   = (unsigned long)1;
00271           map_info.green_mult = (unsigned long)0;
00272           map_info.blue_mult  = (unsigned long)0;
00273         }
00274         else return(0);
00275         map_info.base_pixel = 0;
00276         return(1);
00277 }
00278 
00279 unsigned long lux_rgb_pixel(win,red, green, blue)
00280 Window win;
00281 float red,green,blue;
00282 {
00283 
00284     register lux_wins *current;
00285     register int      i;
00286     unsigned long     plane_mask[1], pixels[1];
00287     int      redi, greeni, bluei;
00288 
00289     current = get_currentwin(win);
00290 
00291 
00292   if (red<0.000001 && green < 0.000001 && blue < 0.000001) return(BLACK_COLOR);
00293   if (red>0.999999 && green > 0.999999 && blue > 0.999999) return(WHITE_COLOR);
00294 
00295   switch(current->win.lux_colormap) {
00296       case ImmutableColormap:
00297         fprintf(stderr,"Colormap is immutable, use pixel value directly\n");
00298         return(BLACK_COLOR);
00299         break;
00300       case ColormapFromDefault:
00301         redi   = 65535L * (unsigned long)(0.5+red*map_info.red_max)/map_info.red_max;
00302         greeni = 65535L * (unsigned long)(0.5+green*map_info.green_max)/map_info.green_max;
00303         bluei  = 65535L * (unsigned long)(0.5+blue*map_info.blue_max)/map_info.blue_max;
00304 
00305         for(i=0;i<lux_colors;i++) 
00306           if (redi   == colors[i].red   &&
00307               greeni == colors[i].green &&
00308               bluei  == colors[i].blue  )
00309             return(colors[i].pixel);
00310 
00311         colors[lux_colors].red   = redi;
00312         colors[lux_colors].green = greeni;
00313         colors[lux_colors].blue  = bluei;
00314         colors[lux_colors].flags = DoRed | DoGreen | DoBlue;
00315 
00316         if(XAllocColor(current->win.display, current->win.colormap, &colors[lux_colors]))  {
00317             lux_colors ++;
00318             return(colors[lux_colors-1].pixel);    
00319         }   
00320         else {
00321             fprintf(stderr,"Can't set read only color!\n");
00322             return(BLACK_COLOR);
00323         }
00324         break;
00325       case ColormapFromDefaultC:
00326         redi   = 65535L * (unsigned long)(0.5+red*map_info.red_max)/map_info.red_max;
00327         greeni = 65535L * (unsigned long)(0.5+green*map_info.green_max)/map_info.green_max;
00328         bluei  = 65535L * (unsigned long)(0.5+blue*map_info.blue_max)/map_info.blue_max;
00329 
00330         for(i=0;i<lux_colors;i++) 
00331           if (redi   == colors[i].red   &&
00332               greeni == colors[i].green &&
00333               bluei  == colors[i].blue  )
00334             return(colors[i].pixel);
00335 
00336         if(XAllocColorCells(current->win.display, current->win.colormap, False, plane_mask, 0, pixels, 1)) {
00337             colors[lux_colors].red   = redi;
00338             colors[lux_colors].green = greeni;
00339             colors[lux_colors].blue  = bluei;
00340             colors[lux_colors].pixel = pixels[0];
00341             colors[lux_colors].flags = DoRed | DoGreen | DoBlue;
00342             XStoreColors(current->win.display, current->win.colormap, &colors[lux_colors], 1);
00343             lux_colors++;
00344             return(colors[lux_colors-1].pixel);
00345         }
00346         else {
00347             fprintf(stderr,"Can't set red/write color!\n");
00348             return(BLACK_COLOR);
00349         }
00350         break;
00351       case ColormapFromStandard:
00352         colors[lux_colors].pixel = map_info.base_pixel + 
00353              (unsigned long)(0.5+red*map_info.red_max)*map_info.red_mult+
00354              (unsigned long)(0.5+green*map_info.green_max)*map_info.green_mult+
00355              (unsigned long)(0.5+blue*map_info.blue_max)*map_info.blue_mult;
00356         colors[lux_colors].red = 65535L * (unsigned long)(0.5+red*map_info.red_max)/map_info.red_max;
00357         colors[lux_colors].green = 65535L * (unsigned long)(0.5+green*map_info.green_max)/map_info.green_max;
00358         colors[lux_colors].blue = 65535L * (unsigned long)(0.5+blue*map_info.blue_max)/map_info.blue_max;
00359         colors[lux_colors].flags = DoRed | DoGreen | DoBlue;
00360 
00361         for(i=0;i<lux_colors;i++) 
00362           if (colors[lux_colors].red   == colors[i].red   &&
00363               colors[lux_colors].green == colors[i].green &&
00364               colors[lux_colors].blue  == colors[i].blue  )
00365             return(colors[i].pixel);
00366 
00367         lux_colors++;
00368         return(colors[lux_colors-1].pixel);
00369         break;
00370       case ColormapFromFile:
00371         fprintf(stderr,"Using colormap from file!!\n");
00372         return(BLACK_COLOR);
00373         break;
00374       default:
00375         fprintf(stderr,"Unknown case in rgb_pixel\n");
00376         return(BLACK_COLOR);
00377   }
00378 }
00379 
00380 unsigned long lux_lookup_color(win, name) 
00381 Window    win;
00382 char     *name;
00383 {
00384     register lux_wins *current;
00385     register int      i;
00386     unsigned long     plane_mask[1], pixels[1];
00387     float    red, green, blue;
00388     XColor   db_def,  h_def;
00389     int      status;
00390 
00391     current = get_currentwin(win);
00392 
00393     if (!XLookupColor(current->win.display, current->win.colormap, name,
00394                       &db_def, &h_def)) 
00395       {fprintf(stderr,"Color %s not found.\n",name);return(BLACK_COLOR);}
00396 
00397     if (h_def.red   == 256 &&
00398         h_def.green == 256 &&
00399         h_def.blue  == 256) return(WHITE_COLOR);
00400     else if (h_def.red   == 0 &&
00401              h_def.green == 0 &&
00402              h_def.blue  == 0) return(BLACK_COLOR);
00403 
00404 
00405     switch(current->win.lux_colormap) {
00406 
00407         case ImmutableColormap:
00408 
00409             
00410 
00411             status = XAllocColor(current->win.display,
00412                                  current->win.colormap,
00413                                  &h_def);
00414             return h_def.pixel; 
00415             break;
00416 
00417         case ColormapFromDefault:
00418 
00419             for(i = 0; i < lux_colors; i++) 
00420                 if (h_def.red   == colors[i].red   &&
00421                     h_def.green == colors[i].green &&
00422                     h_def.blue  == colors[i].blue  )
00423                     return(colors[i].pixel);
00424 
00425             h_def.flags = DoRed | DoGreen | DoBlue;
00426             if(XAllocColor(current->win.display, current->win.colormap,
00427                            &h_def)) {
00428                 colors[lux_colors].red   = h_def.red;
00429                 colors[lux_colors].green = h_def.green;
00430                 colors[lux_colors].blue  = h_def.blue;
00431                 colors[lux_colors].flags = DoRed | DoGreen | DoBlue;
00432                 colors[lux_colors].pixel = h_def.pixel;
00433                 lux_colors++;
00434                 return(colors[lux_colors-1].pixel);  
00435             }
00436             else {
00437                 fprintf(stderr,"Can't set read only color %s!\n",name);
00438                 return(BLACK_COLOR);
00439             }
00440             break;
00441 
00442         case ColormapFromDefaultC:
00443 
00444             for(i=0;i<lux_colors;i++) 
00445                 if (h_def.red   == colors[i].red   &&
00446                     h_def.green == colors[i].green &&
00447                     h_def.blue  == colors[i].blue  )
00448                     return(colors[i].pixel);
00449 
00450             h_def.flags = DoRed | DoGreen | DoBlue;
00451             if(XAllocColorCells(current->win.display, current->win.colormap,
00452                                 False, plane_mask, 0, pixels, 1)) {
00453                 colors[lux_colors].red   = h_def.red;
00454                 colors[lux_colors].green = h_def.green;
00455                 colors[lux_colors].blue  = h_def.blue;
00456                 colors[lux_colors].pixel = pixels[0];
00457                 colors[lux_colors].flags = DoRed | DoGreen | DoBlue;
00458                 XStoreColors(current->win.display, current->win.colormap,
00459                              &colors[lux_colors], 1);
00460                 lux_colors++;
00461                 return(colors[lux_colors-1].pixel);
00462             }
00463             else {
00464                 fprintf(stderr,"Can't set red/write color!\n");
00465                 return(BLACK_COLOR);
00466             }
00467             break;
00468 
00469       case ColormapFromStandard:
00470 
00471           red   = ((float)h_def.red  )/65535.0;
00472           green = ((float)h_def.green)/65535.0;
00473           blue  = ((float)h_def.blue )/65535.0;
00474           colors[lux_colors].pixel = map_info.base_pixel + 
00475               (unsigned long)(0.5+red*map_info.red_max)*map_info.red_mult+
00476               (unsigned long)(0.5+green*map_info.green_max)*map_info.green_mult+
00477               (unsigned long)(0.5+blue*map_info.blue_max)*map_info.blue_mult;
00478           colors[lux_colors].red
00479               = 65535L * (unsigned long)(0.5+red*map_info.red_max)
00480                                                 /map_info.red_max;
00481           colors[lux_colors].green
00482               = 65535L * (unsigned long)(0.5+green*map_info.green_max)
00483                                                 /map_info.green_max;
00484           colors[lux_colors].blue
00485               = 65535L * (unsigned long)(0.5+blue*map_info.blue_max)
00486                                                 /map_info.blue_max;
00487           colors[lux_colors].flags = DoRed | DoGreen | DoBlue;
00488 
00489           for(i = 0 ; i < lux_colors ; i++) 
00490               if (colors[lux_colors].red   == colors[i].red   &&
00491                   colors[lux_colors].green == colors[i].green &&
00492                   colors[lux_colors].blue  == colors[i].blue  )
00493                   return(colors[i].pixel);
00494 
00495           lux_colors++;
00496           return(colors[lux_colors-1].pixel);
00497           break;
00498 
00499       case ColormapFromFile:
00500 
00501           fprintf(stderr, "Using colormap from file!!\n");
00502           return(BLACK_COLOR);
00503           break;
00504 
00505       default:
00506 
00507           fprintf(stderr, "Unknown case in rgb_pixel\n");
00508 
00509 
00510     }
00511     return(BLACK_COLOR);
00512 }
00513 
00514 
00515 lux_rotate_colormap(win,flag)
00516 Window win;
00517 int    flag;
00518 {
00519     register lux_wins *current;
00520     register unsigned long pixel;
00521     XColor  *exact_defs;
00522     int      i;
00523 
00524     if (flag == 0) return(0);
00525 
00526     current = get_currentwin(win);
00527 
00528     switch(current->win.lux_colormap) {
00529         case ImmutableColormap:
00530         case ColormapFromDefault:
00531         fprintf(stderr,"Colormap can't be rotate\n");
00532         break;
00533         case ColormapFromFile:
00534         exact_defs = (XColor *) calloc(sizeof(XColor), 258); 
00535         for(i=1;i<257;i++) {
00536             exact_defs[i].pixel = i-1;
00537             exact_defs[i].flags = DoRed | DoGreen | DoBlue;
00538         }
00539         XQueryColors(current->win.display, current->win.colormap, 
00540                       &(exact_defs[1]), 256);
00541         exact_defs[ 0 ].pixel = exact_defs[256].pixel;
00542         exact_defs[257].pixel = exact_defs[ 1 ].pixel;
00543         if (flag > 0) {
00544             for(i=0;i<257;i++)  exact_defs[i].pixel = exact_defs[i+1].pixel;
00545 
00546 
00547 
00548 
00549 
00550 
00551 
00552 
00553 
00554 
00555 
00556 
00557 
00558 
00559 
00560 
00561 
00562 
00563         }
00564         else {
00565             for(i=257;i>0;i--) exact_defs[i].pixel = exact_defs[i-1].pixel;
00566 
00567 
00568 
00569 
00570 
00571 
00572 
00573 
00574 
00575 
00576 
00577 
00578 
00579 
00580 
00581 
00582 
00583 
00584 
00585 
00586         }
00587         
00588         XStoreColors(current->win.display, current->win.colormap, 
00589                       &(exact_defs[1]), 256);
00590         free(exact_defs);
00591 
00592 
00593         break;
00594         case ColormapFromDefaultC:
00595         case ColormapFromStandard:
00596         if (flag > 0) {
00597             pixel = colors[0].pixel;
00598             for(i=0;i<lux_colors-2;i++) {
00599                 colors[i].pixel = colors[i+1].pixel;
00600             }
00601             colors[lux_colors-1].pixel = pixel;
00602         }
00603         else {
00604             pixel = colors[lux_colors-1].pixel;
00605             for(i=lux_colors-2;i>=0;i--) {
00606                 colors[i+1].pixel = colors[i].pixel;
00607             }
00608             colors[0].pixel = pixel;
00609         }
00610         XStoreColors(current->win.display,current->win.colormap,colors,lux_colors);
00611 
00612 
00613         return(1);
00614         default:
00615         fprintf(stderr,"Unknown case in rotate colormap\n");
00616         break;
00617     }
00618     return(0);
00619 }
00620 
00621 lux_get_colorinfo(size,im_colormap) 
00622 
00623 int *size, *im_colormap;
00624 {
00625     *size = colormap_size;
00626     if (lux_colormap == ImmutableColormap) *im_colormap = 1;
00627     else *im_colormap = 0;
00628 }
00629 
00630 lux_set_window_colormap(win, name)      
00631 Window win;
00632 char  *name;
00633 {
00634     register lux_wins *current;
00635     Colormap cm;
00636 
00637     current = get_currentwin(win);
00638 
00639     
00640     if (!strcmp(name,"LuxDefaultColormap")) {
00641         if (current->win.colormap != colormap) {
00642             XFreeColormap(current->win.display,current->win.colormap);
00643             if (current->win.colormapfile != NULL) 
00644               free(current->win.colormapfile);
00645             if (colorfile != NULL) {
00646                 current->win.colormapfile = (char *)malloc(strlen(colorfile)+1);
00647                 current->win.colormapfile[0] = 0;
00648                 strcat(current->win.colormapfile,colorfile);
00649             }
00650             else current->win.colormapfile = NULL;
00651             
00652             current->win.lux_colormap = lux_colormap;
00653             current->win.colormap = colormap;
00654             XSetWindowColormap(current->win.display,win,colormap);
00655         }
00656         return 16;
00657     }
00658     
00659 
00660 
00661     if (lux_colormap == ImmutableColormap) {
00662         fprintf(stderr,"Error: The colormap is immutable.\n");
00663         return(0);
00664     }
00665 
00666     cm = XCreateColormap(current->win.display, 
00667                          RootWindow(current->win.display, screen), 
00668                          visual, AllocAll);
00669 
00670     if (lux_store_colorfromfile(current->win.display, cm, screen, name) == 0) {
00671         fprintf(stderr,"Error: File not found.\n");
00672         XFreeColormap(current->win.display, cm);
00673         return(0);
00674     }
00675 
00676     if (current->win.colormap != colormap) 
00677       XFreeColormap(current->win.display,current->win.colormap);
00678 
00679     if (current->win.colormapfile != NULL) free(current->win.colormapfile);
00680         
00681     current->win.colormapfile = (char *)malloc(strlen(name)+1);
00682     current->win.colormapfile[0] = 0;
00683     strcat(current->win.colormapfile,name);
00684 
00685     current->win.lux_colormap = ColormapFromFile;
00686     current->win.colormap = cm;
00687 
00688     XSetWindowColormap(current->win.display,win,cm);
00689     return 256;
00690 }
00691 
00692 
00693 
00694