------------------------------------------------------------------------------
--                                                                          --
--                An Ada2005 binding to the Qt C++ framework                --
--                                                                          --
------------------------------------------------------------------------------
--                                                                          --
-- Copyright © 2009, 2010 Vadim Godunko <vgodunko@gmail.com>                --
--                                                                          --
-- QtAda is free software;  you can  redistribute it and/or modify it under --
-- terms of the  GNU General Public License as published  by the Free Soft- --
-- ware  Foundation;  either version 2,  or (at your option) any later ver- --
-- sion. QtAda is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
-- for  more details.  You should have  received  a copy of the GNU General --
-- Public License distributed with QtAda;  see file COPYING.  If not, write --
-- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
-- Boston, MA 02110-1301, USA.                                              --
--                                                                          --
-- As a special exception,  if other files  instantiate  generics from this --
-- unit, or you link  this unit with other files  to produce an executable, --
-- this  unit  does not  by itself cause  the resulting  executable  to  be --
-- covered  by the  GNU  General  Public  License.  This exception does not --
-- however invalidate  any other reasons why  the executable file  might be --
-- covered by the  GNU Public License.                                      --
--                                                                          --
------------------------------------------------------------------------------
--  $Revision: 3764 $ $Date: 2010-10-23 23:13:39 +0400 (Sat, 23 Oct 2010) $
------------------------------------------------------------------------------
private with Ada.Finalization;
with Interfaces.C;
with System;

with Qt4.Matrices;
with Qt4.Paint_Devices;
with Qt4.Paint_Engines;
with Qt4.Points;
with Qt4.Rects;
with Qt4.Rgbs;
with Qt4.Sizes;
with Qt4.String_Lists;
with Qt4.Strings;
with Qt4.Transforms;
with Qt_Ada.Internals.Paint_Devices;
private with Qt_Ada.Internals.Value_Class_Sizes;

package Qt4.Images is

   --  QImage::Format

   type Image_Format is
    (Format_Invalid,
     Format_Mono,
     Format_Mono_LSB,
     Format_Indexed_8,
     Format_RGB32,
     Format_ARGB32,
     Format_ARGB32_Premultiplied,
     Format_RGB16,
     Format_ARGB8565_Premultiplied,
     Format_RGB666,
     Format_ARGB6666_Premultiplied,
     Format_RGB555,
     Format_ARGB8555_Premultiplied,
     Format_RGB888,
     Format_RGB444,
     Format_ARGB4444_Premultiplied);
   pragma Convention (C, Image_Format);
   for Image_Format'Size use Interfaces.C.unsigned'Size;

   --  QImage::InvertMode

   type Invert_Mode is
    (Invert_Rgb,
     Invert_Rgba);
   pragma Convention (C, Invert_Mode);
   for Invert_Mode'Size use Interfaces.C.unsigned'Size;

   type Q_Image is new Qt4.Paint_Devices.Q_Paint_Device with private;

   function Create
    (Size : Qt4.Sizes.Q_Size'Class;
     Format : Image_Format)
       return Q_Image;

   function Create
    (Width : Qt4.Q_Integer;
     Height : Qt4.Q_Integer;
     Format : Image_Format)
       return Q_Image;

   function All_Gray
    (Self : Q_Image'Class)
       return Boolean;

   function Alpha_Channel
    (Self : Q_Image'Class)
       return Q_Image;

   function Bytes_Per_Line
    (Self : Q_Image'Class)
       return Qt4.Q_Integer;

   function Cache_Key
    (Self : Q_Image'Class)
       return Qt4.Q_Integer_64;

   function Copy
    (Self : Q_Image'Class;
     Rectangle : Qt4.Rects.Q_Rect'Class)
       return Q_Image;

   function Copy
    (Self : Q_Image'Class;
     X : Qt4.Q_Integer;
     Y : Qt4.Q_Integer;
     Width : Qt4.Q_Integer;
     Height : Qt4.Q_Integer)
       return Q_Image;

   function Create_Heuristic_Mask
    (Self : Q_Image'Class;
     Clip_Tight : Boolean
       := True)
       return Q_Image;

   function Depth
    (Self : Q_Image'Class)
       return Qt4.Q_Integer;

   function Dots_Per_Meter_X
    (Self : Q_Image'Class)
       return Qt4.Q_Integer;

   function Dots_Per_Meter_Y
    (Self : Q_Image'Class)
       return Qt4.Q_Integer;

   procedure Fill
    (Self : in out Q_Image'Class;
     Pixel_Value : Qt4.Q_Unsigned_Integer);

   function Format
    (Self : Q_Image'Class)
       return Image_Format;

   function Has_Alpha_Channel
    (Self : Q_Image'Class)
       return Boolean;

   function Height
    (Self : Q_Image'Class)
       return Qt4.Q_Integer;

   procedure Invert_Pixels
    (Self : in out Q_Image'Class;
     Mode : Invert_Mode
       := Invert_Rgb);

   function Is_Grayscale
    (Self : Q_Image'Class)
       return Boolean;

   function Is_Null
    (Self : Q_Image'Class)
       return Boolean;

   function Mirrored
    (Self : Q_Image'Class;
     Horizontally : Boolean
       := False;
     Vertically : Boolean
       := True)
       return Q_Image;

   function Num_Bytes
    (Self : Q_Image'Class)
       return Qt4.Q_Integer;

   function Num_Colors
    (Self : Q_Image'Class)
       return Qt4.Q_Integer;

   function Offset
    (Self : Q_Image'Class)
       return Qt4.Points.Q_Point;

   function Pixel
    (Self : Q_Image'Class;
     Position : Qt4.Points.Q_Point'Class)
       return Qt4.Rgbs.Q_Rgb;

   function Pixel
    (Self : Q_Image'Class;
     X : Qt4.Q_Integer;
     Y : Qt4.Q_Integer)
       return Qt4.Rgbs.Q_Rgb;

   function Pixel_Index
    (Self : Q_Image'Class;
     Position : Qt4.Points.Q_Point'Class)
       return Qt4.Q_Unsigned_Integer;

   function Pixel_Index
    (Self : Q_Image'Class;
     X : Qt4.Q_Integer;
     Y : Qt4.Q_Integer)
       return Qt4.Q_Unsigned_Integer;

   function Rect
    (Self : Q_Image'Class)
       return Qt4.Rects.Q_Rect;

   function Rgb_Swapped
    (Self : Q_Image'Class)
       return Q_Image;

   function Scaled
    (Self : Q_Image'Class;
     Size : Qt4.Sizes.Q_Size'Class;
     Aspect_Mode : Qt4.Aspect_Ratio_Mode
       := Ignore_Aspect_Ratio;
     Mode : Qt4.Transformation_Mode
       := Fast_Transformation)
       return Q_Image;

   function Scaled
    (Self : Q_Image'Class;
     Width : Qt4.Q_Integer;
     Height : Qt4.Q_Integer;
     Aspect_Mode : Qt4.Aspect_Ratio_Mode
       := Ignore_Aspect_Ratio;
     Mode : Qt4.Transformation_Mode
       := Fast_Transformation)
       return Q_Image;

   function Scaled_To_Height
    (Self : Q_Image'Class;
     Height : Qt4.Q_Integer;
     Mode : Qt4.Transformation_Mode
       := Fast_Transformation)
       return Q_Image;

   function Scaled_To_Width
    (Self : Q_Image'Class;
     Width : Qt4.Q_Integer;
     Mode : Qt4.Transformation_Mode
       := Fast_Transformation)
       return Q_Image;

   procedure Set_Alpha_Channel
    (Self : in out Q_Image'Class;
     Alpha_Channel : Q_Image'Class);

   procedure Set_Dots_Per_Meter_X
    (Self : in out Q_Image'Class;
     X : Qt4.Q_Integer);

   procedure Set_Dots_Per_Meter_Y
    (Self : in out Q_Image'Class;
     Y : Qt4.Q_Integer);

   procedure Set_Num_Colors
    (Self : in out Q_Image'Class;
     Num_Colors : Qt4.Q_Integer);

   procedure Set_Offset
    (Self : in out Q_Image'Class;
     Offset : Qt4.Points.Q_Point'Class);

   procedure Set_Pixel
    (Self : in out Q_Image'Class;
     Position : Qt4.Points.Q_Point'Class;
     Index : Qt4.Q_Unsigned_Integer);

   procedure Set_Pixel
    (Self : in out Q_Image'Class;
     X : Qt4.Q_Integer;
     Y : Qt4.Q_Integer;
     Index : Qt4.Q_Unsigned_Integer);

   procedure Set_Pixel
    (Self : in out Q_Image'Class;
     Position : Qt4.Points.Q_Point'Class;
     Rgb : Qt4.Rgbs.Q_Rgb);

   procedure Set_Pixel
    (Self : in out Q_Image'Class;
     X : Qt4.Q_Integer;
     Y : Qt4.Q_Integer;
     Rgb : Qt4.Rgbs.Q_Rgb);

   procedure Set_Text
    (Self : in out Q_Image'Class;
     Key : Qt4.Strings.Q_String'Class;
     Text : Qt4.Strings.Q_String'Class);

   function Size
    (Self : Q_Image'Class)
       return Qt4.Sizes.Q_Size;

   function Text
    (Self : Q_Image'Class;
     Key : Qt4.Strings.Q_String'Class)
       return Qt4.Strings.Q_String;

   function Text_Keys
    (Self : Q_Image'Class)
       return Qt4.String_Lists.Q_String_List;

   function Transformed
    (Self : Q_Image'Class;
     Matrix : Qt4.Matrices.Q_Matrix'Class;
     Mode : Qt4.Transformation_Mode
       := Fast_Transformation)
       return Q_Image;

   function Transformed
    (Self : Q_Image'Class;
     Matrix : Qt4.Transforms.Q_Transform'Class;
     Mode : Qt4.Transformation_Mode
       := Fast_Transformation)
       return Q_Image;

   function Valid
    (Self : Q_Image'Class;
     Pos : Qt4.Points.Q_Point'Class)
       return Boolean;

   function Valid
    (Self : Q_Image'Class;
     X : Qt4.Q_Integer;
     Y : Qt4.Q_Integer)
       return Boolean;

   function Width
    (Self : Q_Image'Class)
       return Qt4.Q_Integer;

   overriding
   function "="
    (Self : Q_Image;
     Image : Q_Image)
       return Boolean;

   function True_Matrix
    (Matrix : Qt4.Matrices.Q_Matrix'Class;
     Width : Qt4.Q_Integer;
     Height : Qt4.Q_Integer)
       return Qt4.Matrices.Q_Matrix;

   function True_Matrix
    (Matrix : Qt4.Transforms.Q_Transform'Class;
     Width : Qt4.Q_Integer;
     Height : Qt4.Q_Integer)
       return Qt4.Transforms.Q_Transform;

   package Internals is

      type QImage is private;

      type QImage_Access is access all QImage;
      pragma Convention (C, QImage_Access);

      function QImage_View
       (Item : Q_Image'Class)
          return QImage_Access;
      pragma Inline (QImage_View);

      function To_Pointer
       (Address : System.Address)
          return QImage_Access;
      pragma Inline (To_Pointer);

      function To_Address
       (Pointer : QImage_Access)
          return System.Address;
      pragma Inline (To_Address);

      function Create_Wrapper
       (Item : Internals.QImage_Access)
          return Q_Image;

   private

      type QImage is record
         Placeholder : Interfaces.C.char_array (1 .. Qt_Ada.Internals.Value_Class_Sizes.QImage_C_Size_Of);
      end record;
      pragma Convention (C, QImage);

   end Internals;

private

   type Q_Image is new Ada.Finalization.Controlled
     and Qt4.Paint_Devices.Q_Paint_Device with
   record
      Storage : aliased Internals.QImage;
      Object  : Internals.QImage_Access := null;
      Wrapper : Boolean := False;
   end record;

   overriding
   procedure Adjust (Self : in out Q_Image);

   overriding
   procedure Finalize (Self : in out Q_Image);

   overriding
   procedure Initialize (Self : in out Q_Image);

   overriding
   function QPaintDevice_View
    (Self : not null access constant Q_Image)
       return not null Qt_Ada.Internals.Paint_Devices.QPaintDevice_Access;

   overriding
   function Paint_Engine
    (Self : not null access Q_Image)
       return not null access Qt4.Paint_Engines.Q_Paint_Engine;

end Qt4.Images;
