Grayscale image: Difference between revisions

Content added Content deleted
(Grayscale image en FreeBASIC)
m (→‎{{header|Phix}}: minor tidy)
Line 1,369: Line 1,369:
=={{header|Phix}}==
=={{header|Phix}}==
{{Trans|Euphoria}}
{{Trans|Euphoria}}
Requires read_ppm() from [[Bitmap/Read_a_PPM_file#Phix|Read_a_PPM_file]], see [[Bitmap/Write_a_PPM_file#Phix|Write_a_PPM_file]] for actual use.
Requires read_ppm() from [[Bitmap/Read_a_PPM_file#Phix|Read a PPM file]] and write_ppm() from [[Bitmap/Write_a_PPM_file#Phix|Write a PPM file]].
Included as demo\rosetta\Bitmap_Greyscale.exw
<lang Phix>-- demo\rosetta\Bitmap_Greyscale.exw (runnable version)

<lang Phix>function to_gray(sequence image)
sequence color
function to_grey(sequence image)
for i=1 to length(image) do
integer dimx = length(image),
for j=1 to length(image[i]) do
dimy = length(image[1])
for x=1 to dimx do
-- unpack color triple
for y=1 to dimy do
color = sq_div(sq_and_bits(image[i][j], {#FF0000,#FF00,#FF}),
{#010000,#0100,#01})
integer pixel = image[x][y] -- red,green,blue
sequence r_g_b = sq_and_bits(pixel,{#FF0000,#FF00,#FF})
image[i][j] = floor(0.2126*color[1] + 0.7152*color[2] + 0.0722*color[3])*#010101
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
end for
end for
return image
return image
end function
end function

--include ppm.e -- read_ppm(), write_ppm(), to_grey() (as distributed, instead of the above)

sequence img = read_ppm("Lena.ppm")
sequence img = read_ppm("Lena.ppm")
img = to_gray(img)</lang>
img = to_grey(img)
write_ppm("LenaGray.ppm",img)</lang>


=={{header|PHP}}==
=={{header|PHP}}==