[squeak-dev] Get raw 24 Bit image data into a Form

tim Rowledge tim at rowledge.org
Sat Aug 29 19:02:27 UTC 2015


On 29-08-2015, at 8:13 AM, Herbert König <herbertkoenig at gmx.net> wrote:

> Hi,
> 
> how do I go about reading a raw RGB 888 (24 bits deep output from raspiyuv) file into a Form?

Well we need to understand the file format first to decode it and so far as some quick googling tells me the yuv files are completely raw; no header to tell us anything, just a long list of bytes. Since you can control the width and height of the image the camera takes (apparently, though it looks like it gets rounded up to 32 pixels in width and 16 in height?) I guess we can at least in principle assume the w & d for the data. The RGB888 is pretty much the Squeak pixels format for 32bpp anyway so there shouldn’t be too much of a problem.

Basically
take your picture and write to file
open file as binary in Squeak `myFileStream := (FileStream readOnlyFileNamed: ‘my.yuv’) binary`
create a Form of appropriate size & depth  `myForm := Form extent: width at height depth: 32`
read bytes from the filestream and stick them in the form’s bits array. There will be issues of byte-endianness to get right (squeak bitmaps are for some demented reason big-endian and I’d guess the pi YUV files are little-endian) and you’ll have to fill in the top (or bottom, see endianness) byte to set the alpha correctly. 

It’ll be something along the lines of checking the sizes match up, reading the data into the form’s bits array and making sure the bits all line up.

Here’s a quick example from my pi2, since it tickled my curiousity

in terminal - `raspiyuv -w 320 -h 208 -rgb -o smple.yuv`
in Squeak
Form extent: 320 at 208 depth: 32 -> inspect it
in the inspector - 
|myfile alpha|
myfile := FileStream readOnlyFileNamed: ‘/home/pi/sample.yuv’.
myfile binary.
bits size * 3 = myfile size ifFalse:[^nil].
alpha := 16rFF<<24.
1 to: bits size do: [ :i| |val|
val := myfile next.
val := val <<8 + myfile next.
val := val <<8 + myfile next.
val := alpha bitOr: val.
bits at: i put: val].
myfile close
self display

I get a pretty decent image displayed. Takes 250 mSec to read in on my pi2 with a cog-spur squeak. A bit over half that is the cost of using the largeinteger ‘alpha’ to set the proper alpha value for each pixel. You *can* leave that out if you’re going to simply do ‘myform display’ since the raw bitblt ignores the alpha. If you are going to be examining the pixels as just rgb values, save the time - I see 120mS in that case.


Obviously once you have the general format sorted it ought to get moved into Form and tidied up as From class>>readRGBFromFileNamed: or similar.


tim
--
tim Rowledge; tim at rowledge.org; http://www.rowledge.org/tim
Useful random insult:- If you give him a penny for his thoughts, you get change back.




More information about the Squeak-dev mailing list