Newbie questions about Pliant
Sized data types
|
Message posted by maybe Gollum on 2004/01/27 18:22:59 |
Why does this program not compile?
function test var Int8 z := 1 console z
test
Pliant complains:
Failed to compile Int8 ()
Do I need to include a module? |
Message posted by hubert.tonneau on 2004/01/28 10:34:38 |
You have to write: console (cast z Int)
The explaination is that 'from string' and 'to string' generic methods are written for 'Int', 'uInt' and 'Intn' data types, but not for things like 'Int8' or 'uInt16_hi' |
Message posted by marcus on 2004/01/28 21:16:46 |
In one of my courses, students are asked to implement a filter for ppm images.
In ppm images, if the max colour value > 25, colour components are encoded as two bytes in the file
Myself, and my students, are not very sure about which colour datatype to use for the above case. That is, for images with max colour component < 255, no problem, the code below would work
var Int8 r8 g8 b8 for (var Int y) 0 h-1 for (var Int x) 0 w-1 s raw_read addressof:r8 1 s raw_read addressof:g8 1 s raw_read addressof:b8 1 (img pixel x y) map ColorRGB888 := color rgb r8 g8 b8
But for the case max colour > 255, the datatype ColorRGB888 wouldn't be correct, and I would have to replace it with ColorRGB, right? That is,
var Int8 r8 g8 b8 for (var Int y) 0 h-1 for (var Int x) 0 w-1 s raw_read addressof:r8 1 s raw_read addressof:g8 1 s raw_read addressof:b8 1 (img pixel x y) map ColorRGB := color rgb r8 g8 b8
I did that, and Pliant did not complain.
However, I am not sure if the automatic casting would not damage the numbers. I could not prepare a test case for that.
|
Message posted by hubert.tonneau on 2004/01/29 10:45:05 |
If the image is 8 bits per component, you could read it with:
var uInt8 r8 g8 b8 for (var Int y) 0 h-1 for (var Int x) 0 w-1 s raw_read addressof:r8 1 s raw_read addressof:g8 1 s raw_read addressof:b8 1 (img pixel x y) map ColorRGB := color rgb r8 g8 b8
Also, there is an absolutely more efficient way to do it:
var Address buffer := memory_allocate img:line_size null for (var Int y) 0 h-1 s raw_read buffer img:line_size img write 0 y buffer img:size_x memory_free buffer
Please also notice that Pliant as a PPM filter, so you might also want to try something like: module "/pliant/graphic/filter/io.pli" var Link:ImagePixmap img :> new ImagePixamp img load "file:/..." ""
Pliant graphic library does not provide 16 bits per components image handling. More precisely, the image format does not care, only the gamut does, and I have not defined something like an 'rgb16' gamut. The reason is that 16 bits per component is very much like a joke. Basically, it does have meaning only if the gamma is very bad, I mean if it is linear as an example. So, 16 bits images truely exists at scanner physical interface level as an example, but the imediat action of the driver or software should be to apply a gamma and maybe a fiew other basic per component corrections, and then reduce to 8 bits through dropping the low bits (maybe with using dithering to do it properly) before storing. So having 16 bits per component file format is not really usefull, even if it would not be a big deal to add it.
Anyway, if the image is 16 bits per component, you could read it with (also dropping the 8 low level bits that way is not optimal):
var uInt16 r16 g16 b16 # might also be uInt16_hi or uInt16_li depending on the file encoding for (var Int y) 0 h-1 for (var Int x) 0 w-1 s raw_read addressof:r16 2 s raw_read addressof:g16 2 s raw_read addressof:b16 2 (img pixel x y) map ColorRGB := color rgb r16\256 g16\256 b16\256
|