summaryrefslogtreecommitdiff
path: root/src/fltk-images-rgb-png.adb
blob: 6023f82b8a85b9a2358b29a3678187cce2d8ffd6 (plain)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98


with

    Interfaces.C,
    System;

use type

    System.Address;


package body FLTK.Images.RGB.PNG is


    function new_fl_png_image
           (F : in Interfaces.C.char_array)
        return System.Address;
    pragma Import (C, new_fl_png_image, "new_fl_png_image");
    pragma Inline (new_fl_png_image);

    function new_fl_png_image2
           (N : in Interfaces.C.char_array;
            D : in System.Address;
            S : in Interfaces.C.int)
        return System.Address;
    pragma Import (C, new_fl_png_image2, "new_fl_png_image2");
    pragma Inline (new_fl_png_image2);

    procedure free_fl_png_image
           (P : in System.Address);
    pragma Import (C, free_fl_png_image, "free_fl_png_image");
    pragma Inline (free_fl_png_image);




    overriding procedure Finalize
           (This : in out PNG_Image) is
    begin
        if  This.Void_Ptr /= System.Null_Address and then
            This in PNG_Image'Class
        then
            free_fl_png_image (This.Void_Ptr);
            This.Void_Ptr := System.Null_Address;
        end if;
        Finalize (RGB_Image (This));
    end Finalize;




    --------------------
    --  Construction  --
    --------------------

    package body Forge is

        function Create
               (Filename : in String)
            return PNG_Image is
        begin
            return This : PNG_Image do
                This.Void_Ptr := new_fl_png_image
                   (Interfaces.C.To_C (Filename));
                case fl_image_fail (This.Void_Ptr) is
                    when 1 => raise No_Image_Error;
                    when 2 => raise File_Access_Error;
                    when 3 => raise Format_Error;
                    when others => null;
                end case;
            end return;
        end Create;

        function Create
               (Name : in String := "";
                Data : in Color_Component_Array)
            return PNG_Image is
        begin
            return This : PNG_Image do
                This.Void_Ptr := new_fl_png_image2
                   (Interfaces.C.To_C (Name),
                    Data (Data'First)'Address,
                    Data'Length);
                case fl_image_fail (This.Void_Ptr) is
                    when 1 => raise No_Image_Error;
                    when 2 => raise File_Access_Error;
                    when 3 => raise Format_Error;
                    when others => null;
                end case;
            end return;
        end Create;

    end Forge;


end FLTK.Images.RGB.PNG;