[9fans] How to read/write pixels from Memimage
Hello. I'm porting Bell Labs' Pico image language over to Plan 9 to
use the Plan 9 native image format (image(6)), and I chose to use
Memimage. I'd like to know how to get the 32-bit RGB pixel
information out of a Memimage and into a properly allocated array of
u32ints, and to do the reverse. Is that possible? Thanks.
Re: [9fans] How to read/write pixels from Memimage
> Hello. I'm porting Bell Labs' Pico image language over to Plan 9 to[color=blue]
> use the Plan 9 native image format (image(6)), and I chose to use
> Memimage. I'd like to know how to get the 32-bit RGB pixel
> information out of a Memimage and into a properly allocated array of
> u32ints, and to do the reverse. Is that possible? Thanks.[/color]
A good way to answer questions like these is to
cd /sys/src/cmd
grep -n Memimage *.c */*.c */*/*.c
Looking through the output, all of these:
/sys/src/cmd/crop.c
/sys/src/cmd/resample.c
/sys/src/cmd/jpg/writepng.c
are examples of programs that use memimages
in a byte-at-a-time fashion.
Russ
Re: [9fans] How to read/write pixels from Memimage
However, I want to be able to read 32-bit color values. How does
Memimage store colors and will the code I use work? I can change it
to 24-bit if necessary, but that would make it slower to read files.
If I do what these programs say, how will my u32int be arranged?
On Jan 26, 2008, at 9:05 AM, Russ Cox wrote:
[color=blue][color=green]
>> Hello. I'm porting Bell Labs' Pico image language over to Plan 9 to
>> use the Plan 9 native image format (image(6)), and I chose to use
>> Memimage. I'd like to know how to get the 32-bit RGB pixel
>> information out of a Memimage and into a properly allocated array of
>> u32ints, and to do the reverse. Is that possible? Thanks.[/color]
>
> A good way to answer questions like these is to
>
> cd /sys/src/cmd
> grep -n Memimage *.c */*.c */*/*.c
>
> Looking through the output, all of these:
>
> /sys/src/cmd/crop.c
> /sys/src/cmd/resample.c
> /sys/src/cmd/jpg/writepng.c
>
> are examples of programs that use memimages
> in a byte-at-a-time fashion.
>
> Russ
>[/color]
Re: [9fans] How to read/write pixels from Memimage
> However, I want to be able to read 32-bit color values. How does[color=blue]
> Memimage store colors and[/color]
You should be able to answer this by reading the programs
I pointed out as well as color(6), image(6), and memdraw(2).
If all else fails, you could try writing a simple program and
see how far you get.
[color=blue]
> will the code I use work?[/color]
Probably not at first (whose code does?), but eventually.
[color=blue]
> I can change it to 24-bit if necessary, but that would make it slower to read files.
> If I do what these programs say, how will my u32int be arranged?[/color]
The answers to these questions are *in* those programs
(not to mention the manual pages!). Given that your reply
came in four minutes after my post, it sounds like you didn't
actually read the programs I pointed out. The first one on
the list, /sys/src/cmd/crop.c, picks up a Plan 9 image file
and then walks over every 32-bit pixel looking for a given color.
And it's only 211 lines. Between that and the documentation
I'd think that would be enough to answer questions about
how colors are stored. At the least it should prompt
questions that are more specific than "how do I do this?"
Read /sys/src/cmd/crop.c, color(6), image(6), and memdraw(2).
Russ
Re: [9fans] How to read/write pixels from Memimage
The code led me to confusion, so I just decided to use wordaddr. It
works properly now, and my Pico is now up at /n/sources/contrib/
pietro/pico9.tgz (note the 9). Details are in README.Plan9, test
files are in /lib/face/.
On Jan 26, 2008, at 9:55 AM, Russ Cox wrote:
[color=blue][color=green]
>> However, I want to be able to read 32-bit color values. How does
>> Memimage store colors and[/color]
>
> You should be able to answer this by reading the programs
> I pointed out as well as color(6), image(6), and memdraw(2).
> If all else fails, you could try writing a simple program and
> see how far you get.
>[color=green]
>> will the code I use work?[/color]
>
> Probably not at first (whose code does?), but eventually.
>[color=green]
>> I can change it to 24-bit if necessary, but that would make it
>> slower to read files.
>> If I do what these programs say, how will my u32int be arranged?[/color]
>
> The answers to these questions are *in* those programs
> (not to mention the manual pages!). Given that your reply
> came in four minutes after my post, it sounds like you didn't
> actually read the programs I pointed out. The first one on
> the list, /sys/src/cmd/crop.c, picks up a Plan 9 image file
> and then walks over every 32-bit pixel looking for a given color.
> And it's only 211 lines. Between that and the documentation
> I'd think that would be enough to answer questions about
> how colors are stored. At the least it should prompt
> questions that are more specific than "how do I do this?"
>
> Read /sys/src/cmd/crop.c, color(6), image(6), and memdraw(2).
>
> Russ
>[/color]
Re: [9fans] How to read/write pixels from Memimage
> The code led me to confusion, so I just decided to use wordaddr. It[color=blue]
> works properly now, and my Pico is now up at /n/sources/contrib/
> pietro/pico9.tgz (note the 9). Details are in README.Plan9, test
> files are in /lib/face/.[/color]
some book examples are failing:
cpu% 8.out
1: new[x,y] = x % y
8.out 181613: suicide: sys: trap: divide error pc=0x000023fd
Re: [9fans] How to read/write pixels from Memimage
That transformation is in the book? It divides by zero for y == 0. I
have to look.
I'm working on an update. It adds:
r x y w h file (done)
Reads a certain rectangle of a file. This makes crop(1)'s -r option
three lines of rc or /bin/sh:
echo 'r '$1' '$2' '$3' '$4' '$5'
new = old
w '$6 | pico
Simple variables (started)
Undo command u (done)
Use of RGB24 instead of RGBA32 to make the examples work (done)
Using Brdstr instead of Bgetc/Bungetc (this is not working)
On Jan 27, 2008, at 1:05 PM, Skip Tavakkolian wrote:
[color=blue][color=green]
>> The code led me to confusion, so I just decided to use wordaddr. It
>> works properly now, and my Pico is now up at /n/sources/contrib/
>> pietro/pico9.tgz (note the 9). Details are in README.Plan9, test
>> files are in /lib/face/.[/color]
>
> some book examples are failing:
>
> cpu% 8.out
> 1: new[x,y] = x % y
> 8.out 181613: suicide: sys: trap: divide error pc=0x000023fd
>[/color]
Re: [9fans] How to read/write pixels from Memimage
Well I just found it, and I couldn't believe it. I'm going to look at
Gerard's original source for the VAX and see what he does on divide
by zero.
On Jan 27, 2008, at 1:05 PM, Skip Tavakkolian wrote:
[color=blue][color=green]
>> The code led me to confusion, so I just decided to use wordaddr. It
>> works properly now, and my Pico is now up at /n/sources/contrib/
>> pietro/pico9.tgz (note the 9). Details are in README.Plan9, test
>> files are in /lib/face/.[/color]
>
> some book examples are failing:
>
> cpu% 8.out
> 1: new[x,y] = x % y
> 8.out 181613: suicide: sys: trap: divide error pc=0x000023fd
>[/color]
Re: [9fans] How to read/write pixels from Memimage
Okay, I just found out that division by zero meant a black pixel
would be placed, so I am going to add that and upload a new version.
On Jan 27, 2008, at 1:05 PM, Skip Tavakkolian wrote:
[color=blue][color=green]
>> The code led me to confusion, so I just decided to use wordaddr. It
>> works properly now, and my Pico is now up at /n/sources/contrib/
>> pietro/pico9.tgz (note the 9). Details are in README.Plan9, test
>> files are in /lib/face/.[/color]
>
> some book examples are failing:
>
> cpu% 8.out
> 1: new[x,y] = x % y
> 8.out 181613: suicide: sys: trap: divide error pc=0x000023fd
>[/color]
Re: [9fans] How to read/write pixels from Memimage
It's up.
On Jan 27, 2008, at 6:44 PM, Pietro Gagliardi wrote:
[color=blue]
> Okay, I just found out that division by zero meant a black pixel
> would be placed, so I am going to add that and upload a new version.
>
> On Jan 27, 2008, at 1:05 PM, Skip Tavakkolian wrote:
>[color=green][color=darkred]
>>> The code led me to confusion, so I just decided to use wordaddr. It
>>> works properly now, and my Pico is now up at /n/sources/contrib/
>>> pietro/pico9.tgz (note the 9). Details are in README.Plan9, test
>>> files are in /lib/face/.[/color]
>>
>> some book examples are failing:
>>
>> cpu% 8.out
>> 1: new[x,y] = x % y
>> 8.out 181613: suicide: sys: trap: divide error pc=0x000023fd
>>[/color]
>[/color]
Re: [9fans] How to read/write pixels from Memimage
Another question: in RGB24, how are colors composited: 0x00RRGGBB or
0xRRGGBB00? I can't seem to get a picture that is solid red; just a
wacky line art picture.
On Jan 27, 2008, at 7:18 PM, Pietro Gagliardi wrote:
[color=blue]
> It's up.
>
> On Jan 27, 2008, at 6:44 PM, Pietro Gagliardi wrote:
>[color=green]
>> Okay, I just found out that division by zero meant a black pixel
>> would be placed, so I am going to add that and upload a new version.
>>
>> On Jan 27, 2008, at 1:05 PM, Skip Tavakkolian wrote:
>>[color=darkred]
>>>> The code led me to confusion, so I just decided to use wordaddr. It
>>>> works properly now, and my Pico is now up at /n/sources/contrib/
>>>> pietro/pico9.tgz (note the 9). Details are in README.Plan9, test
>>>> files are in /lib/face/.
>>>
>>> some book examples are failing:
>>>
>>> cpu% 8.out
>>> 1: new[x,y] = x % y
>>> 8.out 181613: suicide: sys: trap: divide error pc=0x000023fd
>>>[/color]
>>[/color]
>[/color]
Re: [9fans] How to read/write pixels from Memimage
> Another question: in RGB24, how are colors composited: 0x00RRGGBB or[color=blue]
> 0xRRGGBB00? I can't seem to get a picture that is solid red; just a
> wacky line art picture.[/color]
read image(6). all the details are spelled out there. (you likely want an alpha
channel in your image, so that each pixel is 4 bytes.)
- erik
Re: [9fans] How to read/write pixels from Memimage
9fans is not a blog, try blogger.com[color=blue]
>
>[color=green]
>> (you likely want an alpha
>>
>> channel in your image, so that each pixel is 4 bytes.)
>>[/color]
>
> Apparently, my RGB24 manipulation was wrong, and now it works like a
> charm. The next step is to support a construct like new.red and to
> eliminate the use of undocumented stuff (I peeked in
> /sys/include/draw.h and /sys/src/libbio/brdstr.c for some hacks).
>[/color]
Re: [9fans] How to read/write pixels from Memimage
On Jan 28, 2008 1:24 AM, <mattmobile@proweb.co.uk> wrote:[color=blue]
> 9fans is not a blog, try blogger.com[/color]
now now now :-)
Why give the guy a hard time, he's actually discussing real coding he
is doing :-)
ron