Hi Mike,
A few comments on your new code:
1. You still instantiate an ImagickPixelIterator but don't use it - probably forgot to comment it out
Code: Select all
$row = new ImagickPixelIterator($image);
2. The while loops would be easier to read as for loops and when indexing
into an image with ImageMagick the indices start at zero so either use
Code: Select all
$x = 0;
$y = 0;
while ( $y < $h )
{
while ( $x < $w)
OR use
Code: Select all
for($y=0;$y<$h;$y++)
{
for($x=0;$x<$w;$x++)
and remove $x++; and $x=1;$y++; from the bottom of the loops.
3. I converted your example to C and I'm using it as a MagickWand Example in C (see my sig).
While doing this I found that it is about 25% faster to create, draw and destroy
the "line" drawingwand outside the inner loop. Your code is similar to this:
Code: Select all
for($y=0;$y<$h;$y++)
{
for($x=0;$x<$w;$x++)
{
.
.
.
$line = new ImagickDraw;
.
.
$line->line( $x, $start_y, $x, $end_y);
# draw the line
$pallete->drawimage($line);
$line->destroy();
}
It will execute faster arranged like this:
Code: Select all
for($y=0;$y<$h;$y++)
{
$line = new ImagickDraw;
for($x=0;$x<$w;$x++)
{
.
.
$line->line( $x, $start_y, $x, $end_y);
}
# draw the line
$pallete->drawimage($line);
$line->destroy();
I also found that drawing the image from top to bottom, while it is easy to do, requires drawing a lot of lines which will only be overwritten by a later line that is in "front" of them and so covers them up. I modified my C version so that it starts at the bottom of the image and goes up each column, keeping track of the length of the most recently drawn line and only drawing a new one if it is longer. This can speed up the process by a factor of four or more. If you're interested, have a look at my code at
http://members.shaw.ca/el.supremo/Magic ... ape_3d.htm
Pete