-- $Date: 2004/03/05 07:40:04 $
-- $Revision: 1.1 $
-- $Author: jcrocholl $

with Ada.Streams.Stream_IO; use Ada.Streams.Stream_IO;

with Bit_Buffers;

package Depixel is

   -- A buffer for an array of bits.
   type Bit_Buffer(Byte_Count : Positive) is limited private;

   -- Access type.
   type Bit_Buffer_Access is access Bit_Buffer;

   -- Create a bit buffer with a capacity of 8 * Byte_Count bits.
   function Create
     (Byte_Count : in Positive-- The number of bytes in the buffer.
     return Bit_Buffer_Access;  -- The newly created bit buffer.

   -- Free the bit buffer's memory and set the instance variable to
   -- null.
   procedure Deallocate
     (This : in out Bit_Buffer_Access); -- Free this bit buffer.

   -- Restart reading from the left of the bit buffer.
   procedure Reset
     (This : access Bit_Buffer); -- Reset this bit buffer.

   -- Add another row with all bits set to False.
   procedure Clear
     (This : access Bit_Buffer); -- Add row to this bit buffer.

   -- Add another row, filled with data from a stream.
   procedure Read_Row
     (From : in Stream_Access;   -- Read from this stream.
      This : access Bit_Buffer); -- Add row to this bit buffer.

   -- Read the next bit from the bit buffer and advance the bit pointer.
   function Read_Bit
     (This : access Bit_Buffer-- Read from this bit buffer.
     return Boolean;            -- The resulting bit value.

private

   -- Wrap-around type with three values.
   type Triple is mod 3;
   subtype Natural_Triple is Natural range 0 .. 2;

   -- Three regular bit buffers internally.
   type Bit_Buffer_Array is array(Natural range <>) of Bit_Buffers.Bit_Buffer_Access;

   -- Three by three matrix of bits.
   type Bit_Matrix is array(Natural range <>, Natural range <>) of Boolean;

   -- Record for bit data and pointers.
   type Bit_Buffer(Byte_Count : Positive) is record
      Internal : Bit_Buffer_Array(Natural_Triple);
      Matrix   : Bit_Matrix(Natural_Triple, Natural_Triple);
      Center_X : Triple := 1;
      Center_Y : Triple := 1;
   end record;

end Depixel;