Synopsis#include <gdk/gdk.h> void gdk_rgb_init (void); void gdk_draw_rgb_image (GdkDrawable *drawable, GdkGC *gc, gint x, gint y, gint width, gint height, GdkRgbDither dith, const guchar *rgb_buf, gint rowstride); void gdk_draw_rgb_image_dithalign (GdkDrawable *drawable, GdkGC *gc, gint x, gint y, gint width, gint height, GdkRgbDither dith, const guchar *rgb_buf, gint rowstride, gint xdith, gint ydith); void gdk_draw_indexed_image (GdkDrawable *drawable, GdkGC *gc, gint x, gint y, gint width, gint height, GdkRgbDither dith, const guchar *buf, gint rowstride, GdkRgbCmap *cmap); void gdk_draw_gray_image (GdkDrawable *drawable, GdkGC *gc, gint x, gint y, gint width, gint height, GdkRgbDither dith, const guchar *buf, gint rowstride); void gdk_draw_rgb_32_image (GdkDrawable *drawable, GdkGC *gc, gint x, gint y, gint width, gint height, GdkRgbDither dith, const guchar *buf, gint rowstride); void gdk_draw_rgb_32_image_dithalign (GdkDrawable *drawable, GdkGC *gc, gint x, gint y, gint width, gint height, GdkRgbDither dith, const guchar *buf, gint rowstride, gint xdith, gint ydith); enum GdkRgbDither; GdkRgbCmap* gdk_rgb_cmap_new (guint32 *colors, gint n_colors); void gdk_rgb_cmap_free (GdkRgbCmap *cmap); GdkRgbCmap; void gdk_rgb_gc_set_foreground (GdkGC *gc, guint32 rgb); void gdk_rgb_gc_set_background (GdkGC *gc, guint32 rgb); gulong gdk_rgb_xpixel_from_rgb (guint32 rgb); void gdk_rgb_find_color (GdkColormap *colormap, GdkColor *color); void gdk_rgb_set_install (gboolean install); void gdk_rgb_set_min_colors (gint min_colors); GdkVisual* gdk_rgb_get_visual (void); GdkColormap* gdk_rgb_get_colormap (void); #define gdk_rgb_get_cmap gboolean gdk_rgb_ditherable (void); gboolean gdk_rgb_colormap_ditherable (GdkColormap *cmap); void gdk_rgb_set_verbose (gboolean verbose); Description
GdkRGB is a low-level module which renders RGB, grayscale, and indexed
colormap images to a GdkDrawable. It does this as efficiently as
possible, handling issues such as colormaps, visuals, dithering,
temporary buffers, and so on. Most code should use the higher-level
GdkPixbuf features in place of this module; for example,
GdkRGB allocates a color cube to use when rendering images. You can
set the threshold for installing colormaps with
If GDK is built with the Sun mediaLib library, the GdkRGB functions are accelerated using mediaLib, which provides hardware acceleration on Intel, AMD, and Sparc chipsets. If desired, mediaLib support can be turned off by setting the GDK_DISABLE_MEDIALIB environment variable. Example 4. A simple example program using GdkRGB #include <gtk/gtk.h> #define IMAGE_WIDTH 256 #define IMAGE_HEIGHT 256 guchar rgbbuf[IMAGE_WIDTH * IMAGE_HEIGHT * 3]; gboolean on_darea_expose (GtkWidget *widget, GdkEventExpose *event, gpointer user_data); int main (int argc, char *argv[]) { GtkWidget *window, *darea; gint x, y; guchar *pos; gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); darea = gtk_drawing_area_new (); gtk_widget_set_size_request (darea, IMAGE_WIDTH, IMAGE_HEIGHT); gtk_container_add (GTK_CONTAINER (window), darea); gtk_signal_connect (GTK_OBJECT (darea), "expose-event", GTK_SIGNAL_FUNC (on_darea_expose), NULL); gtk_widget_show_all (window); /* Set up the RGB buffer. */ pos = rgbbuf; for (y = 0; y < IMAGE_HEIGHT; y++) { for (x = 0; x < IMAGE_WIDTH; x++) { *pos++ = x - x % 32; /* Red. */ *pos++ = (x / 32) * 4 + y - y % 32; /* Green. */ *pos++ = y - y % 32; /* Blue. */ } } gtk_main (); return 0; } gboolean on_darea_expose (GtkWidget *widget, GdkEventExpose *event, gpointer user_data) { gdk_draw_rgb_image (widget->window, widget->style->fg_gc[GTK_STATE_NORMAL], 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, GDK_RGB_DITHER_MAX, rgbbuf, IMAGE_WIDTH * 3); return TRUE; } Detailsgdk_rgb_init ()void gdk_rgb_init (void); Warning
This function no longer does anything at all. It's completely useless (and harmless). gdk_draw_rgb_image ()void gdk_draw_rgb_image (GdkDrawable *drawable, GdkGC *gc, gint x, gint y, gint width, gint height, GdkRgbDither dith, const guchar *rgb_buf, gint rowstride); Draws an RGB image in the drawable. This is the core GdkRGB function, and likely the only one you will need to use.
The
In general, for 0 <= i <
gdk_draw_rgb_image_dithalign ()void gdk_draw_rgb_image_dithalign (GdkDrawable *drawable, GdkGC *gc, gint x, gint y, gint width, gint height, GdkRgbDither dith, const guchar *rgb_buf, gint rowstride, gint xdith, gint ydith); Draws an RGB image in the drawable, with an adjustment for dither alignment.
This function is useful when drawing dithered images into a window
that may be scrolled. Pixel (x, y) will be drawn dithered as if its
actual location is (x + Setting the dither alignment correctly allows updating of small parts of the screen while avoiding visible "seams" between the different dither textures.
gdk_draw_indexed_image ()void gdk_draw_indexed_image (GdkDrawable *drawable, GdkGC *gc, gint x, gint y, gint width, gint height, GdkRgbDither dith, const guchar *buf, gint rowstride, GdkRgbCmap *cmap); Draws an indexed image in the drawable, using a GdkRgbCmap to assign actual colors to the color indices.
gdk_draw_gray_image ()void gdk_draw_gray_image (GdkDrawable *drawable, GdkGC *gc, gint x, gint y, gint width, gint height, GdkRgbDither dith, const guchar *buf, gint rowstride); Draws a grayscale image in the drawable.
gdk_draw_rgb_32_image ()void gdk_draw_rgb_32_image (GdkDrawable *drawable, GdkGC *gc, gint x, gint y, gint width, gint height, GdkRgbDither dith, const guchar *buf, gint rowstride); Draws a padded RGB image in the drawable. The image is stored as one pixel per 32-bit word. It is laid out as a red byte, a green byte, a blue byte, and a padding byte. It's unlikely that this function will give significant performance gains in practice. In my experience, the performance gain from having pixels aligned to 32-bit boundaries is cancelled out by the increased memory bandwidth.
gdk_draw_rgb_32_image_dithalign ()void gdk_draw_rgb_32_image_dithalign (GdkDrawable *drawable, GdkGC *gc, gint x, gint y, gint width, gint height, GdkRgbDither dith, const guchar *buf, gint rowstride, gint xdith, gint ydith);
Like
enum GdkRgbDithertypedef enum { GDK_RGB_DITHER_NONE, GDK_RGB_DITHER_NORMAL, GDK_RGB_DITHER_MAX } GdkRgbDither; Selects whether or not GdkRGB applies dithering to the image on display. Since GdkRGB currently only handles images with 8 bits per component, dithering on 24 bit per pixel displays is a moot point. gdk_rgb_cmap_new ()GdkRgbCmap* gdk_rgb_cmap_new (guint32 *colors, gint n_colors);
Creates a new GdkRgbCmap structure. The cmap maps color indexes to
RGB colors. If
gdk_rgb_cmap_free ()void gdk_rgb_cmap_free (GdkRgbCmap *cmap);
Frees the memory associated with a GdkRgbCmap created by
GdkRgbCmaptypedef struct { guint32 colors[256]; gint n_colors; } GdkRgbCmap;
A private data structure which maps color indices to actual RGB
colors. This is used only for
gdk_rgb_gc_set_foreground ()void gdk_rgb_gc_set_foreground (GdkGC *gc, guint32 rgb); Warning
Sets the foreground color in
gdk_rgb_gc_set_background ()void gdk_rgb_gc_set_background (GdkGC *gc, guint32 rgb); Warning
Sets the background color in
gdk_rgb_xpixel_from_rgb ()gulong gdk_rgb_xpixel_from_rgb (guint32 rgb); Warning
Finds the X pixel closest in color to the
gdk_rgb_find_color ()void gdk_rgb_find_color (GdkColormap *colormap, GdkColor *color);
In many cases, you can avoid this whole issue by calling
gdk_rgb_set_install ()void gdk_rgb_set_install (gboolean install);
If A private colormap has more colors, leading to better quality display, but also leads to the dreaded "colormap flashing" effect.
gdk_rgb_set_min_colors ()void gdk_rgb_set_min_colors (gint min_colors);
Sets the minimum number of colors for the color cube. Generally,
GdkRGB tries to allocate the largest color cube it can. If it can't
allocate a color cube at least as large as
gdk_rgb_get_visual ()GdkVisual* gdk_rgb_get_visual (void); Gets a "preferred visual" chosen by GdkRGB for rendering image data on the default screen. In previous versions of GDK, this was the only visual GdkRGB could use for rendering. In current versions, it's simply the visual GdkRGB would have chosen as the optimal one in those previous versions. GdkRGB can now render to drawables with any visual.
gdk_rgb_get_colormap ()GdkColormap* gdk_rgb_get_colormap (void); Get the preferred colormap for rendering image data. Not a very useful function; historically, GDK could only render RGB image data to one colormap and visual, but in the current version it can render to any colormap and visual. So there's no need to call this function.
gdk_rgb_get_cmap#define gdk_rgb_get_cmap gdk_rgb_get_colormap Warning
Gets the colormap set by GdkRGB. This colormap and the corresponding visual should be used when creating windows that will be drawn in by GdkRGB.
gdk_rgb_ditherable ()gboolean gdk_rgb_ditherable (void); Determines whether the preferred visual is ditherable. This function may be useful for presenting a user interface choice to the user about which dither mode is desired; if the display is not ditherable, it may make sense to gray out or hide the corresponding UI widget.
gdk_rgb_colormap_ditherable ()gboolean gdk_rgb_colormap_ditherable (GdkColormap *cmap);
Determines whether the visual associated with
See Also
|