1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
<html xmlns="http://www.w3.org/1999/xhtml">
6
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
8
<title>pygame.transform — Pygame v1.9.2 documentation</title>
9
<link rel="stylesheet" href="../_static/pygame.css" type="text/css" />
10
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
11
<script type="text/javascript">
12
var DOCUMENTATION_OPTIONS = {
15
COLLAPSE_INDEX: false,
20
<script type="text/javascript" src="../_static/jquery.js"></script>
21
<script type="text/javascript" src="../_static/underscore.js"></script>
22
<script type="text/javascript" src="../_static/doctools.js"></script>
23
<link rel="shortcut icon" href="../_static/pygame.ico"/>
24
<link rel="top" title="Pygame v1.9.2 documentation" href="../index.html" />
25
<link rel="next" title="File Path Function Arguments" href="../filepaths.html" />
26
<link rel="prev" title="pygame.time" href="time.html" />
30
<div class="document">
36
<a href="http://www.pygame.org/">
37
<img src="../_static/pygame_tiny.png"/>
39
<h5>pygame documentation</h5>
41
<td class="pagelinks">
44
<a href="http://www.pygame.org/">Pygame Home</a> ||
45
<a href="../index.html">Help Contents</a> ||
46
<a href="../genindex.html">Reference Index</a> ||
49
<a href="camera.html">camera</a> ||
50
<a href="cdrom.html">cdrom</a> ||
51
<a href="color.html">Color</a> ||
52
<a href="cursors.html">cursors</a> ||
53
<a href="display.html">display</a> ||
54
<a href="draw.html">draw</a> ||
55
<a href="event.html">event</a> ||
56
<a href="examples.html">examples</a> ||
57
<a href="font.html">font</a> ||
58
<a href="freetype.html">freetype</a> ||
59
<a href="gfxdraw.html">gfxdraw</a> ||
60
<a href="image.html">image</a> ||
61
<a href="joystick.html">joystick</a> ||
62
<a href="key.html">key</a> ||
63
<a href="locals.html">locals</a> ||
64
<a href="mask.html">mask</a> ||
65
<a href="math.html">math</a> ||
66
<a href="midi.html">midi</a> ||
67
<a href="mixer.html">mixer</a> ||
68
<a href="mouse.html">mouse</a> ||
69
<a href="movie.html">movie</a> ||
70
<a href="music.html">music</a> ||
71
<a href="overlay.html">Overlay</a> ||
72
<a href="pixelarray.html">PixelArray</a> ||
73
<a href="pixelcopy.html">pixelcopy</a> ||
74
<a href="pygame.html">pygame</a> ||
75
<a href="rect.html">Rect</a> ||
76
<a href="scrap.html">scrap</a> ||
77
<a href="sndarray.html">sndarray</a> ||
78
<a href="sprite.html">sprite</a> ||
79
<a href="surface.html">Surface</a> ||
80
<a href="surfarray.html">surfarray</a> ||
81
<a href="tests.html">tests</a> ||
82
<a href="time.html">time</a> ||
83
<a href="transform.html">transform</a> ||
84
<a href="pygame.html#module-pygame.version">version</a>
91
<div class="documentwrapper">
94
<div class="sectionwrapper">
95
<div class="section" id="module-pygame.transform">
96
<span id="pygame-transform"></span><dl class="definition module">
97
<dt class="title module">
98
<tt class="docutils literal"><span class="pre">pygame.transform</span></tt></dt>
99
<dd><div class="line-block">
100
<div class="line"><span class="summaryline">pygame module to transform surfaces</span></div>
102
<table border="1" class="toc docutils">
109
<tr><td><a class="toc reference external" href="transform.html#pygame.transform.flip">pygame.transform.flip</a></td>
111
<td>flip vertically and horizontally</td>
113
<tr><td><a class="toc reference external" href="transform.html#pygame.transform.scale">pygame.transform.scale</a></td>
115
<td>resize to new resolution</td>
117
<tr><td><a class="toc reference external" href="transform.html#pygame.transform.rotate">pygame.transform.rotate</a></td>
119
<td>rotate an image</td>
121
<tr><td><a class="toc reference external" href="transform.html#pygame.transform.rotozoom">pygame.transform.rotozoom</a></td>
123
<td>filtered scale and rotation</td>
125
<tr><td><a class="toc reference external" href="transform.html#pygame.transform.scale2x">pygame.transform.scale2x</a></td>
127
<td>specialized image doubler</td>
129
<tr><td><a class="toc reference external" href="transform.html#pygame.transform.smoothscale">pygame.transform.smoothscale</a></td>
131
<td>scale a surface to an arbitrary size smoothly</td>
133
<tr><td><a class="toc reference external" href="transform.html#pygame.transform.get_smoothscale_backend">pygame.transform.get_smoothscale_backend</a></td>
135
<td>return smoothscale filter version in use: ‘GENERIC’, ‘MMX’, or ‘SSE’</td>
137
<tr><td><a class="toc reference external" href="transform.html#pygame.transform.set_smoothscale_backend">pygame.transform.set_smoothscale_backend</a></td>
139
<td>set smoothscale filter version to one of: ‘GENERIC’, ‘MMX’, or ‘SSE’</td>
141
<tr><td><a class="toc reference external" href="transform.html#pygame.transform.chop">pygame.transform.chop</a></td>
143
<td>gets a copy of an image with an interior area removed</td>
145
<tr><td><a class="toc reference external" href="transform.html#pygame.transform.laplacian">pygame.transform.laplacian</a></td>
147
<td>find edges in a surface</td>
149
<tr><td><a class="toc reference external" href="transform.html#pygame.transform.average_surfaces">pygame.transform.average_surfaces</a></td>
151
<td>find the average surface from many surfaces.</td>
153
<tr><td><a class="toc reference external" href="transform.html#pygame.transform.average_color">pygame.transform.average_color</a></td>
155
<td>finds the average color of a surface</td>
157
<tr><td><a class="toc reference external" href="transform.html#pygame.transform.threshold">pygame.transform.threshold</a></td>
159
<td>finds which, and how many pixels in a surface are within a threshold of a color.</td>
163
<p>A Surface transform is an operation that moves or resizes the pixels. All these
164
functions take a Surface to operate on and return a new Surface with the
166
<p>Some of the transforms are considered destructive. These means every time they
167
are performed they lose pixel data. Common examples of this are resizing and
168
rotating. For this reason, it is better to retransform the original surface
169
than to keep transforming an image multiple times. (For example, suppose you
170
are animating a bouncing spring which expands and contracts. If you applied the
171
size changes incrementally to the previous images, you would lose detail.
172
Instead, always begin with the original image and scale to the desired size.)</p>
173
<dl class="definition function">
174
<dt class="title" id="pygame.transform.flip">
175
<tt class="descclassname">pygame.transform.</tt><tt class="descname">flip</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.transform.flip" title="Permalink to this definition">¶</a></dt>
176
<dd><div class="line-block">
177
<div class="line"><span class="summaryline">flip vertically and horizontally</span></div>
178
<div class="line"><span class="signature">flip(Surface, xbool, ybool) -> Surface</span></div>
180
<p>This can flip a Surface either vertically, horizontally, or both. Flipping a
181
Surface is nondestructive and returns a new Surface with the same
185
<dl class="definition function">
186
<dt class="title" id="pygame.transform.scale">
187
<tt class="descclassname">pygame.transform.</tt><tt class="descname">scale</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.transform.scale" title="Permalink to this definition">¶</a></dt>
188
<dd><div class="line-block">
189
<div class="line"><span class="summaryline">resize to new resolution</span></div>
190
<div class="line"><span class="signature">scale(Surface, (width, height), DestSurface = None) -> Surface</span></div>
192
<p>Resizes the Surface to a new resolution. This is a fast scale operation that
193
does not sample the results.</p>
194
<p>An optional destination surface can be used, rather than have it create a
195
new one. This is quicker if you want to repeatedly scale something. However
196
the destination must be the same size as the (width, height) passed in. Also
197
the destination surface must be the same format.</p>
200
<dl class="definition function">
201
<dt class="title" id="pygame.transform.rotate">
202
<tt class="descclassname">pygame.transform.</tt><tt class="descname">rotate</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.transform.rotate" title="Permalink to this definition">¶</a></dt>
203
<dd><div class="line-block">
204
<div class="line"><span class="summaryline">rotate an image</span></div>
205
<div class="line"><span class="signature">rotate(Surface, angle) -> Surface</span></div>
207
<p>Unfiltered counterclockwise rotation. The angle argument represents degrees
208
and can be any floating point value. Negative angle amounts will rotate
210
<p>Unless rotating by 90 degree increments, the image will be padded larger to
211
hold the new size. If the image has pixel alphas, the padded area will be
212
transparent. Otherwise pygame will pick a color that matches the Surface
213
colorkey or the topleft pixel value.</p>
216
<dl class="definition function">
217
<dt class="title" id="pygame.transform.rotozoom">
218
<tt class="descclassname">pygame.transform.</tt><tt class="descname">rotozoom</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.transform.rotozoom" title="Permalink to this definition">¶</a></dt>
219
<dd><div class="line-block">
220
<div class="line"><span class="summaryline">filtered scale and rotation</span></div>
221
<div class="line"><span class="signature">rotozoom(Surface, angle, scale) -> Surface</span></div>
223
<p>This is a combined scale and rotation transform. The resulting Surface will
224
be a filtered 32-bit Surface. The scale argument is a floating point value
225
that will be multiplied by the current resolution. The angle argument is a
226
floating point value that represents the counterclockwise degrees to rotate.
227
A negative rotation angle will rotate clockwise.</p>
230
<dl class="definition function">
231
<dt class="title" id="pygame.transform.scale2x">
232
<tt class="descclassname">pygame.transform.</tt><tt class="descname">scale2x</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.transform.scale2x" title="Permalink to this definition">¶</a></dt>
233
<dd><div class="line-block">
234
<div class="line"><span class="summaryline">specialized image doubler</span></div>
235
<div class="line"><span class="signature">scale2x(Surface, DestSurface = None) -> Surface</span></div>
237
<p>This will return a new image that is double the size of the original. It
238
uses the AdvanceMAME Scale2X algorithm which does a ‘jaggie-less’ scale of
240
<p>This really only has an effect on simple images with solid colors. On
241
photographic and antialiased images it will look like a regular unfiltered
243
<p>An optional destination surface can be used, rather than have it create a
244
new one. This is quicker if you want to repeatedly scale something. However
245
the destination must be twice the size of the source surface passed in. Also
246
the destination surface must be the same format.</p>
249
<dl class="definition function">
250
<dt class="title" id="pygame.transform.smoothscale">
251
<tt class="descclassname">pygame.transform.</tt><tt class="descname">smoothscale</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.transform.smoothscale" title="Permalink to this definition">¶</a></dt>
252
<dd><div class="line-block">
253
<div class="line"><span class="summaryline">scale a surface to an arbitrary size smoothly</span></div>
254
<div class="line"><span class="signature">smoothscale(Surface, (width, height), DestSurface = None) -> Surface</span></div>
256
<p>Uses one of two different algorithms for scaling each dimension of the input
257
surface as required. For shrinkage, the output pixels are area averages of
258
the colors they cover. For expansion, a bilinear filter is used. For the
259
amd64 and i686 architectures, optimized <tt class="docutils literal"><span class="pre">MMX</span></tt> routines are included and
260
will run much faster than other machine types. The size is a 2 number
261
sequence for (width, height). This function only works for 24-bit or 32-bit
262
surfaces. An exception will be thrown if the input surface bit depth is less
264
<p>New in pygame 1.8</p>
267
<dl class="definition function">
268
<dt class="title" id="pygame.transform.get_smoothscale_backend">
269
<tt class="descclassname">pygame.transform.</tt><tt class="descname">get_smoothscale_backend</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.transform.get_smoothscale_backend" title="Permalink to this definition">¶</a></dt>
270
<dd><div class="line-block">
271
<div class="line"><span class="summaryline">return smoothscale filter version in use: ‘GENERIC’, ‘MMX’, or ‘SSE’</span></div>
272
<div class="line"><span class="signature">get_smoothscale_backend() -> String</span></div>
274
<p>Shows whether or not smoothscale is using <tt class="docutils literal"><span class="pre">MMX</span></tt> or <tt class="docutils literal"><span class="pre">SSE</span></tt> acceleration.
275
If no acceleration is available then “GENERIC” is returned. For a x86
276
processor the level of acceleration to use is determined at runtime.</p>
277
<p>This function is provided for Pygame testing and debugging.</p>
280
<dl class="definition function">
281
<dt class="title" id="pygame.transform.set_smoothscale_backend">
282
<tt class="descclassname">pygame.transform.</tt><tt class="descname">set_smoothscale_backend</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.transform.set_smoothscale_backend" title="Permalink to this definition">¶</a></dt>
283
<dd><div class="line-block">
284
<div class="line"><span class="summaryline">set smoothscale filter version to one of: ‘GENERIC’, ‘MMX’, or ‘SSE’</span></div>
285
<div class="line"><span class="signature">set_smoothscale_backend(type) -> None</span></div>
287
<p>Sets smoothscale acceleration. Takes a string argument. A value of ‘GENERIC’
288
turns off acceleration. ‘MMX’ uses <tt class="docutils literal"><span class="pre">MMX</span></tt> instructions only. ‘SSE’ allows
289
<tt class="docutils literal"><span class="pre">SSE</span></tt> extensions as well. A value error is raised if type is not
290
recognized or not supported by the current processor.</p>
291
<p>This function is provided for Pygame testing and debugging. If smoothscale
292
causes an invalid instruction error then it is a Pygame/SDL bug that should
293
be reported. Use this function as a temporary fix only.</p>
296
<dl class="definition function">
297
<dt class="title" id="pygame.transform.chop">
298
<tt class="descclassname">pygame.transform.</tt><tt class="descname">chop</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.transform.chop" title="Permalink to this definition">¶</a></dt>
299
<dd><div class="line-block">
300
<div class="line"><span class="summaryline">gets a copy of an image with an interior area removed</span></div>
301
<div class="line"><span class="signature">chop(Surface, rect) -> Surface</span></div>
303
<p>Extracts a portion of an image. All vertical and horizontal pixels
304
surrounding the given rectangle area are removed. The corner areas (diagonal
305
to the rect) are then brought together. (The original image is not altered
306
by this operation.)</p>
307
<p><tt class="docutils literal"><span class="pre">NOTE</span></tt>: If you want a “crop” that returns the part of an image within a
308
rect, you can blit with a rect to a new surface or copy a subsurface.</p>
311
<dl class="definition function">
312
<dt class="title" id="pygame.transform.laplacian">
313
<tt class="descclassname">pygame.transform.</tt><tt class="descname">laplacian</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.transform.laplacian" title="Permalink to this definition">¶</a></dt>
314
<dd><div class="line-block">
315
<div class="line"><span class="summaryline">find edges in a surface</span></div>
316
<div class="line"><span class="signature">laplacian(Surface, DestSurface = None) -> Surface</span></div>
318
<p>Finds the edges in a surface using the laplacian algorithm.</p>
319
<p>New in pygame 1.8</p>
322
<dl class="definition function">
323
<dt class="title" id="pygame.transform.average_surfaces">
324
<tt class="descclassname">pygame.transform.</tt><tt class="descname">average_surfaces</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.transform.average_surfaces" title="Permalink to this definition">¶</a></dt>
325
<dd><div class="line-block">
326
<div class="line"><span class="summaryline">find the average surface from many surfaces.</span></div>
327
<div class="line"><span class="signature">average_surfaces(Surfaces, DestSurface = None, palette_colors = 1) -> Surface</span></div>
329
<p>Takes a sequence of surfaces and returns a surface with average colors from
330
each of the surfaces.</p>
331
<p>palette_colors - if true we average the colors in palette, otherwise we
332
average the pixel values. This is useful if the surface is actually
333
greyscale colors, and not palette colors.</p>
334
<p>Note, this function currently does not handle palette using surfaces
336
<p>New in pygame 1.8 palette_colors argument new in pygame 1.9</p>
339
<dl class="definition function">
340
<dt class="title" id="pygame.transform.average_color">
341
<tt class="descclassname">pygame.transform.</tt><tt class="descname">average_color</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.transform.average_color" title="Permalink to this definition">¶</a></dt>
342
<dd><div class="line-block">
343
<div class="line"><span class="summaryline">finds the average color of a surface</span></div>
344
<div class="line"><span class="signature">average_color(Surface, Rect = None) -> Color</span></div>
346
<p>Finds the average color of a Surface or a region of a surface specified by a
347
Rect, and returns it as a Color.</p>
350
<dl class="definition function">
351
<dt class="title" id="pygame.transform.threshold">
352
<tt class="descclassname">pygame.transform.</tt><tt class="descname">threshold</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.transform.threshold" title="Permalink to this definition">¶</a></dt>
353
<dd><div class="line-block">
354
<div class="line"><span class="summaryline">finds which, and how many pixels in a surface are within a threshold of a color.</span></div>
355
<div class="line"><span class="signature">threshold(DestSurface, Surface, color, threshold = (0,0,0,0), diff_color = (0,0,0,0), change_return = 1, Surface = None, inverse = False) -> num_threshold_pixels</span></div>
357
<p>Finds which, and how many pixels in a surface are within a threshold of a
359
<p>It can set the destination surface where all of the pixels not within the
360
threshold are changed to diff_color. If inverse is optionally set to True,
361
the pixels that are within the threshold are instead changed to diff_color.</p>
362
<p>If the optional second surface is given, it is used to threshold against
363
rather than the specified color. That is, it will find each pixel in the
364
first Surface that is within the threshold of the pixel at the same
365
coordinates of the second Surface.</p>
366
<p>If change_return is set to 0, it can be used to just count the number of
367
pixels within the threshold if you set</p>
368
<p>If change_return is set to 1, the pixels set in DestSurface will be those
370
<p>If change_return is set to 2, the pixels set in DestSurface will be those
371
from the first Surface.</p>
372
<p>You can use a threshold of (r,g,b,a) where the r,g,b can have different
373
thresholds. So you could use an r threshold of 40 and a blue threshold of 2
375
<p>New in pygame 1.8</p>
385
<div class="clearer"></div>
387
<div class="related">
390
<li class="right" style="margin-right: 10px">
391
<a href="../genindex.html" title="General Index"
392
accesskey="I">index</a></li>
394
<a href="../filepaths.html" title="File Path Function Arguments"
395
accesskey="N">next</a> |</li>
397
<a href="time.html" title="pygame.time"
398
accesskey="P">previous</a> |</li>
399
<li><a href="../index.html">Pygame v1.9.2 documentation</a> »</li>
400
<script type="text/javascript" src="jquery.plugin.docscomments.js"></script>
405
© Copyright 2011, Pygame Developers.
b'\\ No newline at end of file'