pygame / docs / Surface.html

  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
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
<html>
<title>Surface</title>
<body bgcolor=#dddddd text=#333377 link=#7777bb vlink=#7777bb>

<table border=0 width=100% cellpadding=0 cellspacing=0 bgcolor=#f5f5f5><tr valign=top>
<td rowspan=2 width=60%><table border=0 cellpadding=5 cellspacing=0 bgcolor=#333377>
<tr height=86 align=left><td valign=top><font color=#ffffff size=+5>
	<a href=../>
      <img src=mainlogo.gif width=300 height=100 alt="PyGame Logo" border=0></a></td>
<td valign=middle><tt><font color=#dddddd><br>
	PyGame<br>Documentation</font>
</td></tr></table></td><td width=100% height=100% align=center valign=middle>

	||&nbsp;
	<a href=../>Home</a> &nbsp;||&nbsp;
	<a href=index.html>Help Contents</a> &nbsp;||
	<br>&nbsp;<br>

|| <a href=CD.html>CD</a> || 
<a href=Channel.html>Channel</a> || 
<a href=Font.html>Font</a> || 
<a href=Joystick.html>Joystick</a> || 
<a href=Rect.html>Rect</a> ||<br>
|| <a href=Sound.html>Sound</a> || 
<a href=Surface.html>Surface</a> || 
<a href=pygame.html>pygame</a> || 
<a href=pygame_cdrom.html>cdrom</a> || 
<a href=pygame_display.html>display</a> ||<br>
|| <a href=pygame_event.html>event</a> || 
<a href=pygame_font.html>font</a> || 
<a href=pygame_image.html>image</a> || 
<a href=pygame_joystick.html>joystick</a> || 
<a href=pygame_key.html>key</a> ||<br>
|| <a href=pygame_mixer.html>mixer</a> || 
<a href=pygame_mouse.html>mouse</a> || 
<a href=pygame_music.html>music</a> || 
<a href=pygame_surfarray.html>surfarray</a> || 
<a href=pygame_time.html>time</a> ||<br>


</td></tr></table>
<br>
<h2 align=center>Surface</h2>
Contains the Surface object.

<hr>

<table>
<tr><td><a href=#blit>blit</a></td><td> -
copy a one Surface to another.</td></tr>


<tr><td><a href=#convert>convert</a></td><td> -
new copy of surface with different format</td></tr>


<tr><td><a href=#convert_alpha>convert_alpha</a></td><td> -
new copy of surface with different format and per pixel alpha</td></tr>


<tr><td><a href=#fill>fill</a></td><td> -
fill areas of a Surface</td></tr>


<tr><td><a href=#get_alpha>get_alpha</a></td><td> -
query alpha information</td></tr>


<tr><td><a href=#get_at>get_at</a></td><td> -
get a pixel color</td></tr>


<tr><td><a href=#get_bitsize>get_bitsize</a></td><td> -
query size of pixel</td></tr>


<tr><td><a href=#get_bytesize>get_bytesize</a></td><td> -
query size of pixel</td></tr>


<tr><td><a href=#get_clip>get_clip</a></td><td> -
query the clipping area</td></tr>


<tr><td><a href=#get_colorkey>get_colorkey</a></td><td> -
query colorkey</td></tr>


<tr><td><a href=#get_height>get_height</a></td><td> -
query the surface height</td></tr>


<tr><td><a href=#get_losses>get_losses</a></td><td> -
get mapping losses for each colorplane</td></tr>


<tr><td><a href=#get_masks>get_masks</a></td><td> -
get mapping bitmasks for each colorplane</td></tr>


<tr><td><a href=#get_palette>get_palette</a></td><td> -
get the palette</td></tr>


<tr><td><a href=#get_palette_at>get_palette_at</a></td><td> -
get a palette entry</td></tr>


<tr><td><a href=#get_rect>get_rect</a></td><td> -
get a rectangle covering the entire surface</td></tr>


<tr><td><a href=#get_shifts>get_shifts</a></td><td> -
get mapping shifts for each colorplane</td></tr>


<tr><td><a href=#get_size>get_size</a></td><td> -
query the surface size</td></tr>


<tr><td><a href=#get_width>get_width</a></td><td> -
query the surface width</td></tr>


<tr><td><a href=#lock>lock</a></td><td> -
locks Surface for pixel access</td></tr>


<tr><td><a href=#map_rgb>map_rgb</a></td><td> -
convert RGB into a mapped color</td></tr>


<tr><td><a href=#map_rgba>map_rgba</a></td><td> -
convert RGBA into a mapped color</td></tr>


<tr><td><a href=#mustlock>mustlock</a></td><td> -
check if the surface needs locking</td></tr>


<tr><td><a href=#set_alpha>set_alpha</a></td><td> -
change alpha information</td></tr>


<tr><td><a href=#set_at>set_at</a></td><td> -
set pixel at given position</td></tr>


<tr><td><a href=#set_clip>set_clip</a></td><td> -
assign destination clipping rectangle</td></tr>


<tr><td><a href=#set_colorkey>set_colorkey</a></td><td> -
change colorkey information</td></tr>


<tr><td><a href=#set_palette>set_palette</a></td><td> -
set the palette</td></tr>


<tr><td><a href=#set_palette_at>set_palette_at</a></td><td> -
set a palette entry</td></tr>


<tr><td><a href=#unlock>unlock</a></td><td> -
locks Surface for pixel access</td></tr>


<tr><td><a href=#unmap_rgb>unmap_rgb</a></td><td> -
convert mapped color into RGB</td></tr>


<tr><td><a href=#unmap_rgba>unmap_rgba</a></td><td> -
convert mapped color into RGBA</td></tr>


</table>

<hr>

<a name=blit><font size=+2><b>blit
</b></font><br><font size=+1><tt>
Surface.blit(source, destoffset, [srcoffset, [size]]) -> Rect
</tt></font><ul>
The blitting will transfer one surface to another.
It will respect any special modes like colorkeying
and alpha. If hardware support is available, it
will be used. The given source is the Surface to
copy from. The destoffset is a 2-number-sequence
that specifies where on the destination Surface
the blit happens. Without srcoffset and size
supplied, the blit will copy the entire source
surface. If you would like to copy only a portion
of the source, use the srcoffset and size
arguements to control what area is copied.

The blit is subject to be clipped by the active
clipping rectangle. The return value contains the
actual area blitted.
</ul><br>&nbsp;<br>

<a name=convert><font size=+2><b>convert
</b></font><br><font size=+1><tt>
Surface.convert([src_surface]) -> Surface
</tt></font><ul>
Creates a new copy of the surface with the desired
pixel format. Surfaces with the same pixel format
will blit much faster than those with mixed
formats. The pixel format of the new surface will
match the format given as the argument. If no
surface is given, the new surface will have the
same pixel format as the current display.
</ul><br>&nbsp;<br>

<a name=convert_alpha><font size=+2><b>convert_alpha
</b></font><br><font size=+1><tt>
Surface.convert_alpha([src_surface]) -> Surface
</tt></font><ul>
Creates a new copy of the surface with the desired
pixel format. The new surface will be in a format
suited for quick blitting to the given format with
per pixel alpha. If no surface is given, the new
surface will be optimized for blittint to the
current display.

Unlike the <a href=#convert>convert()</a> method, the pixel format for
the new image will not be exactly the same as the
requested source, but it will be optimized for
fast alpha blitting to the destination.
</ul><br>&nbsp;<br>

<a name=fill><font size=+2><b>fill
</b></font><br><font size=+1><tt>
Surface.fill(color, [rectstyle])) -> Rect
</tt></font><ul>
Fills the specified area of the Surface with the
mapped color value. If no destination rectangle is
supplied, it will fill the entire Surface.

The fill is subject to be clipped by the active
clipping rectangle. The return value contains the
actual area filled.
</ul><br>&nbsp;<br>

<a name=get_alpha><font size=+2><b>get_alpha
</b></font><br><font size=+1><tt>
Surface.get_alpha() -> alpha
</tt></font><ul>
Returns the current alpha value for the Surface.
If transparency is disabled for the Surface, it
returns None.
</ul><br>&nbsp;<br>

<a name=get_at><font size=+2><b>get_at
</b></font><br><font size=+1><tt>
Surface.get_at([x, y]) -> int
</tt></font><ul>
Returns the mapped pixel color at the coordinates
given point.
</ul><br>&nbsp;<br>

<a name=get_bitsize><font size=+2><b>get_bitsize
</b></font><br><font size=+1><tt>
Surface.get_bitsize() -> int
</tt></font><ul>
Returns the number of bits used to represent each
pixel. This value may not exactly fill the number
of bytes used per pixel. For example a 15 bit
Surface still requires a full 2 bytes.
</ul><br>&nbsp;<br>

<a name=get_bytesize><font size=+2><b>get_bytesize
</b></font><br><font size=+1><tt>
Surface.get_bytesize() -> int
</tt></font><ul>
Returns the number of bytes used to store each
pixel.
</ul><br>&nbsp;<br>

<a name=get_clip><font size=+2><b>get_clip
</b></font><br><font size=+1><tt>
Surface.get_clip() -> rect
</tt></font><ul>
Returns the current destination clipping area
being used by the Surface. If the clipping area is
not set, it will return a rectangle containing the
full Surface area.
</ul><br>&nbsp;<br>

<a name=get_colorkey><font size=+2><b>get_colorkey
</b></font><br><font size=+1><tt>
Surface.get_colorkey() -> color
</tt></font><ul>
Returns the current mapped color value being used
for colorkeying. If colorkeying is not enabled for
this surface, it returns None
</ul><br>&nbsp;<br>

<a name=get_height><font size=+2><b>get_height
</b></font><br><font size=+1><tt>
Surface.get_height() -> height
</tt></font><ul>
Returns the height of the Surface.
</ul><br>&nbsp;<br>

<a name=get_losses><font size=+2><b>get_losses
</b></font><br><font size=+1><tt>
Surface.get_losses() -> redloss, greenloss, blueloss, alphaloss
</tt></font><ul>
Returns the bitloss for each color plane. The loss
is the number of bits removed for each colorplane
from a full 8 bits of resolution. A value of 8
usually indicates that colorplane is not used
(like the alpha)
</ul><br>&nbsp;<br>

<a name=get_masks><font size=+2><b>get_masks
</b></font><br><font size=+1><tt>
Surface.get_masks() -> redmask, greenmask, bluemask, alphamask
</tt></font><ul>
Returns the bitmasks for each color plane. The
bitmask is used to isolate each colorplane value
from a mapped color value. A value of zero means
that colorplane is not used (like alpha)
</ul><br>&nbsp;<br>

<a name=get_palette><font size=+2><b>get_palette
</b></font><br><font size=+1><tt>
Surface.get_palette() -> [[r, g, b], ...]
</tt></font><ul>
This will return the an array of all the color
indexes in the Surface's palette.
</ul><br>&nbsp;<br>

<a name=get_palette_at><font size=+2><b>get_palette_at
</b></font><br><font size=+1><tt>
Surface.get_palette_at(index) -> r, g, b
</tt></font><ul>
This will retreive an individual color entry from
the Surface's palette.
</ul><br>&nbsp;<br>

<a name=get_rect><font size=+2><b>get_rect
</b></font><br><font size=+1><tt>
Surface.get_rect() -> rect
</tt></font><ul>
Returns a new rectangle covering the entire surface.
This rectangle will always start at 0, 0 with a width.
and height the same size as the image.
</ul><br>&nbsp;<br>

<a name=get_shifts><font size=+2><b>get_shifts
</b></font><br><font size=+1><tt>
Surface.get_shifts() -> redshift, greenshift, blueshift, alphashift
</tt></font><ul>
Returns the bitshifts used for each color plane.
The shift is determine how many bits left-shifted
a colorplane value is in a mapped color value.
</ul><br>&nbsp;<br>

<a name=get_size><font size=+2><b>get_size
</b></font><br><font size=+1><tt>
Surface.get_size() -> x, y
</tt></font><ul>
Returns the width and height of the Surface.
</ul><br>&nbsp;<br>

<a name=get_width><font size=+2><b>get_width
</b></font><br><font size=+1><tt>
Surface.get_width() -> width
</tt></font><ul>
Returns the width of the Surface.
</ul><br>&nbsp;<br>

<a name=lock><font size=+2><b>lock
</b></font><br><font size=+1><tt>
Surface.lock() -> None
</tt></font><ul>
On accelerated surfaces, it is usually required to
lock the surface before you can access the pixel
values. To be safe, it is always a good idea to
lock the surface before entering a block of code
that changes or accesses the pixel values. The
surface must not be locked when performing other
pyGame functions on it like fill and blit.

You can doublecheck to really make sure a lock is
needed by calling the <a href=#mustlock>mustlock()</a> member. This
should not be needed, since it is usually
recommended to lock anyways and work with all
surface types. If the surface does not need to be
locked, the operation will return quickly with
minute overhead.

On some platforms a necessary lock can shut off
some parts of the system. This is not a problem
unless you leave surfaces locked for long periouds
of time. Only keep the surface locked when you
need the pixel access. At the same time, it is not
a good too repeatedly lock and unlock the surface
inside tight loops. It is fine to leave the
surface locked while needed, just don't be lazy.
</ul><br>&nbsp;<br>

<a name=map_rgb><font size=+2><b>map_rgb
</b></font><br><font size=+1><tt>
Surface.map_rgb([r, g, b]) -> int
</tt></font><ul>
Uses the Surface format to convert RGB into a
mapped color value. Note that this will work if
the RGB is passed as three arguments instead of a
sequence.
</ul><br>&nbsp;<br>

<a name=map_rgba><font size=+2><b>map_rgba
</b></font><br><font size=+1><tt>
Surface.map_rgba([r, g, b, a]) -> int
</tt></font><ul>
Uses the Surface format to convert RGBA into a
mapped color value. It is safe to call this on a
surface with no pixel alpha. The alpha will simply
be ignored.
</ul><br>&nbsp;<br>

<a name=mustlock><font size=+2><b>mustlock
</b></font><br><font size=+1><tt>
Surface.mustlock() -> bool
</tt></font><ul>
Returns true if the surface really does need
locking to gain pixel access. Usually the overhead
of checking before locking outweight the overhead
of just locking any surface before access.
</ul><br>&nbsp;<br>

<a name=set_alpha><font size=+2><b>set_alpha
</b></font><br><font size=+1><tt>
Surface.set_alpha([alpha, [flags]]) -> None
</tt></font><ul>
Set the overall transparency for the surface. If
no alpha is passed, alpha blending is disabled for
the surface. An alpha of 0 is fully transparent,
an alpha of 255 is fully opaque.

If your surface has a pixel alpha channel, it will
override the overall surface transparency. You'll
need to change the actual pixel transparency to
make changes.

If your image is nonchanging and will be used
repeatedly, you will probably want to pass the
RLEACCEL flag to the call. This will take a short
time to compile your surface, and increase the
blitting speed.
</ul><br>&nbsp;<br>

<a name=set_at><font size=+2><b>set_at
</b></font><br><font size=+1><tt>
Surface.set_at([x, y], pixel) -> None
</tt></font><ul>
Assigns a mapped pixel color to the image at the
give position.
</ul><br>&nbsp;<br>

<a name=set_clip><font size=+2><b>set_clip
</b></font><br><font size=+1><tt>
Surface.set_clip([rectstyle])) -> Rect
</tt></font><ul>
Assigns the destination clipping rectangle for the
Surface. When blit or fill operations are
performed on the Surface, they are restricted to
the inside of the clipping rectangle. If no
rectangle is passed, the clipping region is set to
the entire Surface area.
</ul><br>&nbsp;<br>

<a name=set_colorkey><font size=+2><b>set_colorkey
</b></font><br><font size=+1><tt>
Surface.set_colorkey([color, [flags]]) -> None
</tt></font><ul>
Set the colorkey for the surface by passing a
mapped color value as the color argument. If no
arguments are passed, colorkeying will be disabled
for this surface.

If your image is nonchanging and will be used
repeatedly, you will probably want to pass the
RLEACCEL flag to the call. This will take a short
time to compile your surface, and increase the
blitting speed.
</ul><br>&nbsp;<br>

<a name=set_palette><font size=+2><b>set_palette
</b></font><br><font size=+1><tt>
Surface.set_palette([[r, g, b], ...]) -> None
</tt></font><ul>
This will replace the entire palette with color
information you provide.
</ul><br>&nbsp;<br>

<a name=set_palette_at><font size=+2><b>set_palette_at
</b></font><br><font size=+1><tt>
Surface.set_palette_at(index, [r, g, b]) -> None
</tt></font><ul>
This function sets the palette color at a specific
entry.
</ul><br>&nbsp;<br>

<a name=unlock><font size=+2><b>unlock
</b></font><br><font size=+1><tt>
Surface.unlock() -> None
</tt></font><ul>
After a surface has been locked, you will need to
unlock it when you are done.

You can doublecheck to really make sure a lock is
needed by calling the <a href=#mustlock>mustlock()</a> member. This
should not be needed, since it is usually
recommended to lock anyways and work with all
surface types. If the surface does not need to be
locked, the operation will return quickly with
minute overhead.
</ul><br>&nbsp;<br>

<a name=unmap_rgb><font size=+2><b>unmap_rgb
</b></font><br><font size=+1><tt>
Surface.unmap_rgb(color) -> r, g, b
</tt></font><ul>
This function returns the RGB components for a
mapped color value.
</ul><br>&nbsp;<br>

<a name=unmap_rgba><font size=+2><b>unmap_rgba
</b></font><br><font size=+1><tt>
Surface.unmap_rgba(color) -> r, g, b, a
</tt></font><ul>
This function returns the RGB components for a
mapped color value. For surfaces with no alpha,
the alpha will always be 255.
</ul><br>&nbsp;<br>


<hr>

</body></html>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.