From: "ara.t.howard" Date: 2008-06-16T13:52:15+09:00 Subject: Re: Binary string packing/unpacking issues On Jun 14, 2008, at 4:53 AM, Lucas L. wrote: > Hi, > I have a packed string of raw binary pixel data that I want to > manipulate. However, I'm facing a few problems. > Firstly, the only way I've managed to unpack the data so far is with > "pixels.unpack('b*')". It works great, but comes out in one massive > string. > Is there a way to: > a)put this into an array with 8 bits in each element, eg. ['00000000', > '01010101'...] > b)unpack small sections of a few bites > The other problem is that I don't know of an efficient way to > manipulate > this data without having to unpack\pack massive strings each time. > > Are there any solutions to these? use narray a rather complicated example http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/155483 the basic starting point is width = 800 height = 600 na = NArray.to_na raw_pixel_data, NArray::BYTE, width, height then to, for example, increase every pixel value by 1 na += 1 see http://narray.rubyforge.org/SPEC.en for more. gem install narray too, of course. regards. a @ http://codeforpeople.com/ -- we can deny everything, except that we have the possibility of being better. simply reflect on that. h.h. the 14th dalai lama