1
.. include:: common.txt
6
.. currentmodule:: pygame
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`
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.
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.
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:
29
HWSURFACE, creates the image in video memory
30
SRCALPHA, the pixel format will include a per-pixel alpha
32
Both flags are only a request, and may not be possible for all displays and
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.
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.
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.
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
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.)
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.
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.
81
Surfaces can also reference sections of other Surfaces. These are created
82
with the ``Surface.subsurface()`` method. Any change to either Surface will
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
91
| :sl:`draw one image onto another`
92
| :sg:`blit(source, dest, area=None, special_flags = 0) -> Rect`
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
101
An optional area rectangle can be passed as well. This represents a
102
smaller portion of the source Surface to draw.
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
112
The return rectangle is the area of the affected pixels, excluding any
113
pixels outside the destination Surface, or outside the clipping area.
115
Pixel alphas will be ignored when blitting to an 8 bit Surface.
117
special_flags new in pygame 1.8.
119
For a surface with colorkey or blanket alpha, a blit to self may give
120
slightly different colors than a non self-blit.
122
.. ## Surface.blit ##
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`
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.
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
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.
146
.. ## Surface.convert ##
148
.. method:: convert_alpha
150
| :sl:`change the pixel format of an image including per pixel alphas`
151
| :sg:`convert_alpha(Surface) -> Surface`
152
| :sg:`convert_alpha() -> Surface`
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.
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.
163
.. ## Surface.convert_alpha ##
167
| :sl:`create a new copy of a Surface`
168
| :sg:`copy() -> Surface`
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.
173
.. ## Surface.copy ##
177
| :sl:`fill Surface with a solid color`
178
| :sg:`fill(color, rect=None, special_flags=0) -> Rect`
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.
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).
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
197
This will return the affected Surface area.
199
.. ## Surface.fill ##
203
| :sl:`Shift the surface image in place`
204
| :sg:`scroll(dx=0, dy=0) -> None`
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.
214
.. ## Surface.scroll ##
216
.. method:: set_colorkey
218
| :sl:`Set the transparent colorkey`
219
| :sg:`set_colorkey(Color, flags=0) -> None`
220
| :sg:`set_colorkey(None) -> None`
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.
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
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.
235
.. ## Surface.set_colorkey ##
237
.. method:: get_colorkey
239
| :sl:`Get the current transparent colorkey`
240
| :sg:`get_colorkey() -> RGB or None`
242
Return the current colorkey value for the Surface. If the colorkey is not
243
set then None is returned.
245
.. ## Surface.get_colorkey ##
247
.. method:: set_alpha
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`
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.
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.
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.
268
.. ## Surface.set_alpha ##
270
.. method:: get_alpha
272
| :sl:`get the current Surface transparency value`
273
| :sg:`get_alpha() -> int_value or None`
275
Return the current alpha value for the Surface. If the alpha value is not
276
set then None is returned.
278
.. ## Surface.get_alpha ##
282
| :sl:`lock the Surface memory for pixel access`
283
| :sg:`lock() -> None`
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.
291
Surfaces should not remain locked for more than necessary. A locked
292
Surface can often not be displayed or managed by Pygame.
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.
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.
303
It is safe to nest locking and unlocking calls. The surface will only be
304
unlocked after the final lock is released.
306
.. ## Surface.lock ##
310
| :sl:`unlock the Surface memory from pixel access`
311
| :sg:`unlock() -> None`
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.
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.
322
It is safe to nest locking and unlocking calls. The surface will only be
323
unlocked after the final lock is released.
325
.. ## Surface.unlock ##
329
| :sl:`test if the Surface requires locking`
330
| :sg:`mustlock() -> bool`
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
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.
342
.. ## Surface.mustlock ##
344
.. method:: get_locked
346
| :sl:`test if the Surface is current locked`
347
| :sg:`get_locked() -> bool`
349
Returns True when the Surface is locked. It doesn't matter how many times
350
the Surface is locked.
352
.. ## Surface.get_locked ##
354
.. method:: get_locks
356
| :sl:`Gets the locks for the Surface`
357
| :sg:`get_locks() -> tuple`
359
Returns the currently existing locks for the Surface.
361
.. ## Surface.get_locks ##
365
| :sl:`get the color value at a single pixel`
366
| :sg:`get_at((x, y)) -> Color`
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.
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.
378
This function will temporarily lock and unlock the Surface as needed.
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.
384
.. ## Surface.get_at ##
388
| :sl:`set the color value for a single pixel`
389
| :sg:`set_at((x, y), Color) -> None`
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
396
Getting and setting pixels one at a time is generally too slow to be used
397
in a game or realtime situation.
399
This function will temporarily lock and unlock the Surface as needed.
401
.. ## Surface.set_at ##
403
.. method:: get_at_mapped
405
| :sl:`get the mapped color value at a single pixel`
406
| :sg:`get_at_mapped((x, y)) -> Color`
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.
411
This method is intended for Pygame unit testing. It unlikely has any use
414
This function will temporarily lock and unlock the Surface as needed.
416
New in pygame. 1.9.2.
418
.. ## Surface.get_at_mapped ##
420
.. method:: get_palette
422
| :sl:`get the color index palette for an 8bit Surface`
423
| :sg:`get_palette() -> [RGB, RGB, RGB, ...]`
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.
429
Returning a list of ``Color(with length 3)`` instances instead of tuples,
432
.. ## Surface.get_palette ##
434
.. method:: get_palette_at
436
| :sl:`get the color for a single entry in a palette`
437
| :sg:`get_palette_at(index) -> RGB`
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.
442
Returning ``Color(with length 3)`` instance instead of a tuple, New in
445
.. ## Surface.get_palette_at ##
447
.. method:: set_palette
449
| :sl:`set the color palette for an 8bit Surface`
450
| :sg:`set_palette([RGB, RGB, RGB, ...]) -> None`
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.
456
This function has no effect on a Surface with more than 8bits per pixel.
458
.. ## Surface.set_palette ##
460
.. method:: set_palette_at
462
| :sl:`set the color for a single index in an 8bit Surface palette`
463
| :sg:`set_palette_at(index, RGB) -> None`
465
Set the palette value for a single entry in a Surface palette. The index
466
should be a value from 0 to 255.
468
This function has no effect on a Surface with more than 8bits per pixel.
470
.. ## Surface.set_palette_at ##
474
| :sl:`convert a color into a mapped color value`
475
| :sg:`map_rgb(Color) -> mapped_int`
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.
482
See the Surface object documentation for more information about colors
485
.. ## Surface.map_rgb ##
487
.. method:: unmap_rgb
489
| :sl:`convert a mapped integer color value into a Color`
490
| :sg:`unmap_rgb(mapped_int) -> Color`
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.
496
See the Surface object documentation for more information about colors
499
.. ## Surface.unmap_rgb ##
503
| :sl:`set the current clipping area of the Surface`
504
| :sg:`set_clip(rect) -> None`
505
| :sg:`set_clip(None) -> None`
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
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
516
.. ## Surface.set_clip ##
520
| :sl:`get the current clipping area of the Surface`
521
| :sg:`get_clip() -> Rect`
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.
528
.. ## Surface.get_clip ##
530
.. method:: subsurface
532
| :sl:`create a new surface that references its parent`
533
| :sg:`subsurface(Rect) -> Surface`
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.
540
The new Surface will inherit the palette, color key, and alpha settings
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.
547
See the ``Surface.get_offset()``, ``Surface.get_parent()`` to learn more
548
about the state of a subsurface.
550
.. ## Surface.subsurface ##
552
.. method:: get_parent
554
| :sl:`find the parent of a subsurface`
555
| :sg:`get_parent() -> Surface`
557
Returns the parent Surface of a subsurface. If this is not a subsurface
558
then None will be returned.
560
.. ## Surface.get_parent ##
562
.. method:: get_abs_parent
564
| :sl:`find the top level parent of a subsurface`
565
| :sg:`get_abs_parent() -> Surface`
567
Returns the parent Surface of a subsurface. If this is not a subsurface
568
then this surface will be returned.
570
.. ## Surface.get_abs_parent ##
572
.. method:: get_offset
574
| :sl:`find the position of a child subsurface inside a parent`
575
| :sg:`get_offset() -> (x, y)`
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).
580
.. ## Surface.get_offset ##
582
.. method:: get_abs_offset
584
| :sl:`find the absolute position of a child subsurface inside its top level parent`
585
| :sg:`get_abs_offset() -> (x, y)`
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,
591
.. ## Surface.get_abs_offset ##
595
| :sl:`get the dimensions of the Surface`
596
| :sg:`get_size() -> (width, height)`
598
Return the width and height of the Surface in pixels.
600
.. ## Surface.get_size ##
602
.. method:: get_width
604
| :sl:`get the width of the Surface`
605
| :sg:`get_width() -> width`
607
Return the width of the Surface in pixels.
609
.. ## Surface.get_width ##
611
.. method:: get_height
613
| :sl:`get the height of the Surface`
614
| :sg:`get_height() -> height`
616
Return the height of the Surface in pixels.
618
.. ## Surface.get_height ##
622
| :sl:`get the rectangular area of the Surface`
623
| :sg:`get_rect(**kwargs) -> Rect`
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.
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.
633
.. ## Surface.get_rect ##
635
.. method:: get_bitsize
637
| :sl:`get the bit depth of the Surface pixel format`
638
| :sg:`get_bitsize() -> int`
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.
644
.. ## Surface.get_bitsize ##
646
.. method:: get_bytesize
648
| :sl:`get the bytes used per Surface pixel`
649
| :sg:`get_bytesize() -> int`
651
Return the number of bytes used per pixel.
653
.. ## Surface.get_bytesize ##
655
.. method:: get_flags
657
| :sl:`get the additional flags used for the Surface`
658
| :sg:`get_flags() -> int`
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``.
664
Here is a more complete list of flags. A full list can be found in
669
SWSURFACE 0x00000000 # Surface is in system memory
670
HWSURFACE 0x00000001 # Surface is in video memory
671
ASYNCBLIT 0x00000004 # Use asynchronous blits if possible
673
Available for ``pygame.display.set_mode()``
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
687
Used internally (read-only)
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
698
.. ## Surface.get_flags ##
700
.. method:: get_pitch
702
| :sl:`get the number of bytes used per Surface row`
703
| :sg:`get_pitch() -> int`
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.
709
This value is not needed for normal Pygame usage.
711
.. ## Surface.get_pitch ##
713
.. method:: get_masks
715
| :sl:`the bitmasks needed to convert between a color and a mapped integer`
716
| :sg:`get_masks() -> (R, G, B, A)`
718
Returns the bitmasks used to isolate each color in a mapped integer.
720
This value is not needed for normal Pygame usage.
722
.. ## Surface.get_masks ##
724
.. method:: set_masks
726
| :sl:`set the bitmasks needed to convert between a color and a mapped integer`
727
| :sg:`set_masks((r,g,b,a)) -> None`
729
This is not needed for normal Pygame usage. New in pygame 1.8.1
731
.. ## Surface.set_masks ##
733
.. method:: get_shifts
735
| :sl:`the bit shifts needed to convert between a color and a mapped integer`
736
| :sg:`get_shifts() -> (R, G, B, A)`
738
Returns the pixel shifts need to convert between each color and a mapped
741
This value is not needed for normal Pygame usage.
743
.. ## Surface.get_shifts ##
745
.. method:: set_shifts
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`
750
This is not needed for normal Pygame usage. New in pygame 1.8.1
752
.. ## Surface.set_shifts ##
754
.. method:: get_losses
756
| :sl:`the significant bits used to convert between a color and a mapped integer`
757
| :sg:`get_losses() -> (R, G, B, A)`
759
Return the least significant number of bits stripped from each color in a
762
This value is not needed for normal Pygame usage.
764
.. ## Surface.get_losses ##
766
.. method:: get_bounding_rect
768
| :sl:`find the smallest rect containing data`
769
| :sg:`get_bounding_rect(min_alpha = 1) -> Rect`
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
775
This function will temporarily lock and unlock the Surface as needed.
779
.. ## Surface.get_bounding_rect ##
783
| :sl:`return a view of a surface's pixel data.`
784
| :sg:`get_view(kind='2') -> <view>`
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
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'.
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.
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.
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'.
811
This method implicitly locks the Surface. The lock will be released, once
812
the returned view object is deleted.
816
.. ## Surface.get_view ##
818
.. method:: get_buffer
820
| :sl:`acquires a buffer object for the pixels of the Surface.`
821
| :sg:`get_buffer() -> BufferProxy`
823
Return a buffer object for the pixels of the Surface. The buffer can be
824
used for direct pixel access and manipulation.
826
This method implicitly locks the Surface. The lock will be released, once
827
the returned BufferProxy object is deleted.
831
.. ## Surface.get_buffer ##
833
.. ## pygame.Surface ##