Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
32
Task/Bitmap-Read-a-PPM-file/Phix/bitmap-read-a-ppm-file.phix
Normal file
32
Task/Bitmap-Read-a-PPM-file/Phix/bitmap-read-a-ppm-file.phix
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
-- demo\rosetta\Bitmap_read_ppm.exw (runnable version)
|
||||
|
||||
function read_ppm(string filename)
|
||||
sequence image, line
|
||||
integer dimx, dimy, maxcolor
|
||||
atom fn = open(filename, "rb")
|
||||
if fn<0 then
|
||||
return -1 -- unable to open
|
||||
end if
|
||||
line = gets(fn)
|
||||
if line!="P6\n" then
|
||||
return -1 -- only ppm6 files are supported
|
||||
end if
|
||||
line = gets(fn)
|
||||
{{dimx,dimy}} = scanf(line,"%d %d%s")
|
||||
line = gets(fn)
|
||||
{{maxcolor}} = scanf(line,"%d%s")
|
||||
image = repeat(repeat(0,dimy),dimx)
|
||||
for y=1 to dimy do
|
||||
for x=1 to dimx do
|
||||
image[x][y] = getc(fn)*#10000 + getc(fn)*#100 + getc(fn)
|
||||
end for
|
||||
end for
|
||||
close(fn)
|
||||
return image
|
||||
end function
|
||||
|
||||
--include ppm.e -- read_ppm(), write_ppm(), to_grey() (as distributed, instead of the above)
|
||||
|
||||
sequence img = read_ppm("Lena.ppm")
|
||||
img = to_grey(img)
|
||||
write_ppm("LenaGray.ppm",img)
|
||||
Loading…
Add table
Add a link
Reference in a new issue