styles and writeable colormaps



Hello, 

I am writing an application which will use a writeable colormap (I use a
PSEUDOCOLOR visual).  The application will display gray-scale images, and
in order to window-level (change the contrast curve for) an image quickly
the colormap will be modified.  I chose to use colormap modification
instead of scaling and redrawing the image for every change of the
contrast curve, which is very time-consuming.  By drawing the image only
once, and then modifying the colormap when windowing and leveling, things
are speedy.  

I allocate 256 colors in this writeable colormap.  I reserve the top 5
colors for window and menu foregrounds, backgrounds, and text.  The other
251 colors are the gray-scale colors which are changed during
window-leveling.  

Creating the colormap, and modifying the colormap is no problem.  However,
I have been unable to force the foreground, background, and text of
widgets to use the reserved colors in my colormap.  I try to do so by
copying the default style, setting the colors in this new style, and
pushing this new style before creating the widgets.  (code below)  I don't
understand how to get the foreground, background and text to use these
reserved colors. 

Also, part of what makes my colormap manipulation so speedy is my use of
gdk_colormap_change.  In one function call, all 251 colors can be
modified.  The gnome website's gdk reference documentation indicates that
this function is obsolete.  If I don't use this function, but use 251
calls to gdk_color_change, things are very slow.  Can anyone tell me if
gdk_colormap_change will really be made obsolete?  

Any help is appreciated.  Thanks, 

Dean


#define CMAP_SIZE 256
#define N_GC_COLS 5
#define FG 0
#define BG 1
#define TX 2

GdkColormap *colormap;
GdkColor colors[CMAP_SIZE];
GdkVisual *visual;
GtkStyle *style; 
  
  /* Create a PRIVATE colormap for this visual */ 
  visual = gdk_visual_get_best(); 
  colormap =  gdk_colormap_new(visual,TRUE);  

  /* setup grayscale colors */ 
 for (i=0;i<CMAP_SIZE-N_GC_COLS;i++)
   {   
     colors[i].red = colors[i].green = colors[i].blue =
       (gushort)(i<<8);
   }
 
 /* foreground */ 
 colors[CMAP_SIZE-N_GC_COLS+FG].red = (gushort)(0<<8);
 colors[CMAP_SIZE-N_GC_COLS+FG].green = (gushort)(255<<8);
 colors[CMAP_SIZE-N_GC_COLS+FG].blue = (gushort)(0<<8);
 /* text */ 
 colors[CMAP_SIZE-N_GC_COLS+TX].red = (gushort)255<<8;
 colors[CMAP_SIZE-N_GC_COLS+TX].green = (gushort)0<<8;
 colors[CMAP_SIZE-N_GC_COLS+TX].blue = (gushort)0<<8; 
 /* background */ 
 colors[CMAP_SIZE-N_GC_COLS+BG].red = (gushort)0;
 colors[CMAP_SIZE-N_GC_COLS+BG].green = (gushort)(0<<8);
 colors[CMAP_SIZE-N_GC_COLS+BG].blue = (gushort)(255<<8);
 
 writeable = TRUE;
 bestmatch = TRUE;
 n_allocated = gdk_colormap_alloc_colors(colormap, colors, 256, writeable,
	bestmatch, success);

 for (i=0;i<256;i++)
     gdk_color_change(colormap,colors+i); 

 defstyle = gtk_widget_get_default_style();
 style = gtk_style_copy(defstyle);
 style->fg[GTK_STATE_NORMAL]   = colors[CMAP_SIZE-N_GC_COLS+FG];
 style->bg[GTK_STATE_NORMAL]   = colors[CMAP_SIZE-N_GC_COLS+BG];
 style->text[GTK_STATE_NORMAL] = colors[CMAP_SIZE-N_GC_COLS+TX];

 gtk_widget_push_style(style);

 ----- create widgets ---------

  gtk_widget_pop_style();

 gtk_widget_show_all (window);
 
 gtk_main ();
 return 0;
}





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]