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-pixbuf/gdk-pixbuf-scale.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-pixbuf/gdk-pixbuf-scale.c')
-rw-r--r-- | gdk-pixbuf/gdk-pixbuf-scale.c | 147 |
1 files changed, 103 insertions, 44 deletions
diff --git a/gdk-pixbuf/gdk-pixbuf-scale.c b/gdk-pixbuf/gdk-pixbuf-scale.c index 0f621d1d61..8b5a159e48 100644 --- a/gdk-pixbuf/gdk-pixbuf-scale.c +++ b/gdk-pixbuf/gdk-pixbuf-scale.c @@ -1,6 +1,31 @@ -#include "gdk-pixbuf.h" +/* GdkPixbuf library - Scaling and compositing functions + * + * Copyright (C) 1999 The Free Software Foundation + * + * Author: Owen Taylor <otaylor@redhat.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * 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 <math.h> +#include "gdk-pixbuf-private.h" #include "pixops/pixops.h" -#include "math.h" + + /** * gdk_pixbuf_scale: @@ -14,7 +39,7 @@ * @offset_y: the offset in the Y direction (currently rounded to an integer) * @scale_x: the scale factor in the X direction * @scale_y: the scale factor in the Y direction - * @filter_level: the filter quality for the transformation. + * @interp_type: the interpolation type for the transformation. * * Transforms the image by source image by scaling by @scale_x and @scale_y then * translating by @offset_x and @offset_y, then renders the rectangle @@ -32,17 +57,22 @@ gdk_pixbuf_scale (const GdkPixbuf *src, double offset_y, double scale_x, double scale_y, - ArtFilterLevel filter_level) + GdkInterpType interp_type) { + g_return_if_fail (src != NULL); + g_return_if_fail (dest != NULL); + g_return_if_fail (dest_x >= 0 && dest_x + dest_width <= dest->width); + g_return_if_fail (dest_y >= 0 && dest_y + dest_height <= dest->height); + offset_x = floor (offset_x + 0.5); offset_y = floor (offset_y + 0.5); - pixops_scale (dest->art_pixbuf->pixels + dest_y * dest->art_pixbuf->rowstride + dest_x * dest->art_pixbuf->n_channels, + pixops_scale (dest->pixels + dest_y * dest->rowstride + dest_x * dest->n_channels, -offset_x, -offset_y, dest_width - offset_x, dest_height - offset_y, - dest->art_pixbuf->rowstride, dest->art_pixbuf->n_channels, dest->art_pixbuf->has_alpha, - src->art_pixbuf->pixels, src->art_pixbuf->width, src->art_pixbuf->height, - src->art_pixbuf->rowstride, src->art_pixbuf->n_channels, src->art_pixbuf->has_alpha, - scale_x, scale_y, filter_level); + dest->rowstride, dest->n_channels, dest->has_alpha, + src->pixels, src->width, src->height, + src->rowstride, src->n_channels, src->has_alpha, + scale_x, scale_y, interp_type); } /** @@ -57,7 +87,7 @@ gdk_pixbuf_scale (const GdkPixbuf *src, * @offset_y: the offset in the Y direction (currently rounded to an integer) * @scale_x: the scale factor in the X direction * @scale_y: the scale factor in the Y direction - * @filter_level: the filter quality for the transformation. + * @interp_type: the interpolation type for the transformation. * @overall_alpha: overall alpha for source image (0..255) * * Transforms the image by source image by scaling by @scale_x and @scale_y then @@ -76,17 +106,23 @@ gdk_pixbuf_composite (const GdkPixbuf *src, double offset_y, double scale_x, double scale_y, - ArtFilterLevel filter_level, + GdkInterpType interp_type, int overall_alpha) { + g_return_if_fail (src != NULL); + g_return_if_fail (dest != NULL); + g_return_if_fail (dest_x >= 0 && dest_x + dest_width <= dest->width); + g_return_if_fail (dest_y >= 0 && dest_y + dest_height <= dest->height); + g_return_if_fail (overall_alpha >= 0 && overall_alpha <= 255); + offset_x = floor (offset_x + 0.5); offset_y = floor (offset_y + 0.5); - pixops_composite (dest->art_pixbuf->pixels + dest_y * dest->art_pixbuf->rowstride + dest_x * dest->art_pixbuf->n_channels, + pixops_composite (dest->pixels + dest_y * dest->rowstride + dest_x * dest->n_channels, -offset_x, -offset_y, dest_width - offset_x, dest_height - offset_y, - dest->art_pixbuf->rowstride, dest->art_pixbuf->n_channels, dest->art_pixbuf->has_alpha, - src->art_pixbuf->pixels, src->art_pixbuf->width, src->art_pixbuf->height, - src->art_pixbuf->rowstride, src->art_pixbuf->n_channels, src->art_pixbuf->has_alpha, - scale_x, scale_y, filter_level, overall_alpha); + dest->rowstride, dest->n_channels, dest->has_alpha, + src->pixels, src->width, src->height, + src->rowstride, src->n_channels, src->has_alpha, + scale_x, scale_y, interp_type, overall_alpha); } /** @@ -101,7 +137,7 @@ gdk_pixbuf_composite (const GdkPixbuf *src, * @offset_y: the offset in the Y direction (currently rounded to an integer) * @scale_x: the scale factor in the X direction * @scale_y: the scale factor in the Y direction - * @filter_level: the filter quality for the transformation. + * @interp_type: the interpolation type for the transformation. * @overall_alpha: overall alpha for source image (0..255) * @check_x: the X offset for the checkboard (origin of checkboard is at -@check_x, -@check_y) * @check_y: the Y offset for the checkboard @@ -126,23 +162,30 @@ gdk_pixbuf_composite_color (const GdkPixbuf *src, double offset_y, double scale_x, double scale_y, - ArtFilterLevel filter_level, + GdkInterpType interp_type, int overall_alpha, int check_x, int check_y, int check_size, - art_u32 color1, - art_u32 color2) + guint32 color1, + guint32 color2) { + g_return_if_fail (src != NULL); + g_return_if_fail (dest != NULL); + g_return_if_fail (dest_x >= 0 && dest_x + dest_width <= dest->width); + g_return_if_fail (dest_y >= 0 && dest_y + dest_height <= dest->height); + g_return_if_fail (overall_alpha >= 0 && overall_alpha <= 255); + offset_x = floor (offset_x + 0.5); offset_y = floor (offset_y + 0.5); - pixops_composite_color (dest->art_pixbuf->pixels + dest_y * dest->art_pixbuf->rowstride + dest_x * dest->art_pixbuf->n_channels, + pixops_composite_color (dest->pixels + dest_y * dest->rowstride + dest_x * dest->n_channels, -offset_x, -offset_y, dest_width - offset_x, dest_height - offset_y, - dest->art_pixbuf->rowstride, dest->art_pixbuf->n_channels, dest->art_pixbuf->has_alpha, - src->art_pixbuf->pixels, src->art_pixbuf->width, src->art_pixbuf->height, - src->art_pixbuf->rowstride, src->art_pixbuf->n_channels, src->art_pixbuf->has_alpha, - scale_x, scale_y, filter_level, overall_alpha, check_x, check_y, check_size, color1, color2); + dest->rowstride, dest->n_channels, dest->has_alpha, + src->pixels, src->width, src->height, + src->rowstride, src->n_channels, src->has_alpha, + scale_x, scale_y, interp_type, overall_alpha, check_x, check_y, + check_size, color1, color2); } /** @@ -150,25 +193,34 @@ gdk_pixbuf_composite_color (const GdkPixbuf *src, * @src: a #GdkPixbuf * @dest_width: the width of destination image * @dest_height: the height of destination image - * @filter_level: the filter quality for the transformation. + * @interp_type: the interpolation type for the transformation. * * Scale the #GdkPixbuf @src to @dest_width x @dest_height and render the result into * a new #GdkPixbuf. * - * Return value: the new #GdkPixbuf + * Return value: the new #GdkPixbuf, or NULL if not enough memory could be + * allocated for it. **/ GdkPixbuf * gdk_pixbuf_scale_simple (const GdkPixbuf *src, int dest_width, int dest_height, - ArtFilterLevel filter_level) + GdkInterpType interp_type) { - GdkPixbuf *dest = gdk_pixbuf_new (ART_PIX_RGB, src->art_pixbuf->has_alpha, 8, dest_width, dest_height); + GdkPixbuf *dest; + + g_return_val_if_fail (src != NULL, NULL); + g_return_val_if_fail (dest_width > 0, NULL); + g_return_val_if_fail (dest_height > 0, NULL); + + dest = gdk_pixbuf_new (GDK_COLORSPACE_RGB, src->has_alpha, 8, dest_width, dest_height); + if (!dest) + return NULL; gdk_pixbuf_scale (src, dest, 0, 0, dest_width, dest_height, 0, 0, - (double)dest_width / src->art_pixbuf->width, - (double)dest_height / src->art_pixbuf->height, - filter_level); + (double) dest_width / src->width, + (double) dest_height / src->height, + interp_type); return dest; } @@ -178,7 +230,7 @@ gdk_pixbuf_scale_simple (const GdkPixbuf *src, * @src: a #GdkPixbuf * @dest_width: the width of destination image * @dest_height: the height of destination image - * @filter_level: the filter quality for the transformation. + * @interp_type: the interpolation type for the transformation. * @overall_alpha: overall alpha for source image (0..255) * @check_size: the size of checks in the checkboard (must be a power of two) * @color1: the color of check at upper left @@ -188,27 +240,34 @@ gdk_pixbuf_scale_simple (const GdkPixbuf *src, * a checkboard of colors @color1 and @color2 and render the result into * a new #GdkPixbuf. * - * Return value: the new #GdkPixbuf + * Return value: the new #GdkPixbuf, or NULL if not enough memory could be + * allocated for it. **/ GdkPixbuf * gdk_pixbuf_composite_color_simple (const GdkPixbuf *src, int dest_width, int dest_height, - ArtFilterLevel filter_level, + GdkInterpType interp_type, int overall_alpha, int check_size, - art_u32 color1, - art_u32 color2) + guint32 color1, + guint32 color2) { - GdkPixbuf *dest = gdk_pixbuf_new (ART_PIX_RGB, src->art_pixbuf->has_alpha, 8, dest_width, dest_height); + GdkPixbuf *dest; + + g_return_val_if_fail (src != NULL, NULL); + g_return_val_if_fail (dest_width > 0, NULL); + g_return_val_if_fail (dest_height > 0, NULL); + g_return_val_if_fail (overall_alpha >= 0 && overall_alpha <= 255, NULL); + + dest = gdk_pixbuf_new (GDK_COLORSPACE_RGB, src->has_alpha, 8, dest_width, dest_height); + if (!dest) + return NULL; gdk_pixbuf_composite_color (src, dest, 0, 0, dest_width, dest_height, 0, 0, - (double)dest_width / src->art_pixbuf->width, - (double)dest_height / src->art_pixbuf->height, - filter_level, overall_alpha, 0, 0, check_size, color1, color2); + (double) dest_width / src->width, + (double) dest_height / src->height, + interp_type, overall_alpha, 0, 0, check_size, color1, color2); return dest; } - - - |