[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: [QUIZ][SOLUTION] Mexican Blanket (#127

Tim Hunter

6/10/2007 8:55:00 PM

Justin Ethier wrote:
> And to draw a JPEG we get a bit fancier, but its the same basic idea.
> There
> must be a better way to code this, because it takes much too long to run.
Nice solution! Regarding the speed, see my earlier reply to Jesse
Merriman. Instead of drawing a pixel at a time, create an array of Pixel
objects and then use import_pixels or store_pixels to "draw" a row at a
time. For that matter, both of these methods can handle arbitrary
rectangles so you can create as many rows as you want and stow them in
the image all at once. You could build the whole image in memory if
that's what you wanted.

--
RMagick OS X Installer [http://rubyforge.org/project...]
RMagick Hints & Tips [http://rubyforge.org/forum/forum.php?for...]
RMagick Installation FAQ [http://rmagick.rubyforge.org/instal...]


1 Answer

Jesse Merriman

6/11/2007 10:35:00 PM

0

On Sunday 10 June 2007 16:54, Tim Hunter wrote:
> <snip>
> For that matter, both of these methods can handle arbitrary
> rectangles so you can create as many rows as you want and stow them in
> the image all at once. You could build the whole image in memory if
> that's what you wanted.

Though that does give a speed boost, its not much. Here's a mod of the
last version of draw_blanket I posted:

def draw_blanket blanket
pixels = []
blanket.each_row_with_index do |row, y|
row.split(//).each do |color_char|
pixels << Magick::Pixel.from_color(StringToColor[color_char])
end
end
store_pixels 0, 0, blanket.width, blanket.height, pixels
end

For a 800x800 image, on my box, this shaves about 1/20 second off a total
run time of about 7 seconds.


--
Jesse Merriman
jessemerriman@warpmail.net
http://www.jessemer...