summaryrefslogtreecommitdiff
path: root/gdk-pixbuf/gdk-pixbuf-scale.c
blob: a3e7859ed7fe2808fe62c7eca84e1b2ae00974df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#include "gdk-pixbuf.h"
#include "pixops/pixops.h"
#include "math.h"

/**
 * gdk_pixbuf_scale:
 * @src: a #GdkPixbuf
 * @dest: the #GdkPixbuf into which to render the results
 * @dest_x: the left coordinate for region to render
 * @dest_y: the top coordinate for region to render
 * @dest_width: the width of the region to render
 * @dest_height: the height of the region to render
 * @offset_x: the offset in the X direction (currently rounded to an integer)
 * @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.
 * 
 * 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
 * (@dest,@dest_y,@dest_width,@dest_height) of the resulting image onto the
 * destination drawable replacing the previous contents.
 **/
void
gdk_pixbuf_scale (GdkPixbuf      *src,
		  GdkPixbuf      *dest,
		  int             dest_x,
		  int             dest_y,
		  int             dest_width,
		  int             dest_height,
		  double          offset_x,
		  double          offset_y,
		  double          scale_x,
		  double          scale_y,
		  ArtFilterLevel  filter_level)
{
  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,
		-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);
}

/**
 * gdk_pixbuf_composite:
 * @src: a #GdkPixbuf
 * @dest: the #GdkPixbuf into which to render the results
 * @dest_x: the left coordinate for region to render
 * @dest_y: the top coordinate for region to render
 * @dest_width: the width of the region to render
 * @dest_height: the height of the region to render
 * @offset_x: the offset in the X direction (currently rounded to an integer)
 * @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.
 * @overall_alpha: overall alpha for source image (0..255)
 * 
 * Transforms the image by source image by scaling by @scale_x and @scale_y then
 * translating by @offset_x and @offset_y, then composites the rectangle
 * (@dest,@dest_y,@dest_width,@dest_height) of the resulting image onto the
 * destination drawable.
 **/
void
gdk_pixbuf_composite (GdkPixbuf      *src,
		      GdkPixbuf      *dest,
		      int             dest_x,
		      int             dest_y,
		      int             dest_width,
		      int             dest_height,
		      double          offset_x,
		      double          offset_y,
		      double          scale_x,
		      double          scale_y,
		      ArtFilterLevel  filter_level,
		      int             overall_alpha)
{
  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,
		    -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);
}

/**
 * gdk_pixbuf_composite_color:
 * @src: a #GdkPixbuf
 * @dest: the #GdkPixbuf into which to render the results
 * @dest_x: the left coordinate for region to render
 * @dest_y: the top coordinate for region to render
 * @dest_width: the width of the region to render
 * @dest_height: the height of the region to render
 * @offset_x: the offset in the X direction (currently rounded to an integer)
 * @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.
 * @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 
 * @check_size: the size of checks in the checkboard (must be a power of two)
 * @color1: the color of check at upper left
 * @color2: the color of the other check
 * 
 * Transforms the image by source image by scaling by @scale_x and @scale_y then
 * translating by @offset_x and @offset_y, then composites the rectangle
 * (@dest,@dest_y,@dest_width,@dest_height) of the resulting image with
 * a checkboard of the colors @color1 and @color2 and renders it onto the
 * destination drawable.
 **/
void
gdk_pixbuf_composite_color (GdkPixbuf      *src,
			    GdkPixbuf      *dest,
			    int             dest_x,
			    int             dest_y,
			    int             dest_width,
			    int             dest_height,
			    double          offset_x,
			    double          offset_y,
			    double          scale_x,
			    double          scale_y,
			    ArtFilterLevel  filter_level,
			    int             overall_alpha,
			    int             check_x,
			    int             check_y,
			    int             check_size,
			    art_u32         color1,
			    art_u32         color2)
{
  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,
			  -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);
}

/**
 * gdk_pixbuf_scale_simple:
 * @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.
 * 
 * Scale the #GdkPixbuf @src to @dest_width x @dest_height and render the result into
 * a new #GdkPixbuf.
 * 
 * Return value: the new #GdkPixbuf
 **/
GdkPixbuf *
gdk_pixbuf_scale_simple (GdkPixbuf      *src,
			 int             dest_width,
			 int             dest_height,
			 ArtFilterLevel  filter_level)
{
  GdkPixbuf *dest = gdk_pixbuf_new (ART_PIX_RGB, src->art_pixbuf->has_alpha, 8, dest_width, dest_height);

  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);

  return dest;
}

/**
 * gdk_pixbuf_composite_color_simple:
 * @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.
 * @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
 * @color2: the color of the other check
 * 
 * Scale the #GdkPixbuf @src to @dest_width x @dest_height composite the result with
 * a checkboard of colors @color1 and @color2 and render the result into
 * a new #GdkPixbuf.
 * 
 * Return value: the new #GdkPixbuf
 **/
GdkPixbuf *
gdk_pixbuf_composite_color_simple (GdkPixbuf      *src,
				   int             dest_width,
				   int             dest_height,
				   ArtFilterLevel  filter_level,
				   int             overall_alpha,
				   int             check_size,
				   art_u32         color1,
				   art_u32         color2)
{
  GdkPixbuf *dest = gdk_pixbuf_new (ART_PIX_RGB, src->art_pixbuf->has_alpha, 8, dest_width, dest_height);

  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);

  return dest;
}