1999-10-27 23:36:44 +00:00
|
|
|
|
/* GdkPixbuf library - Rendering functions
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 1999 The Free Software Foundation
|
|
|
|
|
*
|
|
|
|
|
* Author: Federico Mena-Quintero <federico@gimp.org>
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
2000-07-26 11:33:08 +00:00
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
1999-10-27 23:36:44 +00:00
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2000-07-26 11:33:08 +00:00
|
|
|
|
* Lesser General Public License for more details.
|
1999-10-27 23:36:44 +00:00
|
|
|
|
*
|
2000-07-26 11:33:08 +00:00
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
1999-10-27 23:36:44 +00:00
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#include <gdk/gdk.h>
|
2000-04-11 07:03:25 +00:00
|
|
|
|
#include "gdk-pixbuf-private.h"
|
2000-06-21 20:47:22 +00:00
|
|
|
|
#include "gdkpixbuf.h"
|
1999-10-27 23:36:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gdk_pixbuf_render_threshold_alpha:
|
|
|
|
|
* @pixbuf: A pixbuf.
|
|
|
|
|
* @bitmap: Bitmap where the bilevel mask will be painted to.
|
|
|
|
|
* @src_x: Source X coordinate.
|
|
|
|
|
* @src_y: source Y coordinate.
|
|
|
|
|
* @dest_x: Destination X coordinate.
|
|
|
|
|
* @dest_y: Destination Y coordinate.
|
2001-09-19 20:13:16 +00:00
|
|
|
|
* @width: Width of region to threshold, or -1 to use pixbuf width
|
|
|
|
|
* @height: Height of region to threshold, or -1 to use pixbuf height
|
1999-10-27 23:36:44 +00:00
|
|
|
|
* @alpha_threshold: Opacity values below this will be painted as zero; all
|
|
|
|
|
* other values will be painted as one.
|
1999-10-28 23:25:02 +00:00
|
|
|
|
*
|
|
|
|
|
* Takes the opacity values in a rectangular portion of a pixbuf and thresholds
|
|
|
|
|
* them to produce a bi-level alpha mask that can be used as a clipping mask for
|
|
|
|
|
* a drawable.
|
1999-11-04 20:16:17 +00:00
|
|
|
|
*
|
1999-10-27 23:36:44 +00:00
|
|
|
|
**/
|
|
|
|
|
void
|
2000-06-21 23:29:51 +00:00
|
|
|
|
gdk_pixbuf_render_threshold_alpha (GdkPixbuf *pixbuf,
|
|
|
|
|
GdkBitmap *bitmap,
|
|
|
|
|
int src_x, int src_y,
|
1999-10-27 23:36:44 +00:00
|
|
|
|
int dest_x, int dest_y,
|
2000-06-21 23:29:51 +00:00
|
|
|
|
int width, int height,
|
1999-10-27 23:36:44 +00:00
|
|
|
|
int alpha_threshold)
|
|
|
|
|
{
|
2000-06-21 23:29:51 +00:00
|
|
|
|
GdkGC *gc;
|
|
|
|
|
GdkColor color;
|
|
|
|
|
int x, y;
|
|
|
|
|
guchar *p;
|
|
|
|
|
int start, start_status;
|
|
|
|
|
int status;
|
|
|
|
|
|
2001-09-19 20:13:16 +00:00
|
|
|
|
g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
|
2000-06-21 23:29:51 +00:00
|
|
|
|
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);
|
|
|
|
|
|
2001-09-19 20:13:16 +00:00
|
|
|
|
if (width == -1)
|
|
|
|
|
width = pixbuf->width;
|
|
|
|
|
if (height == -1)
|
|
|
|
|
height = pixbuf->height;
|
|
|
|
|
|
2000-06-21 23:29:51 +00:00
|
|
|
|
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 (alpha_threshold >= 0 && alpha_threshold <= 255);
|
|
|
|
|
|
|
|
|
|
if (width == 0 || height == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
gc = gdk_gc_new (bitmap);
|
|
|
|
|
|
|
|
|
|
if (!pixbuf->has_alpha)
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
gdk_gc_unref (gc);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
color.pixel = 0;
|
|
|
|
|
gdk_gc_set_foreground (gc, &color);
|
|
|
|
|
gdk_draw_rectangle (bitmap, gc, TRUE, dest_x, dest_y, width, height);
|
|
|
|
|
|
|
|
|
|
color.pixel = 1;
|
|
|
|
|
gdk_gc_set_foreground (gc, &color);
|
|
|
|
|
|
|
|
|
|
for (y = 0; y < height; y++)
|
|
|
|
|
{
|
|
|
|
|
p = (pixbuf->pixels + (y + src_y) * pixbuf->rowstride + src_x * pixbuf->n_channels
|
|
|
|
|
+ pixbuf->n_channels - 1);
|
|
|
|
|
|
|
|
|
|
start = 0;
|
|
|
|
|
start_status = *p < alpha_threshold;
|
|
|
|
|
|
|
|
|
|
for (x = 0; x < width; x++)
|
|
|
|
|
{
|
|
|
|
|
status = *p < alpha_threshold;
|
|
|
|
|
|
|
|
|
|
if (status != start_status)
|
|
|
|
|
{
|
|
|
|
|
if (!start_status)
|
|
|
|
|
gdk_draw_line (bitmap, gc,
|
|
|
|
|
start + dest_x, y + dest_y,
|
|
|
|
|
x - 1 + dest_x, y + dest_y);
|
|
|
|
|
|
|
|
|
|
start = x;
|
|
|
|
|
start_status = status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p += pixbuf->n_channels;
|
1999-10-27 23:36:44 +00:00
|
|
|
|
}
|
2000-06-21 23:29:51 +00:00
|
|
|
|
|
|
|
|
|
if (!start_status)
|
|
|
|
|
gdk_draw_line (bitmap, gc,
|
|
|
|
|
start + dest_x, y + dest_y,
|
|
|
|
|
x - 1 + dest_x, y + dest_y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gdk_gc_unref (gc);
|
1999-10-27 23:36:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-10-28 23:25:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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.
|
2001-09-19 20:13:16 +00:00
|
|
|
|
* @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
|
1999-10-28 23:25:02 +00:00
|
|
|
|
* @dither: Dithering mode for GdkRGB.
|
|
|
|
|
* @x_dither: X offset for dither.
|
|
|
|
|
* @y_dither: Y offset for dither.
|
2000-01-17 01:48:21 +00:00
|
|
|
|
*
|
1999-10-28 23:25:02 +00:00
|
|
|
|
* 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.
|
1999-11-04 20:16:17 +00:00
|
|
|
|
*
|
1999-11-04 21:52:08 +00:00
|
|
|
|
* 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.
|
1999-10-28 23:25:02 +00:00
|
|
|
|
**/
|
1999-10-27 23:36:44 +00:00
|
|
|
|
void
|
2000-06-21 23:29:51 +00:00
|
|
|
|
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,
|
1999-10-27 23:36:44 +00:00
|
|
|
|
GdkRgbDither dither,
|
|
|
|
|
int x_dither, int y_dither)
|
|
|
|
|
{
|
2000-06-21 23:29:51 +00:00
|
|
|
|
int rowstride;
|
Add gdk_rgb_find_color() to get a pixel value using GdkRGB functionality
Sun Jul 2 12:45:50 2000 Owen Taylor <otaylor@redhat.com>
* gdk/gdkrgb.[ch]: Add gdk_rgb_find_color() to get a pixel
value using GdkRGB functionality given GdkColormap and GdkColor.
(name not final, waiting for inspiration.)
* gdk/gdkgc.[ch] (gdk_gc_set_rgb_fg/bg_color): New functions to
set the foreground/background of a GC using the GC's colormap
and GdkRGB. (name not final, waiting for inspiration.)
* gdk/gdkcompat.h gdk/gdkrgb.c (gdk_rgb_get_colormap): Rename from
gdk_rgb_get_cmap(), put #define in gdkcompat.h.
* gtk/gtkwidget.[ch] gtkcompat.h: Make visuals for
gtk_widget_get_visual(), gtk_widget_get_default_visual, etc,
purely a function of the corresponding colormap. Make
gtk_widget_set_visual(), etc, noop macros in gtkcompat.h.
* gdk/gdkpixmap.c gdk/x11/gdkpixmap-c11.c: Rewrite
gdk_pixbuf_*create_from_xpm_* in terms of
gdk_pixbuf_new_from_xpm_data(), move into platform independent
code.
* gdk/gdkpixbuf-render.c (gdk_pixbuf_render_to_drawable): Take
advantage of the new draw_rgb_32_image_dithalign.
* gdk/gdkrgb.c (gdk_draw_rgb_32_image_dithalign): Added.
* gtk/gtkgc.c (gtk_gc_new): Set the appropriate colormap
on each created GC.
* gdk/gdkgc.[ch]: Add gdk_gc_get/set_colormap.
* gdk/gdkgc.[ch]: Add a colormap field to the GdkGC structure
which we initialize from the drawable when the GC is created,
if the drawable has a colormap.
* gdk/x11/gdkgc-x11.c: include string.h for memset.
* gdk/x11/gdkinput-x11.c: include string.h for strlen, etc.
* gtk/gtklayout.[ch]: Remove unsed configure serial member.
2000-07-02 17:03:21 +00:00
|
|
|
|
guchar *buf;
|
2000-06-21 23:29:51 +00:00
|
|
|
|
|
2001-09-19 20:13:16 +00:00
|
|
|
|
g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
|
2000-06-21 23:29:51 +00:00
|
|
|
|
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_if_fail (drawable != NULL);
|
|
|
|
|
g_return_if_fail (gc != NULL);
|
|
|
|
|
|
2001-09-19 20:13:16 +00:00
|
|
|
|
if (width == -1)
|
|
|
|
|
width = pixbuf->width;
|
|
|
|
|
if (height == -1)
|
|
|
|
|
height = pixbuf->height;
|
|
|
|
|
|
2000-06-21 23:29:51 +00:00
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
if (width == 0 || height == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* This will have to be modified once we support other image types.
|
|
|
|
|
*/
|
|
|
|
|
|
Add gdk_rgb_find_color() to get a pixel value using GdkRGB functionality
Sun Jul 2 12:45:50 2000 Owen Taylor <otaylor@redhat.com>
* gdk/gdkrgb.[ch]: Add gdk_rgb_find_color() to get a pixel
value using GdkRGB functionality given GdkColormap and GdkColor.
(name not final, waiting for inspiration.)
* gdk/gdkgc.[ch] (gdk_gc_set_rgb_fg/bg_color): New functions to
set the foreground/background of a GC using the GC's colormap
and GdkRGB. (name not final, waiting for inspiration.)
* gdk/gdkcompat.h gdk/gdkrgb.c (gdk_rgb_get_colormap): Rename from
gdk_rgb_get_cmap(), put #define in gdkcompat.h.
* gtk/gtkwidget.[ch] gtkcompat.h: Make visuals for
gtk_widget_get_visual(), gtk_widget_get_default_visual, etc,
purely a function of the corresponding colormap. Make
gtk_widget_set_visual(), etc, noop macros in gtkcompat.h.
* gdk/gdkpixmap.c gdk/x11/gdkpixmap-c11.c: Rewrite
gdk_pixbuf_*create_from_xpm_* in terms of
gdk_pixbuf_new_from_xpm_data(), move into platform independent
code.
* gdk/gdkpixbuf-render.c (gdk_pixbuf_render_to_drawable): Take
advantage of the new draw_rgb_32_image_dithalign.
* gdk/gdkrgb.c (gdk_draw_rgb_32_image_dithalign): Added.
* gtk/gtkgc.c (gtk_gc_new): Set the appropriate colormap
on each created GC.
* gdk/gdkgc.[ch]: Add gdk_gc_get/set_colormap.
* gdk/gdkgc.[ch]: Add a colormap field to the GdkGC structure
which we initialize from the drawable when the GC is created,
if the drawable has a colormap.
* gdk/x11/gdkgc-x11.c: include string.h for memset.
* gdk/x11/gdkinput-x11.c: include string.h for strlen, etc.
* gtk/gtklayout.[ch]: Remove unsed configure serial member.
2000-07-02 17:03:21 +00:00
|
|
|
|
if (pixbuf->n_channels == 4)
|
2000-06-21 23:29:51 +00:00
|
|
|
|
{
|
2000-07-14 20:24:14 +00:00
|
|
|
|
buf = pixbuf->pixels + src_y * pixbuf->rowstride + src_x * 4;
|
2000-06-21 23:29:51 +00:00
|
|
|
|
rowstride = pixbuf->rowstride;
|
|
|
|
|
|
Add gdk_rgb_find_color() to get a pixel value using GdkRGB functionality
Sun Jul 2 12:45:50 2000 Owen Taylor <otaylor@redhat.com>
* gdk/gdkrgb.[ch]: Add gdk_rgb_find_color() to get a pixel
value using GdkRGB functionality given GdkColormap and GdkColor.
(name not final, waiting for inspiration.)
* gdk/gdkgc.[ch] (gdk_gc_set_rgb_fg/bg_color): New functions to
set the foreground/background of a GC using the GC's colormap
and GdkRGB. (name not final, waiting for inspiration.)
* gdk/gdkcompat.h gdk/gdkrgb.c (gdk_rgb_get_colormap): Rename from
gdk_rgb_get_cmap(), put #define in gdkcompat.h.
* gtk/gtkwidget.[ch] gtkcompat.h: Make visuals for
gtk_widget_get_visual(), gtk_widget_get_default_visual, etc,
purely a function of the corresponding colormap. Make
gtk_widget_set_visual(), etc, noop macros in gtkcompat.h.
* gdk/gdkpixmap.c gdk/x11/gdkpixmap-c11.c: Rewrite
gdk_pixbuf_*create_from_xpm_* in terms of
gdk_pixbuf_new_from_xpm_data(), move into platform independent
code.
* gdk/gdkpixbuf-render.c (gdk_pixbuf_render_to_drawable): Take
advantage of the new draw_rgb_32_image_dithalign.
* gdk/gdkrgb.c (gdk_draw_rgb_32_image_dithalign): Added.
* gtk/gtkgc.c (gtk_gc_new): Set the appropriate colormap
on each created GC.
* gdk/gdkgc.[ch]: Add gdk_gc_get/set_colormap.
* gdk/gdkgc.[ch]: Add a colormap field to the GdkGC structure
which we initialize from the drawable when the GC is created,
if the drawable has a colormap.
* gdk/x11/gdkgc-x11.c: include string.h for memset.
* gdk/x11/gdkinput-x11.c: include string.h for strlen, etc.
* gtk/gtklayout.[ch]: Remove unsed configure serial member.
2000-07-02 17:03:21 +00:00
|
|
|
|
gdk_draw_rgb_32_image_dithalign (drawable, gc,
|
|
|
|
|
dest_x, dest_y,
|
|
|
|
|
width, height,
|
|
|
|
|
dither,
|
|
|
|
|
buf, rowstride,
|
|
|
|
|
x_dither, y_dither);
|
|
|
|
|
}
|
|
|
|
|
else /* n_channels == 3 */
|
|
|
|
|
{
|
|
|
|
|
buf = pixbuf->pixels + src_y * pixbuf->rowstride + src_x * 3;
|
|
|
|
|
rowstride = pixbuf->rowstride;
|
2000-06-21 23:29:51 +00:00
|
|
|
|
|
Add gdk_rgb_find_color() to get a pixel value using GdkRGB functionality
Sun Jul 2 12:45:50 2000 Owen Taylor <otaylor@redhat.com>
* gdk/gdkrgb.[ch]: Add gdk_rgb_find_color() to get a pixel
value using GdkRGB functionality given GdkColormap and GdkColor.
(name not final, waiting for inspiration.)
* gdk/gdkgc.[ch] (gdk_gc_set_rgb_fg/bg_color): New functions to
set the foreground/background of a GC using the GC's colormap
and GdkRGB. (name not final, waiting for inspiration.)
* gdk/gdkcompat.h gdk/gdkrgb.c (gdk_rgb_get_colormap): Rename from
gdk_rgb_get_cmap(), put #define in gdkcompat.h.
* gtk/gtkwidget.[ch] gtkcompat.h: Make visuals for
gtk_widget_get_visual(), gtk_widget_get_default_visual, etc,
purely a function of the corresponding colormap. Make
gtk_widget_set_visual(), etc, noop macros in gtkcompat.h.
* gdk/gdkpixmap.c gdk/x11/gdkpixmap-c11.c: Rewrite
gdk_pixbuf_*create_from_xpm_* in terms of
gdk_pixbuf_new_from_xpm_data(), move into platform independent
code.
* gdk/gdkpixbuf-render.c (gdk_pixbuf_render_to_drawable): Take
advantage of the new draw_rgb_32_image_dithalign.
* gdk/gdkrgb.c (gdk_draw_rgb_32_image_dithalign): Added.
* gtk/gtkgc.c (gtk_gc_new): Set the appropriate colormap
on each created GC.
* gdk/gdkgc.[ch]: Add gdk_gc_get/set_colormap.
* gdk/gdkgc.[ch]: Add a colormap field to the GdkGC structure
which we initialize from the drawable when the GC is created,
if the drawable has a colormap.
* gdk/x11/gdkgc-x11.c: include string.h for memset.
* gdk/x11/gdkinput-x11.c: include string.h for strlen, etc.
* gtk/gtklayout.[ch]: Remove unsed configure serial member.
2000-07-02 17:03:21 +00:00
|
|
|
|
gdk_draw_rgb_image_dithalign (drawable, gc,
|
|
|
|
|
dest_x, dest_y,
|
|
|
|
|
width, height,
|
|
|
|
|
dither,
|
|
|
|
|
buf, rowstride,
|
|
|
|
|
x_dither, y_dither);
|
|
|
|
|
}
|
1999-10-28 23:25:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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.
|
2001-09-19 20:13:16 +00:00
|
|
|
|
* @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.
|
2002-01-04 05:58:01 +00:00
|
|
|
|
* @alpha_mode: Ignored. Present for backwards compatibility.
|
|
|
|
|
* @alpha_threshold: Ignored. Present for backwards compatibility
|
1999-10-28 23:25:02 +00:00
|
|
|
|
* @dither: Dithering mode for GdkRGB.
|
|
|
|
|
* @x_dither: X offset for dither.
|
|
|
|
|
* @y_dither: Y offset for dither.
|
|
|
|
|
*
|
2002-01-04 05:58:01 +00:00
|
|
|
|
* 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.
|
1999-11-04 20:16:17 +00:00
|
|
|
|
*
|
2002-01-04 05:58:01 +00:00
|
|
|
|
* On older X servers, rendering pixbufs with an alpha channel involves round trips
|
|
|
|
|
* to the X server, and may be somewhat slow.
|
1999-10-28 23:25:02 +00:00
|
|
|
|
**/
|
|
|
|
|
void
|
2000-06-21 23:29:51 +00:00
|
|
|
|
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,
|
1999-10-28 23:25:02 +00:00
|
|
|
|
GdkPixbufAlphaMode alpha_mode,
|
2000-06-21 23:29:51 +00:00
|
|
|
|
int alpha_threshold,
|
|
|
|
|
GdkRgbDither dither,
|
1999-10-28 23:25:02 +00:00
|
|
|
|
int x_dither, int y_dither)
|
|
|
|
|
{
|
2002-01-04 05:58:01 +00:00
|
|
|
|
_gdk_draw_pixbuf (drawable, NULL, pixbuf,
|
|
|
|
|
src_x, src_y, dest_x, dest_y, width, height,
|
|
|
|
|
dither, x_dither, y_dither);
|
1999-10-27 23:36:44 +00:00
|
|
|
|
}
|
1999-11-30 17:56:02 +00:00
|
|
|
|
|
2000-01-14 20:59:18 +00:00
|
|
|
|
/**
|
2000-01-17 01:48:21 +00:00
|
|
|
|
* gdk_pixbuf_render_pixmap_and_mask:
|
2000-04-11 07:03:25 +00:00
|
|
|
|
* @pixbuf: A pixbuf.
|
2000-01-17 01:48:21 +00:00
|
|
|
|
* @pixmap_return: Return value for the created pixmap.
|
|
|
|
|
* @mask_return: Return value for the created mask.
|
|
|
|
|
* @alpha_threshold: Threshold value for opacity values.
|
2000-01-14 20:59:18 +00:00
|
|
|
|
*
|
2000-01-17 01:48:21 +00:00
|
|
|
|
* Creates a pixmap and a mask bitmap which are returned in the @pixmap_return
|
|
|
|
|
* and @mask_return arguments, respectively, and renders a pixbuf and its
|
2001-09-07 22:33:09 +00:00
|
|
|
|
* corresponding thresholded alpha mask to them. This is merely a convenience
|
2000-01-17 01:48:21 +00:00
|
|
|
|
* function; applications that need to render pixbufs with dither offsets or to
|
|
|
|
|
* given drawables should use gdk_pixbuf_render_to_drawable_alpha() or
|
|
|
|
|
* gdk_pixbuf_render_to_drawable(), and gdk_pixbuf_render_threshold_alpha().
|
2000-04-11 07:03:25 +00:00
|
|
|
|
*
|
2001-09-07 22:33:09 +00:00
|
|
|
|
* 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.
|
|
|
|
|
*
|
2000-04-11 07:03:25 +00:00
|
|
|
|
* If the pixbuf does not have an alpha channel, then *@mask_return will be set
|
|
|
|
|
* to NULL.
|
2000-01-14 20:59:18 +00:00
|
|
|
|
**/
|
|
|
|
|
void
|
2000-06-21 23:29:51 +00:00
|
|
|
|
gdk_pixbuf_render_pixmap_and_mask (GdkPixbuf *pixbuf,
|
|
|
|
|
GdkPixmap **pixmap_return,
|
|
|
|
|
GdkBitmap **mask_return,
|
|
|
|
|
int alpha_threshold)
|
2001-09-07 22:33:09 +00:00
|
|
|
|
{
|
|
|
|
|
gdk_pixbuf_render_pixmap_and_mask_for_colormap (pixbuf,
|
|
|
|
|
gdk_rgb_get_colormap (),
|
|
|
|
|
pixmap_return, mask_return,
|
|
|
|
|
alpha_threshold);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gdk_pixbuf_render_pixmap_and_mask_for_colormap:
|
|
|
|
|
* @pixbuf: A pixbuf.
|
|
|
|
|
* @colormap: A #GdkColormap
|
|
|
|
|
* @pixmap_return: Return value for the created pixmap.
|
|
|
|
|
* @mask_return: Return value for the created mask.
|
|
|
|
|
* @alpha_threshold: Threshold value for opacity values.
|
|
|
|
|
*
|
|
|
|
|
* Creates a pixmap and a mask bitmap which are returned in the @pixmap_return
|
|
|
|
|
* and @mask_return arguments, respectively, and renders a pixbuf and its
|
|
|
|
|
* corresponding tresholded alpha mask to them. This is merely a convenience
|
|
|
|
|
* function; applications that need to render pixbufs with dither offsets or to
|
|
|
|
|
* given drawables should use gdk_pixbuf_render_to_drawable_alpha() or
|
|
|
|
|
* gdk_pixbuf_render_to_drawable(), and gdk_pixbuf_render_threshold_alpha().
|
|
|
|
|
*
|
|
|
|
|
* The pixmap that is created uses the #GdkColormap specified by @colormap.
|
|
|
|
|
* This colormap must match the colormap of the window where the pixmap
|
|
|
|
|
* 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.
|
|
|
|
|
**/
|
|
|
|
|
void
|
|
|
|
|
gdk_pixbuf_render_pixmap_and_mask_for_colormap (GdkPixbuf *pixbuf,
|
|
|
|
|
GdkColormap *colormap,
|
|
|
|
|
GdkPixmap **pixmap_return,
|
|
|
|
|
GdkBitmap **mask_return,
|
|
|
|
|
int alpha_threshold)
|
2000-01-14 20:59:18 +00:00
|
|
|
|
{
|
2000-06-21 23:29:51 +00:00
|
|
|
|
g_return_if_fail (pixbuf != NULL);
|
|
|
|
|
|
|
|
|
|
if (pixmap_return)
|
|
|
|
|
{
|
|
|
|
|
GdkGC *gc;
|
|
|
|
|
|
2001-09-07 22:33:09 +00:00
|
|
|
|
*pixmap_return = gdk_pixmap_new (NULL, gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf),
|
|
|
|
|
gdk_colormap_get_visual (colormap)->depth);
|
|
|
|
|
gdk_drawable_set_colormap (GDK_DRAWABLE (*pixmap_return),
|
|
|
|
|
colormap);
|
2000-06-21 23:29:51 +00:00
|
|
|
|
gc = gdk_gc_new (*pixmap_return);
|
|
|
|
|
gdk_pixbuf_render_to_drawable (pixbuf, *pixmap_return, gc,
|
|
|
|
|
0, 0, 0, 0,
|
2001-09-07 22:33:09 +00:00
|
|
|
|
gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf),
|
2000-06-21 23:29:51 +00:00
|
|
|
|
GDK_RGB_DITHER_NORMAL,
|
|
|
|
|
0, 0);
|
|
|
|
|
gdk_gc_unref (gc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mask_return)
|
|
|
|
|
{
|
2001-09-07 22:33:09 +00:00
|
|
|
|
if (gdk_pixbuf_get_has_alpha (pixbuf))
|
2000-06-21 23:29:51 +00:00
|
|
|
|
{
|
2001-09-07 22:33:09 +00:00
|
|
|
|
*mask_return = gdk_pixmap_new (NULL, gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf), 1);
|
|
|
|
|
|
2000-06-21 23:29:51 +00:00
|
|
|
|
gdk_pixbuf_render_threshold_alpha (pixbuf, *mask_return,
|
|
|
|
|
0, 0, 0, 0,
|
2001-09-07 22:33:09 +00:00
|
|
|
|
gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf),
|
2000-06-21 23:29:51 +00:00
|
|
|
|
alpha_threshold);
|
2000-01-17 01:48:21 +00:00
|
|
|
|
}
|
2000-06-21 23:29:51 +00:00
|
|
|
|
else
|
|
|
|
|
*mask_return = NULL;
|
|
|
|
|
}
|
2000-01-14 20:59:18 +00:00
|
|
|
|
}
|