Joe Van Dyk wrote:
> On 8/30/05, Timothy Hunter <cyclists / nc.rr.com> wrote:
>>Joe, what is the format of the pixel data in your input file? Is it just
>>8-bit R,G,B values in top-down scanline order?
> 
> 
> Nope.  The data starts in the SW corner, then goes east and then
> north.  The data for each pixel is packed into 8 bytes (a short for
> elevation, a char for terrain info, a char for monochrome brightness,
> and a network long that contains the color data).  Don't ask me why.
> 

Darn. After reading Ara's post I started thinking about a way to move 
pixels more-or-less directly from a file into an image, bypassing the 
need to create Magick::Pixel objects. I emailed the ImageMagick team and 
asked for their recommendation. The absolute fastest way to get pixel 
data into an image is via the ImageMagick API that RMagick's 
Image::import_pixels method 
(http://www.simplesystems.org/RMagick/doc/image2.html#import_pixels) 
uses, called ImportImagePixels. ImportImagePixels expects a C array of 
pixel data in scanline order, top-to-bottom, right-to-left. You can 
specify the data type of the array (char, short, int, long) and the 
order in which the channel data appear (RGB, RGBA, CMYK, etc.) The IM 
developers tell me that ImportImagePixels is optimized for the RGB case 
so I suspect that this would be a very - I repeat, very - fast way to 
load pixels into an image.

Currently #import_pixels wants a Ruby array of Fixnums which it then 
converts to a C array. Lotsa overhead.

Following Ara's suggestion, I was thinking about changing #import_pixels 
to accept a string (to be exact, any object that responds to to_str) in 
place of the array. In this case #import_pixels would simply call to_str 
and assume that the result is a C array of the correct type and size and 
with the channel data in the specified order and hand it off to 
ImportImagePixels directly.

I realize this doesn't really help you since your input data isn't in 
the  format ImportImagePixels wants. However, if you (or Ara, or anybody 
else with an interest) have an opinion about the usefulness of this idea 
I'd like to hear it.