]> Pileus Git - ~andy/gtk/blobdiff - gdk/gdkpixbuf-render.c
add missing #ifndef GDK_DISABLE_DEPRECATED.
[~andy/gtk] / gdk / gdkpixbuf-render.c
index 6e3891f7587fb3f1f42b47a9c4913f9f0bcca88a..a702e2e7ca8d889f10f418a016738017be258b04 100644 (file)
@@ -20,7 +20,7 @@
  * Boston, MA 02111-1307, USA.
  */
 
-#include <config.h>
+#include "config.h"
 #include <gdk/gdk.h>
 #include "gdk-pixbuf-private.h"
 #include "gdkpixbuf.h"
@@ -163,7 +163,7 @@ gdk_pixbuf_render_threshold_alpha (GdkPixbuf *pixbuf,
  * for consistent visual results.  If you do not have any of these cases, the
  * dither offsets can be both zero.
  *
- * Deprecated: This function is obsolete. Use gdk_draw_pixbuf() instead.
+ * Deprecated: 2.4: This function is obsolete. Use gdk_draw_pixbuf() instead.
  **/
 void
 gdk_pixbuf_render_to_drawable (GdkPixbuf   *pixbuf,
@@ -200,13 +200,13 @@ gdk_pixbuf_render_to_drawable (GdkPixbuf   *pixbuf,
  *
  * Renders a rectangular portion of a pixbuf to a drawable.  The destination
  * drawable must have a colormap. All windows have a colormap, however, pixmaps
- * only have colormap by default if they were created with a non-NULL window argument.
+ * only have colormap by default if they were created with a non-%NULL window argument.
  * Otherwise a colormap must be set on them with gdk_drawable_set_colormap.
  *
  * On older X servers, rendering pixbufs with an alpha channel involves round trips
  * to the X server, and may be somewhat slow.
  *
- * Deprecated: This function is obsolete. Use gdk_draw_pixbuf() instead.
+ * Deprecated: 2.4: This function is obsolete. Use gdk_draw_pixbuf() instead.
  **/
 void
 gdk_pixbuf_render_to_drawable_alpha (GdkPixbuf   *pixbuf,
@@ -242,10 +242,10 @@ gdk_pixbuf_render_to_drawable_alpha (GdkPixbuf   *pixbuf,
  * The pixmap that is created is created for the colormap returned
  * by gdk_rgb_get_colormap(). You normally will want to instead use
  * the actual colormap for a widget, and use
- * gdk_pixbuf_render_pixmap_and_mask_for_colormap.
+ * gdk_pixbuf_render_pixmap_and_mask_for_colormap().
  *
  * If the pixbuf does not have an alpha channel, then *@mask_return will be set
- * to NULL.
+ * to %NULL.
  **/
 void
 gdk_pixbuf_render_pixmap_and_mask (GdkPixbuf  *pixbuf,
@@ -280,7 +280,7 @@ gdk_pixbuf_render_pixmap_and_mask (GdkPixbuf  *pixbuf,
  * will eventually be used or an error will result.
  *
  * If the pixbuf does not have an alpha channel, then *@mask_return will be set
- * to NULL.
+ * to %NULL.
  **/
 void
 gdk_pixbuf_render_pixmap_and_mask_for_colormap (GdkPixbuf   *pixbuf,
@@ -305,11 +305,24 @@ gdk_pixbuf_render_pixmap_and_mask_for_colormap (GdkPixbuf   *pixbuf,
 
       gdk_drawable_set_colormap (GDK_DRAWABLE (*pixmap_return), colormap);
       gc = _gdk_drawable_get_scratch_gc (*pixmap_return, FALSE);
-      gdk_draw_pixbuf (*pixmap_return, gc, pixbuf, 
-                      0, 0, 0, 0,
-                      gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf),
-                      GDK_RGB_DITHER_NORMAL,
-                      0, 0);
+
+      /* If the pixbuf has an alpha channel, using gdk_pixbuf_draw would give
+       * random pixel values in the area that are within the mask, but semi-
+       * transparent. So we treat the pixbuf like a pixbuf without alpha channel;
+       * see bug #487865.
+       */
+      if (gdk_pixbuf_get_has_alpha (pixbuf))
+        gdk_draw_rgb_32_image (*pixmap_return, gc,
+                               0, 0,
+                               gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf),
+                               GDK_RGB_DITHER_NORMAL,
+                               gdk_pixbuf_get_pixels (pixbuf), gdk_pixbuf_get_rowstride (pixbuf));
+      else
+        gdk_draw_pixbuf (*pixmap_return, gc, pixbuf, 
+                         0, 0, 0, 0,
+                         gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf),
+                         GDK_RGB_DITHER_NORMAL,
+                         0, 0);
     }
   
   if (mask_return)
@@ -329,114 +342,6 @@ gdk_pixbuf_render_pixmap_and_mask_for_colormap (GdkPixbuf   *pixbuf,
     }
 }
 
-/**
- * gdk_pixbuf_set_as_cairo_source:
- * @pixbuf: a #GdkPixbuf
- * @cr: a #Cairo context
- * 
- * Sets the given pixbuf as the source pattern for the Cairo context.
- * The pattern has an extend mode of %CAIRO_EXTEND_NONE and is aligned
- * so that the origin of @pixbuf is at the current point.
- **/
-void
-gdk_pixbuf_set_as_cairo_source (GdkPixbuf *pixbuf,
-                               cairo_t   *cr)
-{
-  gint width = gdk_pixbuf_get_width (pixbuf);
-  gint height = gdk_pixbuf_get_height (pixbuf);
-  guchar *gdk_pixels = gdk_pixbuf_get_pixels (pixbuf);
-  int gdk_rowstride = gdk_pixbuf_get_rowstride (pixbuf);
-  int n_channels = gdk_pixbuf_get_n_channels (pixbuf);
-  guchar *cairo_pixels;
-  cairo_format_t format;
-  cairo_surface_t *surface;
-  cairo_pattern_t *pattern;
-  static const cairo_user_data_key_t key;
-  cairo_matrix_t *matrix;
-  double x, y;
-  int j;
-
-  if (n_channels == 3)
-    format = CAIRO_FORMAT_RGB24;
-  else
-    format = CAIRO_FORMAT_ARGB32;
-
-  cairo_pixels = g_malloc (4 * width * height);
-  surface = cairo_image_surface_create_for_data ((unsigned char *)cairo_pixels,
-                                                format,
-                                                width, height, 4 * width);
-  cairo_surface_set_user_data (surface, &key,
-                              cairo_pixels, (cairo_destroy_func_t)g_free);
-
-  for (j = height; j; j--)
-    {
-      guchar *p = gdk_pixels;
-      guchar *q = cairo_pixels;
-
-      if (n_channels == 3)
-       {
-         guchar *end = p + 3 * width;
-         
-         while (p < end)
-           {
-#if G_BYTE_ORDER == GDK_LSB_FIRST
-             q[0] = p[2];
-             q[1] = p[1];
-             q[2] = p[2];
-#else    
-             q[0] = p[0];
-             q[1] = p[1];
-             q[2] = p[2];
-#endif
-             p += 3;
-             q += 4;
-           }
-       }
-      else
-       {
-         guchar *end = p + 4 * width;
-         guint t1,t2,t3;
-           
-#define MULT(d,c,a,t) G_STMT_START { t = c * a; d = ((t >> 8) + t) >> 8; } G_STMT_END
-
-         while (p < end)
-           {
-#if G_BYTE_ORDER == G_LITTLE_ENDIAN
-             MULT(q[0], p[2], p[3], t1);
-             MULT(q[1], p[1], p[3], t2);
-             MULT(q[2], p[0], p[3], t3);
-             q[3] = p[3];
-#else    
-             q[0] = p[3];
-             MULT(q[1], p[0], p[3], t1);
-             MULT(q[2], p[1], p[3], t2);
-             MULT(q[3], p[2], p[3], t3);
-#endif
-             
-             p += 4;
-             q += 4;
-           }
-         
-#undef MULT
-       }
-
-      gdk_pixels += gdk_rowstride;
-      cairo_pixels += 4 * width;
-    }
-
-  pattern = cairo_pattern_create_for_surface (surface);
-  cairo_surface_destroy (surface);
-  
-  cairo_current_point (cr, &x, &y);
-  matrix = cairo_matrix_create ();
-  cairo_matrix_translate (matrix, -x, -y);
-  cairo_pattern_set_matrix (pattern, matrix);
-  cairo_matrix_destroy (matrix);
-
-  cairo_set_source (cr, pattern);
-  cairo_pattern_destroy (pattern);
-}
-
 #define __GDK_PIXBUF_RENDER_C__
 #include "gdkaliasdef.c"