comp.lang.ada
 help / color / mirror / Atom feed
* How do I use Direct_IO many times on the same opened file?
@ 1997-07-26  0:00 Matthew Kennedy
  1997-07-29  0:00 ` Stephen Leake
  0 siblings, 1 reply; 2+ messages in thread
From: Matthew Kennedy @ 1997-07-26  0:00 UTC (permalink / raw)



I need to read in a BMP file for image analysis. First I read the header
into a packed record, then I need to read in the palette based on the
information in the header (this goes into an array) and then, finally, I
read in the raw data.

My approach was to instantiate a BMP_Header_IO, a BMP_Palette_IO and a
BMP_Data_IO from the Direct_IO package.

This is the bare essentials of my original code... (errors follow after)

with Direct_IO, Interfaces, Interfaces.C, Text_IO, Mode_13h;
use  Interfaces, Interfaces.C, Mode_13h;

procedure BMP_Info is

   type Bmp_Header is
      record
         Identification          : Char_Array(1..2);
         -- etc ...
         Colours_Important       : Unsigned_32;
      end record;

   type Bmp_Palette_Entry is
      record
         Blue, Red, Green, Reserved : Unsigned_8;
      end record;

   type Bmp_Palette is array(0..Unsigned_8'Last) of Bmp_Palette_Entry;

   pragma Pack(Bmp_Header);
   pragma Pack(Bmp_Palette_Entry);
   pragma Pack(Bmp_Palette);

   procedure Put(Item : in Bmp_Header) is
      use Text_IO;
      B : Char := Item.Identification(1);
      M : Char := Item.Identification(2);
   begin
      Put_Line("Identification     : " & Char'Image(B) & "," &
Char'Image(M));
      -- etc ...
   end Put;

   package Bmp_Header_IO is new Direct_IO(Bmp_Header);
   use Bmp_Header_IO;

   package Bmp_Palette_IO is new Direct_IO(Bmp_Palette);
   use Bmp_Palette_IO;

   Header : Bmp_Header;
   Palette : Bmp_Palette;
   Bitmap_File : File_Type;
   Bmp_Not_Supported : exception;

begin
   Open(Bitmap_File, In_File, "C:/TEMP/TEST.BMP");
   Read(Bitmap_File, Header);
   if Header.Bits /= 8 then
      raise Bmp_Not_Supported;
   end if;
   Read(Bitmap_File, Palette);
   Close(Bitmap_File);

   Put(Specification.Header);

exception
   when Bmp_Not_Supported =>
      Set_Mode_Revert;
      Text_IO.Put_Line("This BMP file format is not supported.");
end BMP_Info;


These are the errors I experienced:

cd f:/gnu/
gnatmake bmp_info 
gcc -c bmp_info.adb
bmp_info.adb:62:18: "File_Type" is not visible
bmp_info.adb:62:18: multiple use clauses cause hiding
bmp_info.adb:62:18: hidden declaration at a-direio.ads:28, instance at
line 57
bmp_info.adb:62:18: hidden declaration at a-direio.ads:28, instance at
line 54
f:/gnu/bin/gnatmake.exe: "bmp_info.adb" compilation error

I sort-of understand why File_Type isn't visible but I would like to
hear from you if you can suggest a work-around or a different approach.

-- 
Matthew Kennedy
Student of Electronics Engineering
University of Southern Queensland, Australia
  "When will you realise your already there?" 
      - Marilyn Manson




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1997-07-29  0:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-07-26  0:00 How do I use Direct_IO many times on the same opened file? Matthew Kennedy
1997-07-29  0:00 ` Stephen Leake

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox