Re: Image manipulation and Scaling



The following code does it:

// your original data assumed to be in a continous structure of gray.
// Preferably in a structure.
float *src_buf;
int img_width = 256;
int img_height = 256;

// You destination
GdkPixbuf *dst = gdk_pixbuf_new(...);
guint8 *dst_buf = gdk_pixbuf_get_data();
guint src_stride = gdk_pixbuf_get_row_stride(dst);

// Find min and max unless you have user min and user max
float min = HUGE;
float max = -HUGE;
for (int i=0; i<img_width*img_height; i++) {
    float gl = src_buf[i];
    if (gl < min)
        min = gl;
    else if (gl > max)
        max = gl;
}

// Rescale
for (int row_idx=0; row_idx<img_height; row_idx++) {
    guint *dst_row = src_buf + row_stride;
    for (int col_idx=0; col_idx<img_height; col_idx++) {
        float src_gl = src_buf[row_idx*img_width + col_idx];
        float dst_gl = (src_gl - min) / (max-min) * 255;
        // clip
        if (dst_gl < 0)
            dst_gl = 0;
        else if (dst_gl > 255)
            dst_gl = 255;
        // Assign to rgb
        for (int i=0; i<3; i++) {
            dst_row[col_idx*3+i] = dst_gl;
    }
}

Changing to support user min and max and source RGB image is left as an
exercise to the reader.

And regarding whether you can support zoom without GtkImageView or
GtkImageViewer, obviously yes since these are written based on lower level
gtk structures. The trivial (and memory wasteful way) is to rescale the
image based on zoom level and show it in a view port.

Regards,
Dov

Wed, Feb 3, 2010 at 08:41, Gorav <gorav s mst-india com> wrote:
On Wed, Feb 3, 2010 at 08:41, Gorav <gorav s mst-india com> wrote:

Thanks for reply.


Can you please elaborate more on Converting More than 8bit image to 8 bit
image.

And, apart from GtkImageView, is there no other way of image scaling?


Thanks
Gorav


On 02/03/2010 12:02 PM, Dov Grobgeld wrote:

Even if your image has more than eight bits you can always convert it to
8-bit according to a user setting defining the grey level max and min to
be
used for the convertion (known as window and level in the medical image
community). That's exactly how I do it in my image viewer giv. The image
is
held in a GivImage that is overloaded for various bit integer or floating
widths and is then converted according to the user level setting before
being displayed.

Btw, if you would like to have interactive zooming of the image being
displayed you may want to consider using my GtkImageViewer instead of
GtkImage. (There is also the GtkImageView by Björn Lindquist with similar
and different functionality.)

See: http://giv.sourceforge.net/gtk-image-viewer/

Regards,
Dov

On Wed, Feb 3, 2010 at 04:19, Lars Wirzenius<liw liw fi>  wrote:



On Tue, 2010-02-02 at 17:25 +0530, Gorav wrote:


Hi


I need to do some image manipulation using GTK, and I want to view some
proprietary image formats. So, I can prepare RGB data. But, which widget
and API to be use to draw pixels on screen.


I used GtkImage using Pixbuf, but it supports only 8 bits per sample.


Have you looked at GdkPixbuf for holding the image data? You may need to
write converter plugins to load and store images from files for your
proprietary formats, but after that, all the in-memory stuff should work
fine.


_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list



_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list







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