Jump to content

Bitmap/Write a PPM file: Difference between revisions

Ada solution added
(Forth)
(Ada solution added)
Line 4:
(Read [http://en.wikipedia.org/wiki/Netpbm_format the definition of PPM file] on Wikipedia.)
 
=={{header|Ada}}==
<ada>
procedure Put_PPM (File : File_Type; Picture : Image) is
Size : constant String := Integer'Image (Picture'Length (2)) & Integer'Image (Picture'Length (1));
begin
Put_Line (File, "P6");
Put_Line (File, Size (2..Size'Last));
Put_Line (File, "255");
for I in Picture'Range (1) loop
for J in Picture'Range (2) loop
Put (File, Character'Val (Picture (I, J).R));
Put (File, Character'Val (Picture (I, J).G));
Put (File, Character'Val (Picture (I, J).B));
end loop;
end loop;
New_Line (File);
end Put_PPM;
</ada>
The solution writes the image into an opened file. The file format might fail to work on certain [[OS]] because text output might mangle control characters like LF, CR, FF, HT, VT etc. In general it is a bad idea to mix binary and text output in one file.
=={{header|C}}==
 
Cookies help us deliver our services. By using our services, you agree to our use of cookies.