]> Pileus Git - ~andy/gtk/blob - docs/reference/gdk/tmpl/rgb.sgml
Merge branch 'gtk-2-90'
[~andy/gtk] / docs / reference / gdk / tmpl / rgb.sgml
1 <!-- ##### SECTION Title ##### -->
2 GdkRGB
3
4 <!-- ##### SECTION Short_Description ##### -->
5 Renders RGB, grayscale, or indexed image data to a GdkDrawable
6
7 <!-- ##### SECTION Long_Description ##### -->
8
9 <para>
10 GdkRGB is a low-level module which renders RGB, grayscale, and indexed
11 colormap images to a #GdkDrawable. It does this as efficiently as
12 possible, handling issues such as colormaps, visuals, dithering,
13 temporary buffers, and so on. Most code should use the higher-level
14 #GdkPixbuf features in place of this module; for example,
15 gdk_draw_pixbuf() uses GdkRGB in its implementation.
16 </para>
17
18 <para>
19 GdkRGB allocates a color cube to use when rendering images.  You can
20 set the threshold for installing colormaps with
21 gdk_rgb_set_min_colors(). The default is 5x5x5 (125). If a colorcube
22 of this size or larger can be allocated in the default colormap, then
23 that's done. Otherwise, GdkRGB creates its own private colormap.
24 Setting it to 0 means that it always tries to use the default
25 colormap, and setting it to 216 means that it always creates a private
26 one if it cannot allocate the 6x6x6 colormap in the default. If you
27 always want a private colormap (to avoid consuming too many colormap
28 entries for other apps, say), you can use 
29 <literal>gdk_rgb_set_install(TRUE)</literal>.
30 Setting the value greater than 216 exercises a bug in older versions
31 of GdkRGB. Note, however, that setting it to 0 doesn't let you get
32 away with ignoring the colormap and visual - a colormap is always
33 created in grayscale and direct color modes, and the visual is changed
34 in cases where a "better" visual than the default is available.
35 </para>
36
37 <para>
38 If GDK is built with the Sun mediaLib library, the GdkRGB functions are
39 accelerated using mediaLib, which provides hardware acceleration on Intel,
40 AMD, and Sparc chipsets.  If desired, mediaLib support can be turned off
41 by setting the GDK_DISABLE_MEDIALIB environment variable.
42 </para>
43
44 <example>
45 <title>A simple example program using GdkRGB</title>
46 <programlisting>
47 &num;include &lt;gtk/gtk.h&gt;
48
49 &num;define IMAGE_WIDTH 256
50 &num;define IMAGE_HEIGHT        256
51
52 guchar rgbbuf[IMAGE_WIDTH * IMAGE_HEIGHT * 3];
53
54 gboolean on_darea_expose (GtkWidget *widget,
55                           GdkEventExpose *event,
56                           gpointer user_data);
57
58 int
59 main (int argc, char *argv[])
60 {
61   GtkWidget *window, *darea;
62   gint x, y;
63   guchar *pos;
64
65   gtk_init (&amp;argc, &amp;argv);
66
67   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
68   darea = gtk_drawing_area_new (<!-- -->);
69   gtk_widget_set_size_request (darea, IMAGE_WIDTH, IMAGE_HEIGHT);
70   gtk_container_add (GTK_CONTAINER (window), darea);
71   gtk_signal_connect (GTK_OBJECT (darea), "expose-event",
72                       GTK_SIGNAL_FUNC (on_darea_expose), NULL);
73   gtk_widget_show_all (window);
74
75   /* Set up the RGB buffer. */
76   pos = rgbbuf;
77   for (y = 0; y &lt; IMAGE_HEIGHT; y++)
78     {
79       for (x = 0; x &lt; IMAGE_WIDTH; x++)
80         {
81           *pos++ = x - x % 32;                  /* Red. */
82           *pos++ = (x / 32) * 4 + y - y % 32;   /* Green. */
83           *pos++ = y - y % 32;                  /* Blue. */
84         }
85     }
86
87   gtk_main (<!-- -->);
88   return 0;
89 }
90
91
92 gboolean
93 on_darea_expose (GtkWidget *widget,
94                  GdkEventExpose *event,
95                  gpointer user_data)
96 {
97   gdk_draw_rgb_image (widget->window, widget->style->fg_gc[GTK_STATE_NORMAL],
98                       0, 0, IMAGE_WIDTH, IMAGE_HEIGHT,
99                       GDK_RGB_DITHER_MAX, rgbbuf, IMAGE_WIDTH * 3);
100
101   return TRUE;
102 }
103 </programlisting>
104 </example>
105
106 <!-- ##### SECTION See_Also ##### -->
107 <para>
108 <variablelist>
109
110 <varlistentry>
111 <term>#GdkColor</term>
112 <listitem><para>The underlying GDK mechanism for allocating
113 colors.</para></listitem>
114 </varlistentry>
115
116 <varlistentry>
117 <term>#GdkPixbuf and gdk_draw_pixbuf()</term>
118 <listitem><para>Higher-level image handling.</para></listitem>
119 </varlistentry>
120
121 </variablelist>
122
123 </para>
124
125 <!-- ##### SECTION Stability_Level ##### -->
126
127
128 <!-- ##### FUNCTION gdk_draw_rgb_image ##### -->
129 <para>
130 Draws an RGB image in the drawable. This is the core GdkRGB
131 function, and likely the only one you will need to use.
132 </para>
133
134 <para>
135 The @rowstride parameter allows for lines to be aligned more flexibly.
136 For example, lines may be allocated to begin on 32-bit boundaries,
137 even if the width of the rectangle is odd. Rowstride is also useful
138 when drawing a subrectangle of a larger image in memory. Finally, to
139 replicate the same line a number of times, the trick of setting
140 @rowstride to 0 is allowed.
141 </para>
142
143 <para>
144 In general, for 0 &lt;= i &lt; @width and 0 &lt;= j &lt; height,
145 the pixel (x + i, y + j) is colored with red value @rgb_buf[@j *
146 @rowstride + @i * 3], green value @rgb_buf[@j * @rowstride + @i * 3 +
147 1], and blue value @rgb_buf[@j * @rowstride + @i * 3 + 2].
148 </para>
149
150 @drawable: The #GdkDrawable to draw in (usually a #GdkWindow).
151 @gc: The graphics context (all GDK drawing operations require one; its
152 contents are ignored).
153 @x: The x coordinate of the top-left corner in the drawable.
154 @y: The y coordinate of the top-left corner in the drawable.
155 @width: The width of the rectangle to be drawn.
156 @height: The height of the rectangle to be drawn.
157 @dith: A #GdkRgbDither value, selecting the desired dither mode.
158 @rgb_buf: The pixel data, represented as packed 24-bit data.
159 @rowstride: The number of bytes from the start of one row in @rgb_buf to the
160 start of the next.
161
162
163 <!-- ##### FUNCTION gdk_draw_rgb_image_dithalign ##### -->
164 <para>
165 Draws an RGB image in the drawable, with an adjustment for dither alignment.
166 </para>
167
168 <para>
169 This function is useful when drawing dithered images into a window
170 that may be scrolled. Pixel (x, y) will be drawn dithered as if its
171 actual location is (x + @xdith, y + @ydith). Thus, if you draw an
172 image into a window using zero dither alignment, then scroll up one
173 pixel, subsequent draws to the window should have @ydith = 1.
174 </para>
175
176 <para>
177 Setting the dither alignment correctly allows updating of small parts
178 of the screen while avoiding visible "seams" between the different
179 dither textures.
180 </para>
181
182 @drawable: The #GdkDrawable to draw in (usually a #GdkWindow).
183 @gc: The graphics context.
184 @x: The x coordinate of the top-left corner in the drawable.
185 @y: The y coordinate of the top-left corner in the drawable.
186 @width: The width of the rectangle to be drawn.
187 @height: The height of the rectangle to be drawn.
188 @dith: A #GdkRgbDither value, selecting the desired dither mode.
189 @rgb_buf: The pixel data, represented as packed 24-bit data.
190 @rowstride: The number of bytes from the start of one row in @rgb_buf to the
191 start of the next.
192 @xdith: An x offset for dither alignment.
193 @ydith: A y offset for dither alignment.
194
195
196 <!-- ##### FUNCTION gdk_draw_indexed_image ##### -->
197 <para>
198 Draws an indexed image in the drawable, using a #GdkRgbCmap to assign
199 actual colors to the color indices.
200 </para>
201
202 @drawable: The #GdkDrawable to draw in (usually a #GdkWindow).
203 @gc: The graphics context.
204 @x: The x coordinate of the top-left corner in the drawable.
205 @y: The y coordinate of the top-left corner in the drawable.
206 @width: The width of the rectangle to be drawn.
207 @height: The height of the rectangle to be drawn.
208 @dith: A #GdkRgbDither value, selecting the desired dither mode.
209 @buf: The pixel data, represented as 8-bit color indices.
210 @rowstride: The number of bytes from the start of one row in @buf to the
211 start of the next.
212 @cmap: The #GdkRgbCmap used to assign colors to the color indices.
213
214
215 <!-- ##### FUNCTION gdk_draw_gray_image ##### -->
216 <para>
217 Draws a grayscale image in the drawable.
218
219 </para>
220
221 @drawable: The #GdkDrawable to draw in (usually a #GdkWindow).
222 @gc: The graphics context.
223 @x: The x coordinate of the top-left corner in the drawable.
224 @y: The y coordinate of the top-left corner in the drawable.
225 @width: The width of the rectangle to be drawn.
226 @height: The height of the rectangle to be drawn.
227 @dith: A #GdkRgbDither value, selecting the desired dither mode.
228 @buf: The pixel data, represented as 8-bit gray values.
229 @rowstride: The number of bytes from the start of one row in @buf to the
230 start of the next.
231
232
233 <!-- ##### FUNCTION gdk_draw_rgb_32_image ##### -->
234 <para>
235 Draws a padded RGB image in the drawable. The image is stored as one
236 pixel per 32-bit word. It is laid out as a red byte, a green byte, a
237 blue byte, and a padding byte.
238 </para>
239
240 <para>
241 It's unlikely that this function will give significant performance
242 gains in practice. In my experience, the performance gain from having
243 pixels aligned to 32-bit boundaries is cancelled out by the increased
244 memory bandwidth.
245 </para>
246
247 @drawable: The #GdkDrawable to draw in (usually a #GdkWindow).
248 @gc: The graphics context.
249 @x: The x coordinate of the top-left corner in the drawable.
250 @y: The y coordinate of the top-left corner in the drawable.
251 @width: The width of the rectangle to be drawn.
252 @height: The height of the rectangle to be drawn.
253 @dith: A #GdkRgbDither value, selecting the desired dither mode.
254 @buf: The pixel data, represented as padded 32-bit data.
255 @rowstride: The number of bytes from the start of one row in @buf to the
256 start of the next.
257
258
259 <!-- ##### FUNCTION gdk_draw_rgb_32_image_dithalign ##### -->
260 <para>
261
262 </para>
263
264 @drawable: 
265 @gc: 
266 @x: 
267 @y: 
268 @width: 
269 @height: 
270 @dith: 
271 @buf: 
272 @rowstride: 
273 @xdith: 
274 @ydith: 
275
276
277 <!-- ##### ENUM GdkRgbDither ##### -->
278 <para>
279 Selects whether or not GdkRGB applies dithering
280 to the image on display. 
281 </para>
282
283 <para>
284 Since GdkRGB currently only handles images with 8 bits per component,
285 dithering on 24 bit per pixel displays is a moot point.
286 </para>
287
288 @GDK_RGB_DITHER_NONE: Never use dithering.
289 @GDK_RGB_DITHER_NORMAL: Use dithering in 8 bits per pixel (and below)
290 only.
291 @GDK_RGB_DITHER_MAX: Use dithering in 16 bits per pixel and below.
292
293 <!-- ##### FUNCTION gdk_rgb_cmap_new ##### -->
294 <para>
295 Creates a new #GdkRgbCmap structure. The cmap maps color indexes to
296 RGB colors. If @n_colors is less than 256, then images containing
297 color values greater than or equal to @n_colors will produce undefined
298 results, including possibly segfaults.
299 </para>
300
301 @colors: The colors, represented as 0xRRGGBB integer values.
302 @n_colors: The number of colors in the cmap.
303 @Returns: The newly created #GdkRgbCmap
304
305
306 <!-- ##### FUNCTION gdk_rgb_cmap_free ##### -->
307 <para>
308 Frees the memory associated with a #GdkRgbCmap created by gdk_rgb_cmap_new().
309 </para>
310
311 @cmap: The #GdkRgbCmap to free.
312
313
314 <!-- ##### STRUCT GdkRgbCmap ##### -->
315 <para>
316 A private data structure which maps color indices to actual RGB
317 colors. This is used only for gdk_draw_indexed_image().
318 </para>
319
320 @colors: The colors, represented as 0xRRGGBB integer values.
321 @n_colors: The number of colors in the cmap.
322
323 <!-- ##### FUNCTION gdk_rgb_find_color ##### -->
324 <para>
325
326 </para>
327
328 @colormap: 
329 @color: 
330
331
332 <!-- ##### FUNCTION gdk_rgb_set_install ##### -->
333 <para>
334 If @install is %TRUE, directs GdkRGB to always install a new "private"
335 colormap rather than trying to find a best fit with the colors already
336 allocated. Ordinarily, GdkRGB will install a colormap only if a
337 sufficient cube cannot be allocated.
338 </para>
339
340 <para>
341 A private colormap has more colors, leading to better quality display,
342 but also leads to the dreaded "colormap flashing" effect.
343 </para>
344
345 @install: %TRUE to set install mode.
346
347
348 <!-- ##### FUNCTION gdk_rgb_set_min_colors ##### -->
349 <para>
350 Sets the minimum number of colors for the color cube. Generally,
351 GdkRGB tries to allocate the largest color cube it can. If it can't
352 allocate a color cube at least as large as @min_colors, it installs a
353 private colormap.
354 </para>
355
356 @min_colors: The minimum number of colors accepted.
357
358
359 <!-- ##### FUNCTION gdk_rgb_get_visual ##### -->
360 <para>
361 </para>
362
363 @Returns: 
364
365
366 <!-- ##### FUNCTION gdk_rgb_get_colormap ##### -->
367 <para>
368
369 </para>
370
371 @Returns: 
372
373
374 <!-- ##### MACRO gdk_rgb_get_cmap ##### -->
375 <para>
376 Gets the colormap set by GdkRGB. This colormap and the corresponding
377 visual should be used when creating windows that will be drawn in by GdkRGB.
378 </para>
379
380 @Returns: The #GdkColormap set by GdkRGB.
381
382
383 <!-- ##### FUNCTION gdk_rgb_ditherable ##### -->
384 <para>
385 Determines whether the preferred visual is ditherable. This function may be
386 useful for presenting a user interface choice to the user about which
387 dither mode is desired; if the display is not ditherable, it may make
388 sense to gray out or hide the corresponding UI widget.
389 </para>
390
391 @Returns: %TRUE if the preferred visual is ditherable.
392
393
394 <!-- ##### FUNCTION gdk_rgb_colormap_ditherable ##### -->
395 <para>
396 Determines whether the visual associated with @cmap is ditherable. This 
397 function may be useful for presenting a user interface choice to the user 
398 about which dither mode is desired; if the display is not ditherable, it may 
399 make sense to gray out or hide the corresponding UI widget.
400 </para>
401
402 @cmap: a #GdkColormap
403 @Returns: %TRUE if the visual associated with @cmap is ditherable.
404
405
406 <!-- ##### FUNCTION gdk_rgb_set_verbose ##### -->
407 <para>
408 Sets the "verbose" flag. This is generally only useful for debugging.
409 </para>
410
411 @verbose: %TRUE if verbose messages are desired.
412
413