]> Pileus Git - ~andy/gtk/blob - docs/reference/gdk/tmpl/rgb.sgml
d61da71768226e4abace7d5ce315105c820a5ed3
[~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_pixbuf_render_to_drawable() 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_pixbuf_render_to_drawable()</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_rgb_init ##### -->
129 <para>
130 This function no longer does anything at all. It's completely useless
131 (and harmless).
132 </para>
133
134
135
136 <!-- ##### FUNCTION gdk_draw_rgb_image ##### -->
137 <para>
138 Draws an RGB image in the drawable. This is the core GdkRGB
139 function, and likely the only one you will need to use.
140 </para>
141
142 <para>
143 The @rowstride parameter allows for lines to be aligned more flexibly.
144 For example, lines may be allocated to begin on 32-bit boundaries,
145 even if the width of the rectangle is odd. Rowstride is also useful
146 when drawing a subrectangle of a larger image in memory. Finally, to
147 replicate the same line a number of times, the trick of setting
148 @rowstride to 0 is allowed.
149 </para>
150
151 <para>
152 In general, for 0 &lt;= i &lt; @width and 0 &lt;= j &lt; height,
153 the pixel (x + i, y + j) is colored with red value @rgb_buf[@j *
154 @rowstride + @i * 3], green value @rgb_buf[@j * @rowstride + @i * 3 +
155 1], and blue value @rgb_buf[@j * @rowstride + @i * 3 + 2].
156 </para>
157
158 @drawable: The #GdkDrawable to draw in (usually a #GdkWindow).
159 @gc: The graphics context (all GDK drawing operations require one; its
160 contents are ignored).
161 @x: The x coordinate of the top-left corner in the drawable.
162 @y: The y coordinate of the top-left corner in the drawable.
163 @width: The width of the rectangle to be drawn.
164 @height: The height of the rectangle to be drawn.
165 @dith: A #GdkRgbDither value, selecting the desired dither mode.
166 @rgb_buf: The pixel data, represented as packed 24-bit data.
167 @rowstride: The number of bytes from the start of one row in @rgb_buf to the
168 start of the next.
169
170
171 <!-- ##### FUNCTION gdk_draw_rgb_image_dithalign ##### -->
172 <para>
173 Draws an RGB image in the drawable, with an adjustment for dither alignment.
174 </para>
175
176 <para>
177 This function is useful when drawing dithered images into a window
178 that may be scrolled. Pixel (x, y) will be drawn dithered as if its
179 actual location is (x + @xdith, y + @ydith). Thus, if you draw an
180 image into a window using zero dither alignment, then scroll up one
181 pixel, subsequent draws to the window should have @ydith = 1.
182 </para>
183
184 <para>
185 Setting the dither alignment correctly allows updating of small parts
186 of the screen while avoiding visible "seams" between the different
187 dither textures.
188 </para>
189
190 @drawable: The #GdkDrawable to draw in (usually a #GdkWindow).
191 @gc: The graphics context.
192 @x: The x coordinate of the top-left corner in the drawable.
193 @y: The y coordinate of the top-left corner in the drawable.
194 @width: The width of the rectangle to be drawn.
195 @height: The height of the rectangle to be drawn.
196 @dith: A #GdkRgbDither value, selecting the desired dither mode.
197 @rgb_buf: The pixel data, represented as packed 24-bit data.
198 @rowstride: The number of bytes from the start of one row in @rgb_buf to the
199 start of the next.
200 @xdith: An x offset for dither alignment.
201 @ydith: A y offset for dither alignment.
202
203
204 <!-- ##### FUNCTION gdk_draw_indexed_image ##### -->
205 <para>
206 Draws an indexed image in the drawable, using a #GdkRgbCmap to assign
207 actual colors to the color indices.
208 </para>
209
210 @drawable: The #GdkDrawable to draw in (usually a #GdkWindow).
211 @gc: The graphics context.
212 @x: The x coordinate of the top-left corner in the drawable.
213 @y: The y coordinate of the top-left corner in the drawable.
214 @width: The width of the rectangle to be drawn.
215 @height: The height of the rectangle to be drawn.
216 @dith: A #GdkRgbDither value, selecting the desired dither mode.
217 @buf: The pixel data, represented as 8-bit color indices.
218 @rowstride: The number of bytes from the start of one row in @buf to the
219 start of the next.
220 @cmap: The #GdkRgbCmap used to assign colors to the color indices.
221
222
223 <!-- ##### FUNCTION gdk_draw_gray_image ##### -->
224 <para>
225 Draws a grayscale image in the drawable.
226
227 </para>
228
229 @drawable: The #GdkDrawable to draw in (usually a #GdkWindow).
230 @gc: The graphics context.
231 @x: The x coordinate of the top-left corner in the drawable.
232 @y: The y coordinate of the top-left corner in the drawable.
233 @width: The width of the rectangle to be drawn.
234 @height: The height of the rectangle to be drawn.
235 @dith: A #GdkRgbDither value, selecting the desired dither mode.
236 @buf: The pixel data, represented as 8-bit gray values.
237 @rowstride: The number of bytes from the start of one row in @buf to the
238 start of the next.
239
240
241 <!-- ##### FUNCTION gdk_draw_rgb_32_image ##### -->
242 <para>
243 Draws a padded RGB image in the drawable. The image is stored as one
244 pixel per 32-bit word. It is laid out as a red byte, a green byte, a
245 blue byte, and a padding byte.
246 </para>
247
248 <para>
249 It's unlikely that this function will give significant performance
250 gains in practice. In my experience, the performance gain from having
251 pixels aligned to 32-bit boundaries is cancelled out by the increased
252 memory bandwidth.
253 </para>
254
255 @drawable: The #GdkDrawable to draw in (usually a #GdkWindow).
256 @gc: The graphics context.
257 @x: The x coordinate of the top-left corner in the drawable.
258 @y: The y coordinate of the top-left corner in the drawable.
259 @width: The width of the rectangle to be drawn.
260 @height: The height of the rectangle to be drawn.
261 @dith: A #GdkRgbDither value, selecting the desired dither mode.
262 @buf: The pixel data, represented as padded 32-bit data.
263 @rowstride: The number of bytes from the start of one row in @buf to the
264 start of the next.
265
266
267 <!-- ##### FUNCTION gdk_draw_rgb_32_image_dithalign ##### -->
268 <para>
269
270 </para>
271
272 @drawable: 
273 @gc: 
274 @x: 
275 @y: 
276 @width: 
277 @height: 
278 @dith: 
279 @buf: 
280 @rowstride: 
281 @xdith: 
282 @ydith: 
283
284
285 <!-- ##### ENUM GdkRgbDither ##### -->
286 <para>
287 Selects whether or not GdkRGB applies dithering
288 to the image on display. 
289 </para>
290
291 <para>
292 Since GdkRGB currently only handles images with 8 bits per component,
293 dithering on 24 bit per pixel displays is a moot point.
294 </para>
295
296 @GDK_RGB_DITHER_NONE: Never use dithering.
297 @GDK_RGB_DITHER_NORMAL: Use dithering in 8 bits per pixel (and below)
298 only.
299 @GDK_RGB_DITHER_MAX: Use dithering in 16 bits per pixel and below.
300
301 <!-- ##### FUNCTION gdk_rgb_cmap_new ##### -->
302 <para>
303 Creates a new #GdkRgbCmap structure. The cmap maps color indexes to
304 RGB colors. If @n_colors is less than 256, then images containing
305 color values greater than or equal to @n_colors will produce undefined
306 results, including possibly segfaults.
307 </para>
308
309 @colors: The colors, represented as 0xRRGGBB integer values.
310 @n_colors: The number of colors in the cmap.
311 @Returns: The newly created #GdkRgbCmap
312
313
314 <!-- ##### FUNCTION gdk_rgb_cmap_free ##### -->
315 <para>
316 Frees the memory associated with a #GdkRgbCmap created by gdk_rgb_cmap_new().
317 </para>
318
319 @cmap: The #GdkRgbCmap to free.
320
321
322 <!-- ##### STRUCT GdkRgbCmap ##### -->
323 <para>
324 A private data structure which maps color indices to actual RGB
325 colors. This is used only for gdk_draw_indexed_image().
326 </para>
327
328 @colors: The colors, represented as 0xRRGGBB integer values.
329 @n_colors: The number of colors in the cmap.
330
331
332 <!-- ##### FUNCTION gdk_rgb_gc_set_foreground ##### -->
333 <para>
334 Sets the foreground color in @gc to the specified color (or the
335 closest approximation, in the case of limited visuals).
336 </para>
337
338 @gc: The #GdkGC to modify.
339 @rgb: The color, represented as a 0xRRGGBB integer value.
340
341
342 <!-- ##### FUNCTION gdk_rgb_gc_set_background ##### -->
343 <para>
344 Sets the background color in @gc to the specified color (or the
345 closest approximation, in the case of limited visuals).
346 </para>
347
348 @gc: The #GdkGC to modify.
349 @rgb: The color, represented as a 0xRRGGBB integer value.
350
351
352 <!-- ##### FUNCTION gdk_rgb_xpixel_from_rgb ##### -->
353 <para>
354 Finds the X pixel closest in color to the @rgb color specified. This
355 value may be used to set the <structfield>pixel</structfield> field of
356 a #GdkColor struct.
357 </para>
358
359 @rgb: The color, represented as a 0xRRGGBB integer value.
360 @Returns: The X pixel value.
361
362
363 <!-- ##### FUNCTION gdk_rgb_find_color ##### -->
364 <para>
365
366 </para>
367
368 @colormap: 
369 @color: 
370
371
372 <!-- ##### FUNCTION gdk_rgb_set_install ##### -->
373 <para>
374 If @install is %TRUE, directs GdkRGB to always install a new "private"
375 colormap rather than trying to find a best fit with the colors already
376 allocated. Ordinarily, GdkRGB will install a colormap only if a
377 sufficient cube cannot be allocated.
378 </para>
379
380 <para>
381 A private colormap has more colors, leading to better quality display,
382 but also leads to the dreaded "colormap flashing" effect.
383 </para>
384
385 @install: %TRUE to set install mode.
386
387
388 <!-- ##### FUNCTION gdk_rgb_set_min_colors ##### -->
389 <para>
390 Sets the minimum number of colors for the color cube. Generally,
391 GdkRGB tries to allocate the largest color cube it can. If it can't
392 allocate a color cube at least as large as @min_colors, it installs a
393 private colormap.
394 </para>
395
396 @min_colors: The minimum number of colors accepted.
397
398
399 <!-- ##### FUNCTION gdk_rgb_get_visual ##### -->
400 <para>
401 </para>
402
403 @Returns: 
404
405
406 <!-- ##### FUNCTION gdk_rgb_get_colormap ##### -->
407 <para>
408
409 </para>
410
411 @Returns: 
412
413
414 <!-- ##### MACRO gdk_rgb_get_cmap ##### -->
415 <para>
416 Gets the colormap set by GdkRGB. This colormap and the corresponding
417 visual should be used when creating windows that will be drawn in by GdkRGB.
418 </para>
419
420 @Returns: The #GdkColormap set by GdkRGB.
421
422
423 <!-- ##### FUNCTION gdk_rgb_ditherable ##### -->
424 <para>
425 Determines whether the preferred visual is ditherable. This function may be
426 useful for presenting a user interface choice to the user about which
427 dither mode is desired; if the display is not ditherable, it may make
428 sense to gray out or hide the corresponding UI widget.
429 </para>
430
431 @Returns: %TRUE if the preferred visual is ditherable.
432
433
434 <!-- ##### FUNCTION gdk_rgb_colormap_ditherable ##### -->
435 <para>
436 Determines whether the visual associated with @cmap is ditherable. This 
437 function may be useful for presenting a user interface choice to the user 
438 about which dither mode is desired; if the display is not ditherable, it may 
439 make sense to gray out or hide the corresponding UI widget.
440 </para>
441
442 @cmap: a #GdkColormap
443 @Returns: %TRUE if the visual associated with @cmap is ditherable.
444
445
446 <!-- ##### FUNCTION gdk_rgb_set_verbose ##### -->
447 <para>
448 Sets the "verbose" flag. This is generally only useful for debugging.
449 </para>
450
451 @verbose: %TRUE if verbose messages are desired.
452
453