Re: Prima and PDL

From: Dmitry Karasik <dmitry_at_karasik.eu.org>
Date: 04 Feb 2003 10:18:51 +0100
To: prima_at_prima.eu.org

        Hi Michael!

On 03 Feb 03 at 23:20, "Michael" (Michael Peuser h) wrote:

 Michael> Hi, because PDL seems to have no graphics in Windows, I try to
 Michael> visualize some "pidls" with Prima.

 Michael> # $a is a (3,$N,$N) piddle
  
 Michael> foreach my $x (0..$N-1) { foreach my $y (0..$N-1) { my @rgb=list
 Michael> ($a->slice(":,($x),($y)")); $bild[$x][$y]
 Michael> =256*(256*$rgb[0]+$rgb[1])+$rgb[2] ## so it can be used with
 Michael> color and pixel } }

 Michael> So I habe something to feed into a Prima Canvas. This takes
 Michael> horrible time; in fact it is only slightly faster than outputting
 Michael> the piddle as picture and importing it as Prima image....

 Michael> 'list' is the worst culprit, but it adds up.....

 Michael> Any suggestions? It would be phantastic to convert a piddle into
 Michael> an image directly; cann anyone give me a hint about formats? I
 Michael> have no time to look through a host of C-sources, but I am able
 Michael> to do some C-programming..

 Michael> Kindly Mike

An excerpt from `man Prima::Image`:

       The pixel values can be accessed in Prima::Drawable style,
       via ::pixel property. However, Prima::Image introduces
       several helper functions, for different aims. The ::data
       property is used to set or retrieve a scalar
       representation of bitmap data. The data are expected to be
       lined up to a 'line size' margin ( 4-byte boundary ),
       which is calculated as

         $lineSize = int(( $image->width * ( $image-> type & im::BPP) + 31) / 32) * 4;

       This is a default line size, but ::data can be accompanied
       with a write-only flag 'lineSize':

         $image-> set( width => 1, height=> 2);
         $image-> type( im::RGB);
         $image-> set(
            data => 'RGB----RGB----',
            lineSize => 7,
         );
         print $image-> data, "\n";

         output: RGB-RGB-

       Although it is possible to perform all kinds of
       calculations and modification with the pixels, returned by
       ::data, it is not advisable unless the speed does not
       matter.

This should speed up the thing a bit. If you need to access data from C,
you should look into Image.c, - or ask a more explicit question here.
I am not really familiar with PDL data representation so I cannot suggest
an effective conversion routine, but if you'll find one, I'll be glad
to add it up as an example into Prima::Image.pod .

--
Sincerely,
	Dmitry
--- www.karasik.eu.org ---
Life ain't fair, but the root password helps.
                      - BOFH
Received on Tue 04 Feb 2003 - 10:18:53 CET

This archive was generated by hypermail 2.2.0 : Sat 19 Mar 2011 - 18:35:04 CET