comparison gtk/dw.c @ 1253:28c2c7e6671c

On GTK2 save the original pixbuf that is loaded so we can use it to store the alpha channel for use later when doing stretched bitblts... only negative is when drawing to pixmaps it won't modify the alpha mask.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Mon, 24 Oct 2011 05:21:29 +0000
parents b31056c321a2
children 3df86772b625
comparison
equal deleted inserted replaced
1252:575663435272 1253:28c2c7e6671c
8352 */ 8352 */
8353 HPIXMAP dw_pixmap_new_from_file(HWND handle, char *filename) 8353 HPIXMAP dw_pixmap_new_from_file(HWND handle, char *filename)
8354 { 8354 {
8355 int _locked_by_me = FALSE; 8355 int _locked_by_me = FALSE;
8356 HPIXMAP pixmap; 8356 HPIXMAP pixmap;
8357 #if GTK_MAJOR_VERSION > 1 8357 #ifdef USE_IMLIB
8358 GdkPixbuf *pixbuf;
8359 #elif defined(USE_IMLIB)
8360 GdkImlibImage *image; 8358 GdkImlibImage *image;
8361 #endif 8359 #endif
8362 char *file = alloca(strlen(filename) + 5); 8360 char *file = alloca(strlen(filename) + 5);
8363 int found_ext = 0; 8361 int found_ext = 0;
8364 int i; 8362 int i;
8389 } 8387 }
8390 } 8388 }
8391 8389
8392 DW_MUTEX_LOCK; 8390 DW_MUTEX_LOCK;
8393 #if GTK_MAJOR_VERSION > 1 8391 #if GTK_MAJOR_VERSION > 1
8394 pixbuf = gdk_pixbuf_new_from_file(file, NULL); 8392 pixmap->pixbuf = gdk_pixbuf_new_from_file(file, NULL);
8395 pixmap->width = gdk_pixbuf_get_width(pixbuf); 8393 pixmap->width = gdk_pixbuf_get_width(pixmap->pixbuf);
8396 pixmap->height = gdk_pixbuf_get_height(pixbuf); 8394 pixmap->height = gdk_pixbuf_get_height(pixmap->pixbuf);
8397 gdk_pixbuf_render_pixmap_and_mask(pixbuf, &pixmap->pixmap, &pixmap->bitmap, 1); 8395 gdk_pixbuf_render_pixmap_and_mask(pixmap->pixbuf, &pixmap->pixmap, &pixmap->bitmap, 1);
8398 g_object_unref(pixbuf);
8399 #elif defined(USE_IMLIB) 8396 #elif defined(USE_IMLIB)
8400 image = gdk_imlib_load_image(file); 8397 image = gdk_imlib_load_image(file);
8401 8398
8402 pixmap->width = image->rgb_width; 8399 pixmap->width = image->rgb_width;
8403 pixmap->height = image->rgb_height; 8400 pixmap->height = image->rgb_height;
8580 8577
8581 DW_MUTEX_LOCK; 8578 DW_MUTEX_LOCK;
8582 gdk_pixmap_unref(pixmap->pixmap); 8579 gdk_pixmap_unref(pixmap->pixmap);
8583 if(pixmap->font) 8580 if(pixmap->font)
8584 free(pixmap->font); 8581 free(pixmap->font);
8582 if(pixmap->pixbuf)
8583 g_object_unref(pixmap->pixbuf);
8585 free(pixmap); 8584 free(pixmap);
8586 DW_MUTEX_UNLOCK; 8585 DW_MUTEX_UNLOCK;
8587 } 8586 }
8588 8587
8589 #if GTK_CHECK_VERSION(2,10,0) 8588 #if GTK_CHECK_VERSION(2,10,0)
8735 */ 8734 */
8736 GdkPixbuf *pbdst, *pbsrc = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, srcwidth, srcheight); 8735 GdkPixbuf *pbdst, *pbsrc = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, srcwidth, srcheight);
8737 /* Now that with have a pixbuf with alpha, copy from the drawable to create the source */ 8736 /* Now that with have a pixbuf with alpha, copy from the drawable to create the source */
8738 gdk_pixbuf_get_from_drawable(pbsrc, src ? src->window : srcp->pixmap, NULL, xsrc, ysrc, 0, 0, srcwidth, srcheight); 8737 gdk_pixbuf_get_from_drawable(pbsrc, src ? src->window : srcp->pixmap, NULL, xsrc, ysrc, 0, 0, srcwidth, srcheight);
8739 8738
8740 /* If the pixmap has an associated alpha mask, include that in the pixbuf */
8741 //if( srcp && srcp->bitmap )
8742 // Need to apply the mask to the pixmap if possible here
8743 /* Scale the pixbuf to the desired size */ 8739 /* Scale the pixbuf to the desired size */
8744 pbdst = gdk_pixbuf_scale_simple(pbsrc, width, height, GDK_INTERP_BILINEAR); 8740 pbdst = gdk_pixbuf_scale_simple(pbsrc, width, height, GDK_INTERP_BILINEAR);
8745 /* Create a new clipping mask from the scaled pixbuf */ 8741 /* Create a new clipping mask from the scaled pixbuf */
8746 if( srcp && srcp->bitmap ) 8742 if( srcp && srcp->bitmap && srcp->pixbuf )
8747 { 8743 {
8748 GdkBitmap *bitmap = gdk_pixmap_new(NULL, width, height, 1); 8744 GdkBitmap *bitmap = gdk_pixmap_new(NULL, width, height, 1);
8749 gdk_pixbuf_render_threshold_alpha(pbdst, bitmap, 0, 0, 0, 0, width, height, 1); 8745 GdkPixbuf *pborig = gdk_pixbuf_scale_simple(srcp->pixbuf, width, height, GDK_INTERP_BILINEAR);
8746 gdk_pixbuf_render_threshold_alpha(pborig, bitmap, 0, 0, 0, 0, width, height, 1);
8750 gdk_gc_set_clip_mask( gc, bitmap ); 8747 gdk_gc_set_clip_mask( gc, bitmap );
8751 gdk_gc_set_clip_origin( gc, xdest, ydest ); 8748 gdk_gc_set_clip_origin( gc, xdest, ydest );
8752 gdk_bitmap_unref(bitmap); 8749 gdk_bitmap_unref(bitmap);
8750 gdk_pixbuf_unref(pborig);
8753 } 8751 }
8754 /* Draw the final pixbuf onto the destination drawable */ 8752 /* Draw the final pixbuf onto the destination drawable */
8755 gdk_draw_pixbuf(dest ? dest->window : destp->pixmap, gc, pbdst, 0, 0, xdest, ydest, width, height, GDK_RGB_DITHER_NONE, 0, 0); 8753 gdk_draw_pixbuf(dest ? dest->window : destp->pixmap, gc, pbdst, 0, 0, xdest, ydest, width, height, GDK_RGB_DITHER_NONE, 0, 0);
8756 /* Cleanup so we don't leak */ 8754 /* Cleanup so we don't leak */
8757 gdk_pixbuf_unref(pbsrc); 8755 gdk_pixbuf_unref(pbsrc);