gdk_put_image() and ColorMap
- From: "John Que" <qwejohn hotmail com>
- To: gtk-app-devel-list gnome org
- Subject: gdk_put_image() and ColorMap
- Date: Thu, 26 Aug 2004 18:57:42 +0300
Hello ,
I have an X application which displays an XImgae instance.
This instance is created thus:
.....
XImage* image= XCreateImage(dpy, visual, depth,
ZPixmap, 0,
(char*)0, w, h, 8, 0);
Now , I do display this image correctly using XLib app (without gtk).
I should port this to gtk/gdk.
I read the documentation from gtk website and also from
gnome web site.
There are many explanations there but not many example (at least not
reagarding displaying images).
So I tried the following little "C" app;
This app reads a raw file (which was created from the Xlib application
that works) and tries to display it (after the user press
the button on the widget) using gtk (with gdk_new_image()
and gdk_draw_image();
Now in fact what happens after the user press
the button on the widget is that I can see a picture that has resemblance to
the original, but the colors are badly wrong (much more pale) and in fact
this
result is not satisiable.
I assume it has to do with setting colormap or Visual or Graphic Conext.
(BTW: I am using gtk 1.2 (for legacy reasons) but my question will probably
stays the same also for gtk-2.)
Any help will be welcome.
// test.c
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
#include <stdio.h>
//////////////////////////////////////////////////////////////////////////////
static void destroy(GtkWidget* widget,gpointer data)
{
gtk_main_quit();
}
//////////////////////////////////////////////////////////////////////////////
static void hello(GtkWidget* window,
gpointer data)
{
g_print("IN TEST\n");
int x,y;
FILE* in;
int max_frame_size = 202752;
char* frame = NULL;
GdkImage* image = NULL;
char c;
GdkWindowAttr attrs;
GdkImage* gdkImage = NULL;
attrs.visual = gtk_widget_get_visual(window);
gdkImage = gdk_image_new(GDK_IMAGE_NORMAL,
attrs.visual,
352,
288);
// reading raw data which was created by an XWindows app
// from file
in = fopen("outvw.rgb","rb");
frame = (char*)malloc(max_frame_size);
fread(frame, 1, max_frame_size, in);
fclose(in);
for (y=0; y<288; y++)
for (x = 0; x < 352; x++)
{
c = frame[352*y+x];
gdk_image_put_pixel(gdkImage,
x,
y,
c);
}
gdk_draw_image( window->window, window->style->fg_gc[0], gdkImage, 0, 0, 0,
0, 388, 252 );
printf("after gdk_draw_image\n");
getchar();
}
//////////////////////////////////////////////////////////////////////////////
int main(int argc,char* argv[])
{
GtkWidget* window;
GdkWindowAttr attrs;
GdkImage* gdkImage = NULL;
GdkVisual* visual = NULL;
GtkWidget* button;
GdkGC* gc = NULL;
int x,y;
if (!gtk_init_check(&argc,&argv))
{
printf("couldn't gtk_init_check\n");
}
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
button = gtk_button_new_with_label("test");
// gtk_widget_set_usize(GTK_WIDGET(button),30,30);
// gdk_window_set_colormap(window->window, gdk_colormap_get_system ());
gtk_signal_connect(GTK_OBJECT(button),
"clicked",
GTK_SIGNAL_FUNC(hello),
NULL);
gtk_signal_connect(GTK_OBJECT(window),
"destroy",
GTK_SIGNAL_FUNC(destroy),
NULL);
gtk_widget_set_usize(window,352,288);
gtk_container_add(GTK_CONTAINER(window),button);
gtk_widget_show(window);
gtk_widget_show(button);
gtk_main();
}
regards,
John
_________________________________________________________________
MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*.
http://join.msn.com/?page=features/virus
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]