[REBOL] Re: Not so smart pick !
From: carl:cybercraft at: 29-Dec-2002 15:33
On 29-Dec-02, pat665 wrote:
> Hi List,
> Trying to manipulate image, I have found this :
>>> i: make image! 2x2
> == make image! [2x2 #{000000000000000000000000}]
>>> poke i 2 white
> == make image! [2x2 #{000000FFFFFF000000000000}]
>>> white
> == 255.255.255
>>> pick i 2
> == 255.255.255.0
> Pick seems to be right for locating the value, but wrong when
> picking it. We got an extra byte.
What version are you using? I get...
>> img: make image! 2x2
== make image! [2x2 #{000000000000000000000000}]
>> poke img 2 1.2.3
== make image! [2x2 #{000000030201000000000000}]
>> pick img 2
== 1.2.3
with View 1.2.1.
If a later version though, I wouldn't think it's a bug, but just
support for 24bit images. (If that's the case though, then the
image's binary display should be showing 16 bytes and not just 12, so
that could be considered a bug.) I assume you can poke in a 4-byte
tuple and get the correct 4-byte tuple back with pick?
> From RCUG (rebolcore-16.html#_Toc487519976), it looks like a bug to
> me:
> <<The pixel values of an image are obtained using pick and changed
> using poke . The value returned by pick is an RGB tuple value. The
> value replaced with poke also should be a tuple value.
> Picking specific pixels:
> probe pick img 1
> probe pick img 1500
> Poking specific pixels:
> poke img 1 255.255.255
> probe pick img 1
>>>
> Is there a way of getting rid of the extra byte?
>>> pix: pick i 2
>>> remove back tail pix ; not good
>>> pix: copy/part pix 3 ; not good
Tuples aren't series, unfortunately, which is why that approach
doesn't work. The following will do what you want, but there may be
a better way...
>> tup: 1.2.3.4
== 1.2.3.4
>> make tuple! reduce [tup/1 tup/2 tup/3]
== 1.2.3
You could also get the 3-byte tuple directly from the image, since
they are a series...
>> img: make image! 2x2
== make image! [2x2 #{000000000000000000000000}]
>> poke img 2 1.2.3
== make image! [2x2 #{000000030201000000000000}]
>> make tuple! to-binary copy/part skip img 5 3
== 1.2.3
Hmmm. Anyone know the reason why make image! displays its binary
values the other way around to how normal binaries are displayed? ...
>> to-binary img
== #{00000000000102030000000000000000}
--
Carl Read