Hi all,

I am writing an application that reads medical imaging files (CT, MRI, etc
in DICOM format) and simply displays them. However, I am having trouble
using Gtk2::Gdk::Pixmap. I must use a pixmap since DICOM images are usually
16-bit, and almost always grayscale.

I've pared my program to a simple example displaying a random color instead
of an DICOM file. Below are 2 implementations: one using pixbuf (which works
fine), and one using pixmap. The pixmap example throws no warnings, but
displays only a window containing a black square. Unfortunately, I cannot
make use of the much simpler pixbuf, since it only supports 8-bit pixels.

I believe the problem lies within the pixmap method "create_from_data" where
the first parameter is supposed to be a Gtk2::Gtk::Drawable. If I create
just a simple drawable, the program complains that the object is undefined.
So, I get the root window using "get_default_root_window" since the
Gtk2::Gdk::Window is technically a Drawable. I admit to not fully
understanding the difference between Gtk2::Window and Gtk2::Gdk::Window. Any
help would be greatly appreciated, as I'm now wandering around aimlessly
with several baldspots.

Thanks,
Scott

----------
Pixbuf example:
#! /usr/bin/perl -w

use Gtk2 '-init';
$window = Gtk2::Window->new;

# create a random color
$r = int(rand(255));
$g = int(rand(255));
$b = int(rand(255));

# create pixel data for a 512x512 image
foreach (1..262144)
{
   $data .= pack ("B8B8B8", $r, $g, $b);
}

# Pixbuf implementation, only uses 8-bit pixels
$pixbuf = Gtk2::Gdk::Pixbuf->new_from_data ($data, 'rgb', 0, 8, 512, 512,
3*512);
$image = Gtk2::Image->new_from_pixbuf ($pixbuf);

$window->add ($image);
$window->signal_connect ("destroy", sub { exit(0); });
$window->show_all;
Gtk2->main;

----------
Pixmap example:
#! /usr/bin/perl -w

use Gtk2 '-init';

$window = Gtk2::Window->new;

# create a random color
$r = int(rand(65535));
$g = int(rand(65535));
$b = int(rand(65535));

# create pixel data for a 512x512 image
foreach (1..262144)
{
   $data .= pack ("B24B24B24", $r, $g, $b);
}

# Pixmap implementation, using 24-bit pixels
$root = Gtk2::Gdk->get_default_root_window;
$color = Gtk2::Gdk::Color->new (0,0,0);
$pixmap = Gtk2::Gdk::Pixmap->create_from_data ($root, $data, 512, 512, 24,
$color, $color);

$image = Gtk2::Image->new;
$image->set_from_pixmap ($pixmap, undef);

$window->add ($image);
$image->queue_draw;

$window->signal_connect ("destroy", sub { exit(0); });
$window->show_all;
Gtk2->main;
----------
_______________________________________________
gtk-perl-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Reply via email to