]> Pileus Git - ~andy/gtk/blob - gdk-pixbuf/gdk-pixbuf-scale.c
By order of jrb: const patch for various bits, io-gif.c fixup for
[~andy/gtk] / gdk-pixbuf / gdk-pixbuf-scale.c
1 #include "gdk-pixbuf.h"
2 #include "pixops/pixops.h"
3 #include "math.h"
4
5 /**
6  * gdk_pixbuf_scale:
7  * @src: a #GdkPixbuf
8  * @dest: the #GdkPixbuf into which to render the results
9  * @dest_x: the left coordinate for region to render
10  * @dest_y: the top coordinate for region to render
11  * @dest_width: the width of the region to render
12  * @dest_height: the height of the region to render
13  * @offset_x: the offset in the X direction (currently rounded to an integer)
14  * @offset_y: the offset in the Y direction (currently rounded to an integer)
15  * @scale_x: the scale factor in the X direction
16  * @scale_y: the scale factor in the Y direction
17  * @filter_level: the filter quality for the transformation.
18  * 
19  * Transforms the image by source image by scaling by @scale_x and @scale_y then
20  * translating by @offset_x and @offset_y, then renders the rectangle
21  * (@dest,@dest_y,@dest_width,@dest_height) of the resulting image onto the
22  * destination drawable replacing the previous contents.
23  **/
24 void
25 gdk_pixbuf_scale (const GdkPixbuf *src,
26                   GdkPixbuf       *dest,
27                   int              dest_x,
28                   int              dest_y,
29                   int              dest_width,
30                   int              dest_height,
31                   double           offset_x,
32                   double           offset_y,
33                   double           scale_x,
34                   double           scale_y,
35                   ArtFilterLevel   filter_level)
36 {
37   offset_x = floor (offset_x + 0.5);
38   offset_y = floor (offset_y + 0.5);
39   
40   pixops_scale (dest->art_pixbuf->pixels + dest_y * dest->art_pixbuf->rowstride + dest_x * dest->art_pixbuf->n_channels,
41                 -offset_x, -offset_y, dest_width - offset_x, dest_height - offset_y,
42                 dest->art_pixbuf->rowstride, dest->art_pixbuf->n_channels, dest->art_pixbuf->has_alpha,
43                 src->art_pixbuf->pixels, src->art_pixbuf->width, src->art_pixbuf->height,
44                 src->art_pixbuf->rowstride, src->art_pixbuf->n_channels, src->art_pixbuf->has_alpha,
45                 scale_x, scale_y, filter_level);
46 }
47
48 /**
49  * gdk_pixbuf_composite:
50  * @src: a #GdkPixbuf
51  * @dest: the #GdkPixbuf into which to render the results
52  * @dest_x: the left coordinate for region to render
53  * @dest_y: the top coordinate for region to render
54  * @dest_width: the width of the region to render
55  * @dest_height: the height of the region to render
56  * @offset_x: the offset in the X direction (currently rounded to an integer)
57  * @offset_y: the offset in the Y direction (currently rounded to an integer)
58  * @scale_x: the scale factor in the X direction
59  * @scale_y: the scale factor in the Y direction
60  * @filter_level: the filter quality for the transformation.
61  * @overall_alpha: overall alpha for source image (0..255)
62  * 
63  * Transforms the image by source image by scaling by @scale_x and @scale_y then
64  * translating by @offset_x and @offset_y, then composites the rectangle
65  * (@dest,@dest_y,@dest_width,@dest_height) of the resulting image onto the
66  * destination drawable.
67  **/
68 void
69 gdk_pixbuf_composite (const GdkPixbuf *src,
70                       GdkPixbuf       *dest,
71                       int              dest_x,
72                       int              dest_y,
73                       int              dest_width,
74                       int              dest_height,
75                       double           offset_x,
76                       double           offset_y,
77                       double           scale_x,
78                       double           scale_y,
79                       ArtFilterLevel   filter_level,
80                       int              overall_alpha)
81 {
82   offset_x = floor (offset_x + 0.5);
83   offset_y = floor (offset_y + 0.5);
84   pixops_composite (dest->art_pixbuf->pixels + dest_y * dest->art_pixbuf->rowstride + dest_x * dest->art_pixbuf->n_channels,
85                     -offset_x, -offset_y, dest_width - offset_x, dest_height - offset_y,
86                     dest->art_pixbuf->rowstride, dest->art_pixbuf->n_channels, dest->art_pixbuf->has_alpha,
87                     src->art_pixbuf->pixels, src->art_pixbuf->width, src->art_pixbuf->height,
88                     src->art_pixbuf->rowstride, src->art_pixbuf->n_channels, src->art_pixbuf->has_alpha,
89                     scale_x, scale_y, filter_level, overall_alpha);
90 }
91
92 /**
93  * gdk_pixbuf_composite_color:
94  * @src: a #GdkPixbuf
95  * @dest: the #GdkPixbuf into which to render the results
96  * @dest_x: the left coordinate for region to render
97  * @dest_y: the top coordinate for region to render
98  * @dest_width: the width of the region to render
99  * @dest_height: the height of the region to render
100  * @offset_x: the offset in the X direction (currently rounded to an integer)
101  * @offset_y: the offset in the Y direction (currently rounded to an integer)
102  * @scale_x: the scale factor in the X direction
103  * @scale_y: the scale factor in the Y direction
104  * @filter_level: the filter quality for the transformation.
105  * @overall_alpha: overall alpha for source image (0..255)
106  * @check_x: the X offset for the checkboard (origin of checkboard is at -@check_x, -@check_y)
107  * @check_y: the Y offset for the checkboard 
108  * @check_size: the size of checks in the checkboard (must be a power of two)
109  * @color1: the color of check at upper left
110  * @color2: the color of the other check
111  * 
112  * Transforms the image by source image by scaling by @scale_x and @scale_y then
113  * translating by @offset_x and @offset_y, then composites the rectangle
114  * (@dest,@dest_y,@dest_width,@dest_height) of the resulting image with
115  * a checkboard of the colors @color1 and @color2 and renders it onto the
116  * destination drawable.
117  **/
118 void
119 gdk_pixbuf_composite_color (const GdkPixbuf *src,
120                             GdkPixbuf       *dest,
121                             int              dest_x,
122                             int              dest_y,
123                             int              dest_width,
124                             int              dest_height,
125                             double           offset_x,
126                             double           offset_y,
127                             double           scale_x,
128                             double           scale_y,
129                             ArtFilterLevel   filter_level,
130                             int              overall_alpha,
131                             int              check_x,
132                             int              check_y,
133                             int              check_size,
134                             art_u32          color1,
135                             art_u32          color2)
136 {
137   offset_x = floor (offset_x + 0.5);
138   offset_y = floor (offset_y + 0.5);
139   
140   pixops_composite_color (dest->art_pixbuf->pixels + dest_y * dest->art_pixbuf->rowstride + dest_x * dest->art_pixbuf->n_channels,
141                           -offset_x, -offset_y, dest_width - offset_x, dest_height - offset_y,
142                           dest->art_pixbuf->rowstride, dest->art_pixbuf->n_channels, dest->art_pixbuf->has_alpha,
143                           src->art_pixbuf->pixels, src->art_pixbuf->width, src->art_pixbuf->height,
144                           src->art_pixbuf->rowstride, src->art_pixbuf->n_channels, src->art_pixbuf->has_alpha,
145                           scale_x, scale_y, filter_level, overall_alpha, check_x, check_y, check_size, color1, color2);
146 }
147
148 /**
149  * gdk_pixbuf_scale_simple:
150  * @src: a #GdkPixbuf
151  * @dest_width: the width of destination image
152  * @dest_height: the height of destination image
153  * @filter_level: the filter quality for the transformation.
154  * 
155  * Scale the #GdkPixbuf @src to @dest_width x @dest_height and render the result into
156  * a new #GdkPixbuf.
157  * 
158  * Return value: the new #GdkPixbuf
159  **/
160 GdkPixbuf *
161 gdk_pixbuf_scale_simple (const GdkPixbuf *src,
162                          int              dest_width,
163                          int              dest_height,
164                          ArtFilterLevel   filter_level)
165 {
166   GdkPixbuf *dest = gdk_pixbuf_new (ART_PIX_RGB, src->art_pixbuf->has_alpha, 8, dest_width, dest_height);
167
168   gdk_pixbuf_scale (src, dest,  0, 0, dest_width, dest_height, 0, 0,
169                     (double)dest_width / src->art_pixbuf->width,
170                     (double)dest_height / src->art_pixbuf->height,
171                     filter_level);
172
173   return dest;
174 }
175
176 /**
177  * gdk_pixbuf_composite_color_simple:
178  * @src: a #GdkPixbuf
179  * @dest_width: the width of destination image
180  * @dest_height: the height of destination image
181  * @filter_level: the filter quality for the transformation.
182  * @overall_alpha: overall alpha for source image (0..255)
183  * @check_size: the size of checks in the checkboard (must be a power of two)
184  * @color1: the color of check at upper left
185  * @color2: the color of the other check
186  * 
187  * Scale the #GdkPixbuf @src to @dest_width x @dest_height composite the result with
188  * a checkboard of colors @color1 and @color2 and render the result into
189  * a new #GdkPixbuf.
190  * 
191  * Return value: the new #GdkPixbuf
192  **/
193 GdkPixbuf *
194 gdk_pixbuf_composite_color_simple (const GdkPixbuf *src,
195                                    int              dest_width,
196                                    int              dest_height,
197                                    ArtFilterLevel   filter_level,
198                                    int              overall_alpha,
199                                    int              check_size,
200                                    art_u32          color1,
201                                    art_u32          color2)
202 {
203   GdkPixbuf *dest = gdk_pixbuf_new (ART_PIX_RGB, src->art_pixbuf->has_alpha, 8, dest_width, dest_height);
204
205   gdk_pixbuf_composite_color (src, dest, 0, 0, dest_width, dest_height, 0, 0,
206                               (double)dest_width / src->art_pixbuf->width,
207                               (double)dest_height / src->art_pixbuf->height,
208                               filter_level, overall_alpha, 0, 0, check_size, color1, color2);
209
210   return dest;
211 }
212
213
214