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