On Apr 4, 2005 11:09 AM, Tim Hunter <sastph / sas.com> wrote: > Joe Van Dyk wrote: > > Hi, > > > > I'm generating a fairly large image file (can be 10000x10000) pixels > > by reading some binary data and setting each pixel. As you can > > imagine, pure Ruby is REALLY slow, I think because of the loops. I've > > written the program in C and it's literally hundreds to thousands of > > times faster (depending on image size). > > Have you tried RMagick? http://rmagick.rubyforge.org. > > The constitute method may be useful: > http://www.simplesystems.org/RMagick/doc/image1.html#constitute > > That method requires you to have all the pixel data in memory at once, > though, which could be a problem unless you have a LOT of RAM. > > You could use import_pixels to set just a subset of pixels at a time: > http://www.simplesystems.org/RMagick/doc/image2.html#import_pixels > > That would minimize the memory requirements. > > In both cases you'd have to convert your binary data to a Ruby numeric > type. Don't know whether that would be too slow or not. Ooh, that looks nice. The image can be up to (and probably more than) 10,000x10,000 pixels though... that's a heck of a lot of memory. And converting the data in Ruby would take a long time, I believe. Too many iterations.