48design
02-21-2012, 05:10 PM
Hi!
I tried the following to create a PFM (portable float map) file:
(
local out_name = getSaveFileName types: "Portable Floatmap (*.pfm) |*.pfm|" filename:"c:\\"
local out_file = createfile out_name
local img = bitmap 10 10 hdr:true
for x=0 to img.width-1 do
(
for y=0 to img.height-1 do
(
setPixels img [x,y] #([1.5,2.3,3.3333,1])
)
)
display img
local header_magic = "PF"
local header_comment ="# pfm created with MaxScript by 48design"
local header_width = img.width
local header_height = img.height
local header_byteOrder = "-1.0000"
format "%\n%\n% %\n%\n" header_magic header_comment header_width header_height header_byteOrder to:out_file
close out_file
free out_file
f = fopen out_name "ab"
for x=0 to img.width-1 do
(
for y=0 to img.height-1 do
(
px = getPixels img [x,y] 1
-- write bytes
fseek f -1 #seek_cur
WriteFloat f (px[1].r/255 as float)
fseek f -1 #seek_cur
WriteFloat f (px[1].g/255 as float)
fseek f -1 #seek_cur
WriteFloat f (px[1].b/255 as float)
)
)
fflush f
fclose f
--format "[%,%,%]" (px[1].r/255) (px[1].g/255) (px[1].b/255)
)
This didn't work. Opening in Photohop gives different results than I thought it should...
I'm not one of those hardcore programmers but after reading those two webpages I thought it can't be that hard, even for MaxScript. Wrong?
http://netpbm.sourceforge.net/doc/pfm.html
http://people.cs.kuleuven.be/~ares.lagae/libpfm/index.html (http://people.cs.kuleuven.be/%7Eares.lagae/libpfm/index.html)
I tried the following to create a PFM (portable float map) file:
(
local out_name = getSaveFileName types: "Portable Floatmap (*.pfm) |*.pfm|" filename:"c:\\"
local out_file = createfile out_name
local img = bitmap 10 10 hdr:true
for x=0 to img.width-1 do
(
for y=0 to img.height-1 do
(
setPixels img [x,y] #([1.5,2.3,3.3333,1])
)
)
display img
local header_magic = "PF"
local header_comment ="# pfm created with MaxScript by 48design"
local header_width = img.width
local header_height = img.height
local header_byteOrder = "-1.0000"
format "%\n%\n% %\n%\n" header_magic header_comment header_width header_height header_byteOrder to:out_file
close out_file
free out_file
f = fopen out_name "ab"
for x=0 to img.width-1 do
(
for y=0 to img.height-1 do
(
px = getPixels img [x,y] 1
-- write bytes
fseek f -1 #seek_cur
WriteFloat f (px[1].r/255 as float)
fseek f -1 #seek_cur
WriteFloat f (px[1].g/255 as float)
fseek f -1 #seek_cur
WriteFloat f (px[1].b/255 as float)
)
)
fflush f
fclose f
--format "[%,%,%]" (px[1].r/255) (px[1].g/255) (px[1].b/255)
)
This didn't work. Opening in Photohop gives different results than I thought it should...
I'm not one of those hardcore programmers but after reading those two webpages I thought it can't be that hard, even for MaxScript. Wrong?
http://netpbm.sourceforge.net/doc/pfm.html
http://people.cs.kuleuven.be/~ares.lagae/libpfm/index.html (http://people.cs.kuleuven.be/%7Eares.lagae/libpfm/index.html)
