Source

pygame / docs / ref / transform.html

Full commit
  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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>pygame.transform &mdash; Pygame v1.9.2 documentation</title>
    <link rel="stylesheet" href="../_static/pygame.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '1.9.2',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <link rel="shortcut icon" href="../_static/pygame.ico"/>
    <link rel="top" title="Pygame v1.9.2 documentation" href="../index.html" />
    <link rel="next" title="File Path Function Arguments" href="../filepaths.html" />
    <link rel="prev" title="pygame.time" href="time.html" /> 
  </head>
  <body>  

    <div class="document">

  <div class="header">
    <table>
      <tr>
	<td class="logo">
	  <a href="http://www.pygame.org/">
	    <img src="../_static/pygame_tiny.png"/>
	  </a>
	  <h5>pygame documentation</h5>
	</td>
	<td class="pagelinks">
	  <p class="top">
	    ||
	    <a href="http://www.pygame.org/">Pygame Home</a> ||
	    <a href="../index.html">Help Contents</a> ||
	    <a href="../genindex.html">Reference Index</a> ||
	  </p>
	  <p class="bottom">
	    <a href="camera.html">camera</a> || 
	    <a href="cdrom.html">cdrom</a> || 
	    <a href="color.html">Color</a> || 
	    <a href="cursors.html">cursors</a> || 
	    <a href="display.html">display</a> || 
	    <a href="draw.html">draw</a> || 
	    <a href="event.html">event</a> || 
	    <a href="examples.html">examples</a> || 
	    <a href="font.html">font</a> || 
	    <a href="freetype.html">freetype</a> || 
	    <a href="gfxdraw.html">gfxdraw</a> || 
	    <a href="image.html">image</a> || 
	    <a href="joystick.html">joystick</a> || 
	    <a href="key.html">key</a> || 
	    <a href="locals.html">locals</a> || 
	    <a href="mask.html">mask</a> || 
	    <a href="math.html">math</a> || 
	    <a href="midi.html">midi</a> || 
	    <a href="mixer.html">mixer</a> || 
	    <a href="mouse.html">mouse</a> || 
	    <a href="movie.html">movie</a> || 
	    <a href="music.html">music</a> || 
	    <a href="overlay.html">Overlay</a> || 
	    <a href="pixelarray.html">PixelArray</a> || 
	    <a href="pixelcopy.html">pixelcopy</a> || 
	    <a href="pygame.html">pygame</a> || 
	    <a href="rect.html">Rect</a> || 
	    <a href="scrap.html">scrap</a> || 
	    <a href="sndarray.html">sndarray</a> || 
	    <a href="sprite.html">sprite</a> || 
	    <a href="surface.html">Surface</a> || 
	    <a href="surfarray.html">surfarray</a> || 
	    <a href="tests.html">tests</a> || 
	    <a href="time.html">time</a> || 
	    <a href="transform.html">transform</a> || 
	    <a href="pygame.html#module-pygame.version">version</a>
	  </p>
	</td>
      </tr>
    </table>
  </div>

      <div class="documentwrapper">
          <div class="body">
            
  <div class="sectionwrapper">
<div class="section" id="module-pygame.transform">
<span id="pygame-transform"></span><dl class="definition module">
<dt class="title module">
<tt class="docutils literal"><span class="pre">pygame.transform</span></tt></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">pygame module to transform surfaces</span></div>
</div>
<table border="1" class="toc docutils">
<colgroup>
<col width="32%" />
<col width="1%" />
<col width="68%" />
</colgroup>
<tbody valign="top">
<tr><td><a class="toc reference external" href="transform.html#pygame.transform.flip">pygame.transform.flip</a></td>
<td></td>
<td>flip vertically and horizontally</td>
</tr>
<tr><td><a class="toc reference external" href="transform.html#pygame.transform.scale">pygame.transform.scale</a></td>
<td></td>
<td>resize to new resolution</td>
</tr>
<tr><td><a class="toc reference external" href="transform.html#pygame.transform.rotate">pygame.transform.rotate</a></td>
<td></td>
<td>rotate an image</td>
</tr>
<tr><td><a class="toc reference external" href="transform.html#pygame.transform.rotozoom">pygame.transform.rotozoom</a></td>
<td></td>
<td>filtered scale and rotation</td>
</tr>
<tr><td><a class="toc reference external" href="transform.html#pygame.transform.scale2x">pygame.transform.scale2x</a></td>
<td></td>
<td>specialized image doubler</td>
</tr>
<tr><td><a class="toc reference external" href="transform.html#pygame.transform.smoothscale">pygame.transform.smoothscale</a></td>
<td></td>
<td>scale a surface to an arbitrary size smoothly</td>
</tr>
<tr><td><a class="toc reference external" href="transform.html#pygame.transform.get_smoothscale_backend">pygame.transform.get_smoothscale_backend</a></td>
<td></td>
<td>return smoothscale filter version in use: &#8216;GENERIC&#8217;, &#8216;MMX&#8217;, or &#8216;SSE&#8217;</td>
</tr>
<tr><td><a class="toc reference external" href="transform.html#pygame.transform.set_smoothscale_backend">pygame.transform.set_smoothscale_backend</a></td>
<td></td>
<td>set smoothscale filter version to one of: &#8216;GENERIC&#8217;, &#8216;MMX&#8217;, or &#8216;SSE&#8217;</td>
</tr>
<tr><td><a class="toc reference external" href="transform.html#pygame.transform.chop">pygame.transform.chop</a></td>
<td></td>
<td>gets a copy of an image with an interior area removed</td>
</tr>
<tr><td><a class="toc reference external" href="transform.html#pygame.transform.laplacian">pygame.transform.laplacian</a></td>
<td></td>
<td>find edges in a surface</td>
</tr>
<tr><td><a class="toc reference external" href="transform.html#pygame.transform.average_surfaces">pygame.transform.average_surfaces</a></td>
<td></td>
<td>find the average surface from many surfaces.</td>
</tr>
<tr><td><a class="toc reference external" href="transform.html#pygame.transform.average_color">pygame.transform.average_color</a></td>
<td></td>
<td>finds the average color of a surface</td>
</tr>
<tr><td><a class="toc reference external" href="transform.html#pygame.transform.threshold">pygame.transform.threshold</a></td>
<td></td>
<td>finds which, and how many pixels in a surface are within a threshold of a color.</td>
</tr>
</tbody>
</table>
<p>A Surface transform is an operation that moves or resizes the pixels. All these
functions take a Surface to operate on and return a new Surface with the
results.</p>
<p>Some of the transforms are considered destructive. These means every time they
are performed they lose pixel data. Common examples of this are resizing and
rotating. For this reason, it is better to retransform the original surface
than to keep transforming an image multiple times. (For example, suppose you
are animating a bouncing spring which expands and contracts. If you applied the
size changes incrementally to the previous images, you would lose detail.
Instead, always begin with the original image and scale to the desired size.)</p>
<dl class="definition function">
<dt class="title" id="pygame.transform.flip">
<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>
<dd><div class="line-block">
<div class="line"><span class="summaryline">flip vertically and horizontally</span></div>
<div class="line"><span class="signature">flip(Surface, xbool, ybool) -&gt; Surface</span></div>
</div>
<p>This can flip a Surface either vertically, horizontally, or both. Flipping a
Surface is nondestructive and returns a new Surface with the same
dimensions.</p>
</dd></dl>

<dl class="definition function">
<dt class="title" id="pygame.transform.scale">
<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>
<dd><div class="line-block">
<div class="line"><span class="summaryline">resize to new resolution</span></div>
<div class="line"><span class="signature">scale(Surface, (width, height), DestSurface = None) -&gt; Surface</span></div>
</div>
<p>Resizes the Surface to a new resolution. This is a fast scale operation that
does not sample the results.</p>
<p>An optional destination surface can be used, rather than have it create a
new one. This is quicker if you want to repeatedly scale something. However
the destination must be the same size as the (width, height) passed in. Also
the destination surface must be the same format.</p>
</dd></dl>

<dl class="definition function">
<dt class="title" id="pygame.transform.rotate">
<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>
<dd><div class="line-block">
<div class="line"><span class="summaryline">rotate an image</span></div>
<div class="line"><span class="signature">rotate(Surface, angle) -&gt; Surface</span></div>
</div>
<p>Unfiltered counterclockwise rotation. The angle argument represents degrees
and can be any floating point value. Negative angle amounts will rotate
clockwise.</p>
<p>Unless rotating by 90 degree increments, the image will be padded larger to
hold the new size. If the image has pixel alphas, the padded area will be
transparent. Otherwise pygame will pick a color that matches the Surface
colorkey or the topleft pixel value.</p>
</dd></dl>

<dl class="definition function">
<dt class="title" id="pygame.transform.rotozoom">
<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>
<dd><div class="line-block">
<div class="line"><span class="summaryline">filtered scale and rotation</span></div>
<div class="line"><span class="signature">rotozoom(Surface, angle, scale) -&gt; Surface</span></div>
</div>
<p>This is a combined scale and rotation transform. The resulting Surface will
be a filtered 32-bit Surface. The scale argument is a floating point value
that will be multiplied by the current resolution. The angle argument is a
floating point value that represents the counterclockwise degrees to rotate.
A negative rotation angle will rotate clockwise.</p>
</dd></dl>

<dl class="definition function">
<dt class="title" id="pygame.transform.scale2x">
<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>
<dd><div class="line-block">
<div class="line"><span class="summaryline">specialized image doubler</span></div>
<div class="line"><span class="signature">scale2x(Surface, DestSurface = None) -&gt; Surface</span></div>
</div>
<p>This will return a new image that is double the size of the original. It
uses the AdvanceMAME Scale2X algorithm which does a &#8216;jaggie-less&#8217; scale of
bitmap graphics.</p>
<p>This really only has an effect on simple images with solid colors. On
photographic and antialiased images it will look like a regular unfiltered
scale.</p>
<p>An optional destination surface can be used, rather than have it create a
new one. This is quicker if you want to repeatedly scale something. However
the destination must be twice the size of the source surface passed in. Also
the destination surface must be the same format.</p>
</dd></dl>

<dl class="definition function">
<dt class="title" id="pygame.transform.smoothscale">
<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>
<dd><div class="line-block">
<div class="line"><span class="summaryline">scale a surface to an arbitrary size smoothly</span></div>
<div class="line"><span class="signature">smoothscale(Surface, (width, height), DestSurface = None) -&gt; Surface</span></div>
</div>
<p>Uses one of two different algorithms for scaling each dimension of the input
surface as required. For shrinkage, the output pixels are area averages of
the colors they cover. For expansion, a bilinear filter is used. For the
amd64 and i686 architectures, optimized <tt class="docutils literal"><span class="pre">MMX</span></tt> routines are included and
will run much faster than other machine types. The size is a 2 number
sequence for (width, height). This function only works for 24-bit or 32-bit
surfaces. An exception will be thrown if the input surface bit depth is less
than 24.</p>
<p>New in pygame 1.8</p>
</dd></dl>

<dl class="definition function">
<dt class="title" id="pygame.transform.get_smoothscale_backend">
<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>
<dd><div class="line-block">
<div class="line"><span class="summaryline">return smoothscale filter version in use: &#8216;GENERIC&#8217;, &#8216;MMX&#8217;, or &#8216;SSE&#8217;</span></div>
<div class="line"><span class="signature">get_smoothscale_backend() -&gt; String</span></div>
</div>
<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.
If no acceleration is available then &#8220;GENERIC&#8221; is returned. For a x86
processor the level of acceleration to use is determined at runtime.</p>
<p>This function is provided for Pygame testing and debugging.</p>
</dd></dl>

<dl class="definition function">
<dt class="title" id="pygame.transform.set_smoothscale_backend">
<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>
<dd><div class="line-block">
<div class="line"><span class="summaryline">set smoothscale filter version to one of: &#8216;GENERIC&#8217;, &#8216;MMX&#8217;, or &#8216;SSE&#8217;</span></div>
<div class="line"><span class="signature">set_smoothscale_backend(type) -&gt; None</span></div>
</div>
<p>Sets smoothscale acceleration. Takes a string argument. A value of &#8216;GENERIC&#8217;
turns off acceleration. &#8216;MMX&#8217; uses <tt class="docutils literal"><span class="pre">MMX</span></tt> instructions only. &#8216;SSE&#8217; allows
<tt class="docutils literal"><span class="pre">SSE</span></tt> extensions as well. A value error is raised if type is not
recognized or not supported by the current processor.</p>
<p>This function is provided for Pygame testing and debugging. If smoothscale
causes an invalid instruction error then it is a Pygame/SDL bug that should
be reported. Use this function as a temporary fix only.</p>
</dd></dl>

<dl class="definition function">
<dt class="title" id="pygame.transform.chop">
<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>
<dd><div class="line-block">
<div class="line"><span class="summaryline">gets a copy of an image with an interior area removed</span></div>
<div class="line"><span class="signature">chop(Surface, rect) -&gt; Surface</span></div>
</div>
<p>Extracts a portion of an image. All vertical and horizontal pixels
surrounding the given rectangle area are removed. The corner areas (diagonal
to the rect) are then brought together. (The original image is not altered
by this operation.)</p>
<p><tt class="docutils literal"><span class="pre">NOTE</span></tt>: If you want a &#8220;crop&#8221; that returns the part of an image within a
rect, you can blit with a rect to a new surface or copy a subsurface.</p>
</dd></dl>

<dl class="definition function">
<dt class="title" id="pygame.transform.laplacian">
<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>
<dd><div class="line-block">
<div class="line"><span class="summaryline">find edges in a surface</span></div>
<div class="line"><span class="signature">laplacian(Surface, DestSurface = None) -&gt; Surface</span></div>
</div>
<p>Finds the edges in a surface using the laplacian algorithm.</p>
<p>New in pygame 1.8</p>
</dd></dl>

<dl class="definition function">
<dt class="title" id="pygame.transform.average_surfaces">
<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>
<dd><div class="line-block">
<div class="line"><span class="summaryline">find the average surface from many surfaces.</span></div>
<div class="line"><span class="signature">average_surfaces(Surfaces, DestSurface = None, palette_colors = 1) -&gt; Surface</span></div>
</div>
<p>Takes a sequence of surfaces and returns a surface with average colors from
each of the surfaces.</p>
<p>palette_colors - if true we average the colors in palette, otherwise we
average the pixel values. This is useful if the surface is actually
greyscale colors, and not palette colors.</p>
<p>Note, this function currently does not handle palette using surfaces
correctly.</p>
<p>New in pygame 1.8 palette_colors argument new in pygame 1.9</p>
</dd></dl>

<dl class="definition function">
<dt class="title" id="pygame.transform.average_color">
<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>
<dd><div class="line-block">
<div class="line"><span class="summaryline">finds the average color of a surface</span></div>
<div class="line"><span class="signature">average_color(Surface, Rect = None) -&gt; Color</span></div>
</div>
<p>Finds the average color of a Surface or a region of a surface specified by a
Rect, and returns it as a Color.</p>
</dd></dl>

<dl class="definition function">
<dt class="title" id="pygame.transform.threshold">
<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>
<dd><div class="line-block">
<div class="line"><span class="summaryline">finds which, and how many pixels in a surface are within a threshold of a color.</span></div>
<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) -&gt; num_threshold_pixels</span></div>
</div>
<p>Finds which, and how many pixels in a surface are within a threshold of a
color.</p>
<p>It can set the destination surface where all of the pixels not within the
threshold are changed to diff_color. If inverse is optionally set to True,
the pixels that are within the threshold are instead changed to diff_color.</p>
<p>If the optional second surface is given, it is used to threshold against
rather than the specified color. That is, it will find each pixel in the
first Surface that is within the threshold of the pixel at the same
coordinates of the second Surface.</p>
<p>If change_return is set to 0, it can be used to just count the number of
pixels within the threshold if you set</p>
<p>If change_return is set to 1, the pixels set in DestSurface will be those
from the color.</p>
<p>If change_return is set to 2, the pixels set in DestSurface will be those
from the first Surface.</p>
<p>You can use a threshold of (r,g,b,a) where the r,g,b can have different
thresholds. So you could use an r threshold of 40 and a blue threshold of 2
if you like.</p>
<p>New in pygame 1.8</p>
</dd></dl>

</dd></dl>

</div>

  </div>
          </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../filepaths.html" title="File Path Function Arguments"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="time.html" title="pygame.time"
             accesskey="P">previous</a> |</li>
        <li><a href="../index.html">Pygame v1.9.2 documentation</a> &raquo;</li>
    <script type="text/javascript" src="jquery.plugin.docscomments.js"></script>

      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2011, Pygame Developers.
    </div>
  </body>
</html>