Re: scaling a GdkImage

Thanks for your reply.

At 18:03 28/04/02 -0400, Havoc Pennington wrote:

>The way we'd do this in GTK 2 is to get the pixmap pixels as a
>GdkPixbuf (gdk_pixbuf_get_from_drawable()), scale the pixbuf with
>gdk_pixbuf_scale(), then draw the pixbuf back to a drawable.  We
>encourage using pixbufs instead of GdkImage because GdkImage's variety
>of pixel formats makes it quite difficult to deal with.
>For example here you are having to use the "nearest" scaling algorithm
>and I think you'd find implementing any of the other scaling
>algorithms quite challenging for all 20 or so image formats.
>And "nearest" pretty much sucks quality-wise.

For my purposes, "nearest" is good enough, image quality isn't important, it just needs to be recognizable.

>I doubt using images is even much faster than using pixbufs,
>especially since you have two function calls in your inner loop.
>Pixbufs are not appreciably slow in GTK 2.

Although I've 2 function calls in the inner loop, overall they're only being called once for every pixel in the scaled-down image, and I'm using a scale factor of 4. Converting to an unscaled temporary pixbuf obviously requires every pixel to be processed one way, and if the code is faster, perhaps the image scaling could similarly be speeded up...

There's another factor, in that using pixbufs brought me colormap problems. Maybe it's down to my lack of experience, but it seemed as though if I used pixbufs for the scaled-down image, I would need to use them for the unscaled images, slower certainly than drawing directly to the screen - the transition from one to the other is at the click of a button, since it's a zoom facility. Where in my program I found pixbufs a boon was in saving to a png image, where the RGB conversion is a benefit not a hindrance.

>I'd sort of like to see a routine that combined scaling and
>get_from_drawable() (avoiding the temporary pixbuf and just creating
>the scaled one to begin with), but it sure would be a world of pain to
>implement and debug.

Doesn't gdk_pixbuf_get_from_drawable() start by getting the GdkImage ? The GdkImage could be scaled before converting to RGB :-)

I guess given finite resources (time, programmers, patience, pain-tolerance...) it's down to priorities.

David J. Cooke

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