World: r4wp
[#Red] Red language group
older newer | first last |
Bo 6-Feb-2013 [5435x4] | If I wanted to access JPG pixel data in Red/System, is there an easy way to do that? |
As the youngsters say, EPIC! I just compiled and ran my first Red/System program on the Raspberry Pi running Arch Linux. | |
But I still want to figure out how to access JPG pixel data. :-) | |
Reading the Red/System Documentation on red-lang.org, I don't see any way to access files. IIRC, someone said that wasn't implemented yet? | |
Pekr 7-Feb-2013 [5439] | Bo - R/S is low level - mostly a wrapper to C to enable Red like syntax. It will not contain stuff to open files and do more advanced things imo, unless you link to some library and create a wrapper for such a purpose. I am too eagerly waiting for Red to get more advanced stuff. I think, that once Doc finishes the interpreter stuff ec., he is back to objects/ports, and then networking/files IO will come and more fun begins :-) |
DocKimbel 7-Feb-2013 [5440x2] | FOREVER: not yet supported by the compiler. |
mostly a wrapper to C Red/System doesn't wrap C, it replaces it. ;-) | |
Pekr 7-Feb-2013 [5442] | :-) |
Kaj 7-Feb-2013 [5443x11] | Congrats, Bo |
Feels good, doesn't it? :-) | |
File I/O is available for Red/System in the C library binding: | |
http://red.esperconsultancy.nl/Red-C-library/dir?ci=tip | |
There's also standard input for Red there. Further, there's a wrapper for full-file I/O for both Red and Red/System that includes network I/O through the cURL binding: | |
http://red.esperconsultancy.nl/Red-common/dir?ci=tip | |
This gets you reading and writing files, but you have to do any decoding yourself. So for reading JPEG data, you would probably write a binding to LibJPEG | |
If it doesn't need to be as specific as JPEG, you could write a binding to some wrapper library that supports multiple formats. For example, a simple BMP loading function is available for Red/System in the SDL binding: | |
http://red.esperconsultancy.nl/Red-SDL/dir?ci=tip | |
An example of loading an image is here in PeterPaint: | |
http://red.esperconsultancy.nl/Red-SDL/dir?ci=tip&name=examples | |
Pekr 7-Feb-2013 [5454x2] | or xnview command line - then you just need a CALL .... |
ah, wrong, I thought that you just need an image info, not actually an access to the bitmap data ... | |
Kaj 7-Feb-2013 [5456x2] | There's also a basic binding to image loading in GDK, so that would load you all image types that GDK supports, including JPEG: |
http://red.esperconsultancy.nl/Red-GTK/dir?ci=tip | |
Bo 7-Feb-2013 [5458x3] | GTK sounds like a winner. Thanks for all the tips, guys! |
For future reference, is it possible to use Red/System for commercial products? Are there any restrictions? | |
Also, does anyone have an idea of how fast Red/System code is compared to comparable C code? | |
BrianH 7-Feb-2013 [5461x2] | It's as fast as C core with the optimizer turned off, at least for now. |
core -> code | |
Bo 7-Feb-2013 [5463] | Sorry for my ignorance, but how much faster is C with the optimizer turned on? 2x faster, 10% faster...? |
DocKimbel 7-Feb-2013 [5464] | No restriction for commercial use of binaries produced by Red and Red/System compilers. |
Kaj 7-Feb-2013 [5465] | Bo, in my tests, GCC produced twice as fast code with the regular optimisation of -O2. More than I thought |
BrianH 7-Feb-2013 [5466x2] | Bo, it depends on the code in question and the processor it's running on. It could be the same speed, it could be many times faster, and for some code it could be resolved completely at compile time and replaced with a constant. |
We could run similar optimizations on Red/System code, as soon as we've implemented them. | |
Bo 7-Feb-2013 [5468] | Great! |
BrianH 7-Feb-2013 [5469] | Some optimizations will be very difficult or impossible to do if Red/System is used as the intermediate language, because those optimizations sometimes depend on the semantic model of the intermediate language, and Red/System doesn't have the semantic model of a compiler intermediate language. Optimization is hard work and people get PHDs for doing it. We can hope to catch up with modern C compilers, but don't expect it. One advantage is that Red is a high-level-enough language that an optimizer can make assumptions that a C compiler can't, so it is possible that we could get better code - it depends on the language and how much time we want to allocate on optimization. |
Bo 7-Feb-2013 [5470] | I'm feeling nostalgic. I used to hand-craft machine code on the 6502/6510 series of processors back in the 80's, so I have an idea of what you're talking about. There are some pretty neat tricks you can do when you're dealing with memory addresses directly. I crafted more than one self-modifying program to squeeze every bit of computing power out of a processor. I know that a lot of that ability has been removed by protected memory and abstraction, though. |
Bo 8-Feb-2013 [5471] | Kaj, now that I've had a chance to do some work with Red/System, it's amazing to me how much work you've already done on adding features! Here's something that I think would really help out a lot of us who want to make use of all your hard work. Would it be hard to create http://red.esperconsultancy.nl/index.htmlwith a link to all the Red stuff you've done? The only way I found what I needed to download was by searching through AltME for links, and had to manually enter in things like Red-common, Red-C-library, Red-cURL, Red-GTK, etc. |
Kaj 8-Feb-2013 [5472x6] | Thanks. A website is planned, but I haven't gotten around to it yet. I figure the time is better spent doing Red work |
What I've done so far is the download.r script: | |
http://red.esperconsultancy.nl/Red-test/dir?ci=tip | |
If you combine it with Fossil, it will set up your entire environment automatically | |
It will also auto-update all bindings to new versions | |
Have you seen my 6502 emulator in Red/System yet? :-) | |
Bo 8-Feb-2013 [5478] | I saw that you wrote a 6502 emulator, but haven't had time to look at it yet. Sounds like a fun project! |
Kaj 8-Feb-2013 [5479] | It is. :-) If you run the download.r script, you'll get it automatically |
Bo 8-Feb-2013 [5480x2] | Recalling from the days when I didn't have an assembler, I had most of the decimal equivalents of the commands remembered because I input values into memory manually when I was writing code. Going back in my brain 20 years, I believe LDA (Load the accumulator) was 169. :-) |
So 'with in Red/System is like 'context in R2? | |
Kaj 8-Feb-2013 [5482x3] | It's more like USE. CONTEXT exists as such in Red/System, but it's a compile time namespace instead of a runtime object |
You first define a CONTEXT, then you can use it with WITH, or path notation | |
You're right about LDA #. :-) It's also $A9. I had the same problem, wrote a disassembler in Atari BASIC until I could get hold of an assembler, so also have a considerable part of my brain dedicated to such numbers :-) | |
older newer | first last |