Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] explanation, gurus? :-) (image memory representation)

From: petr::krenzelok::trz::cz at: 21-Aug-2001 0:21

Hi, I visited today my friend, who helped me to do .dll library in gcc under Windows. Kind of a pain :-) We tried to prepare small function for image manipulation. I remember Jeff stating that the way to allow library space code to access rebol word data is by using pointer thru structurre .. ( ) Because we are trying a little bit to prepare ourselves for our camera, and data received, we did a small function. We receive primare data in bytes (binary form), so receiving them thru rebol port, we will get something like: ->> to-string #{FFFF} == "" for FFFF = 65535 pixel value. As we need to convert to RGB, we did it in following way: str1 ... our raw image data received from camera in above form str2 ... preallocated string (we have to use insert/dup to prevent library crash), of size 3 * (lenght? str1) len ... length of image data we send into library ... We found out, that once we send string into library, it is hopefully not copied (or we think so), but only pointer is received and data is manipulated directly in 'str1 or 'str2 rebol storage space. So the result is - our 'str2 contains data "ready" to display ... So now is the time to convert it to image datatype: img: make image! reduce [XxY str2] view layout [image img] So - it somehow works (or so did our very primitive test example ...) Now the question is - we have data in display, or let's say - 'img already exists, and we would like to do something directly in it (e.g. user adjusted img data by some effect, e.g. brightness). How to easily get the image data back into string, avoiding copying data? I came to a little bit ugly aproach :-) mold img, cutted off "#{.....}" string, loaded it, converted into string, ready to be sent into library once again. But, with large images, it is sure time consuming aproach :-) Would using structures help here? Would it allow us to modify image data directly? I am a little bit confused by rebol "polymorphism" though: img: make image! [1x1 #{FFFFFF}] ->> first img == 255.255.255 ->> second img == 0.255.255 ->> third img == 99.0.255 ->> fourth img == 108.99.0 where do second, third, fourth come from? What about this one? img: make image! [10x10 #{FFFFFF}] == make image! [10x10 #{ FFFFFFCC96CFD8A9CD0000000A00004C96CFE8B0CD0000000A00001C90CF E8B0CD0000000A0000C4E3D9E8B0CD0000000A000084E... ->> view layout [size 100x100 backdrop img] Christopher Ross-Gill: loop 20 [probe make image! [1x1]] courtesy of Chris Ross-Gill, midnight RIM session :-) Ryan Cole: I: make image! [1x1] Ryan Cole: >> I: make image! [1x1] == make image! [1x1 #{00E6E1}] Ryan Cole: >> I: make image! [1x1] == make image! [1x1 #{00E7E1}] Ryan Cole: its different every time. Ryan Cole: >> i: make image! [1x2 #{FFDDCCBBAA99}] == make image! [1x2 #{FFDDCCBBAA99}] ->> next i == make image! [1x2 #{DDCC00AA9900}]
Ryan Cole: The next thing was how next, first and second work on the image binary data, just by offsetting by one, instead of 3 as you would expect. courtesy of Ryan Cole :-) OK, let's hope our Rebol gurus will find some nice explanations ...:-) Thanks and Cheers, -pekr-