File: surfarray.rst

package info (click to toggle)
pygame 1.9.4.post1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 10,412 kB
  • sloc: ansic: 54,632; python: 28,791; objc: 334; php: 92; sh: 76; makefile: 36; cpp: 25
file content (265 lines) | stat: -rw-r--r-- 9,060 bytes parent folder | download
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
.. include:: common.txt

:mod:`pygame.surfarray`
=======================

.. module:: pygame.surfarray
   :synopsis: pygame module for accessing surface pixel data using array interfaces

| :sl:`pygame module for accessing surface pixel data using array interfaces`

Functions to convert pixel data between pygame Surfaces and arrays. This module
will only be functional when pygame can use the external NumPy package.

Every pixel is stored as a single integer value to represent the red, green,
and blue colors. The 8-bit images use a value that looks into a colormap. Pixels
with higher depth use a bit packing process to place three or four values into
a single number.

The arrays are indexed by the ``X`` axis first, followed by the ``Y`` axis.
Arrays that treat the pixels as a single integer are referred to as 2D arrays.
This module can also separate the red, green, and blue color values into
separate indices. These types of arrays are referred to as 3D arrays, and the
last index is 0 for red, 1 for green, and 2 for blue.

.. function:: array2d

   | :sl:`Copy pixels into a 2d array`
   | :sg:`array2d(Surface) -> array`

   Copy the :meth:`mapped <pygame.Surface.map_rgb>` (raw) pixels from a Surface
   into a 2D array.
   The bit depth of the surface will control the size of the integer values,
   and will work for any type of pixel format.

   This function will temporarily lock the Surface as pixels are copied
   (see the :meth:`pygame.Surface.lock` - lock the Surface memory for pixel
   access method).

   .. ## pygame.surfarray.array2d ##

.. function:: pixels2d

   | :sl:`Reference pixels into a 2d array`
   | :sg:`pixels2d(Surface) -> array`

   Create a new 2D array that directly references the pixel values in a
   Surface. Any changes to the array will affect the pixels in the Surface.
   This is a fast operation since no data is copied.

   Pixels from a 24-bit Surface cannot be referenced, but all other Surface bit
   depths can.

   The Surface this references will remain locked for the lifetime of the array
   (see the :meth:`pygame.Surface.lock` - lock the Surface memory for pixel
   access method).

   .. ## pygame.surfarray.pixels2d ##

.. function:: array3d

   | :sl:`Copy pixels into a 3d array`
   | :sg:`array3d(Surface) -> array`

   Copy the pixels from a Surface into a 3D array. The bit depth of the surface
   will control the size of the integer values, and will work for any type of
   pixel format.

   This function will temporarily lock the Surface as pixels are copied (see
   the :meth:`pygame.Surface.lock` - lock the Surface memory for pixel
   access method).

   .. ## pygame.surfarray.array3d ##

.. function:: pixels3d

   | :sl:`Reference pixels into a 3d array`
   | :sg:`pixels3d(Surface) -> array`

   Create a new 3D array that directly references the pixel values in a
   Surface. Any changes to the array will affect the pixels in the Surface.
   This is a fast operation since no data is copied.

   This will only work on Surfaces that have 24-bit or 32-bit formats. Lower
   pixel formats cannot be referenced.

   The Surface this references will remain locked for the lifetime of the array
   (see the :meth:`pygame.Surface.lock` - lock the Surface memory for pixel
   access method).

   .. ## pygame.surfarray.pixels3d ##

.. function:: array_alpha

   | :sl:`Copy pixel alphas into a 2d array`
   | :sg:`array_alpha(Surface) -> array`

   Copy the pixel alpha values (degree of transparency) from a Surface into a
   2D array. This will work for any type of Surface format. Surfaces without a
   pixel alpha will return an array with all opaque values.

   This function will temporarily lock the Surface as pixels are copied (see
   the :meth:`pygame.Surface.lock` - lock the Surface memory for pixel
   access method).

   .. ## pygame.surfarray.array_alpha ##

.. function:: pixels_alpha

   | :sl:`Reference pixel alphas into a 2d array`
   | :sg:`pixels_alpha(Surface) -> array`

   Create a new 2D array that directly references the alpha values (degree of
   transparency) in a Surface. Any changes to the array will affect the pixels
   in the Surface. This is a fast operation since no data is copied.

   This can only work on 32-bit Surfaces with a per-pixel alpha value.

   The Surface this array references will remain locked for the lifetime of the
   array.

   .. ## pygame.surfarray.pixels_alpha ##

.. function:: pixels_red

   | :sl:`Reference pixel red into a 2d array.`
   | :sg:`pixels_red (Surface) -> array`

   Create a new 2D array that directly references the red values in a Surface.
   Any changes to the array will affect the pixels in the Surface. This is a
   fast operation since no data is copied.

   This can only work on 24-bit or 32-bit Surfaces.

   The Surface this array references will remain locked for the lifetime of the
   array.

   .. ## pygame.surfarray.pixels_red ##

.. function:: pixels_green

   | :sl:`Reference pixel green into a 2d array.`
   | :sg:`pixels_green (Surface) -> array`

   Create a new 2D array that directly references the green values in a
   Surface. Any changes to the array will affect the pixels in the Surface.
   This is a fast operation since no data is copied.

   This can only work on 24-bit or 32-bit Surfaces.

   The Surface this array references will remain locked for the lifetime of the
   array.

   .. ## pygame.surfarray.pixels_green ##

.. function:: pixels_blue

   | :sl:`Reference pixel blue into a 2d array.`
   | :sg:`pixels_blue (Surface) -> array`

   Create a new 2D array that directly references the blue values in a Surface.
   Any changes to the array will affect the pixels in the Surface. This is a
   fast operation since no data is copied.

   This can only work on 24-bit or 32-bit Surfaces.

   The Surface this array references will remain locked for the lifetime of the
   array.

   .. ## pygame.surfarray.pixels_blue ##

.. function:: array_colorkey

   | :sl:`Copy the colorkey values into a 2d array`
   | :sg:`array_colorkey(Surface) -> array`

   Create a new array with the colorkey transparency value from each pixel. If
   the pixel matches the colorkey it will be fully transparent; otherwise it
   will be fully opaque.

   This will work on any type of Surface format. If the image has no colorkey a
   solid opaque array will be returned.

   This function will temporarily lock the Surface as pixels are copied.

   .. ## pygame.surfarray.array_colorkey ##

.. function:: make_surface

   | :sl:`Copy an array to a new surface`
   | :sg:`make_surface(array) -> Surface`

   Create a new Surface that best resembles the data and format on the array.
   The array can be 2D or 3D with any sized integer values. Function
   make_surface uses the array struct interface to acquire array properties,
   so is not limited to just NumPy arrays. See :mod:`pygame.pixelcopy`.

   New in pygame 1.9.2: array struct interface support.

   .. ## pygame.surfarray.make_surface ##

.. function:: blit_array

   | :sl:`Blit directly from a array values`
   | :sg:`blit_array(Surface, array) -> None`

   Directly copy values from an array into a Surface. This is faster than
   converting the array into a Surface and blitting. The array must be the same
   dimensions as the Surface and will completely replace all pixel values. Only
   integer, ASCII character and record arrays are accepted.

   This function will temporarily lock the Surface as the new values are
   copied.

   .. ## pygame.surfarray.blit_array ##

.. function:: map_array

   | :sl:`Map a 3d array into a 2d array`
   | :sg:`map_array(Surface, array3d) -> array2d`

   Convert a 3D array into a 2D array. This will use the given Surface format
   to control the conversion. Palette surface formats are supported for NumPy
   arrays.

   .. ## pygame.surfarray.map_array ##

.. function:: use_arraytype

   | :sl:`Sets the array system to be used for surface arrays`
   | :sg:`use_arraytype (arraytype) -> None`

   DEPRECATED: Uses the requested array type for the module functions.
   The only supported arraytype is ``'numpy'``. Other values will raise
   ValueError.

   .. ## pygame.surfarray.use_arraytype ##

.. function:: get_arraytype

   | :sl:`Gets the currently active array type.`
   | :sg:`get_arraytype () -> str`

   DEPRECATED: Returns the currently active array type. This will be a value of the
   ``get_arraytypes()`` tuple and indicates which type of array module is used
   for the array creation.

   New in pygame 1.8

   .. ## pygame.surfarray.get_arraytype ##

.. function:: get_arraytypes

   | :sl:`Gets the array system types currently supported.`
   | :sg:`get_arraytypes () -> tuple`

   DEPRECATED: Checks, which array systems are available and returns them as a tuple of
   strings. The values of the tuple can be used directly in the
   :func:`pygame.surfarray.use_arraytype` () method. If no supported array
   system could be found, None will be returned.

   New in pygame 1.8.

   .. ## pygame.surfarray.get_arraytypes ##

.. ## pygame.surfarray ##