GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Apr 18, 2014 11:17 pm

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Problem - Transparent pixels in image are drawn as black
PostPosted: Fri Feb 15, 2008 6:25 am 
Offline

Joined: Tue Feb 05, 2008 1:51 pm
Posts: 3
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â€


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group