• Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r4wp

[#Red] Red language group

Bo
27-Jun-2013
[8920]
I'm amazed by how fast Red/System is.
PeterWood
27-Jun-2013
[8921]
Excellent !
Kaj
27-Jun-2013
[8922]
Your code could be optimised a bit :-)
james_nak
27-Jun-2013
[8923]
Kaj, I think there was something to the jarsigner being commented 
out in the file. I'll have to wait for Doc and Pekr to chime in.
Kaj
27-Jun-2013
[8924]
Yes
Bo
27-Jun-2013
[8925]
I'd love to learn how to optimize my code!
Kaj
27-Jun-2013
[8926]
Are you low on memory?
PeterWood
27-Jun-2013
[8927]
A simple one:

im1:  (as integer! r + g + b) / 3
Kaj
27-Jun-2013
[8928]
That won't work
PeterWood
27-Jun-2013
[8929x2]
I meant :

im1: (as integer! r) + (as integer! g) + (as integer! b) / 3
2 additions & 1 division against 3 divisions & 2 additions
Kaj
27-Jun-2013
[8931x2]
im1: (as-integer img1/r) + img1/g + img1/b / 3
But yes, that was my general idea
PeterWood
27-Jun-2013
[8933]
:-)
Bo
27-Jun-2013
[8934]
I now have a working rudimentary motion detection algorithm.  Now 
it's time to tune it with my special formula.
Kaj
27-Jun-2013
[8935]
If you're not memory constrained, you can leave the / 3 out completely 
and compare two grayscales as integer values
PeterWood
27-Jun-2013
[8936x3]
Im1 is already an integer in Bo's code.
if you're desparate for a few millisecs, reversing the loop to start 
at the end and work toward the front will help.
(Subtraction being marginally faster then addiiton).
Kaj
27-Jun-2013
[8939]
That could be cast to byte again, to save the grayscale, but yes, 
there's no need to divide by 3 if it's just for the comparison
Bo
27-Jun-2013
[8940]
I'm passing the processed image back out to Rebol to convert back 
into an image for visual verification of the motion detection algorithm. 
 That part works fine. :-)
Kaj
27-Jun-2013
[8941x3]
Subtraction faster than addition? That would surprise me. It's comparison 
to 0 that may be faster
Further, the bumping of r, g and b each iteration is relatively much 
work, because you're also having to use them as indexes. It's more 
efficient to make a byte pointer for each and advance those
But it's probably even faster to iterate through the image with one 
integer pointer, because the pixels happen to be four bytes, and 
then use indexes of 2, 3 and 4 for r, g and b
Bo
27-Jun-2013
[8944]
So are you saying that if 'img1 is a pointer, to do the following?

	img1r: img1 + 2
	img1g: img1 + 3
	img1b: img1 + 4

and then

	img1r: img1r + 4
	img1g: img1g + 4
	img1b: img1b + 4

would be faster than what I'm doing now?
PeterWood
27-Jun-2013
[8945]
You're correct. I checked and the optimisation benefit through "loop 
inversion" apparently comes from reducing the number of jumps in 
the underlying code not difference in speed in atrithmetic.
Bo
27-Jun-2013
[8946]
OK, so this would be even faster:

r: 2
g: 3
b: 4
until [
	...do stuff here...
	img1: img1 + 4
	...comparison...
]
Kaj
27-Jun-2013
[8947]
Bo, yes, that would be more efficient, because you can then index 
with 1
Maxim
27-Jun-2013
[8948]
Bo, that's basically how it'd be done in C
PeterWood
27-Jun-2013
[8949]
Kaj do you know if Red/System generates the same code for :

	img1/value and img!/1 ?
Kaj
27-Jun-2013
[8950]
Yes, it's equivalent
Bo
27-Jun-2013
[8951x2]
Thanks for the tips, guys!
There is no way for Red/System to read a directory listing, is there?
Kaj
27-Jun-2013
[8953x2]
Perhaps fastest:
pixel: as int-ptr! img1 + 1
...
rgb: as-binary pixel
im1: (as-integer rgb/1) + rgb/2 + rgb/3 / 3
pixel: pixel + 1
That code would have to be tested, depends on lots of details
Bo
27-Jun-2013
[8955]
I'm only looping 20'000 times or so...not a lot for Red/System to 
handle. ;-)
Kaj
27-Jun-2013
[8956]
But it's going to run on a Raspberry in realtime
Bo
27-Jun-2013
[8957x2]
I was joking. :-)
Can Red/System read a directory listing?
Kaj
27-Jun-2013
[8959x3]
It should, but you have to interpret the data manually
I haven't looked into it yet
I see you'd need some extra definitions that aren't in my C library 
binding yet
Pekr
28-Jun-2013
[8962x2]
james & kaj: I have JDK installed too, you should be sure, that you 
can call java, javac from whatever dir = it is in the system lookup 
PATH. And - Rebol was downloading supporting tools, then it hang 
in console, but in fact, there was a dialog box hidden in the background, 
asking me for write permission. Unless you allow that, the tools 
are not going to be saved into requested directory ...
My directory structure is:

build\tools:

\api\android.jar
jli.dll
aapt.exe
keytool.exe
zipalign.exe
DocKimbel
28-Jun-2013
[8964]
@james_nak, first delete any jarsigner exe you might have downloaded 
or copied outside of the java folders. Then try to run jarsigner 
from the Red folder, if it says it can't be found, then you have 
to add to your PATH environment variable, the path to the java/bin/ 
folder of your installed JDK.
Pekr
28-Jun-2013
[8965]
Doc - how do your slides go? :-) I hope you have prepared many questions 
for Carl :-)
DocKimbel
28-Jun-2013
[8966x2]
Barely started, gone to see "Man of Steel" yesterday night to get 
some inspiration. ;-)
I'm trying to extend the build script for other platforms, but my 
Ubuntu 11.04 image somehow got stuck with old source repository versions 
and no way to install/update any packages...So I now need to install 
a 12.04 package in order to check the requirement for the build script 
and test it. I'm baffled that the support for a 2 years old Ubuntu 
version is so bad...
Pekr
28-Jun-2013
[8968]
How was the movie? Seen trailer, liked it ...
DocKimbel
28-Jun-2013
[8969]
I've found the trailer better than the movie, I was quite disappointed 
(I'm a huge DC comics fan)...the "epic" moments weren't that much 
epic to me, so the whole movie (2h30) was a bit borring...The Krypton 
civilisation and display technology were the most interesting parts 
to me. ;-) Actually, the movie reminded me a lot the "Tree of Life", 
like a mosaic of sequences, and with almost the same soporific audio 
track... No real breathtaking moments...Even the mandatory "love 
story" sounds fake... The fx +  3D was too much to me, you're quickly 
lost in the fight sequences. But that's just my opinion, others might 
like it very much. ;-)