Bitmap/Write a PPM file: Difference between revisions

Content added Content deleted
m (Category:Input Output)
(→‎{{header|Ada}}: Blocked output for better performance)
Line 12: Line 12:
procedure Put_PPM (File : File_Type; Picture : Image) is
procedure Put_PPM (File : File_Type; Picture : Image) is
use Ada.Characters.Latin_1;
use Ada.Characters.Latin_1;
Size : constant String := Integer'Image (Picture'Length (2)) & Integer'Image (Picture'Length (1));
Size : constant String := Integer'Image (Picture'Length (2)) & Integer'Image (Picture'Length (1));
Buffer : String (1..Picture'Length (2) * 3);
Color : Pixel;
Index : Positive;
begin
begin
String'Write (Stream (File), "P6" & LF);
String'Write (Stream (File), "P6" & LF);
Line 18: Line 21:
String'Write (Stream (File), "255" & LF);
String'Write (Stream (File), "255" & LF);
for I in Picture'Range (1) loop
for I in Picture'Range (1) loop
Index := Buffer'First;
for J in Picture'Range (2) loop
for J in Picture'Range (2) loop
Character'Write (Stream (File), Character'Val (Picture (I, J).R));
Color := Picture (I, J);
Character'Write (Stream (File), Character'Val (Picture (I, J).G));
Buffer (Index) := Character'Val (Color.R);
Character'Write (Stream (File), Character'Val (Picture (I, J).B));
Buffer (Index + 1) := Character'Val (Color.G);
Buffer (Index + 2) := Character'Val (Color.B);
Index := Index + 3;
end loop;
end loop;
String'Write (Stream (File), Buffer);
end loop;
end loop;
Character'Write (Stream (File), LF);
Character'Write (Stream (File), LF);