Linux中国 Linux中国门户站!
设为主页 设为主页
收藏本站 收藏本站
 
当前位置 :首页 ->Linux技术 ->系统管理 ->正文

GDK Reference Manual

来源:Linux-cn.com 作者:Webmaster 时间:2007-05-05 点击: [收藏] [投稿]

#include <gdk/gdk.h>
voidgdk_rgb_init(void);
voidgdk_draw_rgb_image(GdkDrawable *drawable,
GdkGC *gc,gint x,gint y,
gint width,gint height,GdkRgbDither dith,
guchar *rgb_buf,gint rowstride);
voidgdk_draw_rgb_image_dithalign(GdkDrawable *drawable,
GdkGC *gc,gint x,gint y,gint width,gint height,GdkRgbDither dith,
guchar *rgb_buf,gint rowstride,gint xdith,gint ydith);
voidgdk_draw_indexed_image(GdkDrawable *drawable,
GdkGC *gc,gint x,gint y,gint width,gint height,GdkRgbDither dith,
guchar *buf,gint rowstride,GdkRgbCmap *cmap);
voidgdk_draw_gray_image (GdkDrawable *drawable,
GdkGC *gc,gint x,gint y,gint width,gint height,GdkRgbDither dith,
guchar *buf,gint rowstride);
voidgdk_draw_rgb_32_image (GdkDrawable *drawable,
GdkGC *gc,gint x,gint y,gint width,gint height,
GdkRgbDither dith,guchar *buf,gint rowstride);
enumGdkRgbDither;
GdkRgbCmap* gdk_rgb_cmap_new(guint32 *colors,gint n_colors);
voidgdk_rgb_cmap_free (GdkRgbCmap *cmap);
structGdkRgbCmap;
voidgdk_rgb_gc_set_foreground (GdkGC *gc,guint32 rgb);
voidgdk_rgb_gc_set_background (GdkGC *gc,guint32 rgb);
gulonggdk_rgb_xpixel_from_rgb (guint32 rgb);
voidgdk_rgb_set_install (gboolean install);
voidgdk_rgb_set_min_colors(gint min_colors);
GdkVisual*gdk_rgb_get_visual(void);
GdkColormap* gdk_rgb_get_cmap (void);
gbooleangdk_rgb_ditherable(void);
voidgdk_rgb_set_verbose (gboolean verbose); 

  Description

  GdkRgb converts RGB, grayscale, and colormapped images into the native window pixel format and displays them. It takes care of colormaps, visuals, dithering, and management of the temporary buffers.

  You must call gdk_rgb_init() before using any GdkRgb functionality. If you fail to do so, expect coredumps. All Gtk+ widgets that use GdkRgb (including GtkPreview) call gdk_rgb_init() in their class_init method. Thus, if you use GdkRgb only indirectly, you don't need to worry about it.

  GdkRgb tries to use the system default visual and colormap, but doesn't always succeed. Thus, you have to be prepared to install the visual and colormap generated by GdkRgb. The following code sequence (before any widgets are created) should work in most applications:


gdk_rgb_init();
gtk_widget_set_default_colormap (gdk_rgb_get_cmap());
gtk_widget_set_default_visual (gdk_rgb_get_visual()); 

  You can also push the colormap and visual, but in general it doesn't work unless the push wraps the window creation call. If you wrap the push around a widget which is embedded in a window without the GdkRgb colormap and visual, it probably won't work, and is likely to cause colormap flashing, as well.

  On 8-bit systems, the colormaps used by Imlib and GdkRgb may conflict. There is no good general solution to this other than phasing out the dependence on Imlib.

  You can set the threshold for installing colormaps with gdk_rgb_set_min_colors(). The default is 5x5x5 (125). If a colorcube of this size or larger can be allocated in the default colormap, then that's done. Otherwise, GdkRgb creates its own private colormap. Setting it to 0 means that it always tries to use the default colormap, and setting it to 216 means that it always creates a private one if it cannot allocate the 6x6x6 colormap in the default. If you always want a private colormap (to avoid consuming too many colormap entries for other apps, say), you can use gdk_rgb_set_install(TRUE). Setting the value greater than 216 exercises a bug in older versions of GdkRgb. Note, however, that setting it to 0 doesn't let you get away with ignoring the colormap and visual - a colormap is always created in grayscale and direct color modes, and the visual is changed in cases where a "better" visual than the default is available.

  Example 1. A simple example program using GdkRGB.


include <gtk/gtk.h>
define IMAGE_WIDTH256
define IMAGE_HEIGHT256
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);
gdk_rgb_init();
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
darea = gtk_drawing_area_new();
gtk_drawing_area_size (GTK_DRAWING_AREA (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);
} 


 如果您对本文有任何疑问或者建议,请到讨论区发表您的意见: >> 论坛入口 <<



上一篇:GTK v1.2 Tutorial(英文)   下一篇:Java入门(12) 事件与错误处理

文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【我要投稿】 【论坛讨论
更多相关文章
Power by linux-cn.com 粤ICP备05006655号