Rosetta Code Task: "Bitmap/Write a PPM file" fails to compile

Hi;

What did I fail to do? Either the Task code is broken, or it doesn’t work with GNAT compiler or there are insufficient hints about what to modify to get it to work. This does not look like a snippet to me, it looks like it should compile and execute correctly.

Rosetta Code Task: “Bitmap/Write a PPM file” fails to compile.

which gnatmake
/opt/gcc-13.2.0-aarch64/bin/gnatmake

with Ada.Characters.Latin_1;
with Ada.Streams.Stream_IO; use Ada.Streams.Stream_IO;

procedure Put_PPM (File : 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;

– The solution writes the image into an opened file. The file format
– might fail to work on certain OSes, 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.

gnatmake ./put_ppm.adb
gcc -c -I./ -I- ./put_ppm.adb
put_ppm.adb:4:48: error: “Image” is undefined
put_ppm.adb:8:13: error: “Pixel” is undefined
put_ppm.adb:18:47: error: invalid prefix in selected component “Color”
put_ppm.adb:19:47: error: invalid prefix in selected component “Color”
put_ppm.adb:20:47: error: invalid prefix in selected component “Color”
gnatmake: “./put_ppm.adb” compilation error

Thanks,
Retired Build Engineer

I would assume the procedure in question is a subprogram of a main program where you define the image to be used.

The problem statement of the Rosetta Code task is this:

Using the data storage type defined on this page for raster images, write the image to a PPM file (binary P6 preferred).

(Read the definition of PPM file on Wikipedia.).

Just as the compiler indicated, the Image and Pixel types are not defined. You’ll have to add those before the program can successfully be compiled.

The description of the task clarifies it.

Using the data storage type defined on this page for raster images, write the image to a PPM file (binary P6 preferred).

The code should use the package defined in the other task. At least, it would lead the user who wants to compile it to seek that package. I will do that unless someone volunteers first.