r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[rebcode] Rebcode discussion

Ladislav
23-Oct-2005
[676x4]
then I think, that your suggestion is exactly like mine...
(as opposed to Gabriele's proposal, that is different)
May I ask you to put it to RAMBO?
(both USE and IF look worth it, maybe you can have each in its own 
ticket?)
Geomol
23-Oct-2005
[680]
Would it be nice to have the raised to exponent (**) operation in 
rebcode? And with decimal exponent. Maybe we should ask Carl about 
that before the first version is closed? Maybe also root operation? 
(Not just square-root, as we already have.)
Ladislav
23-Oct-2005
[681]
a ** b can be "translated" as follows:

log-e a
muld a b
exp a

similarly root:

log-e a
divd a b
exp a
Oldes
23-Oct-2005
[682]
;this is probably key rebcode if you want to deal with colors of 
image pixels:)
rgb-to-dec: rebcode[r g b][
	to-dec r r
	to-dec g g
	to-dec b b
	muld g 256.0
	muld r 65536.0
	addd b g
	addd b r
	return b
]
Pekr
23-Oct-2005
[683]
and alpha? :-)
Oldes
23-Oct-2005
[684]
rgba-to-int: rebcode[r g b a][
	to-dec r r
	to-dec g g
	to-dec b b
	to-dec a a
	muld g 256.0
	muld r 65536.0
	muld a 16777216.0
	addd b g
	addd b r
	addd b a
	to-int b b
	return b
]
Geomol
23-Oct-2005
[685]
Thanks Ladislav! Been a while since I learned about the math. I can 
cope with it using those 3 operations instead of exponent or root.
Cyphre
24-Oct-2005
[686]
Oldes, I think this is a bit faster ;)
rgba-to-int: rebcode [r g b a][
	lsl a 24
	lsl r 16
	lsl g 8
	add a r
	add a g
	add a b
	return a
]
BrianH
24-Oct-2005
[687]
Cyphre, use OR instead of ADD and there will be no troubles with 
arithmetic overflow. It'll be faster too.
Cyphre
24-Oct-2005
[688x2]
I think there shouldn't be aritmetic overflows as the passed arguments 
are meant within range 0-255 but you are right that OR should be 
even faster!
so probably final version:
rgba-to-int: rebcode [r g b a][
	lsl a 24
	lsl r 16
	lsl g 8
	or a r
	or a g
	or a b
	return a
]
BrianH
24-Oct-2005
[690]
There might be a problem with arithmetic overflow if a < 127, as 
lsl a 24 would result in a negative integer, but I may be wrong here. 
Still, why risk it?
Rebolek
24-Oct-2005
[691]
>> rgba-to-int 255 255 255 255
== -1
BrianH
24-Oct-2005
[692]
Kru, which version did you use?
Rebolek
24-Oct-2005
[693]
last one
BrianH
24-Oct-2005
[694]
Cool, it works the way I thought it would :)
Cyphre
24-Oct-2005
[695x2]
BTW negative integer doesn't  matter when changing pixels in IMAGE!
>> to-integer to-binary  255.255.255.255
== -1
Rebolek
24-Oct-2005
[697]
but to integer! to binary! [issue!] is not same as rgba-to-int
Cyphre
24-Oct-2005
[698]
OTOH the pixelformat of accesing IMAGE! in RebCode id ARGB
Rebolek
24-Oct-2005
[699]
>> rgba-to-int 255 255 255 1
== 33554431
>> to-integer to binary! 255.255.255.1
== -255
Cyphre
24-Oct-2005
[700x3]
>> to-integer to-binary  1.255.255.255
== 33554431
ALPHA is the first component
(in Rebcode)
BrianH
24-Oct-2005
[703]
Really?
Cyphre
24-Oct-2005
[704]
rgba-to-int: rebcode [r g b a][
	lsl a 24
	lsl r 16
	lsl g 8
	or a r
	or a g
	or a b
	return a
]

draw-pix: rebcode [r g b a][
	apply a rgba-to-int [r g b a]
	poke img 1 a
]

update-pixel: does [
	do draw-pix col/1 col/2 col/3 col/4
	probe img
	show i
]

col: 0.0.0.0
img: make image! 1x1

view layout [
	backcolor black
	i: image img 100x100
	scroller 200x16 [
		col/1: to-integer face/data * 255
		update-pixel
	]
	scroller 200x16 [
		col/2: to-integer face/data * 255
		update-pixel
	]
	scroller 200x16 [
		col/3: to-integer face/data * 255
		update-pixel
	]
	scroller 200x16 [
		col/4: to-integer face/data * 255
		update-pixel
	]
]
Rebolek
24-Oct-2005
[705]
not if you do PICK on image!
BrianH
24-Oct-2005
[706]
I mean in regular REBOL code.
Volker
24-Oct-2005
[707]
I guess Cyphre has a good qualification for such statements ;)
Cyphre
24-Oct-2005
[708]
I REBOL the pixelformat is RGBA due to tuple! behaviour (you can 
left the last value of tupple == opaque pixel)
Rebolek
24-Oct-2005
[709]
So another coversion needed :)
Cyphre
24-Oct-2005
[710x2]
In REBCODE you are accessing image! internally so the pixelformat 
is ARGB.
Kru: yes, in Rebol there is conversion done. In Rebcode you are at 
full speed ;)
Rebolek
24-Oct-2005
[712]
Cypher, have you looked at the apply problem?
Cyphre
24-Oct-2005
[713]
not yet
BrianH
24-Oct-2005
[714]
There's an apply problem?
Rebolek
24-Oct-2005
[715]
trying to reproduce the problem I've just crashed REBOL with CRASH 
Should not happen
Cyphre
24-Oct-2005
[716]
Maybe not a problem, but overhead?
Rebolek
24-Oct-2005
[717]
And REBOL ate all memory
Cyphre
24-Oct-2005
[718]
can you post the code?
Ladislav
24-Oct-2005
[719]
yes, show us!
Rebolek
24-Oct-2005
[720x2]
two testing functions:
>> mulr: rebcode [a][mul a 2 return a]
>> mull: rebcode [a][loop 10000000 [apply a mulr [a]] return a]
Cyphre
24-Oct-2005
[722]
From my tests calling a REBCODE function (or subroutine) using APPLY 
is by 100% slower than reusing the same code.
Rebolek
24-Oct-2005
[723]
first test: xt: now/time/precise loop 10000000 [mulr 2] now/time/precise 
- xt
Cyphre
24-Oct-2005
[724]
Is that neccessary?
Rebolek
24-Oct-2005
[725]
second test: xt: now/time/precise mull 2 now/time/precise - xt