diff options
author | Federico Mena Quintero <federico@helixcode.com> | 2000-04-11 07:03:25 +0000 |
---|---|---|
committer | Federico Mena Quintero <federico@src.gnome.org> | 2000-04-11 07:03:25 +0000 |
commit | 829ed02435b643c2b3da57dfc1f5abb8124e55cc (patch) | |
tree | f0d9b9a6c0c047d93f634bab8d22bced16be3253 /gdk/gdkpixbuf-render.c | |
parent | daaae930ad946e06f183794ffda8e17c4125b3d4 (diff) | |
download | gtk+-829ed02435b643c2b3da57dfc1f5abb8124e55cc.tar.gz |
Most of this patch is based on a patch by Havoc Pennington (hp@redhat.com)
2000-04-11 Federico Mena Quintero <federico@helixcode.com>
Most of this patch is based on a patch by Havoc Pennington
(hp@redhat.com) to make GdkPixbuf's structures opaque and to
remove the libart dependency.
* gdk-pixbuf/gdk-pixbuf.h: Removed the public structures.
(GdkColorspace): New enum that for now only contains
GDK_COLORSPACE_RGB.
(GdkPixbufDestroyNotify): New type for the pixbuf's pixels destroy
notification function.
(GdkInterpType): New num with interpolation types.
* *.[ch]: Replace the libart stuff with our own stuff.
* pixops/*.[ch]: Likewise.
* gdk-pixbuf/gdk-pixbuf-private.h: New file with the private
declarations of the GdkPixbuf structures.
* gdk-pixbuf/gdk-pixbuf.c (gdk_pixbuf_new_from_art_pixbuf):
Removed function.
(gdk_pixbuf_get_format): Constify.
(gdk_pixbuf_get_n_channels): Constify.
(gdk_pixbuf_get_has_alpha): Constify.
(gdk_pixbuf_get_bits_per_sample): Constify.
(gdk_pixbuf_get_pixels): Constify.
(gdk_pixbuf_get_width): Constify.
(gdk_pixbuf_get_height): Constify.
(gdk_pixbuf_get_rowstride): Constify.
* gdk-pixbuf/gdk-pixbuf.c (gdk_pixbuf_copy): New function to copy
a pixbuf.
* gdk-pixbuf/gdk-pixbuf-data.c (gdk_pixbuf_new_from_data): Added a
bits_per_sample argument; currently only 8 bits per sample are
supported.
* gdk-pixbuf/gdk-pixbuf-animation.c (gdk_pixbuf_frame_get_pixbuf):
New accessor.
(gdk_pixbuf_frame_get_x_offset): New accessor.
(gdk_pixbuf_frame_get_y_offset): New accessor.
(gdk_pixbuf_frame_get_delay_time): New accessor.
(gdk_pixbuf_frame_get_action): New accessor.
* gdk-pixbuf/gdk-pixbuf-render.c
(gdk_pixbuf_render_pixmap_and_mask): Instead of returning a solid
mask rectangle for pixbufs without an alpha channel, set the
*mask_return to NULL.
* gdk-pixbuf/gdk-pixbuf-util.c (gdk_pixbuf_add_alpha): Constify.
* gdk-pixbuf/gdk-pixbuf-scale.c: Fix includes.
* gdk-pixbuf/gdk-pixbuf-scale.c (gdk_pixbuf_scale): Added some
preconditions. Maybe we should also check for the colorspace,
bits per pixel, and such.
(gdk_pixbuf_composite): Likewise.
(gdk_pixbuf_composite_color): Likewise.
(gdk_pixbuf_scale_simple): Likewise, and fail gracefully if we
cannot allocate the new pixbuf.
(gdk_pixbuf_composite_color_simple): Likewise.
* gdk-pixbuf/gnome-canvas-pixbuf.c (gnome_canvas_pixbuf_render):
Use art_rgb_rgba_affine() or art_rgb_affine() since we no longer
have an ArtPixBuf.
* gdk-pixbuf/io-bmp.c: Fix includes.
* gdk-pixbuf/pixops/pixops.c (pixops_scale_nearest): Fixed cast in
an lvalue.
* TODO: Populated.
* configure.in: Removed checks for libart.
* gdk-pixbuf/Makefile.am: Removed references to libart.
(noinst_HEADERS): Added gdk-pixbuf-private.h.
* gdk-pixbuf/Makefile.am (libgdk_pixbuf_la_LDFLAGS): Incremented
the version number of the libtool library to indicate that this
definitely is not compatible with the old usage. I know you love
me. I know you do.
* configure.in: Bumped version number to 0.7.0.
* README: Updated.
* gdk-pixbuf-config.in (--libs): We no longer require libart.
* DEPENDS.libgdk_pixbuf: We no longer depend on libart.
* gdk-pixbuf.spec.in: Updated, but I don't guarantee anything.
Diffstat (limited to 'gdk/gdkpixbuf-render.c')
-rw-r--r-- | gdk/gdkpixbuf-render.c | 105 |
1 files changed, 49 insertions, 56 deletions
diff --git a/gdk/gdkpixbuf-render.c b/gdk/gdkpixbuf-render.c index 19bf30deab..706d43b595 100644 --- a/gdk/gdkpixbuf-render.c +++ b/gdk/gdkpixbuf-render.c @@ -22,8 +22,7 @@ #include <config.h> #include <gdk/gdk.h> -#include <libart_lgpl/art_rect.h> -#include "gdk-pixbuf.h" +#include "gdk-pixbuf-private.h" @@ -52,7 +51,6 @@ gdk_pixbuf_render_threshold_alpha (GdkPixbuf *pixbuf, GdkBitmap *bitmap, int width, int height, int alpha_threshold) { - ArtPixBuf *apb; GdkGC *gc; GdkColor color; int x, y; @@ -61,16 +59,14 @@ gdk_pixbuf_render_threshold_alpha (GdkPixbuf *pixbuf, GdkBitmap *bitmap, int status; g_return_if_fail (pixbuf != NULL); - apb = pixbuf->art_pixbuf; - - g_return_if_fail (apb->format == ART_PIX_RGB); - g_return_if_fail (apb->n_channels == 3 || apb->n_channels == 4); - g_return_if_fail (apb->bits_per_sample == 8); + 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 (bitmap != NULL); g_return_if_fail (width >= 0 && height >= 0); - g_return_if_fail (src_x >= 0 && src_x + width <= apb->width); - g_return_if_fail (src_y >= 0 && src_y + height <= apb->height); + 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); @@ -79,7 +75,7 @@ gdk_pixbuf_render_threshold_alpha (GdkPixbuf *pixbuf, GdkBitmap *bitmap, gc = gdk_gc_new (bitmap); - if (!apb->has_alpha) { + 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); @@ -95,8 +91,8 @@ gdk_pixbuf_render_threshold_alpha (GdkPixbuf *pixbuf, GdkBitmap *bitmap, gdk_gc_set_foreground (gc, &color); for (y = 0; y < height; y++) { - p = (apb->pixels + (y + src_y) * apb->rowstride + src_x * apb->n_channels - + apb->n_channels - 1); + p = (pixbuf->pixels + (y + src_y) * pixbuf->rowstride + src_x * pixbuf->n_channels + + pixbuf->n_channels - 1); start = 0; start_status = *p < alpha_threshold; @@ -114,7 +110,7 @@ gdk_pixbuf_render_threshold_alpha (GdkPixbuf *pixbuf, GdkBitmap *bitmap, start_status = status; } - p += apb->n_channels; + p += pixbuf->n_channels; } if (!start_status) @@ -130,24 +126,24 @@ gdk_pixbuf_render_threshold_alpha (GdkPixbuf *pixbuf, GdkBitmap *bitmap, /* Creates a buffer by stripping the alpha channel of a pixbuf */ static guchar * -remove_alpha (ArtPixBuf *apb, int x, int y, int width, int height, int *rowstride) +remove_alpha (GdkPixbuf *pixbuf, int x, int y, int width, int height, int *rowstride) { guchar *buf; int xx, yy; guchar *src, *dest; - g_assert (apb->n_channels == 4); - g_assert (apb->has_alpha); + g_assert (pixbuf->n_channels == 4); + g_assert (pixbuf->has_alpha); g_assert (width > 0 && height > 0); - g_assert (x >= 0 && x + width <= apb->width); - g_assert (y >= 0 && y + height <= apb->height); + g_assert (x >= 0 && x + width <= pixbuf->width); + g_assert (y >= 0 && y + height <= pixbuf->height); *rowstride = 4 * ((width * 3 + 3) / 4); buf = g_new (guchar, *rowstride * height); for (yy = 0; yy < height; yy++) { - src = apb->pixels + apb->rowstride * (yy + y) + x * apb->n_channels; + src = pixbuf->pixels + pixbuf->rowstride * (yy + y) + x * pixbuf->n_channels; dest = buf + *rowstride * yy; for (xx = 0; xx < width; xx++) { @@ -198,37 +194,34 @@ gdk_pixbuf_render_to_drawable (GdkPixbuf *pixbuf, GdkRgbDither dither, int x_dither, int y_dither) { - ArtPixBuf *apb; guchar *buf; int rowstride; g_return_if_fail (pixbuf != NULL); - apb = pixbuf->art_pixbuf; - - g_return_if_fail (apb->format == ART_PIX_RGB); - g_return_if_fail (apb->n_channels == 3 || apb->n_channels == 4); - g_return_if_fail (apb->bits_per_sample == 8); + 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); g_return_if_fail (width >= 0 && height >= 0); - g_return_if_fail (src_x >= 0 && src_x + width <= apb->width); - g_return_if_fail (src_y >= 0 && src_y + height <= apb->height); + 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 libart supports other image types. + /* This will have to be modified once we support other image types. * Also, GdkRGB does not have gdk_draw_rgb_32_image_dithalign(), so we - * have to pack the buffer first. + * have to pack the buffer first. Sigh. */ - if (apb->has_alpha) - buf = remove_alpha (apb, src_x, src_y, width, height, &rowstride); + if (pixbuf->has_alpha) + buf = remove_alpha (pixbuf, src_x, src_y, width, height, &rowstride); else { - buf = apb->pixels + src_y * apb->rowstride + src_x * 3; - rowstride = apb->rowstride; + buf = pixbuf->pixels + src_y * pixbuf->rowstride + src_x * 3; + rowstride = pixbuf->rowstride; } gdk_draw_rgb_image_dithalign (drawable, gc, @@ -238,7 +231,7 @@ gdk_pixbuf_render_to_drawable (GdkPixbuf *pixbuf, buf, rowstride, x_dither, y_dither); - if (apb->has_alpha) + if (pixbuf->has_alpha) g_free (buf); } @@ -284,28 +277,25 @@ gdk_pixbuf_render_to_drawable_alpha (GdkPixbuf *pixbuf, GdkDrawable *drawable, GdkRgbDither dither, int x_dither, int y_dither) { - ArtPixBuf *apb; GdkBitmap *bitmap = NULL; GdkGC *gc; g_return_if_fail (pixbuf != NULL); - apb = pixbuf->art_pixbuf; - - g_return_if_fail (apb->format == ART_PIX_RGB); - g_return_if_fail (apb->n_channels == 3 || apb->n_channels == 4); - g_return_if_fail (apb->bits_per_sample == 8); + 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 (width >= 0 && height >= 0); - g_return_if_fail (src_x >= 0 && src_x + width <= apb->width); - g_return_if_fail (src_y >= 0 && src_y + height <= apb->height); + 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; gc = gdk_gc_new (drawable); - if (apb->has_alpha) { + if (pixbuf->has_alpha) { /* Right now we only support GDK_PIXBUF_ALPHA_BILEVEL, so we * unconditionally create the clipping mask. */ @@ -330,12 +320,13 @@ gdk_pixbuf_render_to_drawable_alpha (GdkPixbuf *pixbuf, GdkDrawable *drawable, if (bitmap) gdk_bitmap_unref (bitmap); + gdk_gc_unref (gc); } /** * gdk_pixbuf_render_pixmap_and_mask: - * @pixbuf: A pixbuf + * @pixbuf: A pixbuf. * @pixmap_return: Return value for the created pixmap. * @mask_return: Return value for the created mask. * @alpha_threshold: Threshold value for opacity values. @@ -346,37 +337,39 @@ gdk_pixbuf_render_to_drawable_alpha (GdkPixbuf *pixbuf, GdkDrawable *drawable, * 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(). + * + * If the pixbuf does not have an alpha channel, then *@mask_return will be set + * to NULL. **/ void gdk_pixbuf_render_pixmap_and_mask (GdkPixbuf *pixbuf, GdkPixmap **pixmap_return, GdkBitmap **mask_return, int alpha_threshold) { - ArtPixBuf *apb; - g_return_if_fail (pixbuf != NULL); - apb = pixbuf->art_pixbuf; - if (pixmap_return) { GdkGC *gc; - *pixmap_return = gdk_pixmap_new (NULL, apb->width, apb->height, + *pixmap_return = gdk_pixmap_new (NULL, pixbuf->width, pixbuf->height, gdk_rgb_get_visual ()->depth); gc = gdk_gc_new (*pixmap_return); gdk_pixbuf_render_to_drawable (pixbuf, *pixmap_return, gc, 0, 0, 0, 0, - apb->width, apb->height, + pixbuf->width, pixbuf->height, GDK_RGB_DITHER_NORMAL, 0, 0); gdk_gc_unref (gc); } if (mask_return) { - *mask_return = gdk_pixmap_new (NULL, apb->width, apb->height, 1); - gdk_pixbuf_render_threshold_alpha (pixbuf, *mask_return, - 0, 0, 0, 0, - apb->width, apb->height, - alpha_threshold); + if (pixbuf->has_alpha) { + *mask_return = gdk_pixmap_new (NULL, pixbuf->width, pixbuf->height, 1); + gdk_pixbuf_render_threshold_alpha (pixbuf, *mask_return, + 0, 0, 0, 0, + pixbuf->width, pixbuf->height, + alpha_threshold); + } else + *mask_return = NULL; } } |