annotate src/transform.doc @ 1849:301bc61643a9 math_module

merged changes from trunk
author lorenz
date Mon, 16 Nov 2009 18:31:40 +0000
parents 3e6eb68af370
children 517f55dc5a8c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
627
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
1 pygame.transform
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
2 pygame module to transform surfaces
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
3
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
4 A Surface transform is an operation that moves or resizes the pixels. All
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
5 these functions take a Surface to operate on and return a new Surface with
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
6 the results.
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
7
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
8 Some of the transforms are considered destructive. These means every time
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
9 they are performed they lose pixel data. Common examples of this are resizing
629
85f2ac863647 documentation revisions from Dan Richter
pygame
parents: 627
diff changeset
10 and rotating. For this reason, it is better to retransform the original surface than to
85f2ac863647 documentation revisions from Dan Richter
pygame
parents: 627
diff changeset
11 keep transforming an image multiple times. (For example, suppose you are animating
85f2ac863647 documentation revisions from Dan Richter
pygame
parents: 627
diff changeset
12 a bouncing spring which expands and contracts. If you applied the size changes
85f2ac863647 documentation revisions from Dan Richter
pygame
parents: 627
diff changeset
13 incrementally to the previous images, you would lose detail. Instead, always
85f2ac863647 documentation revisions from Dan Richter
pygame
parents: 627
diff changeset
14 begin with the original image and scale to the desired size.)
627
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
15 <SECTION>
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
16
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
17
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
18
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
19 flip
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
20 flip vertically and horizontally
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
21 pygame.transform.flip(Surface, xbool, ybool): return Surface
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
22
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
23 This can flip a Surface either vertically, horizontally, or both. Flipping
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
24 a Surface is nondestructive and returns a new Surface with the same dimensions.
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
25 <END>
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
26
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
27
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
28
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
29 scale
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
30 resize to new resolution
740
bc4b1b23d8c9 Added support to transform.scale and transform.scale2x so that a destination
Rene Dudfield <renesd@gmail.com>
parents: 696
diff changeset
31 pygame.transform.scale(Surface, (width, height), DestSurface = None): return Surface
627
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
32
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
33 Resizes the Surface to a new resolution. This is a fast scale operation
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
34 that does not sample the results.
740
bc4b1b23d8c9 Added support to transform.scale and transform.scale2x so that a destination
Rene Dudfield <renesd@gmail.com>
parents: 696
diff changeset
35
bc4b1b23d8c9 Added support to transform.scale and transform.scale2x so that a destination
Rene Dudfield <renesd@gmail.com>
parents: 696
diff changeset
36 An optional destination surface can be used, rather than have it create
bc4b1b23d8c9 Added support to transform.scale and transform.scale2x so that a destination
Rene Dudfield <renesd@gmail.com>
parents: 696
diff changeset
37 a new one. This is quicker if you want to repeatedly scale something.
bc4b1b23d8c9 Added support to transform.scale and transform.scale2x so that a destination
Rene Dudfield <renesd@gmail.com>
parents: 696
diff changeset
38 However the destination must be the same size as the (width, height) passed
bc4b1b23d8c9 Added support to transform.scale and transform.scale2x so that a destination
Rene Dudfield <renesd@gmail.com>
parents: 696
diff changeset
39 in. Also the destination surface must be the same format.
627
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
40 <END>
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
41
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
42
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
43
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
44 rotate
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
45 rotate an image
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
46 pygame.transform.rotate(Surface, angle): return Surface
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
47
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
48 Unfiltered counterclockwise rotation. The angle argument represents degrees
629
85f2ac863647 documentation revisions from Dan Richter
pygame
parents: 627
diff changeset
49 and can be any floating point value. Negative angle amounts will rotate
627
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
50 clockwise.
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
51
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
52 Unless rotating by 90 degree increments, the image will be padded larger
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
53 to hold the new size. If the image has pixel alphas, the padded area will
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
54 be transparent. Otherwise pygame will pick a color that matches the Surface
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
55 colorkey or the topleft pixel value.
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
56 <END>
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
57
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
58
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
59
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
60 rotozoom
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
61 filtered scale and rotation
696
cc66586f274d some changes from doc comments on website.
Rene Dudfield <renesd@gmail.com>
parents: 629
diff changeset
62 pygame.transform.rotozoom(Surface, angle, scale): return Surface
627
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
63
629
85f2ac863647 documentation revisions from Dan Richter
pygame
parents: 627
diff changeset
64 This is a combined scale and rotation transform. The resulting Surface will
85f2ac863647 documentation revisions from Dan Richter
pygame
parents: 627
diff changeset
65 be a filtered 32-bit Surface. The scale argument is a floating point value
627
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
66 that will be multiplied by the current resolution. The angle argument is
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
67 a floating point value that represents the counterclockwise degrees to
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
68 rotate. A negative rotation angle will rotate clockwise.
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
69 <END>
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
70
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
71
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
72
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
73 scale2x
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
74 specialized image doubler
740
bc4b1b23d8c9 Added support to transform.scale and transform.scale2x so that a destination
Rene Dudfield <renesd@gmail.com>
parents: 696
diff changeset
75 pygame.transform.scale2x(Surface, DestSurface = None): Surface
627
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
76
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
77 This will return a new image that is double the size of the original. It uses
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
78 the AdvanceMAME Scale2X algorithm which does a 'jaggie-less' scale of bitmap
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
79 graphics.
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
80
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
81 This really only has an effect on simple images with solid colors. On
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
82 photographic and antialiased images it will look like a regular unfiltered
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
83 scale.
740
bc4b1b23d8c9 Added support to transform.scale and transform.scale2x so that a destination
Rene Dudfield <renesd@gmail.com>
parents: 696
diff changeset
84
bc4b1b23d8c9 Added support to transform.scale and transform.scale2x so that a destination
Rene Dudfield <renesd@gmail.com>
parents: 696
diff changeset
85 An optional destination surface can be used, rather than have it create
bc4b1b23d8c9 Added support to transform.scale and transform.scale2x so that a destination
Rene Dudfield <renesd@gmail.com>
parents: 696
diff changeset
86 a new one. This is quicker if you want to repeatedly scale something.
bc4b1b23d8c9 Added support to transform.scale and transform.scale2x so that a destination
Rene Dudfield <renesd@gmail.com>
parents: 696
diff changeset
87 However the destination must be twice the size of the source surface passed
bc4b1b23d8c9 Added support to transform.scale and transform.scale2x so that a destination
Rene Dudfield <renesd@gmail.com>
parents: 696
diff changeset
88 in. Also the destination surface must be the same format.
627
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
89 <END>
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
90
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
91
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
92
834
714963434e23 Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents: 740
diff changeset
93 smoothscale
714963434e23 Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents: 740
diff changeset
94 scale a surface to an arbitrary size smoothly
714963434e23 Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents: 740
diff changeset
95 pygame.transform.smoothscale(Surface, (width, height), DestSurface = None): return Surface
714963434e23 Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents: 740
diff changeset
96
714963434e23 Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents: 740
diff changeset
97 Uses one of two different algorithms for scaling each
714963434e23 Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents: 740
diff changeset
98 dimension of the input surface as required. For shrinkage,
714963434e23 Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents: 740
diff changeset
99 the output pixels are area averages of the colors they
714963434e23 Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents: 740
diff changeset
100 cover. For expansion, a bilinear filter is used. For the
714963434e23 Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents: 740
diff changeset
101 amd64 and i686 architectures, optimized MMX routines are
714963434e23 Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents: 740
diff changeset
102 included and will run much faster than other machine types.
714963434e23 Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents: 740
diff changeset
103 The size is a 2 number sequence for (width, height). This
714963434e23 Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents: 740
diff changeset
104 function only works for 24-bit or 32-bit surfaces. An
714963434e23 Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents: 740
diff changeset
105 exception will be thrown if the input surface bit depth is
714963434e23 Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents: 740
diff changeset
106 less than 24.
714963434e23 Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents: 740
diff changeset
107
714963434e23 Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents: 740
diff changeset
108 New in pygame 1.8
714963434e23 Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents: 740
diff changeset
109 <END>
714963434e23 Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents: 740
diff changeset
110
714963434e23 Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents: 740
diff changeset
111
714963434e23 Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents: 740
diff changeset
112
1363
b56766170e70 color and transform doc updates
Lenard Lindstrom <len-l@telus.net>
parents: 1360
diff changeset
113 get_smoothscale_backend
b56766170e70 color and transform doc updates
Lenard Lindstrom <len-l@telus.net>
parents: 1360
diff changeset
114 return smoothscale filter version in use: 'GENERIC', 'MMX', or 'SSE'
b56766170e70 color and transform doc updates
Lenard Lindstrom <len-l@telus.net>
parents: 1360
diff changeset
115 pygame.transform.get_smoothscale_backend(): return String
b56766170e70 color and transform doc updates
Lenard Lindstrom <len-l@telus.net>
parents: 1360
diff changeset
116
b56766170e70 color and transform doc updates
Lenard Lindstrom <len-l@telus.net>
parents: 1360
diff changeset
117 Shows whether or not smoothscale is using MMX or SSE acceleration.
b56766170e70 color and transform doc updates
Lenard Lindstrom <len-l@telus.net>
parents: 1360
diff changeset
118 If no acceleration is available then "GENERIC" is returned. For a
b56766170e70 color and transform doc updates
Lenard Lindstrom <len-l@telus.net>
parents: 1360
diff changeset
119 x86 processor the level of acceleration to use is determined at
b56766170e70 color and transform doc updates
Lenard Lindstrom <len-l@telus.net>
parents: 1360
diff changeset
120 runtime.
1367
4be2e6337c3f add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents: 1363
diff changeset
121
4be2e6337c3f add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents: 1363
diff changeset
122 This function is provided for Pygame testing and debugging.
4be2e6337c3f add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents: 1363
diff changeset
123 <END>
4be2e6337c3f add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents: 1363
diff changeset
124
4be2e6337c3f add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents: 1363
diff changeset
125
4be2e6337c3f add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents: 1363
diff changeset
126
4be2e6337c3f add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents: 1363
diff changeset
127 set_smoothscale_backend
4be2e6337c3f add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents: 1363
diff changeset
128 set smoothscale filter version to one of: 'GENERIC', 'MMX', or 'SSE'
4be2e6337c3f add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents: 1363
diff changeset
129 pygame.transform.get_smoothscale_backend(type): return None
4be2e6337c3f add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents: 1363
diff changeset
130
4be2e6337c3f add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents: 1363
diff changeset
131 Sets smoothscale acceleration. Takes a string argument. A value
4be2e6337c3f add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents: 1363
diff changeset
132 of 'GENERIC' turns off acceleration. 'MMX' uses MMX instructions
4be2e6337c3f add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents: 1363
diff changeset
133 only. 'SSE' allows SSE extensions as well. A value error is raised
4be2e6337c3f add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents: 1363
diff changeset
134 if type is not recognized or not supported by the current processor.
4be2e6337c3f add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents: 1363
diff changeset
135
4be2e6337c3f add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents: 1363
diff changeset
136 This function is provided for Pygame testing and debugging. If
4be2e6337c3f add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents: 1363
diff changeset
137 smoothscale causes an invalid instruction error then it is a
4be2e6337c3f add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents: 1363
diff changeset
138 Pygame/SDL bug that should be reported. Use this function as a
4be2e6337c3f add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents: 1363
diff changeset
139 temporary fix only.
1363
b56766170e70 color and transform doc updates
Lenard Lindstrom <len-l@telus.net>
parents: 1360
diff changeset
140 <END>
b56766170e70 color and transform doc updates
Lenard Lindstrom <len-l@telus.net>
parents: 1360
diff changeset
141
b56766170e70 color and transform doc updates
Lenard Lindstrom <len-l@telus.net>
parents: 1360
diff changeset
142
b56766170e70 color and transform doc updates
Lenard Lindstrom <len-l@telus.net>
parents: 1360
diff changeset
143
627
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
144 chop
934
d3b1773c8422 Fixing up some minor doc stuff
brian
parents: 902
diff changeset
145 gets a copy of an image with an interior area removed
627
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
146 pygame.transform.chop(Surface, rect): return Surface
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
147
629
85f2ac863647 documentation revisions from Dan Richter
pygame
parents: 627
diff changeset
148 Extracts a portion of an image. All vertical and
934
d3b1773c8422 Fixing up some minor doc stuff
brian
parents: 902
diff changeset
149 horizontal pixels surrounding the given rectangle area are removed.
d3b1773c8422 Fixing up some minor doc stuff
brian
parents: 902
diff changeset
150 The corner areas (diagonal to the rect) are then brought together.
629
85f2ac863647 documentation revisions from Dan Richter
pygame
parents: 627
diff changeset
151 (The original image is not altered by this operation.)
934
d3b1773c8422 Fixing up some minor doc stuff
brian
parents: 902
diff changeset
152
d3b1773c8422 Fixing up some minor doc stuff
brian
parents: 902
diff changeset
153 NOTE: If you want a "crop" that returns the part of an image within
d3b1773c8422 Fixing up some minor doc stuff
brian
parents: 902
diff changeset
154 a rect, you can blit with a rect to a new surface or copy a subsurface.
627
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
155 <END>
862
57ac2edacc4d Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents: 834
diff changeset
156
57ac2edacc4d Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents: 834
diff changeset
157
57ac2edacc4d Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents: 834
diff changeset
158
57ac2edacc4d Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents: 834
diff changeset
159 laplacian
57ac2edacc4d Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents: 834
diff changeset
160 find edges in a surface
57ac2edacc4d Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents: 834
diff changeset
161 pygame.transform.laplacian(Surface, DestSurface = None): return Surface
57ac2edacc4d Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents: 834
diff changeset
162
57ac2edacc4d Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents: 834
diff changeset
163 Finds the edges in a surface using the laplacian algorithm.
934
d3b1773c8422 Fixing up some minor doc stuff
brian
parents: 902
diff changeset
164
d3b1773c8422 Fixing up some minor doc stuff
brian
parents: 902
diff changeset
165 New in pygame 1.8
627
18b5fa9180bf new reference documentation system
pygame
parents:
diff changeset
166 <END>
862
57ac2edacc4d Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents: 834
diff changeset
167
57ac2edacc4d Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents: 834
diff changeset
168
57ac2edacc4d Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents: 834
diff changeset
169
57ac2edacc4d Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents: 834
diff changeset
170 average_surfaces
57ac2edacc4d Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents: 834
diff changeset
171 find the average surface from many surfaces.
1813
3e6eb68af370 Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents: 1367
diff changeset
172 pygame.transform.average_surfaces(Surfaces, DestSurface = None, palette_colors = 1): return Surface
862
57ac2edacc4d Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents: 834
diff changeset
173
57ac2edacc4d Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents: 834
diff changeset
174 Takes a sequence of surfaces and returns a surface with average colors from each
57ac2edacc4d Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents: 834
diff changeset
175 of the surfaces.
934
d3b1773c8422 Fixing up some minor doc stuff
brian
parents: 902
diff changeset
176
1813
3e6eb68af370 Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents: 1367
diff changeset
177 palette_colors - if true we average the colors in palette, otherwise we
3e6eb68af370 Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents: 1367
diff changeset
178 average the pixel values. This is useful if the surface is actually greyscale
3e6eb68af370 Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents: 1367
diff changeset
179 colors, and not palette colors.
3e6eb68af370 Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents: 1367
diff changeset
180
3e6eb68af370 Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents: 1367
diff changeset
181 Note, this function currently does not handle palette using surfaces correctly.
3e6eb68af370 Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents: 1367
diff changeset
182
934
d3b1773c8422 Fixing up some minor doc stuff
brian
parents: 902
diff changeset
183 New in pygame 1.8
1813
3e6eb68af370 Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents: 1367
diff changeset
184 palette_colors argument new in pygame 1.9
862
57ac2edacc4d Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents: 834
diff changeset
185 <END>
57ac2edacc4d Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents: 834
diff changeset
186
1813
3e6eb68af370 Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents: 1367
diff changeset
187
3e6eb68af370 Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents: 1367
diff changeset
188
1264
eeaeedcd46b8 transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents: 1221
diff changeset
189 average_color
eeaeedcd46b8 transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents: 1221
diff changeset
190 finds the average color of a surface
eeaeedcd46b8 transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents: 1221
diff changeset
191 pygame.transform.average_color(Surface, Rect = None): return Color
862
57ac2edacc4d Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents: 834
diff changeset
192
1264
eeaeedcd46b8 transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents: 1221
diff changeset
193 Finds the average color of a Surface or a region of a surface specified by a
eeaeedcd46b8 transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents: 1221
diff changeset
194 Rect, and returns it as a Color.
eeaeedcd46b8 transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents: 1221
diff changeset
195 <END>
862
57ac2edacc4d Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents: 834
diff changeset
196
1813
3e6eb68af370 Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents: 1367
diff changeset
197
3e6eb68af370 Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents: 1367
diff changeset
198
862
57ac2edacc4d Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents: 834
diff changeset
199 threshold
57ac2edacc4d Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents: 834
diff changeset
200 finds which, and how many pixels in a surface are within a threshold of a color.
1360
7b18b561457f Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents: 1264
diff changeset
201 pygame.transform.threshold(DestSurface, Surface, color, threshold = (0,0,0,0), diff_color = (0,0,0,0), change_return = 1, Surface = None, inverse = False): return num_threshold_pixels
862
57ac2edacc4d Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents: 834
diff changeset
202
1264
eeaeedcd46b8 transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents: 1221
diff changeset
203 Finds which, and how many pixels in a surface are within a threshold of a color.
862
57ac2edacc4d Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents: 834
diff changeset
204
57ac2edacc4d Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents: 834
diff changeset
205 It can set the destination surface where all of the pixels not within the
1264
eeaeedcd46b8 transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents: 1221
diff changeset
206 threshold are changed to diff_color. If inverse is optionally set to True, the
eeaeedcd46b8 transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents: 1221
diff changeset
207 pixels that are within the threshold are instead changed to diff_color.
eeaeedcd46b8 transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents: 1221
diff changeset
208
eeaeedcd46b8 transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents: 1221
diff changeset
209 If the optional second surface is given, it is used to threshold against
eeaeedcd46b8 transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents: 1221
diff changeset
210 rather than the specified color. That is, it will find each pixel in the first
eeaeedcd46b8 transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents: 1221
diff changeset
211 Surface that is within the threshold of the pixel at the same coordinates of
1360
7b18b561457f Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents: 1264
diff changeset
212 the second Surface.
7b18b561457f Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents: 1264
diff changeset
213
7b18b561457f Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents: 1264
diff changeset
214 If change_return is set to 0, it can be used to just count the number of
7b18b561457f Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents: 1264
diff changeset
215 pixels within the threshold if you set
862
57ac2edacc4d Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents: 834
diff changeset
216
1360
7b18b561457f Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents: 1264
diff changeset
217 If change_return is set to 1, the pixels set in DestSurface will be
7b18b561457f Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents: 1264
diff changeset
218 those from the color.
7b18b561457f Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents: 1264
diff changeset
219
7b18b561457f Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents: 1264
diff changeset
220 If change_return is set to 2, the pixels set in DestSurface will be
7b18b561457f Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents: 1264
diff changeset
221 those from the first Surface.
862
57ac2edacc4d Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents: 834
diff changeset
222
57ac2edacc4d Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents: 834
diff changeset
223 You can use a threshold of (r,g,b,a) where the r,g,b can have different thresholds. So
57ac2edacc4d Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents: 834
diff changeset
224 you could use an r threshold of 40 and a blue threshold of 2 if you like.
934
d3b1773c8422 Fixing up some minor doc stuff
brian
parents: 902
diff changeset
225
d3b1773c8422 Fixing up some minor doc stuff
brian
parents: 902
diff changeset
226 New in pygame 1.8
862
57ac2edacc4d Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents: 834
diff changeset
227 <END>
57ac2edacc4d Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents: 834
diff changeset
228 <END>