Bitmap/Write a PPM file: Difference between revisions
Content added Content deleted
(Vedit macro language added) |
No edit summary |
||
Line 6: | Line 6: | ||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
<ada> |
<lang ada> |
||
with Ada.Characters.Latin_1; |
with Ada.Characters.Latin_1; |
||
with Ada.Streams.Stream_IO; use Ada.Streams.Stream_IO; |
with Ada.Streams.Stream_IO; use Ada.Streams.Stream_IO; |
||
Line 33: | Line 33: | ||
Character'Write (Stream (File), LF); |
Character'Write (Stream (File), LF); |
||
end Put_PPM; |
end Put_PPM; |
||
</ |
</lang> |
||
The solution writes the image into an opened file. The file format might fail to work on certain [[OS]]es, because output might mangle control characters like LF, CR, FF, HT, VT etc. The OS might also limit the line length of a text file. In general it is a bad idea to mix binary and text output in one file. This solution uses ''stream I/O'', which should be as portable as possible. |
The solution writes the image into an opened file. The file format might fail to work on certain [[OS]]es, because output might mangle control characters like LF, CR, FF, HT, VT etc. The OS might also limit the line length of a text file. In general it is a bad idea to mix binary and text output in one file. This solution uses ''stream I/O'', which should be as portable as possible. |
||
Line 67: | Line 67: | ||
== {{Header|OCaml}} == |
== {{Header|OCaml}} == |
||
<ocaml>let output_ppm ~oc ~img:(_, r_channel, g_channel, b_channel) = |
<lang ocaml>let output_ppm ~oc ~img:(_, r_channel, g_channel, b_channel) = |
||
let width = Bigarray.Array2.dim1 r_channel |
let width = Bigarray.Array2.dim1 r_channel |
||
and height = Bigarray.Array2.dim2 r_channel in |
and height = Bigarray.Array2.dim2 r_channel in |
||
Line 80: | Line 80: | ||
output_char oc '\n'; |
output_char oc '\n'; |
||
flush oc; |
flush oc; |
||
;;</ |
;;</lang> |
||
=={{header|Vedit macro language}}== |
=={{header|Vedit macro language}}== |