File: gdk-rgb.ads

package info (click to toggle)
libgtkada2 2.8.1-6lenny3
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 13,496 kB
  • ctags: 3,886
  • sloc: ada: 103,189; ansic: 45,411; perl: 5,500; sh: 2,812; makefile: 1,169; xml: 19
file content (243 lines) | stat: -rw-r--r-- 10,405 bytes parent folder | download | duplicates (2)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
-----------------------------------------------------------------------
--               GtkAda - Ada95 binding for Gtk+/Gnome               --
--                                                                   --
--   Copyright (C) 1998-2000 E. Briot, J. Brobecker and A. Charlet   --
--                Copyright (C) 2000-2003 ACT-Europe                 --
--                                                                   --
-- This library is free software; you can redistribute it and/or     --
-- modify it under the terms of the GNU General Public               --
-- License as published by the Free Software Foundation; either      --
-- version 2 of the License, or (at your option) any later version.  --
--                                                                   --
-- This library is distributed in the hope that it will be useful,   --
-- but WITHOUT 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 along with this library; if not, write to the             --
-- Free Software Foundation, Inc., 59 Temple Place - Suite 330,      --
-- Boston, MA 02111-1307, USA.                                       --
--                                                                   --
-----------------------------------------------------------------------

--  <description>
--
--  This package implements a client-side pixmap. As opposed to the pixmaps
--  found in Gdk.Pixmap, this one simply implements a local buffer, which
--  can be manipulated at the pixel level easily. This buffer then needs to
--  be sent to the server.
--  The major efficiency difference is that the same amount of data needs
--  to be sent to the server no matter how much things were modified.
--  Gdk.Pixmaps requires one communication with the server per drawing
--  function.
--  Some X servers are also optimized so that the buffers in this package
--  can be implemented in shared memory with the server, which of course
--  makes it much faster to transfer the data.
--  This package is basically an implementation of XImage (on X-Window),
--  which means that it handles transparently different depths, byte
--  ordering,... It also provides some color dithering functions.
--
--  See the commands Get_Visual and Get_Cmap below on how to use the
--  colormaps and visual with this package
--
--  Dithering simulates a higher number of colors than what is available on
--  the current visual (only for 8-bit and 16-bit displays).
--
--  </description>

--  <c_version>1.3.6</c_version>
--  <group>Gdk, the low-level API</group>

with Glib;
with Gdk.Color;
with Gdk.Visual;
with Gdk.GC;
with Gdk.Drawable;

package Gdk.Rgb is

   function Get_Visual return Gdk.Visual.Gdk_Visual;
   --  See Get_Cmap.

   function Get_Cmap return Gdk.Color.Gdk_Colormap;
   --  Return the visual and the color map used internally in this package.
   --  Note that these are not the same as returned by Gtk.Widget or
   --  Gdk.Window, and you should use these if you are using this package.
   --
   --  The drawable you intend to copy the RGB buffer to must use this visual
   --  and this colormap. Therefore, before creating the widget, you need to do
   --  the following:
   --    - Gtk.Widget.Push_Visual (Gdk.Rgb.Get_Visual);
   --    - Gtk.Widget.Push_Colormap (Gdk.Rgb.Get_Cmap);
   --    - Gtk_New (....)
   --    - Gtk.Widget.Pop_Visual;
   --    - Gtk.Widget.Pop_Colormap;

   type Rgb_Buffer is array (Natural) of Glib.Guchar;
   pragma Convention (C, Rgb_Buffer);
   --  This is the buffer that will contain the image. You can manipulate each
   --  byte in it independantly, although there is no high level routine
   --  to draw lines, circles, ...
   --  Once you are done drawing into this buffer, you can copy it to any
   --  drawable on the screen, *if* the widget was created with the correct
   --  visual and colormap (see above).

   type Rgb_Buffer_Access is access all Rgb_Buffer;
   pragma Convention (C, Rgb_Buffer_Access);
   --  Type used By Gdk.Pixbufs.Get_Pixels below to return an array with no
   --  bound checks that is comatible with C (also known as a flat array).

   type Gdk_Rgb_Dither is (Dither_None, Dither_Normal, Dither_Max);
   --  The three kinds of dithering that are implemented in this package:
   --  - Dither_None: No dithering will be done
   --  - Dither_Normal: Specifies dithering on 8 bit displays, but not 16-bit.
   --                   Usually the best choice.
   --  - Dither_Max: Specifies dithering on every kind of display
   for Gdk_Rgb_Dither'Size use Glib.Gint'Size;

   ------------------------
   -- Color manipulation --
   ------------------------

   subtype Rgb_Item is Glib.Guint32;
   --  This represents the coding for a rbg value. The exact encoding depends
   --  on the visual used and its depth (pseudo-color, true-color, ...)

   function Xpixel_From_Rgb (Value : in Rgb_Item) return Glib.Gulong;
   --  Convert the Rgb representation to the usual one found in Gdk.Color.
   --  pragma Deprecated (Xpixel_From_Rgb);

   procedure GC_Set_Foreground
     (GC : Gdk.GC.Gdk_GC; Value : Rgb_Item);
   --  See GC_Set_Background.
   --  pragma Deprecated (GC_Set_Foreground);

   procedure GC_Set_Background
     (GC : Gdk.GC.Gdk_GC; Value : Rgb_Item);
   --  Modify the foreground and the background of a graphic context with a
   --  value. These are exactly the same functions has found in Gdk.Gc, but do
   --  not use the same parameters.
   --  pragma Deprecated (GC_Set_Background);

   ---------------------------
   -- Colormap manipulation --
   ---------------------------

   type Gdk_Rgb_Cmap is new Gdk.C_Proxy;
   --  This is the full colormap, ie a set of 256 Rgb items.
   --  You can extract values using the functions Get or Set below.

   type Rgb_Cmap_Index is new Natural range 0 .. 255;

   function Get (Cmap : Gdk_Rgb_Cmap; Index : Rgb_Cmap_Index) return Rgb_Item;
   --  Access an item in a colormap.

   procedure Set
     (Cmap : Gdk_Rgb_Cmap; Index : Rgb_Cmap_Index; Value : Rgb_Item);
   --  Set an item in Cmap.

   procedure Gdk_New (Cmap : out Gdk_Rgb_Cmap; Colors : Glib.Guint32_Array);
   --  Create a colormap.

   procedure Free (Cmap : Gdk_Rgb_Cmap);
   --  Free a colormap.

   --------------------
   -- Drawing Images --
   --------------------

   procedure Draw_Rgb_Image
     (Drawable      : Gdk.Drawable.Gdk_Drawable;
      GC            : Gdk.GC.Gdk_GC;
      X, Y          : Glib.Gint;
      Width, Height : Glib.Gint;
      Dith          : Gdk_Rgb_Dither;
      Rgb_Buf       : Rgb_Buffer;
      Rowstride     : Glib.Gint);
   --  Render a Gdk buffer with 24 bit Data.
   --  Such a buffer is a one dimensional array of bytes, where every byte
   --  triplet makes up a pixel (byte 0 is red, byte 1 is green and byte 2 is
   --  blue).
   --
   --  - Width: Number of pixels (byte triplets) per row of the image.
   --  - Height: Number of rows in the image.
   --  - RowStride: Number of bytes between rows... (row n+1 will start at byte
   --     row n + Rowstride). Gdk.Rgb is faster if both the source pointer and
   --     the rowstride are aligned to a 4 byte boundary.
   --  - (X, Y, Width, Height): Define a region in the target to copy the
   --     buffer to.

   procedure Draw_Rgb_Image_Dithalign
     (Drawable      : Gdk.Drawable.Gdk_Drawable;
      GC            : Gdk.GC.Gdk_GC;
      X, Y          : Glib.Gint;
      Width, Height : Glib.Gint;
      Dith          : Gdk_Rgb_Dither;
      Rgb_Buf       : Rgb_Buffer;
      Rowstride     : Glib.Gint;
      Xdith, Ydith  : Glib.Gint);
   --  Same kind of function as above, but for different buffer types (???).

   procedure Draw_Rgb_32_Image
     (Drawable      : Gdk.Drawable.Gdk_Drawable;
      GC            : Gdk.GC.Gdk_GC;
      X, Y          : Glib.Gint;
      Width, Height : Glib.Gint;
      Dith          : Gdk_Rgb_Dither;
      Rgb_Buf       : Rgb_Buffer;
      Rowstride     : Glib.Gint);
   --  Same kind of function as above, but for different buffer types (???).

   procedure Draw_Rgb_32_Image_Dithalign
     (Drawable      : Gdk.Drawable.Gdk_Drawable;
      GC            : Gdk.GC.Gdk_GC;
      X, Y          : Glib.Gint;
      Width, Height : Glib.Gint;
      Dith          : Gdk_Rgb_Dither;
      Rgb_Buf       : Rgb_Buffer;
      Rowstride     : Glib.Gint;
      Xdith, Ydith  : Glib.Gint);
   --  Same kind of function as above, but for different buffer types (???).

   procedure Draw_Gray_Image
     (Drawable      : Gdk.Drawable.Gdk_Drawable;
      GC            : Gdk.GC.Gdk_GC;
      X, Y          : Glib.Gint;
      Width, Height : Glib.Gint;
      Dith          : Gdk_Rgb_Dither;
      Rgb_Buf       : Rgb_Buffer;
      Rowstride     : Glib.Gint);
   --  Same kind of function as above, but for different buffer types (???).

   procedure Draw_Indexed_Image
     (Drawable      : Gdk.Drawable.Gdk_Drawable;
      GC            : Gdk.GC.Gdk_GC;
      X, Y          : Glib.Gint;
      Width, Height : Glib.Gint;
      Dith          : Gdk_Rgb_Dither;
      Rgb_Buf       : Rgb_Buffer;
      Rowstride     : Glib.Gint;
      Cmap          : Gdk_Rgb_Cmap);
   --  Same kind of function as above, but for different buffer types (???).

private
   pragma Inline (Get);
   pragma Inline (Set);

   pragma Import (C, GC_Set_Background, "gdk_rgb_gc_set_background");
   pragma Import (C, GC_Set_Foreground, "gdk_rgb_gc_set_foreground");
   pragma Import (C, Get_Cmap, "gdk_rgb_get_colormap");
   pragma Import (C, Get_Visual, "gdk_rgb_get_visual");
   pragma Import (C, Xpixel_From_Rgb, "gdk_rgb_xpixel_from_rgb");
   pragma Import (C, Get, "ada_rgb_cmap_get");
   pragma Import (C, Set, "ada_rgb_cmap_set");
   pragma Import (C, Free, "gdk_rgb_cmap_free");
   pragma Import (C, Draw_Rgb_Image, "gdk_draw_rgb_image");
   pragma Import (C, Draw_Rgb_Image_Dithalign, "gdk_draw_rgb_image_dithalign");
   pragma Import (C, Draw_Rgb_32_Image, "gdk_draw_rgb_32_image");
   pragma Import
     (C, Draw_Rgb_32_Image_Dithalign, "gdk_draw_rgb_32_image_dithalign");
   pragma Import (C, Draw_Gray_Image, "gdk_draw_gray_image");
   pragma Import (C, Draw_Indexed_Image, "gdk_draw_indexed_image");
end Gdk.Rgb;