]> Pileus Git - ~andy/gtk/blob - docs/reference/gdk/tmpl/rgb.sgml
Markup fixes.
[~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 <example>
38 <title>A simple example program using GdkRGB.</title>
39 <programlisting>
40 #include &lt;gtk/gtk.h&gt;
41
42 #define IMAGE_WIDTH     256
43 #define IMAGE_HEIGHT    256
44
45 guchar rgbbuf[IMAGE_WIDTH * IMAGE_HEIGHT * 3];
46
47 gboolean on_darea_expose (GtkWidget *widget,
48                           GdkEventExpose *event,
49                           gpointer user_data);
50
51 int
52 main (int argc, char *argv[])
53 {
54   GtkWidget *window, *darea;
55   gint x, y;
56   guchar *pos;
57
58   gtk_init (&amp;argc, &amp;argv);
59
60   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
61   darea = gtk_drawing_area_new (<!>);
62   gtk_widget_set_size_request (darea, IMAGE_WIDTH, IMAGE_HEIGHT);
63   gtk_container_add (GTK_CONTAINER (window), darea);
64   gtk_signal_connect (GTK_OBJECT (darea), "expose-event",
65                       GTK_SIGNAL_FUNC (on_darea_expose), NULL);
66   gtk_widget_show_all (window);
67
68   /* Set up the RGB buffer. */
69   pos = rgbbuf;
70   for (y = 0; y < IMAGE_HEIGHT; y++)
71     {
72       for (x = 0; x < IMAGE_WIDTH; x++)
73         {
74           *pos++ = x - x % 32;                  /* Red. */
75           *pos++ = (x / 32) * 4 + y - y % 32;   /* Green. */
76           *pos++ = y - y % 32;                  /* Blue. */
77         }
78     }
79
80   gtk_main (<!>);
81   return 0;
82 }
83
84
85 gboolean
86 on_darea_expose (GtkWidget *widget,
87                  GdkEventExpose *event,
88                  gpointer user_data)
89 {
90   gdk_draw_rgb_image (widget->window, widget->style->fg_gc[GTK_STATE_NORMAL],
91                       0, 0, IMAGE_WIDTH, IMAGE_HEIGHT,
92                       GDK_RGB_DITHER_MAX, rgbbuf, IMAGE_WIDTH * 3);
93 }
94 </programlisting>
95 </example>
96
97 <!-- ##### SECTION See_Also ##### -->
98 <para>
99 <variablelist>
100
101 <varlistentry>
102 <term>#GdkColor</term>
103 <listitem><para>The underlying GDK mechanism for allocating
104 colors.</para></listitem>
105 </varlistentry>
106
107 <varlistentry>
108 <term>#GdkPixbuf and gdk_pixbuf_render_to_drawable()</term>
109 <listitem><para>Higher-level image handling.</para></listitem>
110 </varlistentry>
111
112 </variablelist>
113
114 </para>
115
116 <!-- ##### FUNCTION gdk_rgb_init ##### -->
117 <para>
118 This function no longer does anything at all. It's completely useless
119 (and harmless).
120 </para>
121
122
123
124 <!-- ##### FUNCTION gdk_draw_rgb_image ##### -->
125 <para>
126 Draws an RGB image in the drawable. This is the core GdkRGB
127 function, and likely the only one you will need to use.
128 </para>
129
130 <para>
131 The @rowstride parameter allows for lines to be aligned more flexibly.
132 For example, lines may be allocated to begin on 32-bit boundaries,
133 even if the width of the rectangle is odd. Rowstride is also useful
134 when drawing a subrectangle of a larger image in memory. Finally, to
135 replicate the same line a number of times, the trick of setting
136 @rowstride to 0 is allowed.
137 </para>
138
139 <para>
140 In general, for 0 &lt;= i &lt; @width and 0 &lt;= j &lt; height,
141 the pixel (x + i, y + j) is colored with red value @rgb_buf[@j *
142 @rowstride + @i * 3], green value @rgb_buf[@j * @rowstride + @i * 3 +
143 1], and blue value @rgb_buf[@j * @rowstride + @i * 3 + 2].
144 </para>
145
146 @drawable: The #GdkDrawable to draw in (usually a #GdkWindow).
147 @gc: The graphics context (all GDK drawing operations require one; its
148 contents are ignored).
149 @x: The x coordinate of the top-left corner in the drawable.
150 @y: The y coordinate of the top-left corner in the drawable.
151 @width: The width of the rectangle to be drawn.
152 @height: The height of the rectangle to be drawn.
153 @dith: A #GdkRgbDither value, selecting the desired dither mode.
154 @rgb_buf: The pixel data, represented as packed 24-bit data.
155 @rowstride: The number of bytes from the start of one row in @rgb_buf to the
156 start of the next.
157
158
159 <!-- ##### FUNCTION gdk_draw_rgb_image_dithalign ##### -->
160 <para>
161 Draws an RGB image in the drawable, with an adjustment for dither alignment.
162 </para>
163
164 <para>
165 This function is useful when drawing dithered images into a window
166 that may be scrolled. Pixel (x, y) will be drawn dithered as if its
167 actual location is (x + @xdith, y + @ydith). Thus, if you draw an
168 image into a window using zero dither alignment, then scroll up one
169 pixel, subsequent draws to the window should have @ydith = 1.
170 </para>
171
172 <para>
173 Setting the dither alignment correctly allows updating of small parts
174 of the screen while avoiding visible "seams" between the different
175 dither textures.
176 </para>
177
178 @drawable: The #GdkDrawable to draw in (usually a #GdkWindow).
179 @gc: The graphics context.
180 @x: The x coordinate of the top-left corner in the drawable.
181 @y: The y coordinate of the top-left corner in the drawable.
182 @width: The width of the rectangle to be drawn.
183 @height: The height of the rectangle to be drawn.
184 @dith: A #GdkRgbDither value, selecting the desired dither mode.
185 @rgb_buf: The pixel data, represented as packed 24-bit data.
186 @rowstride: The number of bytes from the start of one row in @rgb_buf to the
187 start of the next.
188 @xdith: An x offset for dither alignment.
189 @ydith: A y offset for dither alignment.
190
191
192 <!-- ##### FUNCTION gdk_draw_indexed_image ##### -->
193 <para>
194 Draws an indexed image in the drawable, using a #GdkRgbCmap to assign
195 actual colors to the color indices.
196 </para>
197
198 @drawable: The #GdkDrawable to draw in (usually a #GdkWindow).
199 @gc: The graphics context.
200 @x: The x coordinate of the top-left corner in the drawable.
201 @y: The y coordinate of the top-left corner in the drawable.
202 @width: The width of the rectangle to be drawn.
203 @height: The height of the rectangle to be drawn.
204 @dith: A #GdkRgbDither value, selecting the desired dither mode.
205 @buf: The pixel data, represented as 8-bit color indices.
206 @rowstride: The number of bytes from the start of one row in @buf to the
207 start of the next.
208 @cmap: The #GdkRgbCmap used to assign colors to the color indices.
209
210
211 <!-- ##### FUNCTION gdk_draw_gray_image ##### -->
212 <para>
213 Draws a grayscale image in the drawable.
214
215 </para>
216
217 @drawable: The #GdkDrawable to draw in (usually a #GdkWindow).
218 @gc: The graphics context.
219 @x: The x coordinate of the top-left corner in the drawable.
220 @y: The y coordinate of the top-left corner in the drawable.
221 @width: The width of the rectangle to be drawn.
222 @height: The height of the rectangle to be drawn.
223 @dith: A #GdkRgbDither value, selecting the desired dither mode.
224 @buf: The pixel data, represented as 8-bit gray values.
225 @rowstride: The number of bytes from the start of one row in @buf to the
226 start of the next.
227
228
229 <!-- ##### FUNCTION gdk_draw_rgb_32_image ##### -->
230 <para>
231 Draws a padded RGB image in the drawable. The image is stored as one
232 pixel per 32-bit word. It is laid out as a red byte, a green byte, a
233 blue byte, and a padding byte.
234 </para>
235
236 <para>
237 It's unlikely that this function will give significant performance
238 gains in practice. In my experience, the performance gain from having
239 pixels aligned to 32-bit boundaries is cancelled out by the increased
240 memory bandwidth.
241 </para>
242
243 @drawable: The #GdkDrawable to draw in (usually a #GdkWindow).
244 @gc: The graphics context.
245 @x: The x coordinate of the top-left corner in the drawable.
246 @y: The y coordinate of the top-left corner in the drawable.
247 @width: The width of the rectangle to be drawn.
248 @height: The height of the rectangle to be drawn.
249 @dith: A #GdkRgbDither value, selecting the desired dither mode.
250 @buf: The pixel data, represented as padded 32-bit data.
251 @rowstride: The number of bytes from the start of one row in @buf to the
252 start of the next.
253
254
255 <!-- ##### FUNCTION gdk_draw_rgb_32_image_dithalign ##### -->
256 <para>
257
258 </para>
259
260 @drawable: 
261 @gc: 
262 @x: 
263 @y: 
264 @width: 
265 @height: 
266 @dith: 
267 @buf: 
268 @rowstride: 
269 @xdith: 
270 @ydith: 
271
272
273 <!-- ##### ENUM GdkRgbDither ##### -->
274 <para>
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 Determines 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