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