21 lines
731 B
Text
21 lines
731 B
Text
-- demo\rosetta\Bitmap_Greyscale.exw (runnable version)
|
|
|
|
function to_grey(sequence image)
|
|
integer dimx = length(image),
|
|
dimy = length(image[1])
|
|
for x=1 to dimx do
|
|
for y=1 to dimy do
|
|
integer pixel = image[x][y] -- red,green,blue
|
|
sequence r_g_b = sq_and_bits(pixel,{#FF0000,#FF00,#FF})
|
|
integer {r,g,b} = sq_floor_div(r_g_b,{#010000,#0100,#01})
|
|
image[x][y] = floor(0.2126*r + 0.7152*g + 0.0722*b)*#010101
|
|
end for
|
|
end for
|
|
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)
|