Re: Working with pixels



On Sun, 2003-04-20 at 02:51, Gregor Pirnaver wrote:
what structure do I need to use if I want to work with 
pixels of an image?

depends on what format you're using, as you seem to have discovered.


So far I have found:
Gtk::Gdk::Pixbuf->get_pixels( $row, $col )
Gtk::Gdk::Pixbuf->put_pixels( $data, $row, $col )

But what is $data anyway?

GdkPixbuf is the simplified client-side pixel buffer, which uses 24-bit
rgb.

in perl this means you have to use pack and unpack to puts whatever you
have into a scalar (corresponding to a guchar array in C).


I have also found
Gtk::Gdk::Image->put_pixel( $image, $x, $y, $pixel ); 
Gtk::Gdk::Image->get_pixel( $image, $x, $y );

GdkImage is an older client-side format.  using it often involves a lot
of pain and suffering.  even worse, using put_pixel and get_pixel, since
X is a client/server architecture, usually involves enormous slowdowns.


But how do I read a bitmap into an "Image":
Gtk::Gdk::Image->new_bitmap ( $visual, $data, $width, 
$height);

Again: what is visual? What is data?

GdkImage is a direct wrapper of the XImage structure, which is a
client-side storage of a color image (as opposed to a pixmap or bitmap,
which is merely a handle to an image resource stored on the server).

the drawback is that X doesn't handle various pixel depths for you; that
is the purpose of the "visual".  there's a pseudocolor visual, a 16-bit
visual, a 15-bit visual, and a truecolor visual.  the format of the data
argument (packed pixel array) depends on the visual.


all of this mess is why GdkPixbuf exists; GdkPixbuf is always 24-bit
RGB, and handles the differences between visuals for you (possibly with
hand-optimized assembly code).


the basic X drawing functions work on server-side drawables, and the
client-side stuff is completely up to the app.  libart exists to do
sophisticated graphics on RGB arrays and is often used with GdkPixbuf
--- however, bindings for libart don't exist for gtk-perl (so far as i
know) and have not yet been written for gtk2-perl.   since manipulating
individual pixels in perl is not so fast as in C, i would recommend you
write an XS extension if you have anything major to do to the pixel
array.


-- 
muppet <scott asofyet org>




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