image_io_20240725.0.0_e3fcdc57/src/image_io-holders.ads

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
-- Image I/O: output in PPM, BMP, PNG, and QOI formats; input in BMP, GIF, JPG, PNG, PNM, QOI, and TGA formats
-- Copyright (C) by Pragmada Software Engineering
-- Released under the terms of the BSD 3-Clause license; see https://opensource.org/licenses

private with Ada.Finalization;

package Image_IO.Holders is
   type Handle is tagged limited private; -- Initially empty

   procedure Create (Holder : in out Handle; Width : in Positive; Height : in Positive);
   -- Makes Holder hold an image Width x Height, default initialized
   -- Any image in Holder is discarded

   function Is_Empty (Holder : in Handle) return Boolean;
   -- Returns True if Create has not been called on Holder; False otherwise

   function Value (Holder : in Handle) return Image_Data with
      Pre => not Holder.Is_Empty;
   -- Returns the image held by Holder

   procedure Update (Holder : in Handle; Process : access procedure (Image : in out Image_Data) ) with
      Pre => not Holder.Is_Empty;
   -- Calls Process with the image in Holder
private -- Image_IO.Holders
   type Image_Ptr is access Image_Data;

   type Handle is new Ada.Finalization.Limited_Controlled with record
      Ptr : Image_Ptr;
   end record;

   overriding procedure Finalize (Object : in out Handle);

   function Value (Holder : in Handle) return Image_Data is
      (Holder.Ptr.all);

   function Is_Empty (Holder : in Handle) return Boolean is
      (Holder.Ptr = null);
end Image_IO.Holders;