1. ----------------------------------------------------------------------- 
  2. --               GtkAda - Ada95 binding for Gtk+/Gnome               -- 
  3. --                                                                   -- 
  4. --   Copyright (C) 1998-2000 E. Briot, J. Brobecker and A. Charlet   -- 
  5. --                Copyright (C) 2000-2013, AdaCore                   -- 
  6. --                                                                   -- 
  7. -- This library is free software; you can redistribute it and/or     -- 
  8. -- modify it under the terms of the GNU General Public               -- 
  9. -- License as published by the Free Software Foundation; either      -- 
  10. -- version 2 of the License, or (at your option) any later version.  -- 
  11. --                                                                   -- 
  12. -- This library is distributed in the hope that it will be useful,   -- 
  13. -- but WITHOUT ANY WARRANTY; without even the implied warranty of    -- 
  14. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -- 
  15. -- General Public License for more details.                          -- 
  16. --                                                                   -- 
  17. -- You should have received a copy of the GNU General Public         -- 
  18. -- License along with this library; if not, write to the             -- 
  19. -- Free Software Foundation, Inc., 59 Temple Place - Suite 330,      -- 
  20. -- Boston, MA 02111-1307, USA.                                       -- 
  21. --                                                                   -- 
  22. -- As a special exception, if other files instantiate generics from  -- 
  23. -- this unit, or you link this unit with other files to produce an   -- 
  24. -- executable, this  unit  does not  by itself cause  the resulting  -- 
  25. -- executable to be covered by the GNU General Public License. This  -- 
  26. -- exception does not however invalidate any other reasons why the   -- 
  27. -- executable file  might be covered by the  GNU Public License.     -- 
  28. ----------------------------------------------------------------------- 
  29.  
  30. --  <description> 
  31. -- 
  32. --  This package implements a client-side pixmap. As opposed to the pixmaps 
  33. --  found in Gdk.Pixmap, this one simply implements a local buffer, which 
  34. --  can be manipulated at the pixel level easily. This buffer then needs to 
  35. --  be sent to the server. 
  36. --  The major efficiency difference is that the same amount of data needs 
  37. --  to be sent to the server no matter how much things were modified. 
  38. --  Gdk.Pixmaps requires one communication with the server per drawing 
  39. --  function. 
  40. --  Some X servers are also optimized so that the buffers in this package 
  41. --  can be implemented in shared memory with the server, which of course 
  42. --  makes it much faster to transfer the data. 
  43. --  This package is basically an implementation of XImage (on X-Window), 
  44. --  which means that it handles transparently different depths, byte 
  45. --  ordering,... It also provides some color dithering functions. 
  46. -- 
  47. --  See the commands Get_Visual and Get_Cmap below on how to use the 
  48. --  colormaps and visual with this package 
  49. -- 
  50. --  Dithering simulates a higher number of colors than what is available on 
  51. --  the current visual (only for 8-bit and 16-bit displays). 
  52. -- 
  53. --  </description> 
  54.  
  55. --  <c_version>1.3.6</c_version> 
  56. --  <group>Gdk, the low-level API</group> 
  57.  
  58. with Glib; 
  59. with Gdk.Color; 
  60. with Gdk.Visual; 
  61. with Gdk.GC; 
  62. with Gdk.Drawable; 
  63.  
  64. package Gdk.Rgb is 
  65.  
  66.    function Get_Visual return Gdk.Visual.Gdk_Visual; 
  67.    --  See Get_Cmap. 
  68.  
  69.    function Get_Cmap return Gdk.Color.Gdk_Colormap; 
  70.    --  Return the visual and the color map used internally in this package. 
  71.    --  Note that these are not the same as returned by Gtk.Widget or 
  72.    --  Gdk.Window, and you should use these if you are using this package. 
  73.    -- 
  74.    --  The drawable you intend to copy the RGB buffer to must use this visual 
  75.    --  and this colormap. Therefore, before creating the widget, you need to do 
  76.    --  the following: 
  77.    --    - Gtk.Widget.Push_Colormap (Gdk.Rgb.Get_Cmap); 
  78.    --    - Gtk_New (....) 
  79.    --    - Gtk.Widget.Pop_Colormap; 
  80.  
  81.    type Rgb_Record is record 
  82.       Red, Green, Blue : Glib.Guchar; 
  83.    end record; 
  84.    pragma Convention (C, Rgb_Record); 
  85.  
  86.    type Rgb_Buffer is array (Glib.Guint range <>) of Rgb_Record; 
  87.    pragma Pack (Rgb_Buffer); 
  88.    --  This is the buffer that will contain the image. You can manipulate each 
  89.    --  byte in it independantly, although there is no high level routine 
  90.    --  to draw lines, circles, ... 
  91.    --  Once you are done drawing into this buffer, you can copy it to any 
  92.    --  drawable on the screen, *if* the widget was created with the correct 
  93.    --  visual and colormap (see above). 
  94.  
  95.    type Unchecked_Rgb_Buffer is array (Glib.Guint) of Rgb_Record; 
  96.    pragma Convention (C, Unchecked_Rgb_Buffer); 
  97.    type Rgb_Buffer_Access is access all Unchecked_Rgb_Buffer; 
  98.    pragma Convention (C, Rgb_Buffer_Access); 
  99.    --  Type used By Gdk.Pixbufs.Get_Pixels to return an array with no 
  100.    --  bound checks that is compatible with C (also known as a flat array). 
  101.  
  102.    type Gdk_Rgb_Dither is (Dither_None, Dither_Normal, Dither_Max); 
  103.    --  The three kinds of dithering that are implemented in this package: 
  104.    --  - Dither_None: No dithering will be done 
  105.    --  - Dither_Normal: Specifies dithering on 8 bit displays, but not 16-bit. 
  106.    --                   Usually the best choice. 
  107.    --  - Dither_Max: Specifies dithering on every kind of display 
  108.    for Gdk_Rgb_Dither'Size use Glib.Gint'Size; 
  109.  
  110.    ------------------------ 
  111.    -- Color manipulation -- 
  112.    ------------------------ 
  113.  
  114.    subtype Rgb_Item is Glib.Guint32; 
  115.    --  This represents the coding for a rbg value. The exact encoding depends 
  116.    --  on the visual used and its depth (pseudo-color, true-color, ...) 
  117.  
  118.    function Xpixel_From_Rgb (Value : in Rgb_Item) return Glib.Gulong; 
  119.    --  Convert the Rgb representation to the usual one found in Gdk.Color. 
  120.    --  pragma Deprecated (Xpixel_From_Rgb); 
  121.  
  122.    procedure GC_Set_Foreground 
  123.      (GC : Gdk.GC.Gdk_GC; Value : Rgb_Item); 
  124.    --  See GC_Set_Background. 
  125.    --  pragma Deprecated (GC_Set_Foreground); 
  126.  
  127.    procedure GC_Set_Background 
  128.      (GC : Gdk.GC.Gdk_GC; Value : Rgb_Item); 
  129.    --  Modify the foreground and the background of a graphic context with a 
  130.    --  value. These are exactly the same functions has found in Gdk.Gc, but do 
  131.    --  not use the same parameters. 
  132.    --  pragma Deprecated (GC_Set_Background); 
  133.  
  134.    --------------------------- 
  135.    -- Colormap manipulation -- 
  136.    --------------------------- 
  137.  
  138.    type Gdk_Rgb_Cmap is new Gdk.C_Proxy; 
  139.    --  This is the full colormap, ie a set of 256 Rgb items. 
  140.    --  You can extract values using the functions Get or Set below. 
  141.  
  142.    type Rgb_Cmap_Index is new Natural range 0 .. 255; 
  143.  
  144.    function Get (Cmap : Gdk_Rgb_Cmap; Index : Rgb_Cmap_Index) return Rgb_Item; 
  145.    --  Access an item in a colormap. 
  146.  
  147.    procedure Set 
  148.      (Cmap : Gdk_Rgb_Cmap; Index : Rgb_Cmap_Index; Value : Rgb_Item); 
  149.    --  Set an item in Cmap. 
  150.  
  151.    procedure Gdk_New (Cmap : out Gdk_Rgb_Cmap; Colors : Glib.Guint32_Array); 
  152.    --  Create a colormap. 
  153.  
  154.    procedure Free (Cmap : Gdk_Rgb_Cmap); 
  155.    --  Free a colormap. 
  156.  
  157.    -------------------- 
  158.    -- Drawing Images -- 
  159.    -------------------- 
  160.  
  161.    procedure Draw_Rgb_Image 
  162.      (Drawable      : Gdk.Drawable.Gdk_Drawable; 
  163.       GC            : Gdk.GC.Gdk_GC; 
  164.       X, Y          : Glib.Gint; 
  165.       Width, Height : Glib.Gint; 
  166.       Dith          : Gdk_Rgb_Dither; 
  167.       Rgb_Buf       : Rgb_Buffer; 
  168.       Rowstride     : Glib.Gint); 
  169.    procedure Draw_Rgb_Image 
  170.      (Drawable      : Gdk.Drawable.Gdk_Drawable; 
  171.       GC            : Gdk.GC.Gdk_GC; 
  172.       X, Y          : Glib.Gint; 
  173.       Width, Height : Glib.Gint; 
  174.       Dith          : Gdk_Rgb_Dither; 
  175.       Rgb_Buf       : Unchecked_Rgb_Buffer; 
  176.       Rowstride     : Glib.Gint); 
  177.    --  Render a Gdk buffer with 24 bit Data. 
  178.    --  Such a buffer is a one dimensional array of bytes, where every byte 
  179.    --  triplet makes up a pixel (byte 0 is red, byte 1 is green and byte 2 is 
  180.    --  blue). 
  181.    -- 
  182.    --  - Width: Number of pixels (byte triplets) per row of the image. 
  183.    --  - Height: Number of rows in the image. 
  184.    --  - RowStride: Number of bytes between rows... (row n+1 will start at byte 
  185.    --     row n + Rowstride). Gdk.Rgb is faster if both the source pointer and 
  186.    --     the rowstride are aligned to a 4 byte boundary. 
  187.    --  - (X, Y, Width, Height): Define a region in the target to copy the 
  188.    --     buffer to. 
  189.  
  190.    procedure Draw_Rgb_Image_Dithalign 
  191.      (Drawable      : Gdk.Drawable.Gdk_Drawable; 
  192.       GC            : Gdk.GC.Gdk_GC; 
  193.       X, Y          : Glib.Gint; 
  194.       Width, Height : Glib.Gint; 
  195.       Dith          : Gdk_Rgb_Dither; 
  196.       Rgb_Buf       : Rgb_Buffer; 
  197.       Rowstride     : Glib.Gint; 
  198.       Xdith, Ydith  : Glib.Gint); 
  199.    procedure Draw_Rgb_Image_Dithalign 
  200.      (Drawable      : Gdk.Drawable.Gdk_Drawable; 
  201.       GC            : Gdk.GC.Gdk_GC; 
  202.       X, Y          : Glib.Gint; 
  203.       Width, Height : Glib.Gint; 
  204.       Dith          : Gdk_Rgb_Dither; 
  205.       Rgb_Buf       : Unchecked_Rgb_Buffer; 
  206.       Rowstride     : Glib.Gint; 
  207.       Xdith, Ydith  : Glib.Gint); 
  208.    --  Same kind of function as above, but for different buffer types (???). 
  209.  
  210.    procedure Draw_Rgb_32_Image 
  211.      (Drawable      : Gdk.Drawable.Gdk_Drawable; 
  212.       GC            : Gdk.GC.Gdk_GC; 
  213.       X, Y          : Glib.Gint; 
  214.       Width, Height : Glib.Gint; 
  215.       Dith          : Gdk_Rgb_Dither; 
  216.       Rgb_Buf       : Rgb_Buffer; 
  217.       Rowstride     : Glib.Gint); 
  218.    procedure Draw_Rgb_32_Image 
  219.      (Drawable      : Gdk.Drawable.Gdk_Drawable; 
  220.       GC            : Gdk.GC.Gdk_GC; 
  221.       X, Y          : Glib.Gint; 
  222.       Width, Height : Glib.Gint; 
  223.       Dith          : Gdk_Rgb_Dither; 
  224.       Rgb_Buf       : Unchecked_Rgb_Buffer; 
  225.       Rowstride     : Glib.Gint); 
  226.    --  Same kind of function as above, but for different buffer types (???). 
  227.  
  228.    procedure Draw_Rgb_32_Image_Dithalign 
  229.      (Drawable      : Gdk.Drawable.Gdk_Drawable; 
  230.       GC            : Gdk.GC.Gdk_GC; 
  231.       X, Y          : Glib.Gint; 
  232.       Width, Height : Glib.Gint; 
  233.       Dith          : Gdk_Rgb_Dither; 
  234.       Rgb_Buf       : Rgb_Buffer; 
  235.       Rowstride     : Glib.Gint; 
  236.       Xdith, Ydith  : Glib.Gint); 
  237.    procedure Draw_Rgb_32_Image_Dithalign 
  238.      (Drawable      : Gdk.Drawable.Gdk_Drawable; 
  239.       GC            : Gdk.GC.Gdk_GC; 
  240.       X, Y          : Glib.Gint; 
  241.       Width, Height : Glib.Gint; 
  242.       Dith          : Gdk_Rgb_Dither; 
  243.       Rgb_Buf       : Unchecked_Rgb_Buffer; 
  244.       Rowstride     : Glib.Gint; 
  245.       Xdith, Ydith  : Glib.Gint); 
  246.    --  Same kind of function as above, but for different buffer types (???). 
  247.  
  248.    procedure Draw_Gray_Image 
  249.      (Drawable      : Gdk.Drawable.Gdk_Drawable; 
  250.       GC            : Gdk.GC.Gdk_GC; 
  251.       X, Y          : Glib.Gint; 
  252.       Width, Height : Glib.Gint; 
  253.       Dith          : Gdk_Rgb_Dither; 
  254.       Rgb_Buf       : Rgb_Buffer; 
  255.       Rowstride     : Glib.Gint); 
  256.    procedure Draw_Gray_Image 
  257.      (Drawable      : Gdk.Drawable.Gdk_Drawable; 
  258.       GC            : Gdk.GC.Gdk_GC; 
  259.       X, Y          : Glib.Gint; 
  260.       Width, Height : Glib.Gint; 
  261.       Dith          : Gdk_Rgb_Dither; 
  262.       Rgb_Buf       : Unchecked_Rgb_Buffer; 
  263.       Rowstride     : Glib.Gint); 
  264.    --  Same kind of function as above, but for different buffer types (???). 
  265.  
  266.    procedure Draw_Indexed_Image 
  267.      (Drawable      : Gdk.Drawable.Gdk_Drawable; 
  268.       GC            : Gdk.GC.Gdk_GC; 
  269.       X, Y          : Glib.Gint; 
  270.       Width, Height : Glib.Gint; 
  271.       Dith          : Gdk_Rgb_Dither; 
  272.       Rgb_Buf       : Rgb_Buffer; 
  273.       Rowstride     : Glib.Gint; 
  274.       Cmap          : Gdk_Rgb_Cmap); 
  275.    procedure Draw_Indexed_Image 
  276.      (Drawable      : Gdk.Drawable.Gdk_Drawable; 
  277.       GC            : Gdk.GC.Gdk_GC; 
  278.       X, Y          : Glib.Gint; 
  279.       Width, Height : Glib.Gint; 
  280.       Dith          : Gdk_Rgb_Dither; 
  281.       Rgb_Buf       : Unchecked_Rgb_Buffer; 
  282.       Rowstride     : Glib.Gint; 
  283.       Cmap          : Gdk_Rgb_Cmap); 
  284.    --  Same kind of function as above, but for different buffer types (???). 
  285.  
  286. private 
  287.    pragma Inline (Get); 
  288.    pragma Inline (Set); 
  289.  
  290.    pragma Import (C, GC_Set_Background, "gdk_rgb_gc_set_background"); 
  291.    pragma Import (C, GC_Set_Foreground, "gdk_rgb_gc_set_foreground"); 
  292.    pragma Import (C, Get_Cmap, "gdk_rgb_get_colormap"); 
  293.    pragma Import (C, Get_Visual, "gdk_rgb_get_visual"); 
  294.    pragma Import (C, Xpixel_From_Rgb, "gdk_rgb_xpixel_from_rgb"); 
  295.    pragma Import (C, Get, "ada_rgb_cmap_get"); 
  296.    pragma Import (C, Set, "ada_rgb_cmap_set"); 
  297.    pragma Import (C, Free, "gdk_rgb_cmap_free"); 
  298. end Gdk.Rgb;