decentdude
Joined: 05 Feb 2008 Posts: 3
|
Posted: Thu Feb 14, 2008 1:59 pm Post subject: Probelm in setting clip mask on Pixmap (image background) |
|
|
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)
{
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);
}
/*------------------------------------------------------------------*/
In the above code, we are setting clip on mask using api "
gdk_gc_set_clip_mask " but in the case of icon image, the background should
be transparent.
But background of image is black.
Please help me to solve this problem.
Thanks in advance. |
|