~ubuntu-branches/debian/experimental/pygame/experimental

« back to all changes in this revision

Viewing changes to docs/_sources/ref/surface.txt

  • Committer: Package Import Robot
  • Author(s): Vincent Cheng
  • Date: 2013-02-21 00:23:03 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20130221002303-08xmo02oym2hxjee
Tags: 1.9.2~pre~r3189-1
* New upstream hg snapshot (rev 3189).
* Avoid potentially overriding a symlink in python3.2-dev. (Closes: #700997)
* Generate correct versioned dependency on python-numpy following ABI change
  using the dh_numpy and dh_numpy3 helpers. (Closes: #698169)
  - Add build-depends on python3-numpy.
* Fix a number of failing tests that rely on pygame being tested with OpenGL
  and a graphical display available, as well as audio/video devices.
* Remove deprecated DMUA flag in debian/control.
* Fix lintian tag vcs-field-not-canonical.
* Update Standards version from 3.9.3 to 3.9.4, no updates required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
.. include:: common.txt
2
 
 
3
 
:mod:`pygame.Surface`
4
 
=====================
5
 
 
6
 
.. currentmodule:: pygame
7
 
 
8
 
.. class:: Surface
9
 
 
10
 
   | :sl:`pygame object for representing images`
11
 
   | :sg:`Surface((width, height), flags=0, depth=0, masks=None) -> Surface`
12
 
   | :sg:`Surface((width, height), flags=0, Surface) -> Surface`
13
 
 
14
 
   A pygame Surface is used to represent any image. The Surface has a fixed
15
 
   resolution and pixel format. Surfaces with 8bit pixels use a color palette
16
 
   to map to 24bit color.
17
 
 
18
 
   Call ``pygame.Surface()`` to create a new image object. The Surface will be
19
 
   cleared to all black. The only required arguments are the sizes. With no
20
 
   additional arguments, the Surface will be created in a format that best
21
 
   matches the display Surface.
22
 
 
23
 
   The pixel format can be controlled by passing the bit depth or an existing
24
 
   Surface. The flags argument is a bitmask of additional features for the
25
 
   surface. You can pass any combination of these flags:
26
 
 
27
 
   ::
28
 
 
29
 
     HWSURFACE, creates the image in video memory
30
 
     SRCALPHA, the pixel format will include a per-pixel alpha
31
 
 
32
 
   Both flags are only a request, and may not be possible for all displays and
33
 
   formats.
34
 
 
35
 
   Advance users can combine a set of bitmasks with a depth value. The masks
36
 
   are a set of 4 integers representing which bits in a pixel will represent
37
 
   each color. Normal Surfaces should not require the masks argument.
38
 
 
39
 
   Surfaces can have many extra attributes like alpha planes, colorkeys, source
40
 
   rectangle clipping. These functions mainly effect how the Surface is blitted
41
 
   to other Surfaces. The blit routines will attempt to use hardware
42
 
   acceleration when possible, otherwise they will use highly optimized
43
 
   software blitting methods.
44
 
 
45
 
   There are three types of transparency supported in Pygame: colorkeys,
46
 
   surface alphas, and pixel alphas. Surface alphas can be mixed with
47
 
   colorkeys, but an image with per pixel alphas cannot use the other modes.
48
 
   Colorkey transparency makes a single color value transparent. Any pixels
49
 
   matching the colorkey will not be drawn. The surface alpha value is a single
50
 
   value that changes the transparency for the entire image. A surface alpha of
51
 
   255 is opaque, and a value of 0 is completely transparent.
52
 
 
53
 
   Per pixel alphas are different because they store a transparency value for
54
 
   every pixel. This allows for the most precise transparency effects, but it
55
 
   also the slowest. Per pixel alphas cannot be mixed with surface alpha and
56
 
   colorkeys.
57
 
 
58
 
   There is support for pixel access for the Surfaces. Pixel access on hardware
59
 
   surfaces is slow and not recommended. Pixels can be accessed using the
60
 
   ``get_at()`` and ``set_at()`` functions. These methods are fine for simple
61
 
   access, but will be considerably slow when doing of pixel work with them. If
62
 
   you plan on doing a lot of pixel level work, it is recommended to use a
63
 
   :class:`pygame.PixelArray`, which gives an array like view of the surface.
64
 
   For involved mathematical manipulations try the :mod:`pygame.surfarray`
65
 
   module (It's quite quick, but requires NumPy.)
66
 
 
67
 
   Any functions that directly access a surface's pixel data will need that
68
 
   surface to be lock()'ed. These functions can ``lock()`` and ``unlock()`` the
69
 
   surfaces themselves without assistance. But, if a function will be called
70
 
   many times, there will be a lot of overhead for multiple locking and
71
 
   unlocking of the surface. It is best to lock the surface manually before
72
 
   making the function call many times, and then unlocking when you are
73
 
   finished. All functions that need a locked surface will say so in their
74
 
   docs. Remember to leave the Surface locked only while necessary.
75
 
 
76
 
   Surface pixels are stored internally as a single number that has all the
77
 
   colors encoded into it. Use the ``Surface.map_rgb()`` and
78
 
   ``Surface.unmap_rgb()`` to convert between individual red, green, and blue
79
 
   values into a packed integer for that Surface.
80
 
 
81
 
   Surfaces can also reference sections of other Surfaces. These are created
82
 
   with the ``Surface.subsurface()`` method. Any change to either Surface will
83
 
   effect the other.
84
 
 
85
 
   Each Surface contains a clipping area. By default the clip area covers the
86
 
   entire Surface. If it is changed, all drawing operations will only effect
87
 
   the smaller area.
88
 
 
89
 
   .. method:: blit
90
 
 
91
 
      | :sl:`draw one image onto another`
92
 
      | :sg:`blit(source, dest, area=None, special_flags = 0) -> Rect`
93
 
 
94
 
      Draws a source Surface onto this Surface. The draw can be positioned with
95
 
      the dest argument. Dest can either be pair of coordinates representing
96
 
      the upper left corner of the source. A Rect can also be passed as the
97
 
      destination and the topleft corner of the rectangle will be used as the
98
 
      position for the blit. The size of the destination rectangle does not
99
 
      effect the blit.
100
 
 
101
 
      An optional area rectangle can be passed as well. This represents a
102
 
      smaller portion of the source Surface to draw.
103
 
 
104
 
      An optional special flags is for passing in new in 1.8.0: ``BLEND_ADD``,
105
 
      ``BLEND_SUB``, ``BLEND_MULT``, ``BLEND_MIN``, ``BLEND_MAX`` new in 1.8.1:
106
 
      ``BLEND_RGBA_ADD``, ``BLEND_RGBA_SUB``, ``BLEND_RGBA_MULT``,
107
 
      ``BLEND_RGBA_MIN``, ``BLEND_RGBA_MAX`` ``BLEND_RGB_ADD``,
108
 
      ``BLEND_RGB_SUB``, ``BLEND_RGB_MULT``, ``BLEND_RGB_MIN``,
109
 
      ``BLEND_RGB_MAX`` With other special blitting flags perhaps added in the
110
 
      future.
111
 
 
112
 
      The return rectangle is the area of the affected pixels, excluding any
113
 
      pixels outside the destination Surface, or outside the clipping area.
114
 
 
115
 
      Pixel alphas will be ignored when blitting to an 8 bit Surface.
116
 
 
117
 
      special_flags new in pygame 1.8.
118
 
 
119
 
      For a surface with colorkey or blanket alpha, a blit to self may give
120
 
      slightly different colors than a non self-blit.
121
 
 
122
 
      .. ## Surface.blit ##
123
 
 
124
 
   .. method:: convert
125
 
 
126
 
      | :sl:`change the pixel format of an image`
127
 
      | :sg:`convert(Surface) -> Surface`
128
 
      | :sg:`convert(depth, flags=0) -> Surface`
129
 
      | :sg:`convert(masks, flags=0) -> Surface`
130
 
      | :sg:`convert() -> Surface`
131
 
 
132
 
      Creates a new copy of the Surface with the pixel format changed. The new
133
 
      pixel format can be determined from another existing Surface. Otherwise
134
 
      depth, flags, and masks arguments can be used, similar to the
135
 
      ``pygame.Surface()`` call.
136
 
 
137
 
      If no arguments are passed the new Surface will have the same pixel
138
 
      format as the display Surface. This is always the fastest format for
139
 
      blitting. It is a good idea to convert all Surfaces before they are
140
 
      blitted many times.
141
 
 
142
 
      The converted Surface will have no pixel alphas. They will be stripped if
143
 
      the original had them. See ``Surface.convert_alpha()`` for preserving or
144
 
      creating per-pixel alphas.
145
 
 
146
 
      .. ## Surface.convert ##
147
 
 
148
 
   .. method:: convert_alpha
149
 
 
150
 
      | :sl:`change the pixel format of an image including per pixel alphas`
151
 
      | :sg:`convert_alpha(Surface) -> Surface`
152
 
      | :sg:`convert_alpha() -> Surface`
153
 
 
154
 
      Creates a new copy of the surface with the desired pixel format. The new
155
 
      surface will be in a format suited for quick blitting to the given format
156
 
      with per pixel alpha. If no surface is given, the new surface will be
157
 
      optimized for blitting to the current display.
158
 
 
159
 
      Unlike the ``Surface.convert()`` method, the pixel format for the new
160
 
      image will not be exactly the same as the requested source, but it will
161
 
      be optimized for fast alpha blitting to the destination.
162
 
 
163
 
      .. ## Surface.convert_alpha ##
164
 
 
165
 
   .. method:: copy
166
 
 
167
 
      | :sl:`create a new copy of a Surface`
168
 
      | :sg:`copy() -> Surface`
169
 
 
170
 
      Makes a duplicate copy of a Surface. The new Surface will have the same
171
 
      pixel formats, color palettes, and transparency settings as the original.
172
 
 
173
 
      .. ## Surface.copy ##
174
 
 
175
 
   .. method:: fill
176
 
 
177
 
      | :sl:`fill Surface with a solid color`
178
 
      | :sg:`fill(color, rect=None, special_flags=0) -> Rect`
179
 
 
180
 
      Fill the Surface with a solid color. If no rect argument is given the
181
 
      entire Surface will be filled. The rect argument will limit the fill to a
182
 
      specific area. The fill will also be contained by the Surface clip area.
183
 
 
184
 
      The color argument can be either a ``RGB`` sequence, a ``RGBA`` sequence
185
 
      or a mapped color index. If using ``RGBA``, the Alpha (A part of
186
 
      ``RGBA``) is ignored unless the surface uses per pixel alpha (Surface has
187
 
      the ``SRCALPHA`` flag).
188
 
 
189
 
      An optional special_flags is for passing in new in 1.8.0: ``BLEND_ADD``,
190
 
      ``BLEND_SUB``, ``BLEND_MULT``, ``BLEND_MIN``, ``BLEND_MAX`` new in 1.8.1:
191
 
      ``BLEND_RGBA_ADD``, ``BLEND_RGBA_SUB``, ``BLEND_RGBA_MULT``,
192
 
      ``BLEND_RGBA_MIN``, ``BLEND_RGBA_MAX`` ``BLEND_RGB_ADD``,
193
 
      ``BLEND_RGB_SUB``, ``BLEND_RGB_MULT``, ``BLEND_RGB_MIN``,
194
 
      ``BLEND_RGB_MAX`` With other special blitting flags perhaps added in the
195
 
      future.
196
 
 
197
 
      This will return the affected Surface area.
198
 
 
199
 
      .. ## Surface.fill ##
200
 
 
201
 
   .. method:: scroll
202
 
 
203
 
      | :sl:`Shift the surface image in place`
204
 
      | :sg:`scroll(dx=0, dy=0) -> None`
205
 
 
206
 
      Move the image by dx pixels right and dy pixels down. dx and dy may be
207
 
      negative for left and up scrolls respectively. Areas of the surface that
208
 
      are not overwritten retain their original pixel values. Scrolling is
209
 
      contained by the Surface clip area. It is safe to have dx and dy values
210
 
      that exceed the surface size.
211
 
 
212
 
      New in Pygame 1.9
213
 
 
214
 
      .. ## Surface.scroll ##
215
 
 
216
 
   .. method:: set_colorkey
217
 
 
218
 
      | :sl:`Set the transparent colorkey`
219
 
      | :sg:`set_colorkey(Color, flags=0) -> None`
220
 
      | :sg:`set_colorkey(None) -> None`
221
 
 
222
 
      Set the current color key for the Surface. When blitting this Surface
223
 
      onto a destination, and pixels that have the same color as the colorkey
224
 
      will be transparent. The color can be an ``RGB`` color or a mapped color
225
 
      integer. If None is passed, the colorkey will be unset.
226
 
 
227
 
      The colorkey will be ignored if the Surface is formatted to use per pixel
228
 
      alpha values. The colorkey can be mixed with the full Surface alpha
229
 
      value.
230
 
 
231
 
      The optional flags argument can be set to ``pygame.RLEACCEL`` to provide
232
 
      better performance on non accelerated displays. An ``RLEACCEL`` Surface
233
 
      will be slower to modify, but quicker to blit as a source.
234
 
 
235
 
      .. ## Surface.set_colorkey ##
236
 
 
237
 
   .. method:: get_colorkey
238
 
 
239
 
      | :sl:`Get the current transparent colorkey`
240
 
      | :sg:`get_colorkey() -> RGB or None`
241
 
 
242
 
      Return the current colorkey value for the Surface. If the colorkey is not
243
 
      set then None is returned.
244
 
 
245
 
      .. ## Surface.get_colorkey ##
246
 
 
247
 
   .. method:: set_alpha
248
 
 
249
 
      | :sl:`set the alpha value for the full Surface image`
250
 
      | :sg:`set_alpha(value, flags=0) -> None`
251
 
      | :sg:`set_alpha(None) -> None`
252
 
 
253
 
      Set the current alpha value fo r the Surface. When blitting this Surface
254
 
      onto a destination, the pixels will be drawn slightly transparent. The
255
 
      alpha value is an integer from 0 to 255, 0 is fully transparent and 255
256
 
      is fully opaque. If None is passed for the alpha value, then the Surface
257
 
      alpha will be disabled.
258
 
 
259
 
      This value is different than the per pixel Surface alpha. If the Surface
260
 
      format contains per pixel alphas, then this alpha value will be ignored.
261
 
      If the Surface contains per pixel alphas, setting the alpha value to None
262
 
      will disable the per pixel transparency.
263
 
 
264
 
      The optional flags argument can be set to ``pygame.RLEACCEL`` to provide
265
 
      better performance on non accelerated displays. An ``RLEACCEL`` Surface
266
 
      will be slower to modify, but quicker to blit as a source.
267
 
 
268
 
      .. ## Surface.set_alpha ##
269
 
 
270
 
   .. method:: get_alpha
271
 
 
272
 
      | :sl:`get the current Surface transparency value`
273
 
      | :sg:`get_alpha() -> int_value or None`
274
 
 
275
 
      Return the current alpha value for the Surface. If the alpha value is not
276
 
      set then None is returned.
277
 
 
278
 
      .. ## Surface.get_alpha ##
279
 
 
280
 
   .. method:: lock
281
 
 
282
 
      | :sl:`lock the Surface memory for pixel access`
283
 
      | :sg:`lock() -> None`
284
 
 
285
 
      Lock the pixel data of a Surface for access. On accelerated Surfaces, the
286
 
      pixel data may be stored in volatile video memory or nonlinear compressed
287
 
      forms. When a Surface is locked the pixel memory becomes available to
288
 
      access by regular software. Code that reads or writes pixel values will
289
 
      need the Surface to be locked.
290
 
 
291
 
      Surfaces should not remain locked for more than necessary. A locked
292
 
      Surface can often not be displayed or managed by Pygame.
293
 
 
294
 
      Not all Surfaces require locking. The ``Surface.mustlock()`` method can
295
 
      determine if it is actually required. There is no performance penalty for
296
 
      locking and unlocking a Surface that does not need it.
297
 
 
298
 
      All pygame functions will automatically lock and unlock the Surface data
299
 
      as needed. If a section of code is going to make calls that will
300
 
      repeatedly lock and unlock the Surface many times, it can be helpful to
301
 
      wrap the block inside a lock and unlock pair.
302
 
 
303
 
      It is safe to nest locking and unlocking calls. The surface will only be
304
 
      unlocked after the final lock is released.
305
 
 
306
 
      .. ## Surface.lock ##
307
 
 
308
 
   .. method:: unlock
309
 
 
310
 
      | :sl:`unlock the Surface memory from pixel access`
311
 
      | :sg:`unlock() -> None`
312
 
 
313
 
      Unlock the Surface pixel data after it has been locked. The unlocked
314
 
      Surface can once again be drawn and managed by Pygame. See the
315
 
      ``Surface.lock()`` documentation for more details.
316
 
 
317
 
      All pygame functions will automatically lock and unlock the Surface data
318
 
      as needed. If a section of code is going to make calls that will
319
 
      repeatedly lock and unlock the Surface many times, it can be helpful to
320
 
      wrap the block inside a lock and unlock pair.
321
 
 
322
 
      It is safe to nest locking and unlocking calls. The surface will only be
323
 
      unlocked after the final lock is released.
324
 
 
325
 
      .. ## Surface.unlock ##
326
 
 
327
 
   .. method:: mustlock
328
 
 
329
 
      | :sl:`test if the Surface requires locking`
330
 
      | :sg:`mustlock() -> bool`
331
 
 
332
 
      Returns True if the Surface is required to be locked to access pixel
333
 
      data. Usually pure software Surfaces do not require locking. This method
334
 
      is rarely needed, since it is safe and quickest to just lock all Surfaces
335
 
      as needed.
336
 
 
337
 
      All pygame functions will automatically lock and unlock the Surface data
338
 
      as needed. If a section of code is going to make calls that will
339
 
      repeatedly lock and unlock the Surface many times, it can be helpful to
340
 
      wrap the block inside a lock and unlock pair.
341
 
 
342
 
      .. ## Surface.mustlock ##
343
 
 
344
 
   .. method:: get_locked
345
 
 
346
 
      | :sl:`test if the Surface is current locked`
347
 
      | :sg:`get_locked() -> bool`
348
 
 
349
 
      Returns True when the Surface is locked. It doesn't matter how many times
350
 
      the Surface is locked.
351
 
 
352
 
      .. ## Surface.get_locked ##
353
 
 
354
 
   .. method:: get_locks
355
 
 
356
 
      | :sl:`Gets the locks for the Surface`
357
 
      | :sg:`get_locks() -> tuple`
358
 
 
359
 
      Returns the currently existing locks for the Surface.
360
 
 
361
 
      .. ## Surface.get_locks ##
362
 
 
363
 
   .. method:: get_at
364
 
 
365
 
      | :sl:`get the color value at a single pixel`
366
 
      | :sg:`get_at((x, y)) -> Color`
367
 
 
368
 
      Return a copy of the ``RGBA`` Color value at the given pixel. If the
369
 
      Surface has no per pixel alpha, then the alpha value will always be 255
370
 
      (opaque). If the pixel position is outside the area of the Surface an
371
 
      IndexError exception will be raised.
372
 
 
373
 
      Getting and setting pixels one at a time is generally too slow to be used
374
 
      in a game or realtime situation. It is better to use methods which
375
 
      operate on many pixels at a time like with the blit, fill and draw
376
 
      methods - or by using surfarray/PixelArray.
377
 
 
378
 
      This function will temporarily lock and unlock the Surface as needed.
379
 
 
380
 
      Returning a Color instead of tuple, New in pygame 1.9.0. Use
381
 
      ``tuple(surf.get_at((x,y)))`` if you want a tuple, and not a Color. This
382
 
      should only matter if you want to use the color as a key in a dict.
383
 
 
384
 
      .. ## Surface.get_at ##
385
 
 
386
 
   .. method:: set_at
387
 
 
388
 
      | :sl:`set the color value for a single pixel`
389
 
      | :sg:`set_at((x, y), Color) -> None`
390
 
 
391
 
      Set the ``RGBA`` or mapped integer color value for a single pixel. If the
392
 
      Surface does not have per pixel alphas, the alpha value is ignored.
393
 
      Settting pixels outside the Surface area or outside the Surface clipping
394
 
      will have no effect.
395
 
 
396
 
      Getting and setting pixels one at a time is generally too slow to be used
397
 
      in a game or realtime situation.
398
 
 
399
 
      This function will temporarily lock and unlock the Surface as needed.
400
 
 
401
 
      .. ## Surface.set_at ##
402
 
 
403
 
   .. method:: get_at_mapped
404
 
 
405
 
      | :sl:`get the mapped color value at a single pixel`
406
 
      | :sg:`get_at_mapped((x, y)) -> Color`
407
 
 
408
 
      Return the integer value of the given pixel. If the pixel position is
409
 
      outside the area of the Surface an IndexError exception will be raised.
410
 
 
411
 
      This method is intended for Pygame unit testing. It unlikely has any use
412
 
      in an application.
413
 
 
414
 
      This function will temporarily lock and unlock the Surface as needed.
415
 
 
416
 
      New in pygame. 1.9.2.
417
 
 
418
 
      .. ## Surface.get_at_mapped ##
419
 
 
420
 
   .. method:: get_palette
421
 
 
422
 
      | :sl:`get the color index palette for an 8bit Surface`
423
 
      | :sg:`get_palette() -> [RGB, RGB, RGB, ...]`
424
 
 
425
 
      Return a list of up to 256 color elements that represent the indexed
426
 
      colors used in an 8bit Surface. The returned list is a copy of the
427
 
      palette, and changes will have no effect on the Surface.
428
 
 
429
 
      Returning a list of ``Color(with length 3)`` instances instead of tuples,
430
 
      New in pygame 1.9.0
431
 
 
432
 
      .. ## Surface.get_palette ##
433
 
 
434
 
   .. method:: get_palette_at
435
 
 
436
 
      | :sl:`get the color for a single entry in a palette`
437
 
      | :sg:`get_palette_at(index) -> RGB`
438
 
 
439
 
      Returns the red, green, and blue color values for a single index in a
440
 
      Surface palette. The index should be a value from 0 to 255.
441
 
 
442
 
      Returning ``Color(with length 3)`` instance instead of a tuple, New in
443
 
      pygame 1.9.0
444
 
 
445
 
      .. ## Surface.get_palette_at ##
446
 
 
447
 
   .. method:: set_palette
448
 
 
449
 
      | :sl:`set the color palette for an 8bit Surface`
450
 
      | :sg:`set_palette([RGB, RGB, RGB, ...]) -> None`
451
 
 
452
 
      Set the full palette for an 8bit Surface. This will replace the colors in
453
 
      the existing palette. A partial palette can be passed and only the first
454
 
      colors in the original palette will be changed.
455
 
 
456
 
      This function has no effect on a Surface with more than 8bits per pixel.
457
 
 
458
 
      .. ## Surface.set_palette ##
459
 
 
460
 
   .. method:: set_palette_at
461
 
 
462
 
      | :sl:`set the color for a single index in an 8bit Surface palette`
463
 
      | :sg:`set_palette_at(index, RGB) -> None`
464
 
 
465
 
      Set the palette value for a single entry in a Surface palette. The index
466
 
      should be a value from 0 to 255.
467
 
 
468
 
      This function has no effect on a Surface with more than 8bits per pixel.
469
 
 
470
 
      .. ## Surface.set_palette_at ##
471
 
 
472
 
   .. method:: map_rgb
473
 
 
474
 
      | :sl:`convert a color into a mapped color value`
475
 
      | :sg:`map_rgb(Color) -> mapped_int`
476
 
 
477
 
      Convert an ``RGBA`` color into the mapped integer value for this Surface.
478
 
      The returned integer will contain no more bits than the bit depth of the
479
 
      Surface. Mapped color values are not often used inside Pygame, but can be
480
 
      passed to most functions that require a Surface and a color.
481
 
 
482
 
      See the Surface object documentation for more information about colors
483
 
      and pixel formats.
484
 
 
485
 
      .. ## Surface.map_rgb ##
486
 
 
487
 
   .. method:: unmap_rgb
488
 
 
489
 
      | :sl:`convert a mapped integer color value into a Color`
490
 
      | :sg:`unmap_rgb(mapped_int) -> Color`
491
 
 
492
 
      Convert an mapped integer color into the ``RGB`` color components for
493
 
      this Surface. Mapped color values are not often used inside Pygame, but
494
 
      can be passed to most functions that require a Surface and a color.
495
 
 
496
 
      See the Surface object documentation for more information about colors
497
 
      and pixel formats.
498
 
 
499
 
      .. ## Surface.unmap_rgb ##
500
 
 
501
 
   .. method:: set_clip
502
 
 
503
 
      | :sl:`set the current clipping area of the Surface`
504
 
      | :sg:`set_clip(rect) -> None`
505
 
      | :sg:`set_clip(None) -> None`
506
 
 
507
 
      Each Surface has an active clipping area. This is a rectangle that
508
 
      represents the only pixels on the Surface that can be modified. If None
509
 
      is passed for the rectangle the full Surface will be available for
510
 
      changes.
511
 
 
512
 
      The clipping area is always restricted to the area of the Surface itself.
513
 
      If the clip rectangle is too large it will be shrunk to fit inside the
514
 
      Surface.
515
 
 
516
 
      .. ## Surface.set_clip ##
517
 
 
518
 
   .. method:: get_clip
519
 
 
520
 
      | :sl:`get the current clipping area of the Surface`
521
 
      | :sg:`get_clip() -> Rect`
522
 
 
523
 
      Return a rectangle of the current clipping area. The Surface will always
524
 
      return a valid rectangle that will never be outside the bounds of the
525
 
      image. If the Surface has had None set for the clipping area, the Surface
526
 
      will return a rectangle with the full area of the Surface.
527
 
 
528
 
      .. ## Surface.get_clip ##
529
 
 
530
 
   .. method:: subsurface
531
 
 
532
 
      | :sl:`create a new surface that references its parent`
533
 
      | :sg:`subsurface(Rect) -> Surface`
534
 
 
535
 
      Returns a new Surface that shares its pixels with its new parent. The new
536
 
      Surface is considered a child of the original. Modifications to either
537
 
      Surface pixels will effect each other. Surface information like clipping
538
 
      area and color keys are unique to each Surface.
539
 
 
540
 
      The new Surface will inherit the palette, color key, and alpha settings
541
 
      from its parent.
542
 
 
543
 
      It is possible to have any number of subsurfaces and subsubsurfaces on
544
 
      the parent. It is also possible to subsurface the display Surface if the
545
 
      display mode is not hardware accelerated.
546
 
 
547
 
      See the ``Surface.get_offset()``, ``Surface.get_parent()`` to learn more
548
 
      about the state of a subsurface.
549
 
 
550
 
      .. ## Surface.subsurface ##
551
 
 
552
 
   .. method:: get_parent
553
 
 
554
 
      | :sl:`find the parent of a subsurface`
555
 
      | :sg:`get_parent() -> Surface`
556
 
 
557
 
      Returns the parent Surface of a subsurface. If this is not a subsurface
558
 
      then None will be returned.
559
 
 
560
 
      .. ## Surface.get_parent ##
561
 
 
562
 
   .. method:: get_abs_parent
563
 
 
564
 
      | :sl:`find the top level parent of a subsurface`
565
 
      | :sg:`get_abs_parent() -> Surface`
566
 
 
567
 
      Returns the parent Surface of a subsurface. If this is not a subsurface
568
 
      then this surface will be returned.
569
 
 
570
 
      .. ## Surface.get_abs_parent ##
571
 
 
572
 
   .. method:: get_offset
573
 
 
574
 
      | :sl:`find the position of a child subsurface inside a parent`
575
 
      | :sg:`get_offset() -> (x, y)`
576
 
 
577
 
      Get the offset position of a child subsurface inside of a parent. If the
578
 
      Surface is not a subsurface this will return (0, 0).
579
 
 
580
 
      .. ## Surface.get_offset ##
581
 
 
582
 
   .. method:: get_abs_offset
583
 
 
584
 
      | :sl:`find the absolute position of a child subsurface inside its top level parent`
585
 
      | :sg:`get_abs_offset() -> (x, y)`
586
 
 
587
 
      Get the offset position of a child subsurface inside of its top level
588
 
      parent Surface. If the Surface is not a subsurface this will return (0,
589
 
      0).
590
 
 
591
 
      .. ## Surface.get_abs_offset ##
592
 
 
593
 
   .. method:: get_size
594
 
 
595
 
      | :sl:`get the dimensions of the Surface`
596
 
      | :sg:`get_size() -> (width, height)`
597
 
 
598
 
      Return the width and height of the Surface in pixels.
599
 
 
600
 
      .. ## Surface.get_size ##
601
 
 
602
 
   .. method:: get_width
603
 
 
604
 
      | :sl:`get the width of the Surface`
605
 
      | :sg:`get_width() -> width`
606
 
 
607
 
      Return the width of the Surface in pixels.
608
 
 
609
 
      .. ## Surface.get_width ##
610
 
 
611
 
   .. method:: get_height
612
 
 
613
 
      | :sl:`get the height of the Surface`
614
 
      | :sg:`get_height() -> height`
615
 
 
616
 
      Return the height of the Surface in pixels.
617
 
 
618
 
      .. ## Surface.get_height ##
619
 
 
620
 
   .. method:: get_rect
621
 
 
622
 
      | :sl:`get the rectangular area of the Surface`
623
 
      | :sg:`get_rect(**kwargs) -> Rect`
624
 
 
625
 
      Returns a new rectangle covering the entire surface. This rectangle will
626
 
      always start at 0, 0 with a width. and height the same size as the image.
627
 
 
628
 
      You can pass keyword argument values to this function. These named values
629
 
      will be applied to the attributes of the Rect before it is returned. An
630
 
      example would be 'mysurf.get_rect(center=(100,100))' to create a
631
 
      rectangle for the Surface centered at a given position.
632
 
 
633
 
      .. ## Surface.get_rect ##
634
 
 
635
 
   .. method:: get_bitsize
636
 
 
637
 
      | :sl:`get the bit depth of the Surface pixel format`
638
 
      | :sg:`get_bitsize() -> int`
639
 
 
640
 
      Returns the number of bits used to represent each pixel. This value may
641
 
      not exactly fill the number of bytes used per pixel. For example a 15 bit
642
 
      Surface still requires a full 2 bytes.
643
 
 
644
 
      .. ## Surface.get_bitsize ##
645
 
 
646
 
   .. method:: get_bytesize
647
 
 
648
 
      | :sl:`get the bytes used per Surface pixel`
649
 
      | :sg:`get_bytesize() -> int`
650
 
 
651
 
      Return the number of bytes used per pixel.
652
 
 
653
 
      .. ## Surface.get_bytesize ##
654
 
 
655
 
   .. method:: get_flags
656
 
 
657
 
      | :sl:`get the additional flags used for the Surface`
658
 
      | :sg:`get_flags() -> int`
659
 
 
660
 
      Returns a set of current Surface features. Each feature is a bit in the
661
 
      flags bitmask. Typical flags are ``HWSURFACE``, ``RLEACCEL``,
662
 
      ``SRCALPHA``, and ``SRCCOLORKEY``.
663
 
 
664
 
      Here is a more complete list of flags. A full list can be found in
665
 
      ``SDL_video.h``
666
 
 
667
 
      ::
668
 
 
669
 
        SWSURFACE       0x00000000      # Surface is in system memory
670
 
        HWSURFACE       0x00000001      # Surface is in video memory
671
 
        ASYNCBLIT       0x00000004      # Use asynchronous blits if possible
672
 
 
673
 
      Available for ``pygame.display.set_mode()``
674
 
 
675
 
      ::
676
 
 
677
 
        ANYFORMAT       0x10000000      # Allow any video depth/pixel-format
678
 
        HWPALETTE       0x20000000      # Surface has exclusive palette
679
 
        DOUBLEBUF       0x40000000      # Set up double-buffered video mode
680
 
        FULLSCREEN      0x80000000      # Surface is a full screen display
681
 
        OPENGL        0x00000002      # Create an OpenGL rendering context
682
 
        OPENGLBLIT      0x0000000A      # Create an OpenGL rendering context
683
 
                                      #   and use it for blitting.  Obsolete.
684
 
        RESIZABLE       0x00000010      # This video mode may be resized
685
 
        NOFRAME       0x00000020        # No window caption or edge frame
686
 
 
687
 
      Used internally (read-only)
688
 
 
689
 
      ::
690
 
 
691
 
        HWACCEL       0x00000100        # Blit uses hardware acceleration
692
 
        SRCCOLORKEY     0x00001000      # Blit uses a source color key
693
 
        RLEACCELOK      0x00002000      # Private flag
694
 
        RLEACCEL        0x00004000      # Surface is RLE encoded
695
 
        SRCALPHA        0x00010000      # Blit uses source alpha blending
696
 
        PREALLOC        0x01000000      # Surface uses preallocated memory
697
 
 
698
 
      .. ## Surface.get_flags ##
699
 
 
700
 
   .. method:: get_pitch
701
 
 
702
 
      | :sl:`get the number of bytes used per Surface row`
703
 
      | :sg:`get_pitch() -> int`
704
 
 
705
 
      Return the number of bytes separating each row in the Surface. Surfaces
706
 
      in video memory are not always linearly packed. Subsurfaces will also
707
 
      have a larger pitch than their real width.
708
 
 
709
 
      This value is not needed for normal Pygame usage.
710
 
 
711
 
      .. ## Surface.get_pitch ##
712
 
 
713
 
   .. method:: get_masks
714
 
 
715
 
      | :sl:`the bitmasks needed to convert between a color and a mapped integer`
716
 
      | :sg:`get_masks() -> (R, G, B, A)`
717
 
 
718
 
      Returns the bitmasks used to isolate each color in a mapped integer.
719
 
 
720
 
      This value is not needed for normal Pygame usage.
721
 
 
722
 
      .. ## Surface.get_masks ##
723
 
 
724
 
   .. method:: set_masks
725
 
 
726
 
      | :sl:`set the bitmasks needed to convert between a color and a mapped integer`
727
 
      | :sg:`set_masks((r,g,b,a)) -> None`
728
 
 
729
 
      This is not needed for normal Pygame usage. New in pygame 1.8.1
730
 
 
731
 
      .. ## Surface.set_masks ##
732
 
 
733
 
   .. method:: get_shifts
734
 
 
735
 
      | :sl:`the bit shifts needed to convert between a color and a mapped integer`
736
 
      | :sg:`get_shifts() -> (R, G, B, A)`
737
 
 
738
 
      Returns the pixel shifts need to convert between each color and a mapped
739
 
      integer.
740
 
 
741
 
      This value is not needed for normal Pygame usage.
742
 
 
743
 
      .. ## Surface.get_shifts ##
744
 
 
745
 
   .. method:: set_shifts
746
 
 
747
 
      | :sl:`sets the bit shifts needed to convert between a color and a mapped integer`
748
 
      | :sg:`set_shifts((r,g,b,a)) -> None`
749
 
 
750
 
      This is not needed for normal Pygame usage. New in pygame 1.8.1
751
 
 
752
 
      .. ## Surface.set_shifts ##
753
 
 
754
 
   .. method:: get_losses
755
 
 
756
 
      | :sl:`the significant bits used to convert between a color and a mapped integer`
757
 
      | :sg:`get_losses() -> (R, G, B, A)`
758
 
 
759
 
      Return the least significant number of bits stripped from each color in a
760
 
      mapped integer.
761
 
 
762
 
      This value is not needed for normal Pygame usage.
763
 
 
764
 
      .. ## Surface.get_losses ##
765
 
 
766
 
   .. method:: get_bounding_rect
767
 
 
768
 
      | :sl:`find the smallest rect containing data`
769
 
      | :sg:`get_bounding_rect(min_alpha = 1) -> Rect`
770
 
 
771
 
      Returns the smallest rectangular region that contains all the pixels in
772
 
      the surface that have an alpha value greater than or equal to the minimum
773
 
      alpha value.
774
 
 
775
 
      This function will temporarily lock and unlock the Surface as needed.
776
 
 
777
 
      New in pygame 1.8.
778
 
 
779
 
      .. ## Surface.get_bounding_rect ##
780
 
 
781
 
   .. method:: get_view
782
 
 
783
 
      | :sl:`return a view of a surface's pixel data.`
784
 
      | :sg:`get_view(kind='2') -> <view>`
785
 
 
786
 
      Return an object which exposes a surface's internal pixel buffer to a
787
 
      NumPy array. For now a custom object with an array struct interface is
788
 
      returned. A Python memoryview may be returned in the future. The buffer
789
 
      is writeable.
790
 
 
791
 
      The kind argument is the length 1 string '2', '3', 'r', 'g', 'b', or 'a'.
792
 
      The letters are case insensitive; 'A' will work as well. The argument can
793
 
      be either a Unicode or byte (char) string. The default is '2'.
794
 
 
795
 
      A kind '2' view is a (surface-width, surface-height) array of raw pixels.
796
 
      The pixels are surface bytesized unsigned integers. The pixel format is
797
 
      surface specific. The 3 byte unsigned integers of 24 bit surfaces are
798
 
      unlikely accepted by anything other than other Pygame functions.
799
 
 
800
 
      '3' returns a (surface-width, surface-height, 3) view of ``RGB`` color
801
 
      components. Each of the red, green, and blue components are unsigned
802
 
      bytes. Only 24-bit and 32-bit surfaces are supported. The color
803
 
      components must be in either ``RGB`` or ``BGR`` order within the pixel.
804
 
 
805
 
      'r' for red, 'g' for green, 'b' for blue, and 'a' for alpha return a
806
 
      (surface-width, surface-height) view of a single color component within a
807
 
      surface: a color plane. Color components are unsigned bytes. Both 24-bit
808
 
      and 32-bit surfaces support 'r', 'g', and 'b'. Only 32-bit surfaces with
809
 
      ``SRCALPHA`` support 'a'.
810
 
 
811
 
      This method implicitly locks the Surface. The lock will be released, once
812
 
      the returned view object is deleted.
813
 
 
814
 
      New in pygame 1.9.2.
815
 
 
816
 
      .. ## Surface.get_view ##
817
 
 
818
 
   .. method:: get_buffer
819
 
 
820
 
      | :sl:`acquires a buffer object for the pixels of the Surface.`
821
 
      | :sg:`get_buffer() -> BufferProxy`
822
 
 
823
 
      Return a buffer object for the pixels of the Surface. The buffer can be
824
 
      used for direct pixel access and manipulation.
825
 
 
826
 
      This method implicitly locks the Surface. The lock will be released, once
827
 
      the returned BufferProxy object is deleted.
828
 
 
829
 
      New in pygame 1.8.
830
 
 
831
 
      .. ## Surface.get_buffer ##
832
 
 
833
 
   .. ## pygame.Surface ##