Hi, I am facing problem in setting mask on pixamp using Gtk+ over DirectFB backend. The code i am using, is given below.
/*------------------------------------------------------------------*/ void SetPixels_And_DrawImage(int x,int y, int w, int h,int[] pixelArray,jint offset,jint scansize) { GtkWidget *pMainWidget; GtkWidget *pMainWindow; pMainWindow = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_widget_realize (pCdcGraphicsDev->pMainWindow); guchar *rgbBuffer = NULL; int height_index = 0; GdkBitmap *mask = (GdkBitmap *) gdk_pixmap_new (NULL, w, h, 1); GdkGC *maskGC = gdk_gc_new (mask); GdkPixbuf *pPixbuf = NULL; GdkPixmap *pixmap = (GdkPixmap *) gdk_pixmap_new (NULL, w, h, gdk_visual_get_system ()->depth); GdkGC *gc = gdk_gc_new (pixmap ); GdkColor opaque, transparent; opaque.pixel = 1; transparent.pixel = 0; /* Fill mask with 1s */ gdk_gc_set_foreground (maskGC, &opaque); gdk_draw_rectangle (mask, maskGC, TRUE, 0, 0, w, h); for (n = 0; n < h; n++) { for (m = 0; m < w; m++) { /* Get the pixel at m, n. */ pixel = (unsigned long) pixelArray[n * scansize + m + offset]; /* Get and store red, green, blue values. */ rgbBuffer[height_index++] = (guchar) ((pixel & 0xff0000) >> 16); rgbBuffer[height_index++] = (guchar) ((pixel & 0xff00) >> 8); rgbBuffer[height_index++] = (guchar) (pixel & 0xff); /* Check if pixel should be transparent. */ if((pixel & 0xff000000) == 0) { gdk_gc_set_foreground (maskGC,&transparent); gdk_draw_point (mask, maskGC, x+m, y+n); } else { gdk_gc_set_foreground (maskGC, &opaque); gdk_draw_point (mask, maskGC, x+m, y+n); } } } pPixbuf = gdk_pixbuf_new_from_data(rgbBuffer,GDK_COLORSPACE_RGB,FALSE,8,w,h,w*3,NULL,NULL); gdk_gc_set_clip_origin (gc, x, y); gdk_gc_set_clip_mask (gc, mask); gdk_draw_pixbuf (pixmap, gc, pPixbuf,0, 0, 0, 0, gdk_pixbuf_get_width (pPixbuf), gdk_pixbuf_get_height (pPixbuf),GDK_RGB_DITHER_NORMAL,0, 0); gtk_image_set_from_pixmap(pMainWidget, pixmap,NULL); gtk_container_add (GTK_CONTAINER (pMainWindow), pMainWidget); gtk_widget_show_all(pMainWindow); gtk_main(); } /*------------------------------------------------------------------*/ In the above code, I am taking one bitmap (i.e. mask) and setting bits in this bitmap according to transparency of the pixel. Using function “gdk_gc_set_clip_mask”, I am setting clip mask in the graphics context (i.e. gc). After that, I am creating “pixbuf” from “rgbBuffer” and drawing pixamp from pixbuf. The above code works fine in case of “opaque” images. But, if some pixels of image are transparent, these pixels are drawn as black. These pixels should be drawn as transparent. When I dig deep in the problem, I found that gdk-directFB API’s are not checking the value of graphics context before drawing. I found that even alpha blending is not suppoerted properly in gdk-directFB API's. Please help me to solve this problem. Thanks in advance. _______________________________________________ directfb-dev mailing list directfb-dev@directfb.org http://mail.directfb.org/cgi-bin/mailman/listinfo/directfb-dev