1 /* GdkPixbuf library - Scaling and compositing functions
3 * Copyright (C) 1999 The Free Software Foundation
5 * Author: Owen Taylor <otaylor@redhat.com>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
25 #include "gdk-pixbuf-private.h"
26 #include "pixops/pixops.h"
33 * @dest: the #GdkPixbuf into which to render the results
34 * @dest_x: the left coordinate for region to render
35 * @dest_y: the top coordinate for region to render
36 * @dest_width: the width of the region to render
37 * @dest_height: the height of the region to render
38 * @offset_x: the offset in the X direction (currently rounded to an integer)
39 * @offset_y: the offset in the Y direction (currently rounded to an integer)
40 * @scale_x: the scale factor in the X direction
41 * @scale_y: the scale factor in the Y direction
42 * @interp_type: the interpolation type for the transformation.
44 * Transforms the image by source image by scaling by @scale_x and @scale_y then
45 * translating by @offset_x and @offset_y, then renders the rectangle
46 * (@dest,@dest_y,@dest_width,@dest_height) of the resulting image onto the
47 * destination drawable replacing the previous contents.
50 gdk_pixbuf_scale (const GdkPixbuf *src,
60 GdkInterpType interp_type)
62 g_return_if_fail (src != NULL);
63 g_return_if_fail (dest != NULL);
64 g_return_if_fail (dest_x >= 0 && dest_x + dest_width <= dest->width);
65 g_return_if_fail (dest_y >= 0 && dest_y + dest_height <= dest->height);
67 offset_x = floor (offset_x + 0.5);
68 offset_y = floor (offset_y + 0.5);
70 pixops_scale (dest->pixels + dest_y * dest->rowstride + dest_x * dest->n_channels,
71 dest_x - offset_x, dest_y - offset_y,
72 dest_x + dest_width - offset_x, dest_y + dest_height - offset_y,
73 dest->rowstride, dest->n_channels, dest->has_alpha,
74 src->pixels, src->width, src->height,
75 src->rowstride, src->n_channels, src->has_alpha,
76 scale_x, scale_y, interp_type);
80 * gdk_pixbuf_composite:
82 * @dest: the #GdkPixbuf into which to render the results
83 * @dest_x: the left coordinate for region to render
84 * @dest_y: the top coordinate for region to render
85 * @dest_width: the width of the region to render
86 * @dest_height: the height of the region to render
87 * @offset_x: the offset in the X direction (currently rounded to an integer)
88 * @offset_y: the offset in the Y direction (currently rounded to an integer)
89 * @scale_x: the scale factor in the X direction
90 * @scale_y: the scale factor in the Y direction
91 * @interp_type: the interpolation type for the transformation.
92 * @overall_alpha: overall alpha for source image (0..255)
94 * Transforms the image by source image by scaling by @scale_x and @scale_y then
95 * translating by @offset_x and @offset_y, then composites the rectangle
96 * (@dest,@dest_y,@dest_width,@dest_height) of the resulting image onto the
97 * destination drawable.
100 gdk_pixbuf_composite (const GdkPixbuf *src,
110 GdkInterpType interp_type,
113 g_return_if_fail (src != NULL);
114 g_return_if_fail (dest != NULL);
115 g_return_if_fail (dest_x >= 0 && dest_x + dest_width <= dest->width);
116 g_return_if_fail (dest_y >= 0 && dest_y + dest_height <= dest->height);
117 g_return_if_fail (overall_alpha >= 0 && overall_alpha <= 255);
119 offset_x = floor (offset_x + 0.5);
120 offset_y = floor (offset_y + 0.5);
121 pixops_composite (dest->pixels + dest_y * dest->rowstride + dest_x * dest->n_channels,
122 dest_x - offset_x, dest_y - offset_y,
123 dest_x + dest_width - offset_x, dest_y + dest_height - offset_y,
124 dest->rowstride, dest->n_channels, dest->has_alpha,
125 src->pixels, src->width, src->height,
126 src->rowstride, src->n_channels, src->has_alpha,
127 scale_x, scale_y, interp_type, overall_alpha);
131 * gdk_pixbuf_composite_color:
133 * @dest: the #GdkPixbuf into which to render the results
134 * @dest_x: the left coordinate for region to render
135 * @dest_y: the top coordinate for region to render
136 * @dest_width: the width of the region to render
137 * @dest_height: the height of the region to render
138 * @offset_x: the offset in the X direction (currently rounded to an integer)
139 * @offset_y: the offset in the Y direction (currently rounded to an integer)
140 * @scale_x: the scale factor in the X direction
141 * @scale_y: the scale factor in the Y direction
142 * @interp_type: the interpolation type for the transformation.
143 * @overall_alpha: overall alpha for source image (0..255)
144 * @check_x: the X offset for the checkboard (origin of checkboard is at -@check_x, -@check_y)
145 * @check_y: the Y offset for the checkboard
146 * @check_size: the size of checks in the checkboard (must be a power of two)
147 * @color1: the color of check at upper left
148 * @color2: the color of the other check
150 * Transforms the image by source image by scaling by @scale_x and @scale_y then
151 * translating by @offset_x and @offset_y, then composites the rectangle
152 * (@dest,@dest_y,@dest_width,@dest_height) of the resulting image with
153 * a checkboard of the colors @color1 and @color2 and renders it onto the
154 * destination drawable.
157 gdk_pixbuf_composite_color (const GdkPixbuf *src,
167 GdkInterpType interp_type,
175 g_return_if_fail (src != NULL);
176 g_return_if_fail (dest != NULL);
177 g_return_if_fail (dest_x >= 0 && dest_x + dest_width <= dest->width);
178 g_return_if_fail (dest_y >= 0 && dest_y + dest_height <= dest->height);
179 g_return_if_fail (overall_alpha >= 0 && overall_alpha <= 255);
181 offset_x = floor (offset_x + 0.5);
182 offset_y = floor (offset_y + 0.5);
184 pixops_composite_color (dest->pixels + dest_y * dest->rowstride + dest_x * dest->n_channels,
185 dest_x - offset_x, dest_y - offset_y,
186 dest_x + dest_width - offset_x, dest_y + dest_height - offset_y,
187 dest->rowstride, dest->n_channels, dest->has_alpha,
188 src->pixels, src->width, src->height,
189 src->rowstride, src->n_channels, src->has_alpha,
190 scale_x, scale_y, interp_type, overall_alpha, check_x, check_y,
191 check_size, color1, color2);
195 * gdk_pixbuf_scale_simple:
197 * @dest_width: the width of destination image
198 * @dest_height: the height of destination image
199 * @interp_type: the interpolation type for the transformation.
201 * Scale the #GdkPixbuf @src to @dest_width x @dest_height and render the result into
204 * Return value: the new #GdkPixbuf, or NULL if not enough memory could be
208 gdk_pixbuf_scale_simple (const GdkPixbuf *src,
211 GdkInterpType interp_type)
215 g_return_val_if_fail (src != NULL, NULL);
216 g_return_val_if_fail (dest_width > 0, NULL);
217 g_return_val_if_fail (dest_height > 0, NULL);
219 dest = gdk_pixbuf_new (GDK_COLORSPACE_RGB, src->has_alpha, 8, dest_width, dest_height);
223 gdk_pixbuf_scale (src, dest, 0, 0, dest_width, dest_height, 0, 0,
224 (double) dest_width / src->width,
225 (double) dest_height / src->height,
232 * gdk_pixbuf_composite_color_simple:
234 * @dest_width: the width of destination image
235 * @dest_height: the height of destination image
236 * @interp_type: the interpolation type for the transformation.
237 * @overall_alpha: overall alpha for source image (0..255)
238 * @check_size: the size of checks in the checkboard (must be a power of two)
239 * @color1: the color of check at upper left
240 * @color2: the color of the other check
242 * Scale the #GdkPixbuf @src to @dest_width x @dest_height composite the result with
243 * a checkboard of colors @color1 and @color2 and render the result into
246 * Return value: the new #GdkPixbuf, or NULL if not enough memory could be
250 gdk_pixbuf_composite_color_simple (const GdkPixbuf *src,
253 GdkInterpType interp_type,
261 g_return_val_if_fail (src != NULL, NULL);
262 g_return_val_if_fail (dest_width > 0, NULL);
263 g_return_val_if_fail (dest_height > 0, NULL);
264 g_return_val_if_fail (overall_alpha >= 0 && overall_alpha <= 255, NULL);
266 dest = gdk_pixbuf_new (GDK_COLORSPACE_RGB, src->has_alpha, 8, dest_width, dest_height);
270 gdk_pixbuf_composite_color (src, dest, 0, 0, dest_width, dest_height, 0, 0,
271 (double) dest_width / src->width,
272 (double) dest_height / src->height,
273 interp_type, overall_alpha, 0, 0, check_size, color1, color2);