------------------------------------------------------------------------------
--                                                                          --
--                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: 3777 $ $Date: 2010-10-24 11:16:05 +0400 (Sun, 24 Oct 2010) $
------------------------------------------------------------------------------
pragma Style_Checks ("M32766");
with System.Address_To_Access_Conversions;

with Qt_Ada.Internals.Boolean_Conversions;

package body Qt4.Images is

   function initialize_QImage
    (Storage : System.Address)
      return Internals.QImage_Access;
   pragma Import (C, initialize_QImage, "__QtAda_inititialize_QImage");

   function initialize_QImage_QSizeCR_Format
    (Storage : System.Address;
     Size : Qt4.Sizes.Internals.QSize_Access;
     Format : Image_Format)
      return Internals.QImage_Access;
   pragma Import (C, initialize_QImage_QSizeCR_Format, "__QtAda_inititialize_QImage_QSizeCR_Format");

   function initialize_QImage_int_int_Format
    (Storage : System.Address;
     Width : Qt4.Q_Integer;
     Height : Qt4.Q_Integer;
     Format : Image_Format)
      return Internals.QImage_Access;
   pragma Import (C, initialize_QImage_int_int_Format, "__QtAda_inititialize_QImage_int_int_Format");

   function adjust_QImage
    (Storage : System.Address;
     From    : Internals.QImage_Access)
       return Internals.QImage_Access;
   pragma Import (C, adjust_QImage, "__QtAda_adjust_QImage");

   procedure finalize_QImage (Object : Internals.QImage_Access);
   pragma Import (C, finalize_QImage, "__QtAda_finalize_QImage");

   function QImage_allGray
    (Self : Internals.QImage_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QImage_allGray, "__QtAda_QImage_allGray_Q");

   procedure QImage_alphaChannel
    (Returns : Internals.QImage_Access;
     Self : Internals.QImage_Access);
   pragma Import (C, QImage_alphaChannel, "__QtAda_QImage_alphaChannel_Q");

   function QImage_bytesPerLine
    (Self : Internals.QImage_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QImage_bytesPerLine, "__QtAda_QImage_bytesPerLine_Q");

   function QImage_cacheKey
    (Self : Internals.QImage_Access)
       return Qt4.Q_Integer_64;
   pragma Import (C, QImage_cacheKey, "__QtAda_QImage_cacheKey_Q");

   procedure QImage_copy_QRectCR
    (Returns : Internals.QImage_Access;
     Self : Internals.QImage_Access;
     Rectangle : Qt4.Rects.Internals.QRect_Access);
   pragma Import (C, QImage_copy_QRectCR, "__QtAda_QImage_copy_QRectCR_Q");

   procedure QImage_copy_int_int_int_int
    (Returns : Internals.QImage_Access;
     Self : Internals.QImage_Access;
     X : Qt4.Q_Integer;
     Y : Qt4.Q_Integer;
     Width : Qt4.Q_Integer;
     Height : Qt4.Q_Integer);
   pragma Import (C, QImage_copy_int_int_int_int, "__QtAda_QImage_copy_int_int_int_int_Q");

   procedure QImage_createHeuristicMask_bool
    (Returns : Internals.QImage_Access;
     Self : Internals.QImage_Access;
     Clip_Tight : Interfaces.C.unsigned);
   pragma Import (C, QImage_createHeuristicMask_bool, "__QtAda_QImage_createHeuristicMask_bool_Q");

   function QImage_depth
    (Self : Internals.QImage_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QImage_depth, "__QtAda_QImage_depth_Q");

   function QImage_dotsPerMeterX
    (Self : Internals.QImage_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QImage_dotsPerMeterX, "__QtAda_QImage_dotsPerMeterX_Q");

   function QImage_dotsPerMeterY
    (Self : Internals.QImage_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QImage_dotsPerMeterY, "__QtAda_QImage_dotsPerMeterY_Q");

   procedure QImage_fill
    (Self : Internals.QImage_Access;
     Pixel_Value : Qt4.Q_Unsigned_Integer);
   pragma Import (C, QImage_fill, "__QtAda_QImage_fill");

   function QImage_format
    (Self : Internals.QImage_Access)
       return Image_Format;
   pragma Import (C, QImage_format, "__QtAda_QImage_format_Q");

   function QImage_hasAlphaChannel
    (Self : Internals.QImage_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QImage_hasAlphaChannel, "__QtAda_QImage_hasAlphaChannel_Q");

   function QImage_height
    (Self : Internals.QImage_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QImage_height, "__QtAda_QImage_height_Q");

   procedure QImage_invertPixels_InvertMode
    (Self : Internals.QImage_Access;
     Mode : Invert_Mode);
   pragma Import (C, QImage_invertPixels_InvertMode, "__QtAda_QImage_invertPixels_InvertMode");

   function QImage_isGrayscale
    (Self : Internals.QImage_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QImage_isGrayscale, "__QtAda_QImage_isGrayscale_Q");

   function QImage_isNull
    (Self : Internals.QImage_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QImage_isNull, "__QtAda_QImage_isNull_Q");

   procedure QImage_mirrored_bool_bool
    (Returns : Internals.QImage_Access;
     Self : Internals.QImage_Access;
     Horizontally : Interfaces.C.unsigned;
     Vertically : Interfaces.C.unsigned);
   pragma Import (C, QImage_mirrored_bool_bool, "__QtAda_QImage_mirrored_bool_bool_Q");

   function QImage_numBytes
    (Self : Internals.QImage_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QImage_numBytes, "__QtAda_QImage_numBytes_Q");

   function QImage_numColors
    (Self : Internals.QImage_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QImage_numColors, "__QtAda_QImage_numColors_Q");

   procedure QImage_offset
    (Returns : Qt4.Points.Internals.QPoint_Access;
     Self : Internals.QImage_Access);
   pragma Import (C, QImage_offset, "__QtAda_QImage_offset_Q");

   function QImage_pixel_QPointCR
    (Self : Internals.QImage_Access;
     Position : Qt4.Points.Internals.QPoint_Access)
       return Qt4.Rgbs.Q_Rgb;
   pragma Import (C, QImage_pixel_QPointCR, "__QtAda_QImage_pixel_QPointCR_Q");

   function QImage_pixel_int_int
    (Self : Internals.QImage_Access;
     X : Qt4.Q_Integer;
     Y : Qt4.Q_Integer)
       return Qt4.Rgbs.Q_Rgb;
   pragma Import (C, QImage_pixel_int_int, "__QtAda_QImage_pixel_int_int_Q");

   function QImage_pixelIndex_QPointCR
    (Self : Internals.QImage_Access;
     Position : Qt4.Points.Internals.QPoint_Access)
       return Qt4.Q_Unsigned_Integer;
   pragma Import (C, QImage_pixelIndex_QPointCR, "__QtAda_QImage_pixelIndex_QPointCR_Q");

   function QImage_pixelIndex_int_int
    (Self : Internals.QImage_Access;
     X : Qt4.Q_Integer;
     Y : Qt4.Q_Integer)
       return Qt4.Q_Unsigned_Integer;
   pragma Import (C, QImage_pixelIndex_int_int, "__QtAda_QImage_pixelIndex_int_int_Q");

   procedure QImage_rect
    (Returns : Qt4.Rects.Internals.QRect_Access;
     Self : Internals.QImage_Access);
   pragma Import (C, QImage_rect, "__QtAda_QImage_rect_Q");

   procedure QImage_rgbSwapped
    (Returns : Internals.QImage_Access;
     Self : Internals.QImage_Access);
   pragma Import (C, QImage_rgbSwapped, "__QtAda_QImage_rgbSwapped_Q");

   procedure QImage_scaled_QSizeCR_AspectRatioMode_TransformationMode
    (Returns : Internals.QImage_Access;
     Self : Internals.QImage_Access;
     Size : Qt4.Sizes.Internals.QSize_Access;
     Aspect_Mode : Qt4.Aspect_Ratio_Mode;
     Mode : Qt4.Transformation_Mode);
   pragma Import (C, QImage_scaled_QSizeCR_AspectRatioMode_TransformationMode, "__QtAda_QImage_scaled_QSizeCR_AspectRatioMode_TransformationMode_Q");

   procedure QImage_scaled_int_int_AspectRatioMode_TransformationMode
    (Returns : Internals.QImage_Access;
     Self : Internals.QImage_Access;
     Width : Qt4.Q_Integer;
     Height : Qt4.Q_Integer;
     Aspect_Mode : Qt4.Aspect_Ratio_Mode;
     Mode : Qt4.Transformation_Mode);
   pragma Import (C, QImage_scaled_int_int_AspectRatioMode_TransformationMode, "__QtAda_QImage_scaled_int_int_AspectRatioMode_TransformationMode_Q");

   procedure QImage_scaledToHeight_int_TransformationMode
    (Returns : Internals.QImage_Access;
     Self : Internals.QImage_Access;
     Height : Qt4.Q_Integer;
     Mode : Qt4.Transformation_Mode);
   pragma Import (C, QImage_scaledToHeight_int_TransformationMode, "__QtAda_QImage_scaledToHeight_int_TransformationMode_Q");

   procedure QImage_scaledToWidth_int_TransformationMode
    (Returns : Internals.QImage_Access;
     Self : Internals.QImage_Access;
     Width : Qt4.Q_Integer;
     Mode : Qt4.Transformation_Mode);
   pragma Import (C, QImage_scaledToWidth_int_TransformationMode, "__QtAda_QImage_scaledToWidth_int_TransformationMode_Q");

   procedure QImage_setAlphaChannel_QImageCR
    (Self : Internals.QImage_Access;
     Alpha_Channel : Internals.QImage_Access);
   pragma Import (C, QImage_setAlphaChannel_QImageCR, "__QtAda_QImage_setAlphaChannel_QImageCR");

   procedure QImage_setDotsPerMeterX_int
    (Self : Internals.QImage_Access;
     X : Qt4.Q_Integer);
   pragma Import (C, QImage_setDotsPerMeterX_int, "__QtAda_QImage_setDotsPerMeterX_int");

   procedure QImage_setDotsPerMeterY_int
    (Self : Internals.QImage_Access;
     Y : Qt4.Q_Integer);
   pragma Import (C, QImage_setDotsPerMeterY_int, "__QtAda_QImage_setDotsPerMeterY_int");

   procedure QImage_setNumColors_int
    (Self : Internals.QImage_Access;
     Num_Colors : Qt4.Q_Integer);
   pragma Import (C, QImage_setNumColors_int, "__QtAda_QImage_setNumColors_int");

   procedure QImage_setOffset_QPointCR
    (Self : Internals.QImage_Access;
     Offset : Qt4.Points.Internals.QPoint_Access);
   pragma Import (C, QImage_setOffset_QPointCR, "__QtAda_QImage_setOffset_QPointCR");

   procedure QImage_setPixel_QPointCR_uint
    (Self : Internals.QImage_Access;
     Position : Qt4.Points.Internals.QPoint_Access;
     Index : Qt4.Q_Unsigned_Integer);
   pragma Import (C, QImage_setPixel_QPointCR_uint, "__QtAda_QImage_setPixel_QPointCR_uint");

   procedure QImage_setPixel_int_int_uint
    (Self : Internals.QImage_Access;
     X : Qt4.Q_Integer;
     Y : Qt4.Q_Integer;
     Index : Qt4.Q_Unsigned_Integer);
   pragma Import (C, QImage_setPixel_int_int_uint, "__QtAda_QImage_setPixel_int_int_uint");

   procedure QImage_setText_QStringCR_QStringCR
    (Self : Internals.QImage_Access;
     Key : Qt4.Strings.Internals.QString_Access;
     Text : Qt4.Strings.Internals.QString_Access);
   pragma Import (C, QImage_setText_QStringCR_QStringCR, "__QtAda_QImage_setText_QStringCR_QStringCR");

   procedure QImage_size
    (Returns : Qt4.Sizes.Internals.QSize_Access;
     Self : Internals.QImage_Access);
   pragma Import (C, QImage_size, "__QtAda_QImage_size_Q");

   procedure QImage_text_QStringCR
    (Returns : Qt4.Strings.Internals.QString_Access;
     Self : Internals.QImage_Access;
     Key : Qt4.Strings.Internals.QString_Access);
   pragma Import (C, QImage_text_QStringCR, "__QtAda_QImage_text_QStringCR_Q");

   procedure QImage_textKeys
    (Returns : Qt4.String_Lists.Internals.QStringList_Access;
     Self : Internals.QImage_Access);
   pragma Import (C, QImage_textKeys, "__QtAda_QImage_textKeys_Q");

   procedure QImage_transformed_QMatrixCR_TransformationMode
    (Returns : Internals.QImage_Access;
     Self : Internals.QImage_Access;
     Matrix : Qt4.Matrices.Internals.QMatrix_Access;
     Mode : Qt4.Transformation_Mode);
   pragma Import (C, QImage_transformed_QMatrixCR_TransformationMode, "__QtAda_QImage_transformed_QMatrixCR_TransformationMode_Q");

   procedure QImage_transformed_QTransformCR_TransformationMode
    (Returns : Internals.QImage_Access;
     Self : Internals.QImage_Access;
     Matrix : Qt4.Transforms.Internals.QTransform_Access;
     Mode : Qt4.Transformation_Mode);
   pragma Import (C, QImage_transformed_QTransformCR_TransformationMode, "__QtAda_QImage_transformed_QTransformCR_TransformationMode_Q");

   function QImage_valid_QPointCR
    (Self : Internals.QImage_Access;
     Pos : Qt4.Points.Internals.QPoint_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QImage_valid_QPointCR, "__QtAda_QImage_valid_QPointCR_Q");

   function QImage_valid_int_int
    (Self : Internals.QImage_Access;
     X : Qt4.Q_Integer;
     Y : Qt4.Q_Integer)
       return Interfaces.C.unsigned;
   pragma Import (C, QImage_valid_int_int, "__QtAda_QImage_valid_int_int_Q");

   function QImage_width
    (Self : Internals.QImage_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QImage_width, "__QtAda_QImage_width_Q");

   function eq_QImageCR
    (Self : Internals.QImage_Access;
     Image : Internals.QImage_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, eq_QImageCR, "__QtAda_QImage_eq_QImageCR_Q");

   procedure QImage_trueMatrix_QMatrixCR_int_int
    (Returns : Qt4.Matrices.Internals.QMatrix_Access;
     Matrix : Qt4.Matrices.Internals.QMatrix_Access;
     Width : Qt4.Q_Integer;
     Height : Qt4.Q_Integer);
   pragma Import (C, QImage_trueMatrix_QMatrixCR_int_int, "__QtAda_QImage_trueMatrix_QMatrixCR_int_int_S");

   procedure QImage_trueMatrix_QTransformCR_int_int
    (Returns : Qt4.Transforms.Internals.QTransform_Access;
     Matrix : Qt4.Transforms.Internals.QTransform_Access;
     Width : Qt4.Q_Integer;
     Height : Qt4.Q_Integer);
   pragma Import (C, QImage_trueMatrix_QTransformCR_int_int, "__QtAda_QImage_trueMatrix_QTransformCR_int_int_S");

   function C_QPaintDevice_View
    (Self : not null Internals.QImage_Access)
       return not null Qt_Ada.Internals.Paint_Devices.QPaintDevice_Access;
   pragma Import (C, C_QPaintDevice_View, "__QtAda_QImage_QPaintDevice_View");

   ------------
   -- Adjust --
   ------------

   overriding
   procedure Adjust (Self : in out Q_Image) is
   begin
      Self.Object := adjust_QImage (Self.Storage'Address, Self.Object);
      Self.Wrapper := False;
   end Adjust;

   --------------
   -- Finalize --
   --------------

   overriding
   procedure Finalize (Self : in out Q_Image) is
   begin
      if not Self.Wrapper then
         finalize_QImage (Self.Object);
      end if;
   end Finalize;

   ----------------
   -- Initialize --
   ----------------

   overriding
   procedure Initialize (Self : in out Q_Image) is
      use type Internals.QImage_Access;

   begin
      if Self.Object = null then
         Self.Object := initialize_QImage (Self.Storage'Address);
      end if;
   end Initialize;

   ------------
   -- Create --
   ------------

   function Create
    (Size : Qt4.Sizes.Q_Size'Class;
     Format : Image_Format)
       return Q_Image
   is
   begin
      return Self : Q_Image
        := (Ada.Finalization.Controlled with others => <>)
      do
         Self.Object := initialize_QImage_QSizeCR_Format (Self.Storage'Address, Qt4.Sizes.Internals.QSize_View (Size), Format);
      end return;
   end Create;

   ------------
   -- Create --
   ------------

   function Create
    (Width : Qt4.Q_Integer;
     Height : Qt4.Q_Integer;
     Format : Image_Format)
       return Q_Image
   is
   begin
      return Self : Q_Image
        := (Ada.Finalization.Controlled with others => <>)
      do
         Self.Object := initialize_QImage_int_int_Format (Self.Storage'Address, Width, Height, Format);
      end return;
   end Create;

   --------------
   -- All_Gray --
   --------------

   function All_Gray
    (Self : Q_Image'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QImage_allGray (Self.Object), 0);
   end All_Gray;

   -------------------
   -- Alpha_Channel --
   -------------------

   function Alpha_Channel
    (Self : Q_Image'Class)
       return Q_Image
   is
   begin
      return Returns : Q_Image do
         QImage_alphaChannel (Returns.Object, Self.Object);
      end return;
   end Alpha_Channel;

   --------------------
   -- Bytes_Per_Line --
   --------------------

   function Bytes_Per_Line
    (Self : Q_Image'Class)
       return Qt4.Q_Integer
   is
   begin
      return QImage_bytesPerLine (Self.Object);
   end Bytes_Per_Line;

   ---------------
   -- Cache_Key --
   ---------------

   function Cache_Key
    (Self : Q_Image'Class)
       return Qt4.Q_Integer_64
   is
   begin
      return QImage_cacheKey (Self.Object);
   end Cache_Key;

   ----------
   -- Copy --
   ----------

   function Copy
    (Self : Q_Image'Class;
     Rectangle : Qt4.Rects.Q_Rect'Class)
       return Q_Image
   is
   begin
      return Returns : Q_Image do
         QImage_copy_QRectCR (Returns.Object, Self.Object, Qt4.Rects.Internals.QRect_View (Rectangle));
      end return;
   end Copy;

   ----------
   -- Copy --
   ----------

   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
   is
   begin
      return Returns : Q_Image do
         QImage_copy_int_int_int_int (Returns.Object, Self.Object, X, Y, Width, Height);
      end return;
   end Copy;

   ---------------------------
   -- Create_Heuristic_Mask --
   ---------------------------

   function Create_Heuristic_Mask
    (Self : Q_Image'Class;
     Clip_Tight : Boolean
       := True)
       return Q_Image
   is
   begin
      return Returns : Q_Image do
         QImage_createHeuristicMask_bool (Returns.Object, Self.Object, Qt_Ada.Internals.Boolean_Conversions.To_unsigned (Clip_Tight));
      end return;
   end Create_Heuristic_Mask;

   -----------
   -- Depth --
   -----------

   function Depth
    (Self : Q_Image'Class)
       return Qt4.Q_Integer
   is
   begin
      return QImage_depth (Self.Object);
   end Depth;

   ----------------------
   -- Dots_Per_Meter_X --
   ----------------------

   function Dots_Per_Meter_X
    (Self : Q_Image'Class)
       return Qt4.Q_Integer
   is
   begin
      return QImage_dotsPerMeterX (Self.Object);
   end Dots_Per_Meter_X;

   ----------------------
   -- Dots_Per_Meter_Y --
   ----------------------

   function Dots_Per_Meter_Y
    (Self : Q_Image'Class)
       return Qt4.Q_Integer
   is
   begin
      return QImage_dotsPerMeterY (Self.Object);
   end Dots_Per_Meter_Y;

   ----------
   -- Fill --
   ----------

   procedure Fill
    (Self : in out Q_Image'Class;
     Pixel_Value : Qt4.Q_Unsigned_Integer)
   is
   begin
      QImage_fill (Self.Object, Pixel_Value);
   end Fill;

   ------------
   -- Format --
   ------------

   function Format
    (Self : Q_Image'Class)
       return Image_Format
   is
   begin
      return QImage_format (Self.Object);
   end Format;

   -----------------------
   -- Has_Alpha_Channel --
   -----------------------

   function Has_Alpha_Channel
    (Self : Q_Image'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QImage_hasAlphaChannel (Self.Object), 0);
   end Has_Alpha_Channel;

   ------------
   -- Height --
   ------------

   function Height
    (Self : Q_Image'Class)
       return Qt4.Q_Integer
   is
   begin
      return QImage_height (Self.Object);
   end Height;

   -------------------
   -- Invert_Pixels --
   -------------------

   procedure Invert_Pixels
    (Self : in out Q_Image'Class;
     Mode : Invert_Mode
       := Invert_Rgb)
   is
   begin
      QImage_invertPixels_InvertMode (Self.Object, Mode);
   end Invert_Pixels;

   ------------------
   -- Is_Grayscale --
   ------------------

   function Is_Grayscale
    (Self : Q_Image'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QImage_isGrayscale (Self.Object), 0);
   end Is_Grayscale;

   -------------
   -- Is_Null --
   -------------

   function Is_Null
    (Self : Q_Image'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QImage_isNull (Self.Object), 0);
   end Is_Null;

   --------------
   -- Mirrored --
   --------------

   function Mirrored
    (Self : Q_Image'Class;
     Horizontally : Boolean
       := False;
     Vertically : Boolean
       := True)
       return Q_Image
   is
   begin
      return Returns : Q_Image do
         QImage_mirrored_bool_bool (Returns.Object, Self.Object, Qt_Ada.Internals.Boolean_Conversions.To_unsigned (Horizontally), Qt_Ada.Internals.Boolean_Conversions.To_unsigned (Vertically));
      end return;
   end Mirrored;

   ---------------
   -- Num_Bytes --
   ---------------

   function Num_Bytes
    (Self : Q_Image'Class)
       return Qt4.Q_Integer
   is
   begin
      return QImage_numBytes (Self.Object);
   end Num_Bytes;

   ----------------
   -- Num_Colors --
   ----------------

   function Num_Colors
    (Self : Q_Image'Class)
       return Qt4.Q_Integer
   is
   begin
      return QImage_numColors (Self.Object);
   end Num_Colors;

   ------------
   -- Offset --
   ------------

   function Offset
    (Self : Q_Image'Class)
       return Qt4.Points.Q_Point
   is
   begin
      return Returns : Qt4.Points.Q_Point do
         QImage_offset (Qt4.Points.Internals.QPoint_View (Returns), Self.Object);
      end return;
   end Offset;

   -----------
   -- Pixel --
   -----------

   function Pixel
    (Self : Q_Image'Class;
     Position : Qt4.Points.Q_Point'Class)
       return Qt4.Rgbs.Q_Rgb
   is
   begin
      return QImage_pixel_QPointCR (Self.Object, Qt4.Points.Internals.QPoint_View (Position));
   end Pixel;

   -----------
   -- Pixel --
   -----------

   function Pixel
    (Self : Q_Image'Class;
     X : Qt4.Q_Integer;
     Y : Qt4.Q_Integer)
       return Qt4.Rgbs.Q_Rgb
   is
   begin
      return QImage_pixel_int_int (Self.Object, X, Y);
   end Pixel;

   -----------------
   -- Pixel_Index --
   -----------------

   function Pixel_Index
    (Self : Q_Image'Class;
     Position : Qt4.Points.Q_Point'Class)
       return Qt4.Q_Unsigned_Integer
   is
   begin
      return QImage_pixelIndex_QPointCR (Self.Object, Qt4.Points.Internals.QPoint_View (Position));
   end Pixel_Index;

   -----------------
   -- Pixel_Index --
   -----------------

   function Pixel_Index
    (Self : Q_Image'Class;
     X : Qt4.Q_Integer;
     Y : Qt4.Q_Integer)
       return Qt4.Q_Unsigned_Integer
   is
   begin
      return QImage_pixelIndex_int_int (Self.Object, X, Y);
   end Pixel_Index;

   ----------
   -- Rect --
   ----------

   function Rect
    (Self : Q_Image'Class)
       return Qt4.Rects.Q_Rect
   is
   begin
      return Returns : Qt4.Rects.Q_Rect do
         QImage_rect (Qt4.Rects.Internals.QRect_View (Returns), Self.Object);
      end return;
   end Rect;

   -----------------
   -- Rgb_Swapped --
   -----------------

   function Rgb_Swapped
    (Self : Q_Image'Class)
       return Q_Image
   is
   begin
      return Returns : Q_Image do
         QImage_rgbSwapped (Returns.Object, Self.Object);
      end return;
   end Rgb_Swapped;

   ------------
   -- Scaled --
   ------------

   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
   is
   begin
      return Returns : Q_Image do
         QImage_scaled_QSizeCR_AspectRatioMode_TransformationMode (Returns.Object, Self.Object, Qt4.Sizes.Internals.QSize_View (Size), Aspect_Mode, Mode);
      end return;
   end Scaled;

   ------------
   -- Scaled --
   ------------

   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
   is
   begin
      return Returns : Q_Image do
         QImage_scaled_int_int_AspectRatioMode_TransformationMode (Returns.Object, Self.Object, Width, Height, Aspect_Mode, Mode);
      end return;
   end Scaled;

   ----------------------
   -- Scaled_To_Height --
   ----------------------

   function Scaled_To_Height
    (Self : Q_Image'Class;
     Height : Qt4.Q_Integer;
     Mode : Qt4.Transformation_Mode
       := Fast_Transformation)
       return Q_Image
   is
   begin
      return Returns : Q_Image do
         QImage_scaledToHeight_int_TransformationMode (Returns.Object, Self.Object, Height, Mode);
      end return;
   end Scaled_To_Height;

   ---------------------
   -- Scaled_To_Width --
   ---------------------

   function Scaled_To_Width
    (Self : Q_Image'Class;
     Width : Qt4.Q_Integer;
     Mode : Qt4.Transformation_Mode
       := Fast_Transformation)
       return Q_Image
   is
   begin
      return Returns : Q_Image do
         QImage_scaledToWidth_int_TransformationMode (Returns.Object, Self.Object, Width, Mode);
      end return;
   end Scaled_To_Width;

   -----------------------
   -- Set_Alpha_Channel --
   -----------------------

   procedure Set_Alpha_Channel
    (Self : in out Q_Image'Class;
     Alpha_Channel : Q_Image'Class)
   is
   begin
      QImage_setAlphaChannel_QImageCR (Self.Object, Alpha_Channel.Object);
   end Set_Alpha_Channel;

   --------------------------
   -- Set_Dots_Per_Meter_X --
   --------------------------

   procedure Set_Dots_Per_Meter_X
    (Self : in out Q_Image'Class;
     X : Qt4.Q_Integer)
   is
   begin
      QImage_setDotsPerMeterX_int (Self.Object, X);
   end Set_Dots_Per_Meter_X;

   --------------------------
   -- Set_Dots_Per_Meter_Y --
   --------------------------

   procedure Set_Dots_Per_Meter_Y
    (Self : in out Q_Image'Class;
     Y : Qt4.Q_Integer)
   is
   begin
      QImage_setDotsPerMeterY_int (Self.Object, Y);
   end Set_Dots_Per_Meter_Y;

   --------------------
   -- Set_Num_Colors --
   --------------------

   procedure Set_Num_Colors
    (Self : in out Q_Image'Class;
     Num_Colors : Qt4.Q_Integer)
   is
   begin
      QImage_setNumColors_int (Self.Object, Num_Colors);
   end Set_Num_Colors;

   ----------------
   -- Set_Offset --
   ----------------

   procedure Set_Offset
    (Self : in out Q_Image'Class;
     Offset : Qt4.Points.Q_Point'Class)
   is
   begin
      QImage_setOffset_QPointCR (Self.Object, Qt4.Points.Internals.QPoint_View (Offset));
   end Set_Offset;

   ---------------
   -- Set_Pixel --
   ---------------

   procedure Set_Pixel
    (Self : in out Q_Image'Class;
     Position : Qt4.Points.Q_Point'Class;
     Index : Qt4.Q_Unsigned_Integer)
   is
   begin
      QImage_setPixel_QPointCR_uint
       (Self.Object, Qt4.Points.Internals.QPoint_View (Position), Index);
   end Set_Pixel;

   ---------------
   -- Set_Pixel --
   ---------------

   procedure Set_Pixel
    (Self : in out Q_Image'Class;
     X : Qt4.Q_Integer;
     Y : Qt4.Q_Integer;
     Index : Qt4.Q_Unsigned_Integer)
   is
   begin
      QImage_setPixel_int_int_uint (Self.Object, X, Y, Index);
   end Set_Pixel;

   ---------------
   -- Set_Pixel --
   ---------------

   procedure Set_Pixel
    (Self : in out Q_Image'Class;
     Position : Qt4.Points.Q_Point'Class;
     Rgb : Qt4.Rgbs.Q_Rgb)
   is
   begin
      QImage_setPixel_QPointCR_uint (Self.Object, Qt4.Points.Internals.QPoint_View (Position), Qt4.Rgbs.To_Unsigned_Integer (Rgb));
   end Set_Pixel;

   ---------------
   -- Set_Pixel --
   ---------------

   procedure Set_Pixel
    (Self : in out Q_Image'Class;
     X : Qt4.Q_Integer;
     Y : Qt4.Q_Integer;
     Rgb : Qt4.Rgbs.Q_Rgb)
   is
   begin
      QImage_setPixel_int_int_uint (Self.Object, X, Y, Qt4.Rgbs.To_Unsigned_Integer (Rgb));
   end Set_Pixel;

   --------------
   -- Set_Text --
   --------------

   procedure Set_Text
    (Self : in out Q_Image'Class;
     Key : Qt4.Strings.Q_String'Class;
     Text : Qt4.Strings.Q_String'Class)
   is
   begin
      QImage_setText_QStringCR_QStringCR (Self.Object, Qt4.Strings.Internals.QString_View (Key), Qt4.Strings.Internals.QString_View (Text));
   end Set_Text;

   ----------
   -- Size --
   ----------

   function Size
    (Self : Q_Image'Class)
       return Qt4.Sizes.Q_Size
   is
   begin
      return Returns : Qt4.Sizes.Q_Size do
         QImage_size (Qt4.Sizes.Internals.QSize_View (Returns), Self.Object);
      end return;
   end Size;

   ----------
   -- Text --
   ----------

   function Text
    (Self : Q_Image'Class;
     Key : Qt4.Strings.Q_String'Class)
       return Qt4.Strings.Q_String
   is
   begin
      return Returns : Qt4.Strings.Q_String do
         QImage_text_QStringCR (Qt4.Strings.Internals.QString_View (Returns), Self.Object, Qt4.Strings.Internals.QString_View (Key));
      end return;
   end Text;

   ---------------
   -- Text_Keys --
   ---------------

   function Text_Keys
    (Self : Q_Image'Class)
       return Qt4.String_Lists.Q_String_List
   is
   begin
      return Returns : Qt4.String_Lists.Q_String_List do
         QImage_textKeys (Qt4.String_Lists.Internals.QStringList_View (Returns), Self.Object);
      end return;
   end Text_Keys;

   -----------------
   -- Transformed --
   -----------------

   function Transformed
    (Self : Q_Image'Class;
     Matrix : Qt4.Matrices.Q_Matrix'Class;
     Mode : Qt4.Transformation_Mode
       := Fast_Transformation)
       return Q_Image
   is
   begin
      return Returns : Q_Image do
         QImage_transformed_QMatrixCR_TransformationMode (Returns.Object, Self.Object, Qt4.Matrices.Internals.QMatrix_View (Matrix), Mode);
      end return;
   end Transformed;

   -----------------
   -- Transformed --
   -----------------

   function Transformed
    (Self : Q_Image'Class;
     Matrix : Qt4.Transforms.Q_Transform'Class;
     Mode : Qt4.Transformation_Mode
       := Fast_Transformation)
       return Q_Image
   is
   begin
      return Returns : Q_Image do
         QImage_transformed_QTransformCR_TransformationMode (Returns.Object, Self.Object, Qt4.Transforms.Internals.QTransform_View (Matrix), Mode);
      end return;
   end Transformed;

   -----------
   -- Valid --
   -----------

   function Valid
    (Self : Q_Image'Class;
     Pos : Qt4.Points.Q_Point'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QImage_valid_QPointCR (Self.Object, Qt4.Points.Internals.QPoint_View (Pos)), 0);
   end Valid;

   -----------
   -- Valid --
   -----------

   function Valid
    (Self : Q_Image'Class;
     X : Qt4.Q_Integer;
     Y : Qt4.Q_Integer)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QImage_valid_int_int (Self.Object, X, Y), 0);
   end Valid;

   -----------
   -- Width --
   -----------

   function Width
    (Self : Q_Image'Class)
       return Qt4.Q_Integer
   is
   begin
      return QImage_width (Self.Object);
   end Width;

   ---------
   -- "=" --
   ---------

   overriding
   function "="
    (Self : Q_Image;
     Image : Q_Image)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (eq_QImageCR (Self.Object, Image.Object), 0);
   end "=";

   -----------------
   -- True_Matrix --
   -----------------

   function True_Matrix
    (Matrix : Qt4.Matrices.Q_Matrix'Class;
     Width : Qt4.Q_Integer;
     Height : Qt4.Q_Integer)
       return Qt4.Matrices.Q_Matrix
   is
   begin
      return Returns : Qt4.Matrices.Q_Matrix do
         QImage_trueMatrix_QMatrixCR_int_int (Qt4.Matrices.Internals.QMatrix_View (Returns), Qt4.Matrices.Internals.QMatrix_View (Matrix), Width, Height);
      end return;
   end True_Matrix;

   -----------------
   -- True_Matrix --
   -----------------

   function True_Matrix
    (Matrix : Qt4.Transforms.Q_Transform'Class;
     Width : Qt4.Q_Integer;
     Height : Qt4.Q_Integer)
       return Qt4.Transforms.Q_Transform
   is
   begin
      return Returns : Qt4.Transforms.Q_Transform do
         QImage_trueMatrix_QTransformCR_int_int (Qt4.Transforms.Internals.QTransform_View (Returns), Qt4.Transforms.Internals.QTransform_View (Matrix), Width, Height);
      end return;
   end True_Matrix;

   -----------------------
   -- QPaintDevice_View --
   -----------------------

   overriding
   function QPaintDevice_View
    (Self : not null access constant Q_Image)
       return not null Qt_Ada.Internals.Paint_Devices.QPaintDevice_Access
   is
   begin
      return
        C_QPaintDevice_View (Internals.QImage_View (Q_Image'Class (Self.all)));
   end QPaintDevice_View;

   ------------------
   -- Paint_Engine --
   ------------------

   overriding
   function Paint_Engine
    (Self : not null access Q_Image)
       return not null access Qt4.Paint_Engines.Q_Paint_Engine
   is
   begin
      pragma Warnings (Off);
      raise Program_Error;
      return null;
      pragma Warnings (On);
   end Paint_Engine;

   ---------------
   -- Internals --
   ---------------

   package body Internals is

   -----------------
   -- QImage_View --
   -----------------

      function QImage_View
       (Item : Q_Image'Class)
          return QImage_Access
      is
      begin
         return Item.Object;
      end QImage_View;

      package QImage_Conversions is
        new System.Address_To_Access_Conversions
             (QImage);

   ----------------------
   -- QImageTo_Pointer --
   ----------------------

      function To_Pointer
       (Address : System.Address)
          return QImage_Access
      is
      begin
         return
           QImage_Access
            (QImage_Conversions.To_Pointer
            (Address));
      end To_Pointer;

   ----------------------
   -- QImageTo_Address --
   ----------------------

      function To_Address
       (Pointer : QImage_Access)
          return System.Address
      is
      begin
         return
           QImage_Conversions.To_Address
            (QImage_Conversions.Object_Pointer
              (Pointer));
      end To_Address;

   --------------------
   -- Create_Wrapper --
   --------------------

      function Create_Wrapper
       (Item : Internals.QImage_Access)
          return Q_Image
      is
      begin
         return Q_Image'
          (Ada.Finalization.Controlled with
             Object  => Item,
             Wrapper => True,
             others  => <>);
      end Create_Wrapper;

   end Internals;

end Qt4.Images;
