Re: Handling new image format



Hi Sylvain,

It is not really necessary to add a new format to gtk in order to
handle these images. What you can do is to use any library that
you like to read the images from disk, and then you can easily
convert these to 8-bit images on your own. (This way you
are e.g. in full control of the contrast of the final displayed
image). Here is some untested code that does roughly what you need:

    gdk_pixbuf *tiff16_to_pixbuf(Tiff16 *tiff_img)
    {
       int width = tiff_img->width;
       int height = tiff_img->height;
       int row_stride;
       int row_idx, col_idx;
       guint8 *buf;
       
       gdk_pixbuf *pb = gdk_pixbuf_new(GDK_COLORSPACE_RGB,
                                       FALSE, 8, width, height);
       row_stride = gdk_pixbuf_get_row_stride(pb);
       buf_row = gdk_pixbuf_get_pixels(pb);

       for (row_idx=0; row_idx < height; row_idx++) 
         {
            for (col_idx=0; col_idx < width; col_idx++) 
              {
                int idx = row_idx * width + col_idx;

                /* Here you can insert a contrast enhancement etc... */
                int gl = tiff_img->buf[idx] / 256;
	        if (gl < 0)
		    gl = 0;
		else if (gl > 255)
		    gl = 256;
                pbuf_row[col_idx*3]
                    = pbuf_row[col_idx*3+1]
                    = pbuf_row[col_idx*3+2] = gl;
              }
            pbuf_row += row_stride;
          }
 		       
       return pb;
    }

Once you have the pixbuf you may e.g. use my gtk_image_viewer widget
(see gnome-cvs or 
http://imagic.weizmann.ac.il/~dov/freesw/gtk/gtk-image-viewer/)
to view it.

Hope this helps.

Regards,
Dov

On Mon, Mar 31, 2003 at 04:58:05PM +1000, foret wrote:
> Hello,
> 
> I am writing a scientific software to analyse high resolution scanner 
> images using glib and gtk 2.
> Unfortunatelly the images are in a 16-bits gray level format which is 
> not supported by libtiff (8-bit maximum for gray level images).
> What is the best way to had support for this format (and in general to a 
> new image format) to gtk/gdk/gdk-pixbuff ?
> 
> Thanks !
> 
> Sylvain



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