
Tipo de parámetro para hacer bitmap en Ada
Publicado por angela (1 intervención) el 17/09/2015 20:09:53
Buenas gente! Tengo un problema con un código que encontré en Internet, es para hacer un bitmap en Ada, el problema es que no se que tipo de dato debo de ponerle el primer parámetro del procedimiento Put_PPM(???,X), les agradecería que me ayudaran.
Este es el código:
procedure Main is
type Luminance is mod 2**8;
type Pixel is record
R, G, B : Luminance;
end record;
Black : constant Pixel := (others => 0);
White : constant Pixel := (others => 255);
type Image is array (Positive range <>, Positive range <>) of Pixel;
type Point is record
X, Y : Positive;
end record;
procedure Fill (Picture : in out Image; Color : Pixel) is
....
end Fill;
procedure Print (Picture : Image) is
...
end Print;
procedure Put_PPM (File : Ada.Streams.Stream_IO.File_Type; Picture : Image) is
use Ada.Characters.Latin_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
String'Write (Stream (File), "P6" & LF);
String'Write (Stream (File), Size (2..Size'Last) & LF);
String'Write (Stream (File), "255" & LF);
for I in Picture'Range (1) loop
Index := Buffer'First;
for J in Picture'Range (2) loop
Color := Picture (I, J);
Buffer (Index) := Character'Val (Color.R);
Buffer (Index + 1) := Character'Val (Color.G);
Buffer (Index + 2) := Character'Val (Color.B);
Index := Index + 3;
end loop;
String'Write (Stream (File), Buffer);
end loop;
Character'Write (Stream (File), LF);
end Put_PPM;
X : Image (1..64, 1..64);
begin
Fill (X, (255, 255, 255));
X (1, 2) := (R => 255, others => 0);
X (3, 4) := X (1, 2);
Print(X);
Put_PPM(???,X);
end Main;
Este es el código:
procedure Main is
type Luminance is mod 2**8;
type Pixel is record
R, G, B : Luminance;
end record;
Black : constant Pixel := (others => 0);
White : constant Pixel := (others => 255);
type Image is array (Positive range <>, Positive range <>) of Pixel;
type Point is record
X, Y : Positive;
end record;
procedure Fill (Picture : in out Image; Color : Pixel) is
....
end Fill;
procedure Print (Picture : Image) is
...
end Print;
procedure Put_PPM (File : Ada.Streams.Stream_IO.File_Type; Picture : Image) is
use Ada.Characters.Latin_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
String'Write (Stream (File), "P6" & LF);
String'Write (Stream (File), Size (2..Size'Last) & LF);
String'Write (Stream (File), "255" & LF);
for I in Picture'Range (1) loop
Index := Buffer'First;
for J in Picture'Range (2) loop
Color := Picture (I, J);
Buffer (Index) := Character'Val (Color.R);
Buffer (Index + 1) := Character'Val (Color.G);
Buffer (Index + 2) := Character'Val (Color.B);
Index := Index + 3;
end loop;
String'Write (Stream (File), Buffer);
end loop;
Character'Write (Stream (File), LF);
end Put_PPM;
X : Image (1..64, 1..64);
begin
Fill (X, (255, 255, 255));
X (1, 2) := (R => 255, others => 0);
X (3, 4) := X (1, 2);
Print(X);
Put_PPM(???,X);
end Main;
Valora esta pregunta


0