to-offset
[1/10] from: rotenca:telvia:it at: 12-Apr-2002 17:56
What is the best way to find the offset of a pixel in an image given a pair?
to-offet: func [image [image!] pos [pair!]][ ??? ]
>> to-offset svv/radio.bmp 5x2
== 73
---
Ciao
Romano
[2/10] from: greggirwin:mindspring at: 12-Apr-2002 11:32
Hi Romano,
<< What is the best way to find the offset of a pixel in an image given a
pair?
to-offet: func [image [image!] pos [pair!]][ ??? ]>>
I wrote an article for the latest 'zine on REBOLForces that deals with this.
Here are some relevant snippets.
to-index: func [pos [pair!] cols [integer!] ] [
pos/y - 1 * cols + pos/x
]
pick-xy: func [data [series!] pos [pair!] cols [integer!] ] [
pick data to-index pos cols
]
poke-xy: func [data [series!] pos [pair!] cols [integer!] value ] [
poke data to-index pos cols value
]
These wrappers just reduce the number of parameters we have to pass, and
make it clear exactly what we're doing. I.e. working with images and pixels.
pick-pixel: func [img [image!] pos [pair!]] [
pick-xy img pos img/size/x
]
poke-pixel: func [img [image!] pos [pair!] value [tuple!]] [
poke-xy img pos img/size/x value
]
HTH!
--Gregg
[3/10] from: rotenca:telvia:it at: 12-Apr-2002 22:11
Hi Gregg,
thank, you confirm me there is not a more direct way to pick an image offset
than multiply.
BTW, first pos is faster than pos/x
---
Ciao
Romano
[4/10] from: rotenca:telvia:it at: 13-Apr-2002 18:15
Hi Gregg,
> to-index: func [pos [pair!] cols [integer!] ] [
> pos/y - 1 * cols + pos/x
> ]
>> to-index 0x0 3
== -3
This should be 1, or not?
---
Ciao
Romano
[5/10] from: greggirwin:mindspring at: 13-Apr-2002 12:20
Hi Romano,
<<
> to-index: func [pos [pair!] cols [integer!] ] [
> pos/y - 1 * cols + pos/x
> ]
>> to-index 0x0 3
== -3
This should be 1, or not?
>>
Not. :) The lowest pair bound you use should be 1x1 (no bounds checking in
the above sample function). I don't like 0 to n-1 numbering.
--Gregg
[6/10] from: rotenca::telvia::it at: 14-Apr-2002 1:13
Hi Gregg,
> >> to-index 0x0 3
> == -3
>
> This should be 1, or not?
> >>
>
> Not. :) The lowest pair bound you use should be 1x1 (no bounds checking in
> the above sample function). I don't like 0 to n-1 numbering.
Mhhhh, offset in Rebol are 0x0 based and then
>> to-index: 1x1 3
== 3
Again, this should be 1, or not?
---
Ciao
Romano
[7/10] from: greggirwin:mindspring at: 14-Apr-2002 10:14
Hi Romano,
<<
> Not. :) The lowest pair bound you use should be 1x1 (no bounds checking in
> the above sample function). I don't like 0 to n-1 numbering.
Mhhhh, offset in Rebol are 0x0 based and then
>>
Are you saying that REBOL uses 0x0 to (n-1)x(n-1) itself? Can you give me an
example? I do like to maintain consistency with native design choices when I
can.
<<
>> to-index: 1x1 3
== 3
Again, this should be 1, or not?
>>
It does. You have an extra colon in there. :)
>> to-index 1x1 3
== 1
--Gregg
[8/10] from: rotenca:telvia:it at: 15-Apr-2002 17:20
Hi Gregg,
> Mhhhh, offset in Rebol are 0x0 based and then
> >>
>
> Are you saying that REBOL uses 0x0 to (n-1)x(n-1) itself? Can you give me an
> example? I do like to maintain consistency with native design choices when I
> can.
1) face/offset start from 0x0
First, a viewer:
display: func [i [image!] /size sz][
view center-face layout compose [
box (either size [sz] [i/size]) i]
]
then try this:
display/size to-image layout [
origin 0x0
t1: box 10x10 red
at 1x1
t2: box 8x8 blue
] 100x100
print t1/offset
print t2/offset
2) draw position start from 0x0
Look at this:
layout [
t3: box red 10x10 effect [
draw [
pen white
line 0x0 9x0
pen black
line 1x9 8x9
]
]
]
display/size to-image t3 100x100
> It does. You have an extra colon in there. :)
Pardon, my error!
---
Ciao
Romano
[9/10] from: rotenca:telvia:it at: 16-Apr-2002 16:09
Hi Gregg,
> 1) face/offset start from 0x0
> 2) draw position start from 0x0
I forgot the most important:
3) event offset start from 0x0
---
Ciao
Romano
[10/10] from: greggirwin:mindspring at: 16-Apr-2002 19:15
Hi Romano,
Ahh, yes. If my brain was working properly I would have thought instantly of
ORIGIN for layouts. Well...this is annoying. :(
Thanks for catching this. I'll have to think about it some more to decide
what I want to do.
--Gregg