hi,
i got to interleave the alpha channel with an rgb image both given as raw
files: please don't laugh at me, but i found myself writing this very short
but slow code:
rgb = File.new rgbfile, 'rb'
# this raw file contains rgb bytes in interleaved order, so one pixel is 3
bytes
alpha = File.new alphafile, 'rb'
# contains 1 byte/pixel alpha channel
#desired result: a binary string, rgba interleaved, 4 byte/pixel, =
4*width*height bytes
data = ''
(width*height).times{
data += rgb.read( 3) + alpha.read( 1)
}
i think alternately reading some bytes is slowing down alot. but also loops
operating on strings are
slow, i think. i know some solutions, but i don t know which one to use.
are there any suggestions how to do this most efficiently in ruby?
-- thanks, mr