]> Pileus Git - ~andy/gtk/blobdiff - gdk/gdkpixbuf-render.c
Make GTK+ use an external gdk-pixbuf
[~andy/gtk] / gdk / gdkpixbuf-render.c
index 0065ed13f814147fcbb8a0339caefa68f9a002a9..614719a82fda8d6aa09849faa494837e1673eeac 100644 (file)
  * Boston, MA 02111-1307, USA.
  */
 
-#include <config.h>
+#include "config.h"
 #include <gdk/gdk.h>
-#include "gdk-pixbuf-private.h"
+#include <gdk-pixbuf/gdk-pixbuf.h>
 #include "gdkpixbuf.h"
 #include "gdkscreen.h"
 #include "gdkinternals.h"
+#include "gdkalias.h"
 
 \f
 
@@ -62,34 +63,33 @@ gdk_pixbuf_render_threshold_alpha (GdkPixbuf *pixbuf,
   int start, start_status;
   int status;
 
-  g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
-  g_return_if_fail (pixbuf->colorspace == GDK_COLORSPACE_RGB);
-  g_return_if_fail (pixbuf->n_channels == 3 || pixbuf->n_channels == 4);
-  g_return_if_fail (pixbuf->bits_per_sample == 8);
+  g_return_val_if_fail (gdk_pixbuf_get_colorspace (pixbuf) == GDK_COLORSPACE_RGB, NULL);
+  g_return_val_if_fail (gdk_pixbuf_get_n_channels (pixbuf) == 3 ||
+                        gdk_pixbuf_get_n_channels (pixbuf) == 4, NULL);
+  g_return_val_if_fail (gdk_pixbuf_get_bits_per_sample (pixbuf) == 8, NULL);
 
   if (width == -1) 
-    width = pixbuf->width;
+    width = gdk_pixbuf_get_width (pixbuf);
   if (height == -1)
-    height = pixbuf->height;
+    height = gdk_pixbuf_get_height (pixbuf);
 
   g_return_if_fail (bitmap != NULL);
   g_return_if_fail (width >= 0 && height >= 0);
-  g_return_if_fail (src_x >= 0 && src_x + width <= pixbuf->width);
-  g_return_if_fail (src_y >= 0 && src_y + height <= pixbuf->height);
+  g_return_if_fail (src_x >= 0 && src_x + width <= gdk_pixbuf_get_width (pixbuf));
+  g_return_if_fail (src_y >= 0 && src_y + height <= gdk_pixbuf_get_height (pixbuf));
 
   g_return_if_fail (alpha_threshold >= 0 && alpha_threshold <= 255);
 
   if (width == 0 || height == 0)
     return;
 
-  gc = gdk_gc_new (bitmap);
+  gc = _gdk_drawable_get_scratch_gc (bitmap, FALSE);
 
-  if (!pixbuf->has_alpha)
+  if (!gdk_pixbuf_get_has_alpha (pixbuf))
     {
       color.pixel = (alpha_threshold == 255) ? 0 : 1;
       gdk_gc_set_foreground (gc, &color);
       gdk_draw_rectangle (bitmap, gc, TRUE, dest_x, dest_y, width, height);
-      g_object_unref (gc);
       return;
     }
 
@@ -102,8 +102,8 @@ gdk_pixbuf_render_threshold_alpha (GdkPixbuf *pixbuf,
 
   for (y = 0; y < height; y++)
     {
-      p = (pixbuf->pixels + (y + src_y) * pixbuf->rowstride + src_x * pixbuf->n_channels
-          + pixbuf->n_channels - 1);
+      p = (gdk_pixbuf_get_pixels (pixbuf) + (y + src_y) * gdk_pixbuf_get_rowstride (pixbuf) + src_x * gdk_pixbuf_get_n_channels (pixbuf)
+          + gdk_pixbuf_get_n_channels (pixbuf) - 1);
            
       start = 0;
       start_status = *p < alpha_threshold;
@@ -123,7 +123,7 @@ gdk_pixbuf_render_threshold_alpha (GdkPixbuf *pixbuf,
              start_status = status;
            }
          
-         p += pixbuf->n_channels;
+         p += gdk_pixbuf_get_n_channels (pixbuf);
        }
       
       if (!start_status)
@@ -131,99 +131,6 @@ gdk_pixbuf_render_threshold_alpha (GdkPixbuf *pixbuf,
                       start + dest_x, y + dest_y,
                       x - 1 + dest_x, y + dest_y);
     }
-
-  g_object_unref (gc);
-}
-
-\f
-
-/**
- * gdk_pixbuf_render_to_drawable:
- * @pixbuf: A pixbuf.
- * @drawable: Destination drawable.
- * @gc: GC used for rendering.
- * @src_x: Source X coordinate within pixbuf.
- * @src_y: Source Y coordinate within pixbuf.
- * @dest_x: Destination X coordinate within drawable.
- * @dest_y: Destination Y coordinate within drawable.
- * @width: Width of region to render, in pixels, or -1 to use pixbuf width
- * @height: Height of region to render, in pixels, or -1 to use pixbuf height
- * @dither: Dithering mode for GdkRGB.
- * @x_dither: X offset for dither.
- * @y_dither: Y offset for dither.
- *
- * Renders a rectangular portion of a pixbuf to a drawable while using the
- * specified GC.  This is done using GdkRGB, so the specified drawable must have
- * the GdkRGB visual and colormap.  Note that this function will ignore the
- * opacity information for images with an alpha channel; the GC must already
- * have the clipping mask set if you want transparent regions to show through.
- *
- * For an explanation of dither offsets, see the GdkRGB documentation.  In
- * brief, the dither offset is important when re-rendering partial regions of an
- * image to a rendered version of the full image, or for when the offsets to a
- * base position change, as in scrolling.  The dither matrix has to be shifted
- * 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.
- **/
-void
-gdk_pixbuf_render_to_drawable (GdkPixbuf   *pixbuf,
-                              GdkDrawable *drawable,
-                              GdkGC       *gc,
-                              int src_x,    int src_y,
-                              int dest_x,   int dest_y,
-                              int width,    int height,
-                              GdkRgbDither dither,
-                              int x_dither, int y_dither)
-{
-  gdk_draw_pixbuf (drawable, gc, pixbuf,
-                  src_x, src_y, dest_x, dest_y, width, height,
-                  dither, x_dither, y_dither);
-}
-
-\f
-
-/**
- * gdk_pixbuf_render_to_drawable_alpha:
- * @pixbuf: A pixbuf.
- * @drawable: Destination drawable.
- * @src_x: Source X coordinate within pixbuf.
- * @src_y: Source Y coordinates within pixbuf.
- * @dest_x: Destination X coordinate within drawable.
- * @dest_y: Destination Y coordinate within drawable.
- * @width: Width of region to render, in pixels, or -1 to use pixbuf width.
- * @height: Height of region to render, in pixels, or -1 to use pixbuf height.
- * @alpha_mode: Ignored. Present for backwards compatibility.
- * @alpha_threshold: Ignored. Present for backwards compatibility
- * @dither: Dithering mode for GdkRGB.
- * @x_dither: X offset for dither.
- * @y_dither: Y offset for dither.
- *
- * 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.
- * 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.
- **/
-void
-gdk_pixbuf_render_to_drawable_alpha (GdkPixbuf   *pixbuf,
-                                    GdkDrawable *drawable,
-                                    int src_x,    int src_y,
-                                    int dest_x,   int dest_y,
-                                    int width,    int height,
-                                    GdkPixbufAlphaMode alpha_mode,
-                                    int                alpha_threshold,
-                                    GdkRgbDither       dither,
-                                    int x_dither, int y_dither)
-{
-  gdk_draw_pixbuf (drawable, NULL, pixbuf,
-                  src_x, src_y, dest_x, dest_y, width, height,
-                  dither, x_dither, y_dither);
 }
 
 /**
@@ -244,10 +151,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,
@@ -282,7 +189,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,
@@ -307,11 +214,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)
@@ -330,3 +250,7 @@ gdk_pixbuf_render_pixmap_and_mask_for_colormap (GdkPixbuf   *pixbuf,
        *mask_return = NULL;
     }
 }
+
+#define __GDK_PIXBUF_RENDER_C__
+#include "gdkaliasdef.c"
+