Bitmap/Read a PPM file: Difference between revisions

no edit summary
(Vedit macro language added)
No edit summary
Line 8:
 
=={{header|Ada}}==
<lang ada>
with Ada.Characters.Latin_1; use Ada.Characters.Latin_1;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
Line 79:
end;
end Get_PPM;
</adalang>
The implementation propagates Data_Error when the file format is incorrect. End_Error is propagated when the file end is prematurely met. The following example illustrates conversion of a color file to grayscale.
<lang ada>
declare
F1, F2 : File_Type;
Line 91:
Close (F2);
end;
</adalang>
 
=={{header|C}}==
Line 98:
[[Read image file through a pipe]] without modification. It only understand the P6 file format.
 
<lang c>#include <stdio.h>
 
#define PPMREADBUFLEN 256
Line 131:
return img;
}
}</clang>
 
The following acts as a filter to convert a PPM file read from standard input into a PPM gray image, and it outputs the converted image to standard output (see [[Grayscale image]], [[Write ppm file]], and [[Raster graphics operations]] in general):
 
<lang c>#include <stdio.h>
/* #include "imglib.h" */
 
Line 150:
free_img(source); free_img((image)idest);
return 0;
}</clang>
 
=={{header|Forth}}==
Line 194:
=={{header|OCaml}}==
 
<lang ocaml>let read_ppm ~filename =
let ic = open_in filename in
let line = input_line ic in
Line 231:
r_channel,
g_channel,
b_channel)</ocamllang>
 
and converting a given color file to grayscale:
<lang ocaml>let () =
let img = read_ppm ~filename:"logo.ppm" in
let img = to_color(to_grayscale ~img) in
output_ppm ~oc:stdout ~img;
;;</ocamllang>
sending the result to <codett>stdout</codett> allows to see the result without creating a temporary file sending it through a pipe to the '''display''' utility of ''ImageMagick'':
ocaml script.ml | display -