gray scale images



Hello, 

I'm writing an application in which I'm trying to display gray scale
images.  One of my concerns/difficulties is that I'm writing this
application to be used on systems with different Visuals (some use
PseudoColor, and others use TrueColor).  So far I've explored two
different approaches:

1.  I recently ran across the function gdk_draw_gray_image().  I
successfully implemented the clock example in the Harlow text in which the
GTK drawing_area widget is used, GCs are set up, and functions like
gdk_draw_arc() are used to draw onto the GDK drawable
drawing_area->window.  I then tried to use gdk_draw_gray_image() to write
a simple grayscale image to this same drawable: 

-----------------------------------------------------------
guchar *buf;  
gint x, y, w, h, rowstride; 
GdkRgbDither dith; 

x = 1; 
y = 1; 
w = 1; 
h = 1; 
rowstride = 1; 
dith = GDK_RGB_DITHER_NONE;
buf = g_malloc(sizeof(guchar)); 
buf = 0xFF; 

gdk_draw_gray_image(drawable, drawing_area->style->black_gc,
	x,y,w,h,dith,buf,rowstride); 
----------------------------------------------------------

One of my problems here is that I don't know what rowstride does.
Nonetheless, the function call fails.  ???  It seems that this is a
valuable approach however, (if I understand this funciton correctly),
because I don't need to deal with modifying the colormap to print a
grayscale image.  


2.  I began by working with the GTK function gtk_image_set().  Here I am
not sure how/if I need to modify the colormap of the widget in order to
produce a grayscale image.  The machine that I work on uses PseudoColor,
where the colormap is indexed by a single byte pointer.  In my test
program I create an image that shows all of the values of the colormap,
and this works just fine:

--------------------------------------------------------------
GdkImage *imagegdk;

for(i=0; i<256; i++) {  
   for(j=0; j<256; j++) {
      ((guchar *)imagegdk->mem)[i*256+j] = (guchar)j; 
   }
}

gtk_image_set( GTK_IMAGE(image), imagegdk, NULL); 
-------------------------------------------------------------

I have tried to set the Visual type to grayscale by doing the following: 

--------------------------------------------------------------
GdkVisual vis; 

vis = gtk_widget_get_visual(image);  vis->type = GDK_VISUAL_GRAYSCALE;
gtk_widget_set_visual(image, vis);
---------------------------------------------------------------- 

but this doesn't work - just no effect.  It still shows an image of all
256 colors. Can anyone tell me how to use a grayscale colormap for
PseudoColor?

For DirectColor, it appears a bit easier - just set the Red, Green, and
Blue values to equivalent values. Is there a way to do this that is
transparent to the Visual type? 


Insight to either approach is greatly appreciated.  


Thanks, 

Dean 

/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
                        Dean Skuldt
                 skuldt@mr.radiology.wisc.edu 
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\









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