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