qoi_0.1.0_25d61809/tests/src/stb-image.adb

 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
with Interfaces.C.Strings;

package body STB.Image is

   ----------
   -- Load --
   ----------

   function Load (Filename : String;
                  X, Y, Channels_In_File : out Interfaces.C.int;
                  Desired_Channels : Interfaces.C.int)
                  return System.Address
   is
      function C_Load (Filename : Interfaces.C.Strings.chars_ptr;
                       X, Y, Comp : access Interfaces.C.int;
                       Req_Comp : Interfaces.C.int)
                       return System.Address;
      pragma Import (C, C_Load, "stbi_load");

      Filename_C : Interfaces.C.Strings.chars_ptr :=
        Interfaces.C.Strings.New_String (Filename);

      Result : System.Address;

      X_A, Y_A, Comp_A : aliased Interfaces.C.int;
   begin

      Result := C_Load (Filename_C, X_A'Access, Y_A'Access,
                        Comp_A 'Access, Desired_Channels);

      Interfaces.C.Strings.Free (Filename_C);

      X := X_A;
      Y := Y_A;
      Channels_In_File := Comp_A;
      return Result;
   end Load;

   ---------------
   -- Write_PNG --
   ---------------

   function Write_PNG (Filename : String;
                       W, H, Channels : Interfaces.C.int;
                       Data : System.Address;
                       Len  : Interfaces.C.int)
                       return Interfaces.C.int
   is

      function C_Write (Filename : Interfaces.C.Strings.chars_ptr;
                        W, H, Comp : Interfaces.C.int;
                        Data : System.Address;
                        Len  : Interfaces.C.int)
                        return Interfaces.C.int;
      pragma Import (C, C_Write, "stbi_write_png");

      Filename_C : Interfaces.C.Strings.chars_ptr :=
        Interfaces.C.Strings.New_String (Filename);
      Result : Interfaces.C.int;
   begin
      Result := C_Write (Filename_C, W, H, Channels, Data, Len);
      Interfaces.C.Strings.Free (Filename_C);
      return Result;
   end Write_PNG;

end STB.Image;