summaryrefslogtreecommitdiff
path: root/docs/reference/gdk-pixbuf/tmpl/scaling.sgml
blob: 7367f86ac23bccd8892235cb80f95b7985a9cf60 (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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<!-- ##### SECTION Title ##### -->
Scaling

<!-- ##### SECTION Short_Description ##### -->
Scaling pixbufs and scaling and compositing pixbufs

<!-- ##### SECTION Long_Description ##### -->
  <para>
    The &gdk-pixbuf; contains functions to scale pixbufs, to scale
    pixbufs and composite against an existing image, and to scale
    pixbufs and composite against a solid color or checkerboard.
    Compositing a checkerboard is a common way to show an image with
    an alpha channel in image-viewing and editing software.
  </para>

  <para>
    Since the full-featured functions (gdk_pixbuf_scale(),
    gdk_pixbuf_composite(), and gdk_pixbuf_composite_color()) are
    rather complex to use and have many arguments, two simple
    convenience functions are provided, gdk_pixbuf_scale_simple() and
    gdk_pixbuf_composite_color_simple() which create a new pixbuf of a
    given size, scale an original image to fit, and then return the
    new pixbuf.
  </para>

  <para>
    The following example demonstrates handling an expose event by
    rendering the appropriate area of a source image (which is scaled
    to fit the widget) onto the widget's window.  The source image is
    rendered against a checkerboard, which provides a visual
    representation of the alpha channel if the image has one. If the
    image doesn't have an alpha channel, calling
    gdk_pixbuf_composite_color() function has exactly the same effect
    as calling gdk_pixbuf_scale().
  </para>

  <example>
  <title>Handling an expose event.</title>
  <programlisting>
gboolean
expose_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data)
{
  GdkPixbuf *dest;

  gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
  
  dest = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, event->area.width, event->area.height);

  gdk_pixbuf_composite_color (pixbuf, dest,
                              0, 0, event->area.width, event->area.height,
                              -event->area.x, -event->area.y,
                              (double) widget->allocation.width / gdk_pixbuf_get_width (pixbuf),
                              (double) widget->allocation.height / gdk_pixbuf_get_height (pixbuf),
                              GDK_INTERP_BILINEAR, 255,
                              event->area.x, event->area.y, 16, 0xaaaaaa, 0x555555);

  gdk_pixbuf_render_to_drawable (dest, widget->window, widget->style->fg_gc[GTK_STATE_NORMAL],
                                 0, 0, event->area.x, event->area.y,
                                 event->area.width, event->area.height,
                                 GDK_RGB_DITHER_NORMAL, event->area.x, event->area.y);
  
  gdk_pixbuf_unref (dest);
  
  return TRUE;
}
  </programlisting>
  </example>

<!-- ##### SECTION See_Also ##### -->
  <para>
    <link linkend="gdk-GdkRGB">GdkRGB</link>.
  </para>

<!-- ##### SECTION Stability_Level ##### -->


<!-- ##### ENUM GdkInterpType ##### -->
  <para>
    This enumeration describes the different interpolation modes that
    can be used with the scaling functions. @GDK_INTERP_NEAREST is 
    the fastest scaling method, but has horrible quality when 
    scaling down. @GDK_INTERP_BILINEAR is the best choice if you 
    aren't sure what to choose, it has a good speed/quality balance.

    <note>
      <para>
	Cubic filtering is missing from the list; hyperbolic
	interpolation is just as fast and results in higher quality.
      </para>
    </note>
  </para>

@GDK_INTERP_NEAREST: Nearest neighbor sampling; this is the fastest
and lowest quality mode. Quality is normally unacceptable when scaling 
down, but may be OK when scaling up.
@GDK_INTERP_TILES: This is an accurate simulation of the PostScript
image operator without any interpolation enabled.  Each pixel is
rendered as a tiny parallelogram of solid color, the edges of which
are implemented with antialiasing.  It resembles nearest neighbor for
enlargement, and bilinear for reduction.
@GDK_INTERP_BILINEAR: Best quality/speed balance; use this mode by
default. Bilinear interpolation.  For enlargement, it is
equivalent to point-sampling the ideal bilinear-interpolated image.
For reduction, it is equivalent to laying down small tiles and
integrating over the coverage area.
@GDK_INTERP_HYPER: This is the slowest and highest quality
reconstruction function. It is derived from the hyperbolic filters in
Wolberg's "Digital Image Warping", and is formally defined as the
hyperbolic-filter sampling the ideal hyperbolic-filter interpolated
image (the filter is designed to be idempotent for 1:1 pixel mapping).

<!-- ##### FUNCTION gdk_pixbuf_scale_simple ##### -->
<para>

</para>

@src: 
@dest_width: 
@dest_height: 
@interp_type: 
@Returns: 


<!-- ##### FUNCTION gdk_pixbuf_scale ##### -->
<para>

</para>

@src: 
@dest: 
@dest_x: 
@dest_y: 
@dest_width: 
@dest_height: 
@offset_x: 
@offset_y: 
@scale_x: 
@scale_y: 
@interp_type: 


<!-- ##### FUNCTION gdk_pixbuf_composite_color_simple ##### -->
<para>

</para>

@src: 
@dest_width: 
@dest_height: 
@interp_type: 
@overall_alpha: 
@check_size: 
@color1: 
@color2: 
@Returns: <!--
Local variables:
mode: sgml
sgml-parent-document: ("../gdk-pixbuf.sgml" "book" "refsect2" "")
End:
-->


<!-- ##### FUNCTION gdk_pixbuf_composite ##### -->
<para>

</para>

@src: 
@dest: 
@dest_x: 
@dest_y: 
@dest_width: 
@dest_height: 
@offset_x: 
@offset_y: 
@scale_x: 
@scale_y: 
@interp_type: 
@overall_alpha: 


<!-- ##### FUNCTION gdk_pixbuf_composite_color ##### -->
<para>

</para>

@src: 
@dest: 
@dest_x: 
@dest_y: 
@dest_width: 
@dest_height: 
@offset_x: 
@offset_y: 
@scale_x: 
@scale_y: 
@interp_type: 
@overall_alpha: 
@check_x: 
@check_y: 
@check_size: 
@color1: 
@color2: 


<!-- ##### ENUM GdkPixbufRotation ##### -->
<para>
The possible rotations which can be passed to gdk_pixbuf_rotate_simple().
To make them easier to use, their numerical values are the actual degrees.
</para>

@GDK_PIXBUF_ROTATE_NONE: No rotation.
@GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE: Rotate by 90 degrees.
@GDK_PIXBUF_ROTATE_UPSIDEDOWN: Rotate by 180 degrees.
@GDK_PIXBUF_ROTATE_CLOCKWISE: Rotate by 270 degrees.

<!-- ##### FUNCTION gdk_pixbuf_rotate_simple ##### -->
<para>

</para>

@src: 
@angle: 
@Returns: 


<!-- ##### FUNCTION gdk_pixbuf_flip ##### -->
<para>

</para>

@src: 
@horizontal: 
@Returns: