World: r4wp
[#Red] Red language group
older newer | first last |
Kaj 7-Feb-2013 [5449x5] | 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 :-) | |
Bo 8-Feb-2013 [5485x2] | With the following code: #include %GTK.reds with gdk [ err: declare struct! [value [g/g-error!]] myimg: load-image "image.jpg" err ] I get the following error: *** Compilation Error: invalid literal syntax: [value [g/g-error!]] If I change it to: err: declare struct! [value [c-string!]] I get the following error: *** Compilation Error: argument type mismatch on calling: gdk/load-image *** expected: [struct! [value [g/g-error!]]], found: [struct! [value [c-string!]]] |
What am I missing? | |
Kaj 8-Feb-2013 [5487x2] | You can't use path notation on types. I've been trying to coerce Doc into implementing that, but he doesn't want to. :-/ |
So you have to use an extra WITH g [...]. You can combine that as WITH [gdk g] [...] | |
Bo 8-Feb-2013 [5489] | Aha! That did the trick! |
Kaj 8-Feb-2013 [5490x3] | By the way, if you only use images, you could do with including only GDK.reds. That would cut down on the dependencies |
Instead of your struct definition, you can use g-error-reference! which is already defined in GLib.reds | |
There's an example of using load-image in GTK.reds in the icon function | |
Bo 8-Feb-2013 [5493x4] | Thanks! When I use load-image, it looks like it is returning a pointer. Is that correct? |
For instance: 00DFD2B8 | |
If 'load-image returns a pointer, how do I know when I have reached the end of the image? | |
Better yet, assuming 'load-image returns a pointer, how do I access the first memory location referenced by the pointer? | |
Kaj 8-Feb-2013 [5497x2] | See the function spec in GDK.reds. It returns a pointer to an image! struct, so if you want to access the image internally, you have to go by that struct definition |
As you can see in the same file, I haven't finished the definition of that struct, because I don't have to look inside the image | |
older newer | first last |