There's something in my pixmap



Hi,

When a GdkPixmap is created with gdk_pixmap_new(), its content seems to
be undefined, but GDK's documention [1] says nothing about it.

According to Xlib − C Language X Interface [2], in 5.1. Creating and
Freeing Pixmaps, "The initial contents of the pixmap are undefined."

GDK's documentation should specify this.

Now questions: 

- how to draw a RGBA GdkPixbuf in this GdkPixmap, discarding the
previous content of the GdkPixmap, e.g. gdk_draw_pixbuf() seems to
compose the GdkPixbuf's content with the GdkPixmap's content, creating
some image corruption.

- if not possible, how to clear GdkPixmap's content with a black, fully
transparent content ?

- without using cairo, if possible, would be better.

Thanks.

[1]
http://library.gnome.org/devel/gdk/stable/gdk-Bitmaps-and-Pixmaps.html#gdk-pixmap-new
[2] http://www.x.org/docs/X11/xlib.pdf

Here is a little program which create a pixmap, convert it in GdkPixbuf
and dump its content to the terminal.

--------------8<-----------------

#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <gdk/gdkx.h>

#include <gdk-pixbuf/gdk-pixbuf.h>

int
main(int   argc,
     char *argv[])
{
  GdkColormap *colormap;
  GdkPixmap *pixmap;
  GdkPixbuf *pixbuf;

  unsigned char  *p;
  guint x;
  guint y;
  guint n;

  gtk_init (&argc, &argv);

  colormap = gdk_screen_get_rgba_colormap(gdk_screen_get_default());
  if (colormap == NULL) {
    g_printerr("no ARGB colormap\n");
    return 1;
  }

  gtk_widget_set_default_colormap(colormap);

  pixmap = gdk_pixmap_new(NULL, 16, 16, 32);

  pixbuf = gdk_pixbuf_get_from_drawable(NULL,
                                        pixmap,
                                        colormap,
                                        0, 0,
                                        0, 0,
                                        16, 16);

  n = gdk_pixbuf_get_n_channels(pixbuf);

  if (n < 3 || n > 4) {
    g_printerr("Invalid pixbuf format\n");
    return 1;
  }

  if (gdk_pixbuf_get_bits_per_sample(pixbuf) != 8) {
    g_printerr("not 8bits per component\n");
    return 1;
  }

  if (gdk_pixbuf_get_has_alpha(pixbuf) == TRUE) {
    g_print("pixbuf has alpha !\n");
  }

  p = gdk_pixbuf_get_pixels(pixbuf);
  for(y = 0;
      y < gdk_pixbuf_get_height(pixbuf);
      y ++) {

    for(x = 0; x < gdk_pixbuf_get_width(pixbuf); x++) {

      printf("(%d,%d) ", x,y);

      switch(n) {
      case 4:
        g_print("%02x %02x %02x %02x\n",
                p[x * 4],
                p[x * 4 + 1],
                p[x * 4 + 2],
                p[x * 4 + 3]);
        break;
      case 3:
        g_print("%02x %02x %02x\n",
                p[x * 3],
                p[x * 3 + 1],
                p[x * 3 + 2]);

        break;
      }
    }

    g_print("\n");
    p += gdk_pixbuf_get_rowstride(pixbuf);
  }

  return 0;
}


-- 
Yann Droneaud <ydroneaud mandriva com>





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]