Mercurial > pygame
annotate src/transform.c @ 3194:9fcb7abf3185 default tip
Remove some gcc 4.7.2 compiler warnings
| author | Lenard Lindstrom <len-l@telus.net> |
|---|---|
| date | Tue, 23 Apr 2013 19:53:36 -0700 |
| parents | 0d661c00c1aa |
| children |
| rev | line source |
|---|---|
| 190 | 1 /* |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
2 pygame - Python Game Library |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
3 Copyright (C) 2000-2001 Pete Shinners |
|
834
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
4 Copyright (C) 2007 Rene Dudfield, Richard Goedeken |
| 190 | 5 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
6 This library is free software; you can redistribute it and/or |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
7 modify it under the terms of the GNU Library General Public |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
8 License as published by the Free Software Foundation; either |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
9 version 2 of the License, or (at your option) any later version. |
| 190 | 10 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
11 This library is distributed in the hope that it will be useful, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
14 Library General Public License for more details. |
| 190 | 15 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
16 You should have received a copy of the GNU Library General Public |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
17 License along with this library; if not, write to the Free |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 190 | 19 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
20 Pete Shinners |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
21 pete@shinners.org |
| 190 | 22 */ |
| 23 | |
| 24 /* | |
| 25 * surface transformations for pygame | |
| 26 */ | |
| 27 #include "pygame.h" | |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
28 #include "pgcompat.h" |
| 1937 | 29 #include "doc/transform_doc.h" |
| 217 | 30 #include <math.h> |
|
1367
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
31 #include <string.h> |
|
1330
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
32 #include "scale.h" |
|
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
33 |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
34 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
35 typedef void (* SMOOTHSCALE_FILTER_P)(Uint8 *, Uint8 *, int, int, int, int, int); |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
36 struct _module_state { |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
37 const char *filter_type; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
38 SMOOTHSCALE_FILTER_P filter_shrink_X; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
39 SMOOTHSCALE_FILTER_P filter_shrink_Y; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
40 SMOOTHSCALE_FILTER_P filter_expand_X; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
41 SMOOTHSCALE_FILTER_P filter_expand_Y; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
42 }; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
43 |
|
1330
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
44 #if defined(SCALE_MMX_SUPPORT) |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
45 |
|
1330
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
46 #include <SDL_cpuinfo.h> |
|
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
47 |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
48 #if PY3 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
49 #define GETSTATE(m) PY3_GETSTATE (_module_state, m) |
|
1330
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
50 #else |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
51 static struct _module_state _state = {0, 0, 0, 0, 0}; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
52 #define GETSTATE(m) PY2_GETSTATE (_state) |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
53 #endif |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
54 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
55 #else /* if defined(SCALE_MMX_SUPPORT) */ |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
56 |
|
1556
67457499ef4a
more code fixes to transform.c for non-MMX machines
Lenard Lindstrom <len-l@telus.net>
parents:
1555
diff
changeset
|
57 static void filter_shrink_X_ONLYC(Uint8 *, Uint8 *, int, int, int, int, int); |
|
67457499ef4a
more code fixes to transform.c for non-MMX machines
Lenard Lindstrom <len-l@telus.net>
parents:
1555
diff
changeset
|
58 static void filter_shrink_Y_ONLYC(Uint8 *, Uint8 *, int, int, int, int, int); |
|
67457499ef4a
more code fixes to transform.c for non-MMX machines
Lenard Lindstrom <len-l@telus.net>
parents:
1555
diff
changeset
|
59 static void filter_expand_X_ONLYC(Uint8 *, Uint8 *, int, int, int, int, int); |
|
67457499ef4a
more code fixes to transform.c for non-MMX machines
Lenard Lindstrom <len-l@telus.net>
parents:
1555
diff
changeset
|
60 static void filter_expand_Y_ONLYC(Uint8 *, Uint8 *, int, int, int, int, int); |
|
67457499ef4a
more code fixes to transform.c for non-MMX machines
Lenard Lindstrom <len-l@telus.net>
parents:
1555
diff
changeset
|
61 |
|
1555
4c60ee82ce2d
fix compiler error in transform.c for non-MMX machines
Lenard Lindstrom <len-l@telus.net>
parents:
1553
diff
changeset
|
62 static struct _module_state _state = { |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
63 "GENERIC", |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
64 filter_shrink_X_ONLYC, |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
65 filter_shrink_Y_ONLYC, |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
66 filter_expand_X_ONLYC, |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
67 filter_expand_Y_ONLYC}; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
68 #define GETSTATE(m) PY2_GETSTATE (_state) |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
69 #define smoothscale_init(st) |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
70 |
|
1330
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
71 #endif /* if defined(SCALE_MMX_SUPPORT) */ |
| 190 | 72 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
73 void scale2x (SDL_Surface *src, SDL_Surface *dst); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
74 extern SDL_Surface* rotozoomSurface (SDL_Surface *src, double angle, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
75 double zoom, int smooth); |
| 190 | 76 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
77 static SDL_Surface* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
78 newsurf_fromsurf (SDL_Surface* surf, int width, int height) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
79 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
80 SDL_Surface* newsurf; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
81 int result; |
| 190 | 82 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
83 if (surf->format->BytesPerPixel <= 0 || surf->format->BytesPerPixel > 4) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
84 return (SDL_Surface*) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
85 (RAISE (PyExc_ValueError, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
86 "unsupport Surface bit depth for transform")); |
| 190 | 87 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
88 newsurf = SDL_CreateRGBSurface (surf->flags, width, height, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
89 surf->format->BitsPerPixel, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
90 surf->format->Rmask, surf->format->Gmask, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
91 surf->format->Bmask, surf->format->Amask); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
92 if (!newsurf) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
93 return (SDL_Surface*) (RAISE (PyExc_SDLError, SDL_GetError ())); |
| 190 | 94 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
95 /* Copy palette, colorkey, etc info */ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
96 if (surf->format->BytesPerPixel==1 && surf->format->palette) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
97 SDL_SetColors (newsurf, surf->format->palette->colors, 0, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
98 surf->format->palette->ncolors); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
99 if (surf->flags & SDL_SRCCOLORKEY) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
100 SDL_SetColorKey (newsurf, (surf->flags&SDL_RLEACCEL) | SDL_SRCCOLORKEY, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
101 surf->format->colorkey); |
|
695
e9524b451579
Made the transform functions retain SRCALPHA stuff after transform.
Rene Dudfield <renesd@gmail.com>
parents:
627
diff
changeset
|
102 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
103 if (surf->flags&SDL_SRCALPHA) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
104 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
105 result = SDL_SetAlpha (newsurf, surf->flags, surf->format->alpha); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
106 if (result == -1) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
107 return (SDL_Surface*) (RAISE (PyExc_SDLError, SDL_GetError ())); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
108 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
109 return newsurf; |
| 190 | 110 } |
| 111 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
112 static SDL_Surface* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
113 rotate90 (SDL_Surface *src, int angle) |
| 321 | 114 { |
| 115 int numturns = (angle / 90) % 4; | |
| 116 int dstwidth, dstheight; | |
| 117 SDL_Surface* dst; | |
| 118 char *srcpix, *dstpix, *srcrow, *dstrow; | |
| 119 int srcstepx, srcstepy, dststepx, dststepy; | |
| 120 int loopx, loopy; | |
| 190 | 121 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
122 if (numturns < 0) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
123 numturns = 4 + numturns; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
124 if (!(numturns % 2)) |
| 321 | 125 { |
| 126 dstwidth = src->w; | |
| 127 dstheight = src->h; | |
| 128 } | |
| 129 else | |
| 130 { | |
| 131 dstwidth = src->h; | |
| 132 dstheight = src->w; | |
| 133 } | |
| 134 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
135 dst = newsurf_fromsurf (src, dstwidth, dstheight); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
136 if (!dst) |
| 321 | 137 return NULL; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
138 SDL_LockSurface (dst); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
139 srcrow = (char*) src->pixels; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
140 dstrow = (char*) dst->pixels; |
| 321 | 141 srcstepx = dststepx = src->format->BytesPerPixel; |
| 142 srcstepy = src->pitch; | |
| 143 dststepy = dst->pitch; | |
| 144 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
145 switch (numturns) |
| 321 | 146 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
147 /*case 0: we don't need to change anything*/ |
| 321 | 148 case 1: |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
149 srcrow += ((src->w - 1) * srcstepx); |
| 321 | 150 srcstepy = -srcstepx; |
| 151 srcstepx = src->pitch; | |
| 152 break; | |
| 153 case 2: | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
154 srcrow += ((src->h - 1) * srcstepy) + ((src->w - 1) * srcstepx); |
| 321 | 155 srcstepx = -srcstepx; |
| 156 srcstepy = -srcstepy; | |
| 157 break; | |
| 158 case 3: | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
159 srcrow += ((src->h - 1) * srcstepy); |
| 321 | 160 srcstepx = -srcstepy; |
| 161 srcstepy = src->format->BytesPerPixel; | |
| 162 break; | |
| 163 } | |
| 164 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
165 switch (src->format->BytesPerPixel) |
| 321 | 166 { |
| 167 case 1: | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
168 for (loopy = 0; loopy < dstheight; ++loopy) |
| 321 | 169 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
170 dstpix = dstrow; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
171 srcpix = srcrow; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
172 for (loopx = 0; loopx < dstwidth; ++loopx) |
| 321 | 173 { |
| 174 *dstpix = *srcpix; | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
175 srcpix += srcstepx; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
176 dstpix += dststepx; |
| 321 | 177 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
178 dstrow += dststepy; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
179 srcrow += srcstepy; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
180 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
181 break; |
| 321 | 182 case 2: |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
183 for (loopy = 0; loopy < dstheight; ++loopy) |
| 321 | 184 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
185 dstpix = dstrow; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
186 srcpix = srcrow; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
187 for (loopx = 0; loopx < dstwidth; ++loopx) |
| 321 | 188 { |
| 189 *(Uint16*)dstpix = *(Uint16*)srcpix; | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
190 srcpix += srcstepx; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
191 dstpix += dststepx; |
| 321 | 192 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
193 dstrow += dststepy; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
194 srcrow += srcstepy; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
195 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
196 break; |
| 321 | 197 case 3: |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
198 for (loopy = 0; loopy < dstheight; ++loopy) |
| 321 | 199 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
200 dstpix = dstrow; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
201 srcpix = srcrow; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
202 for (loopx = 0; loopx < dstwidth; ++loopx) |
| 321 | 203 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
204 dstpix[0] = srcpix[0]; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
205 dstpix[1] = srcpix[1]; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
206 dstpix[2] = srcpix[2]; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
207 srcpix += srcstepx; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
208 dstpix += dststepx; |
| 321 | 209 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
210 dstrow += dststepy; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
211 srcrow += srcstepy; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
212 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
213 break; |
| 321 | 214 case 4: |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
215 for (loopy = 0; loopy < dstheight; ++loopy) |
| 321 | 216 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
217 dstpix = dstrow; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
218 srcpix = srcrow; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
219 for (loopx = 0; loopx < dstwidth; ++loopx) |
| 321 | 220 { |
| 221 *(Uint32*)dstpix = *(Uint32*)srcpix; | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
222 srcpix += srcstepx; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
223 dstpix += dststepx; |
| 321 | 224 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
225 dstrow += dststepy; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
226 srcrow += srcstepy; |
| 341 | 227 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
228 break; |
| 321 | 229 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
230 SDL_UnlockSurface (dst); |
| 321 | 231 return dst; |
| 232 } | |
| 190 | 233 |
| 234 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
235 static void |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
236 rotate (SDL_Surface *src, SDL_Surface *dst, Uint32 bgcolor, double sangle, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
237 double cangle) |
| 190 | 238 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
239 int x, y, dx, dy; |
| 270 | 240 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
241 Uint8 *srcpix = (Uint8*) src->pixels; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
242 Uint8 *dstrow = (Uint8*) dst->pixels; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
243 int srcpitch = src->pitch; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
244 int dstpitch = dst->pitch; |
| 190 | 245 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
246 int cy = dst->h / 2; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
247 int xd = ((src->w - dst->w) << 15); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
248 int yd = ((src->h - dst->h) << 15); |
| 270 | 249 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
250 int isin = (int)(sangle * 65536); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
251 int icos = (int)(cangle * 65536); |
| 270 | 252 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
253 int ax = ((dst->w) << 15) - (int)(cangle * ((dst->w - 1) << 15)); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
254 int ay = ((dst->h) << 15) - (int)(sangle * ((dst->w - 1) << 15)); |
| 190 | 255 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
256 int xmaxval = ((src->w) << 16) - 1; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
257 int ymaxval = ((src->h) << 16) - 1; |
| 270 | 258 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
259 switch (src->format->BytesPerPixel) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
260 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
261 case 1: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
262 for (y = 0; y < dst->h; y++) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
263 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
264 Uint8 *dstpos = (Uint8*)dstrow; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
265 dx = (ax + (isin * (cy - y))) + xd; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
266 dy = (ay - (icos * (cy - y))) + yd; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
267 for (x = 0; x < dst->w; x++) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
268 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
269 if(dx < 0 || dy < 0 || dx > xmaxval || dy > ymaxval) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
270 *dstpos++ = bgcolor; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
271 else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
272 *dstpos++ = *(Uint8*) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
273 (srcpix + ((dy >> 16) * srcpitch) + (dx >> 16)); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
274 dx += icos; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
275 dy += isin; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
276 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
277 dstrow += dstpitch; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
278 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
279 break; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
280 case 2: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
281 for (y = 0; y < dst->h; y++) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
282 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
283 Uint16 *dstpos = (Uint16*)dstrow; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
284 dx = (ax + (isin * (cy - y))) + xd; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
285 dy = (ay - (icos * (cy - y))) + yd; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
286 for (x = 0; x < dst->w; x++) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
287 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
288 if (dx < 0 || dy < 0 || dx > xmaxval || dy > ymaxval) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
289 *dstpos++ = bgcolor; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
290 else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
291 *dstpos++ = *(Uint16*) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
292 (srcpix + ((dy >> 16) * srcpitch) + (dx >> 16 << 1)); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
293 dx += icos; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
294 dy += isin; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
295 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
296 dstrow += dstpitch; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
297 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
298 break; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
299 case 4: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
300 for (y = 0; y < dst->h; y++) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
301 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
302 Uint32 *dstpos = (Uint32*)dstrow; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
303 dx = (ax + (isin * (cy - y))) + xd; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
304 dy = (ay - (icos * (cy - y))) + yd; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
305 for (x = 0; x < dst->w; x++) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
306 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
307 if (dx < 0 || dy < 0 || dx > xmaxval || dy > ymaxval) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
308 *dstpos++ = bgcolor; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
309 else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
310 *dstpos++ = *(Uint32*) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
311 (srcpix + ((dy >> 16) * srcpitch) + (dx >> 16 << 2)); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
312 dx += icos; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
313 dy += isin; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
314 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
315 dstrow += dstpitch; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
316 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
317 break; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
318 default: /*case 3:*/ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
319 for (y = 0; y < dst->h; y++) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
320 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
321 Uint8 *dstpos = (Uint8*)dstrow; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
322 dx = (ax + (isin * (cy - y))) + xd; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
323 dy = (ay - (icos * (cy - y))) + yd; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
324 for (x = 0; x < dst->w; x++) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
325 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
326 if (dx < 0 || dy < 0 || dx > xmaxval || dy > ymaxval) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
327 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
328 dstpos[0] = ((Uint8*) &bgcolor)[0]; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
329 dstpos[1] = ((Uint8*) &bgcolor)[1]; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
330 dstpos[2] = ((Uint8*) &bgcolor)[2]; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
331 dstpos += 3; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
332 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
333 else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
334 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
335 Uint8* srcpos = (Uint8*) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
336 (srcpix + ((dy >> 16) * srcpitch) + ((dx >> 16) * 3)); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
337 dstpos[0] = srcpos[0]; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
338 dstpos[1] = srcpos[1]; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
339 dstpos[2] = srcpos[2]; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
340 dstpos += 3; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
341 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
342 dx += icos; dy += isin; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
343 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
344 dstrow += dstpitch; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
345 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
346 break; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
347 } |
| 190 | 348 } |
| 349 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
350 static void |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
351 stretch (SDL_Surface *src, SDL_Surface *dst) |
| 190 | 352 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
353 int looph, loopw; |
| 190 | 354 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
355 Uint8* srcrow = (Uint8*) src->pixels; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
356 Uint8* dstrow = (Uint8*) dst->pixels; |
| 190 | 357 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
358 int srcpitch = src->pitch; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
359 int dstpitch = dst->pitch; |
| 190 | 360 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
361 int dstwidth = dst->w; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
362 int dstheight = dst->h; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
363 int dstwidth2 = dst->w << 1; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
364 int dstheight2 = dst->h << 1; |
| 190 | 365 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
366 int srcwidth2 = src->w << 1; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
367 int srcheight2 = src->h << 1; |
|
740
bc4b1b23d8c9
Added support to transform.scale and transform.scale2x so that a destination
Rene Dudfield <renesd@gmail.com>
parents:
695
diff
changeset
|
368 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
369 int w_err, h_err = srcheight2 - dstheight2; |
|
740
bc4b1b23d8c9
Added support to transform.scale and transform.scale2x so that a destination
Rene Dudfield <renesd@gmail.com>
parents:
695
diff
changeset
|
370 |
|
bc4b1b23d8c9
Added support to transform.scale and transform.scale2x so that a destination
Rene Dudfield <renesd@gmail.com>
parents:
695
diff
changeset
|
371 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
372 switch (src->format->BytesPerPixel) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
373 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
374 case 1: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
375 for (looph = 0; looph < dstheight; ++looph) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
376 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
377 Uint8 *srcpix = (Uint8*)srcrow, *dstpix = (Uint8*)dstrow; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
378 w_err = srcwidth2 - dstwidth2; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
379 for (loopw = 0; loopw < dstwidth; ++ loopw) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
380 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
381 *dstpix++ = *srcpix; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
382 while (w_err >= 0) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
383 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
384 ++srcpix; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
385 w_err -= dstwidth2; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
386 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
387 w_err += srcwidth2; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
388 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
389 while (h_err >= 0) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
390 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
391 srcrow += srcpitch; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
392 h_err -= dstheight2; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
393 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
394 dstrow += dstpitch; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
395 h_err += srcheight2; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
396 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
397 break; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
398 case 2: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
399 for (looph = 0; looph < dstheight; ++looph) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
400 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
401 Uint16 *srcpix = (Uint16*)srcrow, *dstpix = (Uint16*)dstrow; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
402 w_err = srcwidth2 - dstwidth2; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
403 for (loopw = 0; loopw < dstwidth; ++ loopw) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
404 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
405 *dstpix++ = *srcpix; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
406 while (w_err >= 0) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
407 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
408 ++srcpix; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
409 w_err -= dstwidth2; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
410 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
411 w_err += srcwidth2; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
412 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
413 while (h_err >= 0) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
414 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
415 srcrow += srcpitch; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
416 h_err -= dstheight2; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
417 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
418 dstrow += dstpitch; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
419 h_err += srcheight2; |
|
740
bc4b1b23d8c9
Added support to transform.scale and transform.scale2x so that a destination
Rene Dudfield <renesd@gmail.com>
parents:
695
diff
changeset
|
420 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
421 break; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
422 case 3: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
423 for (looph = 0; looph < dstheight; ++looph) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
424 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
425 Uint8 *srcpix = (Uint8*)srcrow, *dstpix = (Uint8*)dstrow; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
426 w_err = srcwidth2 - dstwidth2; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
427 for (loopw = 0; loopw < dstwidth; ++ loopw) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
428 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
429 dstpix[0] = srcpix[0]; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
430 dstpix[1] = srcpix[1]; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
431 dstpix[2] = srcpix[2]; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
432 dstpix += 3; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
433 while (w_err >= 0) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
434 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
435 srcpix+=3; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
436 w_err -= dstwidth2; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
437 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
438 w_err += srcwidth2; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
439 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
440 while (h_err >= 0) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
441 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
442 srcrow += srcpitch; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
443 h_err -= dstheight2; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
444 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
445 dstrow += dstpitch; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
446 h_err += srcheight2; |
|
740
bc4b1b23d8c9
Added support to transform.scale and transform.scale2x so that a destination
Rene Dudfield <renesd@gmail.com>
parents:
695
diff
changeset
|
447 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
448 break; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
449 default: /*case 4:*/ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
450 for (looph = 0; looph < dstheight; ++looph) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
451 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
452 Uint32 *srcpix = (Uint32*)srcrow, *dstpix = (Uint32*)dstrow; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
453 w_err = srcwidth2 - dstwidth2; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
454 for (loopw = 0; loopw < dstwidth; ++ loopw) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
455 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
456 *dstpix++ = *srcpix; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
457 while (w_err >= 0) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
458 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
459 ++srcpix; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
460 w_err -= dstwidth2; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
461 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
462 w_err += srcwidth2; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
463 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
464 while (h_err >= 0) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
465 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
466 srcrow += srcpitch; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
467 h_err -= dstheight2; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
468 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
469 dstrow += dstpitch; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
470 h_err += srcheight2; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
471 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
472 break; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
473 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
474 } |
| 190 | 475 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
476 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
477 surf_scale (PyObject* self, PyObject* arg) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
478 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
479 PyObject *surfobj, *surfobj2; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
480 SDL_Surface* surf, *newsurf; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
481 int width, height; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
482 surfobj2 = NULL; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
483 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
484 /*get all the arguments*/ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
485 if (!PyArg_ParseTuple (arg, "O!(ii)|O!", &PySurface_Type, &surfobj, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
486 &width, &height, &PySurface_Type, &surfobj2)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
487 return NULL; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
488 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
489 if (width < 0 || height < 0) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
490 return RAISE (PyExc_ValueError, "Cannot scale to negative size"); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
491 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
492 surf = PySurface_AsSurface (surfobj); |
| 528 | 493 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
494 if (!surfobj2) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
495 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
496 newsurf = newsurf_fromsurf (surf, width, height); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
497 if (!newsurf) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
498 return NULL; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
499 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
500 else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
501 newsurf = PySurface_AsSurface (surfobj2); |
|
780
b31db66205b6
releasing GIL around cpu expensive C parts.
Rene Dudfield <renesd@gmail.com>
parents:
740
diff
changeset
|
502 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
503 /* check to see if the size is twice as big. */ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
504 if (newsurf->w != width || newsurf->h != height) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
505 return RAISE (PyExc_ValueError, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
506 "Destination surface not the given width or height."); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
507 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
508 /* check to see if the format of the surface is the same. */ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
509 if (surf->format->BytesPerPixel != newsurf->format->BytesPerPixel) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
510 return RAISE (PyExc_ValueError, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
511 "Source and destination surfaces need the same format."); |
| 190 | 512 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
513 if (width && height) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
514 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
515 SDL_LockSurface (newsurf); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
516 PySurface_Lock (surfobj); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
517 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
518 Py_BEGIN_ALLOW_THREADS; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
519 stretch (surf, newsurf); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
520 Py_END_ALLOW_THREADS; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
521 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
522 PySurface_Unlock (surfobj); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
523 SDL_UnlockSurface (newsurf); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
524 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
525 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
526 if (surfobj2) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
527 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
528 Py_INCREF (surfobj2); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
529 return surfobj2; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
530 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
531 else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
532 return PySurface_New (newsurf); |
| 190 | 533 } |
| 534 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
535 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
536 surf_scale2x (PyObject* self, PyObject* arg) |
| 432 | 537 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
538 PyObject *surfobj, *surfobj2; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
539 SDL_Surface *surf; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
540 SDL_Surface *newsurf; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
541 int width, height; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
542 surfobj2 = NULL; |
|
740
bc4b1b23d8c9
Added support to transform.scale and transform.scale2x so that a destination
Rene Dudfield <renesd@gmail.com>
parents:
695
diff
changeset
|
543 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
544 /*get all the arguments*/ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
545 if (!PyArg_ParseTuple (arg, "O!|O!", &PySurface_Type, &surfobj, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
546 &PySurface_Type, &surfobj2)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
547 return NULL; |
| 432 | 548 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
549 surf = PySurface_AsSurface (surfobj); |
|
740
bc4b1b23d8c9
Added support to transform.scale and transform.scale2x so that a destination
Rene Dudfield <renesd@gmail.com>
parents:
695
diff
changeset
|
550 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
551 /* if the second surface is not there, then make a new one. */ |
| 432 | 552 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
553 if (!surfobj2) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
554 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
555 width = surf->w * 2; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
556 height = surf->h * 2; |
|
740
bc4b1b23d8c9
Added support to transform.scale and transform.scale2x so that a destination
Rene Dudfield <renesd@gmail.com>
parents:
695
diff
changeset
|
557 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
558 newsurf = newsurf_fromsurf (surf, width, height); |
|
740
bc4b1b23d8c9
Added support to transform.scale and transform.scale2x so that a destination
Rene Dudfield <renesd@gmail.com>
parents:
695
diff
changeset
|
559 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
560 if (!newsurf) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
561 return NULL; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
562 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
563 else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
564 newsurf = PySurface_AsSurface (surfobj2); |
|
740
bc4b1b23d8c9
Added support to transform.scale and transform.scale2x so that a destination
Rene Dudfield <renesd@gmail.com>
parents:
695
diff
changeset
|
565 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
566 /* check to see if the size is twice as big. */ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
567 if (newsurf->w != (surf->w * 2) || newsurf->h != (surf->h * 2)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
568 return RAISE (PyExc_ValueError, "Destination surface not 2x bigger."); |
|
740
bc4b1b23d8c9
Added support to transform.scale and transform.scale2x so that a destination
Rene Dudfield <renesd@gmail.com>
parents:
695
diff
changeset
|
569 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
570 /* check to see if the format of the surface is the same. */ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
571 if (surf->format->BytesPerPixel != newsurf->format->BytesPerPixel) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
572 return RAISE (PyExc_ValueError, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
573 "Source and destination surfaces need the same format."); |
| 432 | 574 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
575 SDL_LockSurface (newsurf); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
576 SDL_LockSurface (surf); |
|
740
bc4b1b23d8c9
Added support to transform.scale and transform.scale2x so that a destination
Rene Dudfield <renesd@gmail.com>
parents:
695
diff
changeset
|
577 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
578 Py_BEGIN_ALLOW_THREADS; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
579 scale2x (surf, newsurf); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
580 Py_END_ALLOW_THREADS; |
| 432 | 581 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
582 SDL_UnlockSurface (surf); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
583 SDL_UnlockSurface (newsurf); |
| 432 | 584 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
585 if (surfobj2) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
586 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
587 Py_INCREF (surfobj2); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
588 return surfobj2; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
589 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
590 else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
591 return PySurface_New (newsurf); |
| 432 | 592 } |
| 593 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
594 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
595 surf_rotate (PyObject* self, PyObject* arg) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
596 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
597 PyObject *surfobj; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
598 SDL_Surface* surf, *newsurf; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
599 float angle; |
| 432 | 600 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
601 double radangle, sangle, cangle; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
602 double x, y, cx, cy, sx, sy; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
603 int nxmax,nymax; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
604 Uint32 bgcolor; |
|
740
bc4b1b23d8c9
Added support to transform.scale and transform.scale2x so that a destination
Rene Dudfield <renesd@gmail.com>
parents:
695
diff
changeset
|
605 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
606 /*get all the arguments*/ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
607 if (!PyArg_ParseTuple (arg, "O!f", &PySurface_Type, &surfobj, &angle)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
608 return NULL; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
609 surf = PySurface_AsSurface (surfobj); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
610 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
611 if (surf->format->BytesPerPixel <= 0 || surf->format->BytesPerPixel > 4) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
612 return RAISE (PyExc_ValueError, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
613 "unsupport Surface bit depth for transform"); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
614 |
|
1149
bc8fa65d78df
Added a fix for rotate on multiples of 90.0000001-90.99999 degrees.
Rene Dudfield <renesd@gmail.com>
parents:
1117
diff
changeset
|
615 |
|
bc8fa65d78df
Added a fix for rotate on multiples of 90.0000001-90.99999 degrees.
Rene Dudfield <renesd@gmail.com>
parents:
1117
diff
changeset
|
616 |
| 1157 | 617 if ( !( fmod((double)angle, (double)90.0f) ) ) { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
618 PySurface_Lock (surfobj); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
619 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
620 Py_BEGIN_ALLOW_THREADS; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
621 newsurf = rotate90 (surf, (int) angle); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
622 Py_END_ALLOW_THREADS; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
623 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
624 PySurface_Unlock (surfobj); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
625 if (!newsurf) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
626 return NULL; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
627 return PySurface_New (newsurf); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
628 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
629 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
630 radangle = angle*.01745329251994329; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
631 sangle = sin (radangle); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
632 cangle = cos (radangle); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
633 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
634 x = surf->w; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
635 y = surf->h; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
636 cx = cangle*x; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
637 cy = cangle*y; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
638 sx = sangle*x; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
639 sy = sangle*y; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
640 nxmax = (int) (MAX (MAX (MAX (fabs (cx + sy), fabs (cx - sy)), |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
641 fabs (-cx + sy)), fabs (-cx - sy))); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
642 nymax = (int) (MAX (MAX (MAX (fabs (sx + cy), fabs (sx - cy)), |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
643 fabs (-sx + cy)), fabs (-sx - cy))); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
644 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
645 newsurf = newsurf_fromsurf (surf, nxmax, nymax); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
646 if (!newsurf) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
647 return NULL; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
648 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
649 /* get the background color */ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
650 if (surf->flags & SDL_SRCCOLORKEY) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
651 bgcolor = surf->format->colorkey; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
652 else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
653 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
654 SDL_LockSurface (surf); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
655 switch (surf->format->BytesPerPixel) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
656 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
657 case 1: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
658 bgcolor = *(Uint8*) surf->pixels; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
659 break; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
660 case 2: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
661 bgcolor = *(Uint16*) surf->pixels; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
662 break; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
663 case 4: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
664 bgcolor = *(Uint32*) surf->pixels; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
665 break; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
666 default: /*case 3:*/ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
667 #if SDL_BYTEORDER == SDL_LIL_ENDIAN |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
668 bgcolor = (((Uint8*) surf->pixels)[0]) + |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
669 (((Uint8*) surf->pixels)[1] << 8) + |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
670 (((Uint8*) surf->pixels)[2] << 16); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
671 #else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
672 bgcolor = (((Uint8*) surf->pixels)[2]) + |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
673 (((Uint8*) surf->pixels)[1] << 8) + |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
674 (((Uint8*) surf->pixels)[0] << 16); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
675 #endif |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
676 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
677 SDL_UnlockSurface (surf); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
678 bgcolor &= ~surf->format->Amask; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
679 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
680 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
681 SDL_LockSurface (newsurf); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
682 PySurface_Lock (surfobj); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
683 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
684 Py_BEGIN_ALLOW_THREADS; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
685 rotate (surf, newsurf, bgcolor, sangle, cangle); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
686 Py_END_ALLOW_THREADS; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
687 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
688 PySurface_Unlock (surfobj); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
689 SDL_UnlockSurface (newsurf); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
690 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
691 return PySurface_New (newsurf); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
692 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
693 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
694 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
695 surf_flip (PyObject* self, PyObject* arg) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
696 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
697 PyObject *surfobj; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
698 SDL_Surface* surf, *newsurf; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
699 int xaxis, yaxis; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
700 int loopx, loopy; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
701 int pixsize, srcpitch, dstpitch; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
702 Uint8 *srcpix, *dstpix; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
703 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
704 /*get all the arguments*/ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
705 if (!PyArg_ParseTuple (arg, "O!ii", &PySurface_Type, &surfobj, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
706 &xaxis, &yaxis)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
707 return NULL; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
708 surf = PySurface_AsSurface (surfobj); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
709 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
710 newsurf = newsurf_fromsurf (surf, surf->w, surf->h); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
711 if (!newsurf) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
712 return NULL; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
713 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
714 pixsize = surf->format->BytesPerPixel; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
715 srcpitch = surf->pitch; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
716 dstpitch = newsurf->pitch; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
717 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
718 SDL_LockSurface (newsurf); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
719 PySurface_Lock (surfobj); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
720 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
721 srcpix = (Uint8*) surf->pixels; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
722 dstpix = (Uint8*) newsurf->pixels; |
|
740
bc4b1b23d8c9
Added support to transform.scale and transform.scale2x so that a destination
Rene Dudfield <renesd@gmail.com>
parents:
695
diff
changeset
|
723 |
|
bc4b1b23d8c9
Added support to transform.scale and transform.scale2x so that a destination
Rene Dudfield <renesd@gmail.com>
parents:
695
diff
changeset
|
724 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
725 Py_BEGIN_ALLOW_THREADS; |
| 190 | 726 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
727 if (!xaxis) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
728 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
729 if (!yaxis) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
730 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
731 for (loopy = 0; loopy < surf->h; ++loopy) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
732 memcpy (dstpix + loopy * dstpitch, srcpix + loopy * srcpitch, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
733 surf->w * surf->format->BytesPerPixel); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
734 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
735 else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
736 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
737 for (loopy = 0; loopy < surf->h; ++loopy) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
738 memcpy (dstpix + loopy * dstpitch, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
739 srcpix + (surf->h - 1 - loopy) * srcpitch, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
740 surf->w * surf->format->BytesPerPixel); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
741 } |
| 191 | 742 } |
| 743 else /*if (xaxis)*/ | |
| 744 { | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
745 if (yaxis) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
746 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
747 switch (surf->format->BytesPerPixel) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
748 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
749 case 1: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
750 for (loopy = 0; loopy < surf->h; ++loopy) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
751 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
752 Uint8* dst = (Uint8*) (dstpix + loopy * dstpitch); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
753 Uint8* src = ((Uint8*) (srcpix + (surf->h - 1 - loopy) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
754 * srcpitch)) + surf->w - 1; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
755 for (loopx = 0; loopx < surf->w; ++loopx) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
756 *dst++ = *src--; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
757 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
758 break; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
759 case 2: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
760 for (loopy = 0; loopy < surf->h; ++loopy) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
761 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
762 Uint16* dst = (Uint16*) (dstpix + loopy * dstpitch); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
763 Uint16* src = ((Uint16*) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
764 (srcpix + (surf->h - 1 - loopy) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
765 * srcpitch)) + surf->w - 1; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
766 for (loopx = 0; loopx < surf->w; ++loopx) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
767 *dst++ = *src--; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
768 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
769 break; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
770 case 4: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
771 for (loopy = 0; loopy < surf->h; ++loopy) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
772 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
773 Uint32* dst = (Uint32*) (dstpix + loopy * dstpitch); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
774 Uint32* src = ((Uint32*) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
775 (srcpix + (surf->h - 1 - loopy) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
776 * srcpitch)) + surf->w - 1; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
777 for (loopx = 0; loopx < surf->w; ++loopx) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
778 *dst++ = *src--; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
779 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
780 break; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
781 case 3: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
782 for (loopy = 0; loopy < surf->h; ++loopy) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
783 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
784 Uint8* dst = (Uint8*) (dstpix + loopy * dstpitch); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
785 Uint8* src = ((Uint8*) (srcpix + (surf->h - 1 - loopy) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
786 * srcpitch)) + surf->w * 3 - 3; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
787 for (loopx = 0; loopx < surf->w; ++loopx) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
788 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
789 dst[0] = src[0]; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
790 dst[1] = src[1]; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
791 dst[2] = src[2]; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
792 dst += 3; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
793 src -= 3; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
794 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
795 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
796 break; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
797 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
798 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
799 else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
800 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
801 switch (surf->format->BytesPerPixel) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
802 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
803 case 1: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
804 for (loopy = 0; loopy < surf->h; ++loopy) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
805 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
806 Uint8* dst = (Uint8*) (dstpix + loopy * dstpitch); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
807 Uint8* src = ((Uint8*) (srcpix + loopy * srcpitch)) + |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
808 surf->w - 1; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
809 for (loopx = 0; loopx < surf->w; ++loopx) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
810 *dst++ = *src--; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
811 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
812 break; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
813 case 2: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
814 for (loopy = 0; loopy < surf->h; ++loopy) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
815 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
816 Uint16* dst = (Uint16*) (dstpix + loopy * dstpitch); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
817 Uint16* src = ((Uint16*) (srcpix + loopy * srcpitch)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
818 + surf->w - 1; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
819 for (loopx = 0; loopx < surf->w; ++loopx) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
820 *dst++ = *src--; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
821 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
822 break; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
823 case 4: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
824 for (loopy = 0; loopy < surf->h; ++loopy) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
825 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
826 Uint32* dst = (Uint32*) (dstpix + loopy * dstpitch); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
827 Uint32* src = ((Uint32*) (srcpix + loopy * srcpitch)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
828 + surf->w - 1; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
829 for (loopx = 0; loopx < surf->w; ++loopx) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
830 *dst++ = *src--; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
831 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
832 break; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
833 case 3: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
834 for (loopy = 0; loopy < surf->h; ++loopy) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
835 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
836 Uint8* dst = (Uint8*) (dstpix + loopy * dstpitch); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
837 Uint8* src = ((Uint8*) (srcpix + loopy * srcpitch)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
838 + surf->w * 3 - 3; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
839 for (loopx = 0; loopx < surf->w; ++loopx) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
840 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
841 dst[0] = src[0]; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
842 dst[1] = src[1]; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
843 dst[2] = src[2]; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
844 dst += 3; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
845 src -= 3; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
846 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
847 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
848 break; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
849 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
850 } |
| 191 | 851 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
852 Py_END_ALLOW_THREADS; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
853 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
854 PySurface_Unlock (surfobj); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
855 SDL_UnlockSurface (newsurf); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
856 return PySurface_New (newsurf); |
| 191 | 857 } |
| 858 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
859 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
860 surf_rotozoom (PyObject* self, PyObject* arg) |
| 199 | 861 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
862 PyObject *surfobj; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
863 SDL_Surface *surf, *newsurf, *surf32; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
864 float scale, angle; |
| 199 | 865 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
866 /*get all the arguments*/ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
867 if (!PyArg_ParseTuple (arg, "O!ff", &PySurface_Type, &surfobj, &angle, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
868 &scale)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
869 return NULL; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
870 surf = PySurface_AsSurface (surfobj); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
871 if (scale == 0.0) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
872 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
873 newsurf = newsurf_fromsurf (surf, surf->w, surf->h); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
874 return PySurface_New (newsurf); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
875 } |
| 199 | 876 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
877 if (surf->format->BitsPerPixel == 32) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
878 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
879 surf32 = surf; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
880 PySurface_Lock (surfobj); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
881 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
882 else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
883 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
884 Py_BEGIN_ALLOW_THREADS; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
885 surf32 = SDL_CreateRGBSurface (SDL_SWSURFACE, surf->w, surf->h, 32, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
886 0x000000ff, 0x0000ff00, 0x00ff0000, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
887 0xff000000); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
888 SDL_BlitSurface (surf, NULL, surf32, NULL); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
889 Py_END_ALLOW_THREADS; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
890 } |
| 199 | 891 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
892 Py_BEGIN_ALLOW_THREADS; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
893 newsurf = rotozoomSurface (surf32, angle, scale, 1); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
894 Py_END_ALLOW_THREADS; |
| 332 | 895 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
896 if (surf32 == surf) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
897 PySurface_Unlock (surfobj); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
898 else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
899 SDL_FreeSurface (surf32); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
900 return PySurface_New (newsurf); |
| 199 | 901 } |
| 190 | 902 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
903 static SDL_Surface* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
904 chop (SDL_Surface *src, int x, int y, int width, int height) |
| 526 | 905 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
906 SDL_Surface* dst; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
907 int dstwidth,dstheight; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
908 char *srcpix, *dstpix, *srcrow, *dstrow; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
909 int srcstepx, srcstepy, dststepx, dststepy; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
910 int loopx,loopy; |
| 526 | 911 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
912 if ((x + width) > src->w) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
913 width = src->w - x; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
914 if ((y + height) > src->h) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
915 height=src->h - y; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
916 if (x < 0) |
| 526 | 917 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
918 width -= (-x); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
919 x = 0; |
| 526 | 920 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
921 if (y < 0) |
| 526 | 922 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
923 height -= (-y); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
924 y = 0; |
| 526 | 925 } |
| 926 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
927 dstwidth = src->w-width; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
928 dstheight = src->h-height; |
| 526 | 929 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
930 dst = newsurf_fromsurf (src,dstwidth,dstheight); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
931 if (!dst) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
932 return NULL; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
933 SDL_LockSurface (dst); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
934 srcrow = (char*) src->pixels; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
935 dstrow = (char*) dst->pixels; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
936 srcstepx = dststepx = src->format->BytesPerPixel; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
937 srcstepy = src->pitch; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
938 dststepy = dst->pitch; |
| 526 | 939 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
940 for (loopy = 0; loopy < src->h; loopy++) |
| 526 | 941 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
942 if ((loopy < y) || (loopy >= (y + height))) |
| 526 | 943 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
944 dstpix = dstrow; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
945 srcpix = srcrow; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
946 for (loopx = 0; loopx < src->w; loopx++) |
| 526 | 947 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
948 if ((loopx < x) || (loopx >= (x + width))) |
| 526 | 949 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
950 switch (src->format->BytesPerPixel) |
| 526 | 951 { |
| 952 case 1: | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
953 *dstpix = *srcpix; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
954 break; |
| 526 | 955 case 2: |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
956 *(Uint16*) dstpix = *(Uint16*) srcpix; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
957 break; |
| 526 | 958 case 3: |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
959 dstpix[0] = srcpix[0]; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
960 dstpix[1] = srcpix[1]; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
961 dstpix[2] = srcpix[2]; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
962 break; |
| 526 | 963 case 4: |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
964 *(Uint32*) dstpix = *(Uint32*) srcpix; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
965 break; |
| 526 | 966 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
967 dstpix += dststepx; |
| 526 | 968 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
969 srcpix += srcstepx; |
| 526 | 970 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
971 dstrow += dststepy; |
| 526 | 972 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
973 srcrow += srcstepy; |
| 526 | 974 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
975 SDL_UnlockSurface (dst); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
976 return dst; |
| 526 | 977 } |
| 978 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
979 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
980 surf_chop (PyObject* self, PyObject* arg) |
| 526 | 981 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
982 PyObject *surfobj, *rectobj; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
983 SDL_Surface* surf, *newsurf; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
984 GAME_Rect* rect, temp; |
| 526 | 985 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
986 if (!PyArg_ParseTuple (arg, "O!O", &PySurface_Type, &surfobj, &rectobj)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
987 return NULL; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
988 if (!(rect = GameRect_FromObject (rectobj, &temp))) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
989 return RAISE (PyExc_TypeError, "Rect argument is invalid"); |
| 526 | 990 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
991 surf=PySurface_AsSurface (surfobj); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
992 Py_BEGIN_ALLOW_THREADS; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
993 newsurf = chop (surf, rect->x, rect->y, rect->w, rect->h); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
994 Py_END_ALLOW_THREADS; |
| 526 | 995 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
996 return PySurface_New (newsurf); |
| 526 | 997 } |
| 998 | |
|
834
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
999 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1000 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1001 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1002 /* |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1003 * smooth scale functions. |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1004 */ |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1005 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1006 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1007 /* this function implements an area-averaging shrinking filter in the X-dimension */ |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1008 static void filter_shrink_X_ONLYC(Uint8 *srcpix, Uint8 *dstpix, int height, int srcpitch, int dstpitch, int srcwidth, int dstwidth) |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1009 { |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1010 int srcdiff = srcpitch - (srcwidth * 4); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1011 int dstdiff = dstpitch - (dstwidth * 4); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1012 int x, y; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1013 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1014 int xspace = 0x10000 * srcwidth / dstwidth; /* must be > 1 */ |
|
1330
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
1015 int xrecip = (int) (0x100000000LL / xspace); |
|
834
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1016 for (y = 0; y < height; y++) |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1017 { |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1018 Uint16 accumulate[4] = {0,0,0,0}; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1019 int xcounter = xspace; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1020 for (x = 0; x < srcwidth; x++) |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1021 { |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1022 if (xcounter > 0x10000) |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1023 { |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1024 accumulate[0] += (Uint16) *srcpix++; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1025 accumulate[1] += (Uint16) *srcpix++; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1026 accumulate[2] += (Uint16) *srcpix++; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1027 accumulate[3] += (Uint16) *srcpix++; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1028 xcounter -= 0x10000; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1029 } |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1030 else |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1031 { |
|
863
6cf1fbb0772c
fixes to compile on windows (toolkit compiler) and some bounds checking on event calls to prevent buffer over-runs (thanks to John Popplewell)
brian
parents:
862
diff
changeset
|
1032 int xfrac = 0x10000 - xcounter; |
|
834
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1033 /* write out a destination pixel */ |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1034 *dstpix++ = (Uint8) (((accumulate[0] + ((srcpix[0] * xcounter) >> 16)) * xrecip) >> 16); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1035 *dstpix++ = (Uint8) (((accumulate[1] + ((srcpix[1] * xcounter) >> 16)) * xrecip) >> 16); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1036 *dstpix++ = (Uint8) (((accumulate[2] + ((srcpix[2] * xcounter) >> 16)) * xrecip) >> 16); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1037 *dstpix++ = (Uint8) (((accumulate[3] + ((srcpix[3] * xcounter) >> 16)) * xrecip) >> 16); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1038 /* reload the accumulator with the remainder of this pixel */ |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1039 accumulate[0] = (Uint16) ((*srcpix++ * xfrac) >> 16); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1040 accumulate[1] = (Uint16) ((*srcpix++ * xfrac) >> 16); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1041 accumulate[2] = (Uint16) ((*srcpix++ * xfrac) >> 16); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1042 accumulate[3] = (Uint16) ((*srcpix++ * xfrac) >> 16); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1043 xcounter = xspace - xfrac; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1044 } |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1045 } |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1046 srcpix += srcdiff; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1047 dstpix += dstdiff; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1048 } |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1049 } |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1050 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1051 /* this function implements an area-averaging shrinking filter in the Y-dimension */ |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1052 static void filter_shrink_Y_ONLYC(Uint8 *srcpix, Uint8 *dstpix, int width, int srcpitch, int dstpitch, int srcheight, int dstheight) |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1053 { |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1054 Uint16 *templine; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1055 int srcdiff = srcpitch - (width * 4); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1056 int dstdiff = dstpitch - (width * 4); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1057 int x, y; |
|
863
6cf1fbb0772c
fixes to compile on windows (toolkit compiler) and some bounds checking on event calls to prevent buffer over-runs (thanks to John Popplewell)
brian
parents:
862
diff
changeset
|
1058 int yspace = 0x10000 * srcheight / dstheight; /* must be > 1 */ |
|
1330
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
1059 int yrecip = (int) (0x100000000LL / yspace); |
|
863
6cf1fbb0772c
fixes to compile on windows (toolkit compiler) and some bounds checking on event calls to prevent buffer over-runs (thanks to John Popplewell)
brian
parents:
862
diff
changeset
|
1060 int ycounter = yspace; |
|
834
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1061 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1062 /* allocate and clear a memory area for storing the accumulator line */ |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1063 templine = (Uint16 *) malloc(dstpitch * 2); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1064 if (templine == NULL) return; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1065 memset(templine, 0, dstpitch * 2); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1066 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1067 for (y = 0; y < srcheight; y++) |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1068 { |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1069 Uint16 *accumulate = templine; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1070 if (ycounter > 0x10000) |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1071 { |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1072 for (x = 0; x < width; x++) |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1073 { |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1074 *accumulate++ += (Uint16) *srcpix++; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1075 *accumulate++ += (Uint16) *srcpix++; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1076 *accumulate++ += (Uint16) *srcpix++; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1077 *accumulate++ += (Uint16) *srcpix++; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1078 } |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1079 ycounter -= 0x10000; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1080 } |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1081 else |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1082 { |
|
863
6cf1fbb0772c
fixes to compile on windows (toolkit compiler) and some bounds checking on event calls to prevent buffer over-runs (thanks to John Popplewell)
brian
parents:
862
diff
changeset
|
1083 int yfrac = 0x10000 - ycounter; |
|
834
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1084 /* write out a destination line */ |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1085 for (x = 0; x < width; x++) |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1086 { |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1087 *dstpix++ = (Uint8) (((*accumulate++ + ((*srcpix++ * ycounter) >> 16)) * yrecip) >> 16); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1088 *dstpix++ = (Uint8) (((*accumulate++ + ((*srcpix++ * ycounter) >> 16)) * yrecip) >> 16); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1089 *dstpix++ = (Uint8) (((*accumulate++ + ((*srcpix++ * ycounter) >> 16)) * yrecip) >> 16); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1090 *dstpix++ = (Uint8) (((*accumulate++ + ((*srcpix++ * ycounter) >> 16)) * yrecip) >> 16); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1091 } |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1092 dstpix += dstdiff; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1093 /* reload the accumulator with the remainder of this line */ |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1094 accumulate = templine; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1095 srcpix -= 4 * width; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1096 for (x = 0; x < width; x++) |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1097 { |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1098 *accumulate++ = (Uint16) ((*srcpix++ * yfrac) >> 16); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1099 *accumulate++ = (Uint16) ((*srcpix++ * yfrac) >> 16); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1100 *accumulate++ = (Uint16) ((*srcpix++ * yfrac) >> 16); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1101 *accumulate++ = (Uint16) ((*srcpix++ * yfrac) >> 16); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1102 } |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1103 ycounter = yspace - yfrac; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1104 } |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1105 srcpix += srcdiff; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1106 } /* for (int y = 0; y < srcheight; y++) */ |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1107 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1108 /* free the temporary memory */ |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1109 free(templine); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1110 } |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1111 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1112 /* this function implements a bilinear filter in the X-dimension */ |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1113 static void filter_expand_X_ONLYC(Uint8 *srcpix, Uint8 *dstpix, int height, int srcpitch, int dstpitch, int srcwidth, int dstwidth) |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1114 { |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1115 int dstdiff = dstpitch - (dstwidth * 4); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1116 int *xidx0, *xmult0, *xmult1; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1117 int x, y; |
|
863
6cf1fbb0772c
fixes to compile on windows (toolkit compiler) and some bounds checking on event calls to prevent buffer over-runs (thanks to John Popplewell)
brian
parents:
862
diff
changeset
|
1118 int factorwidth = 4; |
|
834
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1119 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1120 /* Allocate memory for factors */ |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1121 xidx0 = malloc(dstwidth * 4); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1122 if (xidx0 == NULL) return; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1123 xmult0 = (int *) malloc(dstwidth * factorwidth); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1124 xmult1 = (int *) malloc(dstwidth * factorwidth); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1125 if (xmult0 == NULL || xmult1 == NULL) |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1126 { |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1127 free(xidx0); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1128 if (xmult0) free(xmult0); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1129 if (xmult1) free(xmult1); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1130 } |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1131 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1132 /* Create multiplier factors and starting indices and put them in arrays */ |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1133 for (x = 0; x < dstwidth; x++) |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1134 { |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1135 xidx0[x] = x * (srcwidth - 1) / dstwidth; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1136 xmult1[x] = 0x10000 * ((x * (srcwidth - 1)) % dstwidth) / dstwidth; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1137 xmult0[x] = 0x10000 - xmult1[x]; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1138 } |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1139 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1140 /* Do the scaling in raster order so we don't trash the cache */ |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1141 for (y = 0; y < height; y++) |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1142 { |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1143 Uint8 *srcrow0 = srcpix + y * srcpitch; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1144 for (x = 0; x < dstwidth; x++) |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1145 { |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1146 Uint8 *src = srcrow0 + xidx0[x] * 4; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1147 int xm0 = xmult0[x]; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1148 int xm1 = xmult1[x]; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1149 *dstpix++ = (Uint8) (((src[0] * xm0) + (src[4] * xm1)) >> 16); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1150 *dstpix++ = (Uint8) (((src[1] * xm0) + (src[5] * xm1)) >> 16); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1151 *dstpix++ = (Uint8) (((src[2] * xm0) + (src[6] * xm1)) >> 16); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1152 *dstpix++ = (Uint8) (((src[3] * xm0) + (src[7] * xm1)) >> 16); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1153 } |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1154 dstpix += dstdiff; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1155 } |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1156 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1157 /* free memory */ |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1158 free(xidx0); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1159 free(xmult0); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1160 free(xmult1); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1161 } |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1162 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1163 /* this function implements a bilinear filter in the Y-dimension */ |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1164 static void filter_expand_Y_ONLYC(Uint8 *srcpix, Uint8 *dstpix, int width, int srcpitch, int dstpitch, int srcheight, int dstheight) |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1165 { |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1166 int x, y; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1167 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1168 for (y = 0; y < dstheight; y++) |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1169 { |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1170 int yidx0 = y * (srcheight - 1) / dstheight; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1171 Uint8 *srcrow0 = srcpix + yidx0 * srcpitch; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1172 Uint8 *srcrow1 = srcrow0 + srcpitch; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1173 int ymult1 = 0x10000 * ((y * (srcheight - 1)) % dstheight) / dstheight; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1174 int ymult0 = 0x10000 - ymult1; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1175 for (x = 0; x < width; x++) |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1176 { |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1177 *dstpix++ = (Uint8) (((*srcrow0++ * ymult0) + (*srcrow1++ * ymult1)) >> 16); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1178 *dstpix++ = (Uint8) (((*srcrow0++ * ymult0) + (*srcrow1++ * ymult1)) >> 16); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1179 *dstpix++ = (Uint8) (((*srcrow0++ * ymult0) + (*srcrow1++ * ymult1)) >> 16); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1180 *dstpix++ = (Uint8) (((*srcrow0++ * ymult0) + (*srcrow1++ * ymult1)) >> 16); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1181 } |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1182 } |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1183 } |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1184 |
|
1330
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
1185 #if defined(SCALE_MMX_SUPPORT) |
|
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
1186 static void |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1187 smoothscale_init (struct _module_state *st) |
|
834
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1188 { |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1189 if (st->filter_shrink_X == 0) |
|
834
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1190 { |
|
1367
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1191 if (SDL_HasSSE ()) |
|
1330
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
1192 { |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1193 st->filter_type = "SSE"; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1194 st->filter_shrink_X = filter_shrink_X_SSE; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1195 st->filter_shrink_Y = filter_shrink_Y_SSE; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1196 st->filter_expand_X = filter_expand_X_SSE; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1197 st->filter_expand_Y = filter_expand_Y_SSE; |
|
1330
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
1198 } |
|
1367
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1199 else if (SDL_HasMMX ()) |
|
1330
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
1200 { |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1201 st->filter_type = "MMX"; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1202 st->filter_shrink_X = filter_shrink_X_MMX; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1203 st->filter_shrink_Y = filter_shrink_Y_MMX; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1204 st->filter_expand_X = filter_expand_X_MMX; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1205 st->filter_expand_Y = filter_expand_Y_MMX; |
|
1330
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
1206 } |
|
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
1207 else |
|
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
1208 { |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1209 st->filter_type = "GENERIC"; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1210 st->filter_shrink_X = filter_shrink_X_ONLYC; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1211 st->filter_shrink_Y = filter_shrink_Y_ONLYC; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1212 st->filter_expand_X = filter_expand_X_ONLYC; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1213 st->filter_expand_Y = filter_expand_Y_ONLYC; |
|
1330
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
1214 } |
|
834
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1215 } |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1216 } |
|
1330
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
1217 #endif |
|
834
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1218 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1219 static void convert_24_32(Uint8 *srcpix, int srcpitch, Uint8 *dstpix, int dstpitch, int width, int height) |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1220 { |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1221 int srcdiff = srcpitch - (width * 3); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1222 int dstdiff = dstpitch - (width * 4); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1223 int x, y; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1224 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1225 for (y = 0; y < height; y++) |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1226 { |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1227 for (x = 0; x < width; x++) |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1228 { |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1229 *dstpix++ = *srcpix++; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1230 *dstpix++ = *srcpix++; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1231 *dstpix++ = *srcpix++; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1232 *dstpix++ = 0xff; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1233 } |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1234 srcpix += srcdiff; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1235 dstpix += dstdiff; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1236 } |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1237 } |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1238 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1239 static void convert_32_24(Uint8 *srcpix, int srcpitch, Uint8 *dstpix, int dstpitch, int width, int height) |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1240 { |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1241 int srcdiff = srcpitch - (width * 4); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1242 int dstdiff = dstpitch - (width * 3); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1243 int x, y; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1244 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1245 for (y = 0; y < height; y++) |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1246 { |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1247 for (x = 0; x < width; x++) |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1248 { |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1249 *dstpix++ = *srcpix++; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1250 *dstpix++ = *srcpix++; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1251 *dstpix++ = *srcpix++; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1252 srcpix++; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1253 } |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1254 srcpix += srcdiff; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1255 dstpix += dstdiff; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1256 } |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1257 } |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1258 |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1259 static void |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1260 scalesmooth(SDL_Surface *src, SDL_Surface *dst, |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1261 struct _module_state *st) |
|
834
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1262 { |
|
1006
e20d25853e68
Fixed possible memory leak in pygame.transform.smoothscale.
marcus
parents:
863
diff
changeset
|
1263 Uint8* srcpix = (Uint8*)src->pixels; |
|
e20d25853e68
Fixed possible memory leak in pygame.transform.smoothscale.
marcus
parents:
863
diff
changeset
|
1264 Uint8* dstpix = (Uint8*)dst->pixels; |
|
834
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1265 Uint8* dst32 = NULL; |
|
1006
e20d25853e68
Fixed possible memory leak in pygame.transform.smoothscale.
marcus
parents:
863
diff
changeset
|
1266 int srcpitch = src->pitch; |
|
e20d25853e68
Fixed possible memory leak in pygame.transform.smoothscale.
marcus
parents:
863
diff
changeset
|
1267 int dstpitch = dst->pitch; |
|
e20d25853e68
Fixed possible memory leak in pygame.transform.smoothscale.
marcus
parents:
863
diff
changeset
|
1268 |
|
e20d25853e68
Fixed possible memory leak in pygame.transform.smoothscale.
marcus
parents:
863
diff
changeset
|
1269 int srcwidth = src->w; |
|
e20d25853e68
Fixed possible memory leak in pygame.transform.smoothscale.
marcus
parents:
863
diff
changeset
|
1270 int srcheight = src->h; |
|
e20d25853e68
Fixed possible memory leak in pygame.transform.smoothscale.
marcus
parents:
863
diff
changeset
|
1271 int dstwidth = dst->w; |
|
834
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1272 int dstheight = dst->h; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1273 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1274 int bpp = src->format->BytesPerPixel; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1275 |
|
863
6cf1fbb0772c
fixes to compile on windows (toolkit compiler) and some bounds checking on event calls to prevent buffer over-runs (thanks to John Popplewell)
brian
parents:
862
diff
changeset
|
1276 Uint8 *temppix = NULL; |
|
6cf1fbb0772c
fixes to compile on windows (toolkit compiler) and some bounds checking on event calls to prevent buffer over-runs (thanks to John Popplewell)
brian
parents:
862
diff
changeset
|
1277 int tempwidth=0, temppitch=0, tempheight=0; |
|
6cf1fbb0772c
fixes to compile on windows (toolkit compiler) and some bounds checking on event calls to prevent buffer over-runs (thanks to John Popplewell)
brian
parents:
862
diff
changeset
|
1278 |
|
834
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1279 /* convert to 32-bit if necessary */ |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1280 if (bpp == 3) |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1281 { |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1282 int newpitch = srcwidth * 4; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1283 Uint8 *newsrc = (Uint8 *) malloc(newpitch * srcheight); |
|
1006
e20d25853e68
Fixed possible memory leak in pygame.transform.smoothscale.
marcus
parents:
863
diff
changeset
|
1284 if (!newsrc) |
|
e20d25853e68
Fixed possible memory leak in pygame.transform.smoothscale.
marcus
parents:
863
diff
changeset
|
1285 return; |
|
834
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1286 convert_24_32(srcpix, srcpitch, newsrc, newpitch, srcwidth, srcheight); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1287 srcpix = newsrc; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1288 srcpitch = newpitch; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1289 /* create a destination buffer for the 32-bit result */ |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1290 dstpitch = dstwidth << 2; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1291 dst32 = (Uint8 *) malloc(dstpitch * dstheight); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1292 if (dst32 == NULL) |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1293 { |
|
1006
e20d25853e68
Fixed possible memory leak in pygame.transform.smoothscale.
marcus
parents:
863
diff
changeset
|
1294 free(srcpix); |
|
834
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1295 return; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1296 } |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1297 dstpix = dst32; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1298 } |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1299 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1300 /* Create a temporary processing buffer if we will be scaling both X and Y */ |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1301 if (srcwidth != dstwidth && srcheight != dstheight) |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1302 { |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1303 tempwidth = dstwidth; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1304 temppitch = tempwidth << 2; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1305 tempheight = srcheight; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1306 temppix = (Uint8 *) malloc(temppitch * tempheight); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1307 if (temppix == NULL) |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1308 { |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1309 if (bpp == 3) |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1310 { |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1311 free(srcpix); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1312 free(dstpix); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1313 } |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1314 return; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1315 } |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1316 } |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1317 |
|
1330
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
1318 /* Start the filter by doing X-scaling */ |
|
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
1319 if (dstwidth < srcwidth) /* shrink */ |
|
834
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1320 { |
|
1330
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
1321 if (srcheight != dstheight) |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1322 st->filter_shrink_X(srcpix, temppix, srcheight, srcpitch, temppitch, srcwidth, dstwidth); |
|
1330
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
1323 else |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1324 st->filter_shrink_X(srcpix, dstpix, srcheight, srcpitch, dstpitch, srcwidth, dstwidth); |
|
1330
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
1325 } |
|
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
1326 else if (dstwidth > srcwidth) /* expand */ |
|
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
1327 { |
|
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
1328 if (srcheight != dstheight) |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1329 st->filter_expand_X(srcpix, temppix, srcheight, srcpitch, temppitch, srcwidth, dstwidth); |
|
1330
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
1330 else |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1331 st->filter_expand_X(srcpix, dstpix, srcheight, srcpitch, dstpitch, srcwidth, dstwidth); |
|
834
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1332 } |
|
1330
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
1333 /* Now do the Y scale */ |
|
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
1334 if (dstheight < srcheight) /* shrink */ |
|
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
1335 { |
|
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
1336 if (srcwidth != dstwidth) |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1337 st->filter_shrink_Y(temppix, dstpix, tempwidth, temppitch, dstpitch, srcheight, dstheight); |
|
1330
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
1338 else |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1339 st->filter_shrink_Y(srcpix, dstpix, srcwidth, srcpitch, dstpitch, srcheight, dstheight); |
|
1330
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
1340 } |
|
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
1341 else if (dstheight > srcheight) /* expand */ |
|
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
1342 { |
|
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
1343 if (srcwidth != dstwidth) |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1344 st->filter_expand_Y(temppix, dstpix, tempwidth, temppitch, dstpitch, srcheight, dstheight); |
|
1330
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
1345 else |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1346 st->filter_expand_Y(srcpix, dstpix, srcwidth, srcpitch, dstpitch, srcheight, dstheight); |
|
834
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1347 } |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1348 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1349 /* Convert back to 24-bit if necessary */ |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1350 if (bpp == 3) |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1351 { |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1352 convert_32_24(dst32, dstpitch, (Uint8*)dst->pixels, dst->pitch, dstwidth, dstheight); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1353 free(dst32); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1354 dst32 = NULL; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1355 free(srcpix); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1356 srcpix = NULL; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1357 } |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1358 /* free temporary buffer if necessary */ |
|
1006
e20d25853e68
Fixed possible memory leak in pygame.transform.smoothscale.
marcus
parents:
863
diff
changeset
|
1359 if (temppix != NULL) |
|
e20d25853e68
Fixed possible memory leak in pygame.transform.smoothscale.
marcus
parents:
863
diff
changeset
|
1360 free(temppix); |
|
834
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1361 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1362 } |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1363 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1364 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1365 static PyObject* surf_scalesmooth(PyObject* self, PyObject* arg) |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1366 { |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1367 PyObject *surfobj, *surfobj2; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1368 SDL_Surface* surf, *newsurf; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1369 int width, height, bpp; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1370 surfobj2 = NULL; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1371 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1372 /*get all the arguments*/ |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1373 if (!PyArg_ParseTuple (arg, "O!(ii)|O!", &PySurface_Type, &surfobj, |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1374 &width, &height, &PySurface_Type, &surfobj2)) |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1375 return NULL; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1376 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1377 if (width < 0 || height < 0) |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1378 return RAISE (PyExc_ValueError, "Cannot scale to negative size"); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1379 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1380 surf = PySurface_AsSurface (surfobj); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1381 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1382 bpp = surf->format->BytesPerPixel; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1383 if(bpp < 3 || bpp > 4) |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1384 return RAISE(PyExc_ValueError, "Only 24-bit or 32-bit surfaces can be smoothly scaled"); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1385 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1386 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1387 if (!surfobj2) |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1388 { |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1389 newsurf = newsurf_fromsurf (surf, width, height); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1390 if (!newsurf) |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1391 return NULL; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1392 } |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1393 else |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1394 newsurf = PySurface_AsSurface (surfobj2); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1395 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1396 /* check to see if the size is twice as big. */ |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1397 if (newsurf->w != width || newsurf->h != height) |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1398 return RAISE (PyExc_ValueError, |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1399 "Destination surface not the given width or height."); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1400 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1401 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1402 if(((width * bpp + 3) >> 2) > newsurf->pitch) |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1403 return RAISE(PyExc_ValueError, "SDL Error: destination surface pitch not 4-byte aligned."); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1404 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1405 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1406 if(width && height) |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1407 { |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1408 SDL_LockSurface(newsurf); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1409 PySurface_Lock(surfobj); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1410 Py_BEGIN_ALLOW_THREADS; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1411 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1412 /* handle trivial case */ |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1413 if (surf->w == width && surf->h == height) { |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1414 int y; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1415 for (y = 0; y < height; y++) { |
|
863
6cf1fbb0772c
fixes to compile on windows (toolkit compiler) and some bounds checking on event calls to prevent buffer over-runs (thanks to John Popplewell)
brian
parents:
862
diff
changeset
|
1416 memcpy((Uint8*)newsurf->pixels + y * newsurf->pitch, |
|
6cf1fbb0772c
fixes to compile on windows (toolkit compiler) and some bounds checking on event calls to prevent buffer over-runs (thanks to John Popplewell)
brian
parents:
862
diff
changeset
|
1417 (Uint8*)surf->pixels + y * surf->pitch, width * bpp); |
|
834
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1418 } |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1419 } |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1420 else { |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1421 scalesmooth(surf, newsurf, GETSTATE (self)); |
|
834
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1422 } |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1423 Py_END_ALLOW_THREADS; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1424 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1425 PySurface_Unlock(surfobj); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1426 SDL_UnlockSurface(newsurf); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1427 } |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1428 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1429 if (surfobj2) |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1430 { |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1431 Py_INCREF (surfobj2); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1432 return surfobj2; |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1433 } |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1434 else |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1435 return PySurface_New (newsurf); |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1436 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1437 } |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1438 |
|
1330
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
1439 static PyObject * |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1440 surf_get_smoothscale_backend (PyObject *self) |
|
1330
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
1441 { |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1442 return Text_FromUTF8 (GETSTATE (self)->filter_type); |
|
1330
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
1443 } |
|
834
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1444 |
|
1367
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1445 static PyObject * |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1446 surf_set_smoothscale_backend (PyObject *self, PyObject *args, PyObject *kwds) |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1447 { |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1448 struct _module_state *st = GETSTATE (self); |
|
1367
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1449 char *keywords[] = {"type", NULL}; |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1450 const char *type; |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1451 |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1452 if (!PyArg_ParseTupleAndKeywords (args, kwds, "s:set_smoothscale_backend", |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1453 keywords, &type)) |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1454 { |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1455 return NULL; |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1456 } |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1457 |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1458 #if defined(SCALE_MMX_SUPPORT) |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1459 if (strcmp (type, "GENERIC") == 0) |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1460 { |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1461 st->filter_type = "GENERIC"; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1462 st->filter_shrink_X = filter_shrink_X_ONLYC; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1463 st->filter_shrink_Y = filter_shrink_Y_ONLYC; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1464 st->filter_expand_X = filter_expand_X_ONLYC; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1465 st->filter_expand_Y = filter_expand_Y_ONLYC; |
|
1367
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1466 } |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1467 else if (strcmp (type, "MMX") == 0) |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1468 { |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1469 if (!SDL_HasMMX ()) |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1470 { |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1471 return RAISE (PyExc_ValueError, |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1472 "MMX not supported on this machine"); |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1473 } |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1474 st->filter_type = "MMX"; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1475 st->filter_shrink_X = filter_shrink_X_MMX; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1476 st->filter_shrink_Y = filter_shrink_Y_MMX; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1477 st->filter_expand_X = filter_expand_X_MMX; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1478 st->filter_expand_Y = filter_expand_Y_MMX; |
|
1367
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1479 } |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1480 else if (strcmp (type, "SSE") == 0) |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1481 { |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1482 if (!SDL_HasSSE ()) |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1483 { |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1484 return RAISE (PyExc_ValueError, |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1485 "SSE not supported on this machine"); |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1486 } |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1487 st->filter_type = "SSE"; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1488 st->filter_shrink_X = filter_shrink_X_SSE; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1489 st->filter_shrink_Y = filter_shrink_Y_SSE; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1490 st->filter_expand_X = filter_expand_X_SSE; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1491 st->filter_expand_Y = filter_expand_Y_SSE; |
|
1367
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1492 } |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1493 else |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1494 { |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1495 return PyErr_Format (PyExc_ValueError, |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1496 "Unknown backend type %s", type); |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1497 } |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1498 Py_RETURN_NONE; |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1499 #else /* Not an x86 processor */ |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1500 if (strcmp (type, "GENERIC") != 0) |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1501 { |
|
1556
67457499ef4a
more code fixes to transform.c for non-MMX machines
Lenard Lindstrom <len-l@telus.net>
parents:
1555
diff
changeset
|
1502 if (strcmp (st->filter_type, "MMX") == 0 || |
|
67457499ef4a
more code fixes to transform.c for non-MMX machines
Lenard Lindstrom <len-l@telus.net>
parents:
1555
diff
changeset
|
1503 strcmp (st->filter_type, "SSE") == 0 ) |
|
1367
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1504 { |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1505 return PyErr_Format (PyExc_ValueError, |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1506 "%s not supported on this machine", type); |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1507 } |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1508 return PyErr_Format (PyExc_ValueError, |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1509 "Unknown backend type %s", type); |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1510 } |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1511 Py_RETURN_NONE; |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1512 #endif /* defined(SCALE_MMX_SUPPORT) */ |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
1513 } |
|
834
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1514 |
|
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
1515 |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1516 static int get_threshold (SDL_Surface *destsurf, SDL_Surface *surf, |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1517 SDL_Surface *surf2, Uint32 color, Uint32 threshold, |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1518 Uint32 diff_color, int change_return, int inverse) |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1519 { |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1520 int x, y, result, similar, rshift, gshift, bshift, rshift2, gshift2, bshift2; |
|
1267
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
1521 int rloss, gloss, bloss, rloss2, gloss2, bloss2; |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1522 Uint8 *pixels, *destpixels, *pixels2; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1523 SDL_Rect sdlrect; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1524 SDL_PixelFormat *format, *destformat, *format2; |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1525 Uint32 the_color, the_color2, rmask, gmask, bmask, rmask2, gmask2, bmask2; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1526 Uint8 *pix, *byte_buf; |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1527 Uint8 r, g, b, a; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1528 Uint8 dr, dg, db, da; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1529 Uint8 tr, tg, tb, ta; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1530 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1531 similar = 0; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1532 pixels = (Uint8 *) surf->pixels; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1533 format = surf->format; |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1534 rmask = format->Rmask; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1535 gmask = format->Gmask; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1536 bmask = format->Bmask; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1537 rshift = format->Rshift; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1538 gshift = format->Gshift; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1539 bshift = format->Bshift; |
|
1267
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
1540 rloss = format->Rloss; |
|
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
1541 gloss = format->Gloss; |
|
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
1542 bloss = format->Bloss; |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1543 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1544 if(change_return) { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1545 sdlrect.x = sdlrect.y = 0; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1546 sdlrect.w = destsurf->w; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1547 sdlrect.h = destsurf->h; |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1548 destpixels = (Uint8 *) destsurf->pixels; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1549 destformat = destsurf->format; |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1550 result = SDL_FillRect (destsurf, &sdlrect, diff_color); |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1551 } else { /* make gcc stop complaining */ |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1552 destpixels = NULL; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1553 destformat = NULL; |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1554 } |
|
1360
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1555 |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1556 if(surf2) { |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1557 format2 = surf2->format; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1558 rmask2 = format2->Rmask; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1559 gmask2 = format2->Gmask; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1560 bmask2 = format2->Bmask; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1561 rshift2 = format2->Rshift; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1562 gshift2 = format2->Gshift; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1563 bshift2 = format2->Bshift; |
|
1267
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
1564 rloss2 = format2->Rloss; |
|
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
1565 gloss2 = format2->Gloss; |
|
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
1566 bloss2 = format2->Bloss; |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1567 pixels2 = (Uint8 *) surf2->pixels; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1568 } else { /* make gcc stop complaining */ |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1569 rmask2 = gmask2 = bmask2 = 0; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1570 rshift2 = gshift2 = bshift2 = 0; |
|
1267
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
1571 rloss2 = gloss2 = bloss2 = 0; |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1572 format2 = NULL; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1573 pixels2 = NULL; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1574 } |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1575 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1576 SDL_GetRGBA (color, format, &r, &g, &b, &a); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1577 SDL_GetRGBA (threshold, format, &tr, &tg, &tb, &ta); |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1578 SDL_GetRGBA (diff_color, format, &dr, &dg, &db, &da); |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1579 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1580 for(y=0; y < surf->h; y++) { |
|
1267
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
1581 pixels = (Uint8 *) surf->pixels + y*surf->pitch; |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1582 if (surf2) { |
|
1267
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
1583 pixels2 = (Uint8 *) surf2->pixels + y*surf2->pitch; |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1584 } |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1585 for(x=0; x < surf->w; x++) { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1586 /* the_color = surf->get_at(x,y) */ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1587 switch (format->BytesPerPixel) |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1588 { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1589 case 1: |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1590 the_color = (Uint32)*((Uint8 *) pixels); |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1591 pixels++; |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1592 break; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1593 case 2: |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1594 the_color = (Uint32)*((Uint16 *) pixels); |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1595 pixels += 2; |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1596 break; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1597 case 3: |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1598 pix = ((Uint8 *) pixels); |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1599 pixels += 3; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1600 #if SDL_BYTEORDER == SDL_LIL_ENDIAN |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1601 the_color = (pix[0]) + (pix[1] << 8) + (pix[2] << 16); |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1602 #else |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1603 the_color = (pix[2]) + (pix[1] << 8) + (pix[0] << 16); |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1604 #endif |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1605 break; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1606 default: /* case 4: */ |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1607 the_color = *((Uint32 *) pixels); |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1608 pixels += 4; |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1609 break; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1610 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1611 |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1612 if (surf2) { |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1613 switch (format2->BytesPerPixel) { |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1614 case 1: |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1615 the_color2 = (Uint32)*((Uint8 *) pixels2); |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1616 pixels2++; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1617 break; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1618 case 2: |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1619 the_color2 = (Uint32)*((Uint16 *) pixels2); |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1620 pixels2 += 2; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1621 break; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1622 case 3: |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1623 pix = ((Uint8 *) pixels2); |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1624 pixels2 += 3; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1625 #if SDL_BYTEORDER == SDL_LIL_ENDIAN |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1626 the_color2 = (pix[0]) + (pix[1] << 8) + (pix[2] << 16); |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1627 #else |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1628 the_color2 = (pix[2]) + (pix[1] << 8) + (pix[0] << 16); |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1629 #endif |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1630 break; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1631 default: /* case 4: */ |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1632 the_color2 = *((Uint32 *) pixels2); |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1633 pixels2 += 4; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1634 break; |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1635 } |
|
1360
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1636 |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1637 if (((abs((((the_color2 & rmask2) >> rshift2) << rloss2) - (((the_color & rmask) >> rshift) << rloss)) <= tr) & |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1638 (abs((((the_color2 & gmask2) >> gshift2) << gloss2) - (((the_color & gmask) >> gshift) << gloss)) <= tg) & |
|
1267
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
1639 (abs((((the_color2 & bmask2) >> bshift2) << bloss2) - (((the_color & bmask) >> bshift) << bloss)) <= tb)) |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1640 ^ inverse) { |
|
1360
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1641 /* this pixel is within the threshold of the pixel in the |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1642 other surface. */ |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1643 if (change_return == 2) { |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1644 /* change the pixel to the color from the first surface. */ |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1645 |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1646 /* destsurf->set_at((x,y), the_color) */ |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1647 switch (destformat->BytesPerPixel) { |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1648 case 1: |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1649 *((Uint8 *) destpixels + y * destsurf->pitch + x) = (Uint8) the_color; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1650 break; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1651 case 2: |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1652 *((Uint16 *) (destpixels + y * destsurf->pitch) + x) = (Uint16) the_color; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1653 break; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1654 case 3: |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1655 byte_buf = (Uint8 *) (destpixels + y * destsurf->pitch) + x * 3; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1656 #if (SDL_BYTEORDER == SDL_LIL_ENDIAN) |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1657 *(byte_buf + (destformat->Rshift >> 3)) = (Uint8) (the_color >> 16); |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1658 *(byte_buf + (destformat->Gshift >> 3)) = (Uint8) (the_color >> 8); |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1659 *(byte_buf + (destformat->Bshift >> 3)) = (Uint8) the_color; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1660 #else |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1661 *(byte_buf + 2 - (destformat->Rshift >> 3)) = (Uint8) (the_color >> 16); |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1662 *(byte_buf + 2 - (destformat->Gshift >> 3)) = (Uint8) (the_color >> 8); |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1663 *(byte_buf + 2 - (destformat->Bshift >> 3)) = (Uint8) the_color; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1664 #endif |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1665 break; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1666 default: /* case 4: */ |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1667 *((Uint32 *) (destpixels + y * destsurf->pitch) + x) = the_color; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1668 break; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1669 } |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1670 } |
|
1360
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1671 else if (change_return == 1) { |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1672 /* change the pixel to color. */ |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1673 /* destsurf->set_at((x,y), color) */ |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1674 switch (destformat->BytesPerPixel) { |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1675 case 1: |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1676 *((Uint8 *) destpixels + y * destsurf->pitch + x) = (Uint8) color; |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1677 break; |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1678 case 2: |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1679 *((Uint16 *) (destpixels + y * destsurf->pitch) + x) = (Uint16) color; |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1680 break; |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1681 case 3: |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1682 byte_buf = (Uint8 *) (destpixels + y * destsurf->pitch) + x * 3; |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1683 #if (SDL_BYTEORDER == SDL_LIL_ENDIAN) |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1684 *(byte_buf + (destformat->Rshift >> 3)) = (Uint8) (color >> 16); |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1685 *(byte_buf + (destformat->Gshift >> 3)) = (Uint8) (color >> 8); |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1686 *(byte_buf + (destformat->Bshift >> 3)) = (Uint8) color; |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1687 #else |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1688 *(byte_buf + 2 - (destformat->Rshift >> 3)) = (Uint8) (color >> 16); |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1689 *(byte_buf + 2 - (destformat->Gshift >> 3)) = (Uint8) (color >> 8); |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1690 *(byte_buf + 2 - (destformat->Bshift >> 3)) = (Uint8) color; |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1691 #endif |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1692 break; |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1693 default: /* case 4: */ |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1694 *((Uint32 *) (destpixels + y * destsurf->pitch) + x) = color; |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1695 break; |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1696 } |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1697 } |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1698 |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1699 similar++; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1700 } |
|
1360
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1701 |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1702 } else if (((abs((((the_color & rmask) >> rshift) << rloss) - r) <= tr) & |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1703 (abs((((the_color & gmask) >> gshift) << gloss) - g) <= tg) & |
|
1267
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
1704 (abs((((the_color & bmask) >> bshift) << bloss) - b) <= tb)) |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1705 ^ inverse) { |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1706 |
|
1360
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1707 /* Comparing the threshold against the color. */ |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1708 |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1709 /* this pixel is within the threshold. */ |
|
1360
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1710 if (change_return == 2) { |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1711 /* destsurf->set_at((x,y), the_color) */ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1712 switch (destformat->BytesPerPixel) |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1713 { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1714 case 1: |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1715 *((Uint8 *) destpixels + y * destsurf->pitch + x) = (Uint8) the_color; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1716 break; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1717 case 2: |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1718 *((Uint16 *) (destpixels + y * destsurf->pitch) + x) = (Uint16) the_color; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1719 break; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1720 case 3: |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1721 byte_buf = (Uint8 *) (destpixels + y * destsurf->pitch) + x * 3; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1722 #if (SDL_BYTEORDER == SDL_LIL_ENDIAN) |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1723 *(byte_buf + (destformat->Rshift >> 3)) = (Uint8) (the_color >> 16); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1724 *(byte_buf + (destformat->Gshift >> 3)) = (Uint8) (the_color >> 8); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1725 *(byte_buf + (destformat->Bshift >> 3)) = (Uint8) the_color; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1726 #else |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1727 *(byte_buf + 2 - (destformat->Rshift >> 3)) = (Uint8) (the_color >> 16); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1728 *(byte_buf + 2 - (destformat->Gshift >> 3)) = (Uint8) (the_color >> 8); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1729 *(byte_buf + 2 - (destformat->Bshift >> 3)) = (Uint8) the_color; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1730 #endif |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1731 break; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1732 default: /* case 4: */ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1733 *((Uint32 *) (destpixels + y * destsurf->pitch) + x) = the_color; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1734 break; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1735 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1736 } |
|
1360
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1737 else if (change_return == 1) { |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1738 |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1739 /* change the pixel to color. */ |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1740 /* destsurf->set_at((x,y), color) */ |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1741 switch (destformat->BytesPerPixel) |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1742 { |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1743 case 1: |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1744 *((Uint8 *) destpixels + y * destsurf->pitch + x) = (Uint8) color; |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1745 break; |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1746 case 2: |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1747 *((Uint16 *) (destpixels + y * destsurf->pitch) + x) = (Uint16) color; |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1748 break; |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1749 case 3: |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1750 byte_buf = (Uint8 *) (destpixels + y * destsurf->pitch) + x * 3; |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1751 #if (SDL_BYTEORDER == SDL_LIL_ENDIAN) |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1752 *(byte_buf + (destformat->Rshift >> 3)) = (Uint8) (color >> 16); |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1753 *(byte_buf + (destformat->Gshift >> 3)) = (Uint8) (color >> 8); |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1754 *(byte_buf + (destformat->Bshift >> 3)) = (Uint8) color; |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1755 #else |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1756 *(byte_buf + 2 - (destformat->Rshift >> 3)) = (Uint8) (color >> 16); |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1757 *(byte_buf + 2 - (destformat->Gshift >> 3)) = (Uint8) (color >> 8); |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1758 *(byte_buf + 2 - (destformat->Bshift >> 3)) = (Uint8) color; |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1759 #endif |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1760 break; |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1761 default: /* case 4: */ |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1762 *((Uint32 *) (destpixels + y * destsurf->pitch) + x) = color; |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1763 break; |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1764 } |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1765 } |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1766 |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1767 similar++; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1768 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1769 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1770 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1771 return similar; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1772 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1773 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1774 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1775 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1776 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1777 static PyObject* surf_threshold(PyObject* self, PyObject* arg) |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1778 { |
|
1604
e87063486367
fix transform.threshold bug involving a long threshold
Lenard Lindstrom <len-l@telus.net>
parents:
1596
diff
changeset
|
1779 PyObject *surfobj, *surfobj2 = NULL, *surfobj3 = NULL; |
|
e87063486367
fix transform.threshold bug involving a long threshold
Lenard Lindstrom <len-l@telus.net>
parents:
1596
diff
changeset
|
1780 SDL_Surface* surf = NULL, *destsurf = NULL, *surf2 = NULL; |
|
e87063486367
fix transform.threshold bug involving a long threshold
Lenard Lindstrom <len-l@telus.net>
parents:
1596
diff
changeset
|
1781 int bpp, change_return = 1, inverse = 0; |
|
e87063486367
fix transform.threshold bug involving a long threshold
Lenard Lindstrom <len-l@telus.net>
parents:
1596
diff
changeset
|
1782 int num_threshold_pixels = 0; |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1783 |
|
1604
e87063486367
fix transform.threshold bug involving a long threshold
Lenard Lindstrom <len-l@telus.net>
parents:
1596
diff
changeset
|
1784 PyObject *rgba_obj_color; |
|
e87063486367
fix transform.threshold bug involving a long threshold
Lenard Lindstrom <len-l@telus.net>
parents:
1596
diff
changeset
|
1785 PyObject *rgba_obj_threshold = NULL; |
|
e87063486367
fix transform.threshold bug involving a long threshold
Lenard Lindstrom <len-l@telus.net>
parents:
1596
diff
changeset
|
1786 PyObject *rgba_obj_diff_color = NULL; |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1787 Uint8 rgba_color[4]; |
|
1604
e87063486367
fix transform.threshold bug involving a long threshold
Lenard Lindstrom <len-l@telus.net>
parents:
1596
diff
changeset
|
1788 Uint8 rgba_threshold[4] = {0, 0, 0, 255}; |
|
e87063486367
fix transform.threshold bug involving a long threshold
Lenard Lindstrom <len-l@telus.net>
parents:
1596
diff
changeset
|
1789 Uint8 rgba_diff_color[4] = {0, 0, 0, 255}; |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1790 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1791 Uint32 color; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1792 Uint32 color_threshold; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1793 Uint32 color_diff_color; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1794 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1795 /*get all the arguments*/ |
|
1360
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1796 if (!PyArg_ParseTuple (arg, "O!O!O|OOiO!i", &PySurface_Type, &surfobj, |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1797 &PySurface_Type, &surfobj2, |
|
1360
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1798 &rgba_obj_color, &rgba_obj_threshold, &rgba_obj_diff_color, |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1799 &change_return, |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1800 &PySurface_Type, &surfobj3, &inverse)) |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1801 return NULL; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1802 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1803 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1804 destsurf = PySurface_AsSurface (surfobj); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1805 surf = PySurface_AsSurface (surfobj2); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1806 if(surfobj3) { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1807 surf2 = PySurface_AsSurface (surfobj3); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1808 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1809 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1810 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1811 |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1812 if (PyInt_Check (rgba_obj_color)) { |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1813 color = (Uint32) PyInt_AsLong (rgba_obj_color); |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1814 } else if (PyLong_Check (rgba_obj_color)) { |
|
1117
fa8a25ebb16a
Fixed Surface.set_alpha() overflow bug. Minor improvements for integer rgba color values.
marcus
parents:
1037
diff
changeset
|
1815 color = (Uint32) PyLong_AsUnsignedLong (rgba_obj_color); |
|
fa8a25ebb16a
Fixed Surface.set_alpha() overflow bug. Minor improvements for integer rgba color values.
marcus
parents:
1037
diff
changeset
|
1816 } |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1817 else if (RGBAFromColorObj (rgba_obj_color, rgba_color)) { |
|
1117
fa8a25ebb16a
Fixed Surface.set_alpha() overflow bug. Minor improvements for integer rgba color values.
marcus
parents:
1037
diff
changeset
|
1818 color = SDL_MapRGBA (surf->format, rgba_color[0], rgba_color[1], |
|
fa8a25ebb16a
Fixed Surface.set_alpha() overflow bug. Minor improvements for integer rgba color values.
marcus
parents:
1037
diff
changeset
|
1819 rgba_color[2], rgba_color[3]); |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
1820 } else { |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1821 return RAISE (PyExc_TypeError, "invalid color argument"); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1822 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1823 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1824 if(rgba_obj_threshold) { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1825 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1826 if (PyInt_Check (rgba_obj_threshold)) |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1827 color_threshold = (Uint32) PyInt_AsLong (rgba_obj_threshold); |
|
1117
fa8a25ebb16a
Fixed Surface.set_alpha() overflow bug. Minor improvements for integer rgba color values.
marcus
parents:
1037
diff
changeset
|
1828 else if (PyLong_Check (rgba_obj_threshold)) |
|
fa8a25ebb16a
Fixed Surface.set_alpha() overflow bug. Minor improvements for integer rgba color values.
marcus
parents:
1037
diff
changeset
|
1829 color_threshold = (Uint32) PyLong_AsUnsignedLong |
|
fa8a25ebb16a
Fixed Surface.set_alpha() overflow bug. Minor improvements for integer rgba color values.
marcus
parents:
1037
diff
changeset
|
1830 (rgba_obj_threshold); |
| 1037 | 1831 else if (RGBAFromColorObj (rgba_obj_threshold, rgba_threshold)) |
|
1604
e87063486367
fix transform.threshold bug involving a long threshold
Lenard Lindstrom <len-l@telus.net>
parents:
1596
diff
changeset
|
1832 color_threshold = SDL_MapRGBA (surf->format, |
|
e87063486367
fix transform.threshold bug involving a long threshold
Lenard Lindstrom <len-l@telus.net>
parents:
1596
diff
changeset
|
1833 rgba_threshold[0], |
|
e87063486367
fix transform.threshold bug involving a long threshold
Lenard Lindstrom <len-l@telus.net>
parents:
1596
diff
changeset
|
1834 rgba_threshold[1], |
|
e87063486367
fix transform.threshold bug involving a long threshold
Lenard Lindstrom <len-l@telus.net>
parents:
1596
diff
changeset
|
1835 rgba_threshold[2], |
|
e87063486367
fix transform.threshold bug involving a long threshold
Lenard Lindstrom <len-l@telus.net>
parents:
1596
diff
changeset
|
1836 rgba_threshold[3]); |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1837 else |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1838 return RAISE (PyExc_TypeError, "invalid threshold argument"); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1839 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1840 } else { |
|
1604
e87063486367
fix transform.threshold bug involving a long threshold
Lenard Lindstrom <len-l@telus.net>
parents:
1596
diff
changeset
|
1841 color_threshold = SDL_MapRGBA (surf->format, |
|
e87063486367
fix transform.threshold bug involving a long threshold
Lenard Lindstrom <len-l@telus.net>
parents:
1596
diff
changeset
|
1842 rgba_threshold[0], |
|
e87063486367
fix transform.threshold bug involving a long threshold
Lenard Lindstrom <len-l@telus.net>
parents:
1596
diff
changeset
|
1843 rgba_threshold[1], |
|
e87063486367
fix transform.threshold bug involving a long threshold
Lenard Lindstrom <len-l@telus.net>
parents:
1596
diff
changeset
|
1844 rgba_threshold[2], |
|
e87063486367
fix transform.threshold bug involving a long threshold
Lenard Lindstrom <len-l@telus.net>
parents:
1596
diff
changeset
|
1845 rgba_threshold[3]); |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1846 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1847 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1848 if(rgba_obj_diff_color) { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1849 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1850 if (PyInt_Check (rgba_obj_diff_color)) |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1851 color_diff_color = (Uint32) PyInt_AsLong (rgba_obj_diff_color); |
|
1604
e87063486367
fix transform.threshold bug involving a long threshold
Lenard Lindstrom <len-l@telus.net>
parents:
1596
diff
changeset
|
1852 else if (PyLong_Check (rgba_obj_diff_color)) |
|
1117
fa8a25ebb16a
Fixed Surface.set_alpha() overflow bug. Minor improvements for integer rgba color values.
marcus
parents:
1037
diff
changeset
|
1853 color_diff_color = (Uint32) PyLong_AsUnsignedLong |
|
fa8a25ebb16a
Fixed Surface.set_alpha() overflow bug. Minor improvements for integer rgba color values.
marcus
parents:
1037
diff
changeset
|
1854 (rgba_obj_diff_color); |
| 1037 | 1855 else if (RGBAFromColorObj (rgba_obj_diff_color, rgba_diff_color)) |
|
1604
e87063486367
fix transform.threshold bug involving a long threshold
Lenard Lindstrom <len-l@telus.net>
parents:
1596
diff
changeset
|
1856 color_diff_color = SDL_MapRGBA (surf->format, |
|
e87063486367
fix transform.threshold bug involving a long threshold
Lenard Lindstrom <len-l@telus.net>
parents:
1596
diff
changeset
|
1857 rgba_diff_color[0], |
|
e87063486367
fix transform.threshold bug involving a long threshold
Lenard Lindstrom <len-l@telus.net>
parents:
1596
diff
changeset
|
1858 rgba_diff_color[1], |
|
e87063486367
fix transform.threshold bug involving a long threshold
Lenard Lindstrom <len-l@telus.net>
parents:
1596
diff
changeset
|
1859 rgba_diff_color[2], |
|
e87063486367
fix transform.threshold bug involving a long threshold
Lenard Lindstrom <len-l@telus.net>
parents:
1596
diff
changeset
|
1860 rgba_diff_color[3]); |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1861 else |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1862 return RAISE (PyExc_TypeError, "invalid diff_color argument"); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1863 } else { |
|
1604
e87063486367
fix transform.threshold bug involving a long threshold
Lenard Lindstrom <len-l@telus.net>
parents:
1596
diff
changeset
|
1864 color_diff_color = SDL_MapRGBA (surf->format, |
|
e87063486367
fix transform.threshold bug involving a long threshold
Lenard Lindstrom <len-l@telus.net>
parents:
1596
diff
changeset
|
1865 rgba_diff_color[0], |
|
e87063486367
fix transform.threshold bug involving a long threshold
Lenard Lindstrom <len-l@telus.net>
parents:
1596
diff
changeset
|
1866 rgba_diff_color[1], |
|
e87063486367
fix transform.threshold bug involving a long threshold
Lenard Lindstrom <len-l@telus.net>
parents:
1596
diff
changeset
|
1867 rgba_diff_color[2], |
|
e87063486367
fix transform.threshold bug involving a long threshold
Lenard Lindstrom <len-l@telus.net>
parents:
1596
diff
changeset
|
1868 rgba_diff_color[3]); |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1869 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1870 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1871 bpp = surf->format->BytesPerPixel; |
|
1360
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
1872 |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1873 PySurface_Lock(surfobj); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1874 PySurface_Lock(surfobj2); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1875 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1876 if(surfobj3) { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1877 PySurface_Lock(surfobj3); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1878 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1879 Py_BEGIN_ALLOW_THREADS; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1880 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1881 |
|
1604
e87063486367
fix transform.threshold bug involving a long threshold
Lenard Lindstrom <len-l@telus.net>
parents:
1596
diff
changeset
|
1882 num_threshold_pixels = get_threshold (destsurf, |
|
e87063486367
fix transform.threshold bug involving a long threshold
Lenard Lindstrom <len-l@telus.net>
parents:
1596
diff
changeset
|
1883 surf, |
|
e87063486367
fix transform.threshold bug involving a long threshold
Lenard Lindstrom <len-l@telus.net>
parents:
1596
diff
changeset
|
1884 surf2, |
|
e87063486367
fix transform.threshold bug involving a long threshold
Lenard Lindstrom <len-l@telus.net>
parents:
1596
diff
changeset
|
1885 color, |
|
e87063486367
fix transform.threshold bug involving a long threshold
Lenard Lindstrom <len-l@telus.net>
parents:
1596
diff
changeset
|
1886 color_threshold, |
|
e87063486367
fix transform.threshold bug involving a long threshold
Lenard Lindstrom <len-l@telus.net>
parents:
1596
diff
changeset
|
1887 color_diff_color, |
|
e87063486367
fix transform.threshold bug involving a long threshold
Lenard Lindstrom <len-l@telus.net>
parents:
1596
diff
changeset
|
1888 change_return, |
|
e87063486367
fix transform.threshold bug involving a long threshold
Lenard Lindstrom <len-l@telus.net>
parents:
1596
diff
changeset
|
1889 inverse); |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1890 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1891 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1892 Py_END_ALLOW_THREADS; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1893 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1894 PySurface_Unlock(surfobj); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1895 PySurface_Unlock(surfobj2); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1896 if(surfobj3) { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1897 PySurface_Unlock(surfobj3); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1898 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1899 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1900 return PyInt_FromLong (num_threshold_pixels); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1901 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1902 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1903 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1904 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1905 /* |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1906 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1907 TODO: |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1908 add_4 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1909 sub_4 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1910 mul_4 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1911 clamp_4 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1912 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1913 */ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1914 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1915 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1916 #define SURF_GET_AT(p_color, p_surf, p_x, p_y, p_pixels, p_format, p_pix) \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1917 switch (p_format->BytesPerPixel) \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1918 { \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1919 case 1: \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1920 p_color = (Uint32)*((Uint8 *) (p_pixels) + (p_y) * p_surf->pitch + (p_x)); \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1921 break; \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1922 case 2: \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1923 p_color = (Uint32)*((Uint16 *) ((p_pixels) + (p_y) * p_surf->pitch) + (p_x)); \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1924 break; \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1925 case 3: \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1926 p_pix = ((Uint8 *) (p_pixels + (p_y) * p_surf->pitch) + (p_x) * 3); \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1927 p_color = (SDL_BYTEORDER == SDL_LIL_ENDIAN) ? \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1928 (p_pix[0]) + (p_pix[1] << 8) + (p_pix[2] << 16) : \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1929 (p_pix[2]) + (p_pix[1] << 8) + (p_pix[0] << 16); \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1930 break; \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1931 default: /* case 4: */ \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1932 p_color = *((Uint32 *) (p_pixels + (p_y) * p_surf->pitch) + (p_x)); \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1933 break; \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1934 } \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1935 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1936 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1937 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1938 #if (SDL_BYTEORDER == SDL_LIL_ENDIAN) |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1939 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1940 #define SURF_SET_AT(p_color, p_surf, p_x, p_y, p_pixels, p_format, p_byte_buf) \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1941 switch (p_format->BytesPerPixel) \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1942 { \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1943 case 1: \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1944 *((Uint8 *) p_pixels + (p_y) * p_surf->pitch + (p_x)) = (Uint8) p_color; \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1945 break; \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1946 case 2: \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1947 *((Uint16 *) (p_pixels + (p_y) * p_surf->pitch) + (p_x)) = (Uint16) p_color; \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1948 break; \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1949 case 3: \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1950 p_byte_buf = (Uint8 *) (p_pixels + (p_y) * p_surf->pitch) + (p_x) * 3; \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1951 *(p_byte_buf + (p_format->Rshift >> 3)) = (Uint8) (p_color >> 16); \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1952 *(p_byte_buf + (p_format->Gshift >> 3)) = (Uint8) (p_color >> 8); \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1953 *(p_byte_buf + (p_format->Bshift >> 3)) = (Uint8) p_color; \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1954 break; \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1955 default: \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1956 *((Uint32 *) (p_pixels + (p_y) * p_surf->pitch) + (p_x)) = p_color; \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1957 break; \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1958 } \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1959 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1960 #else |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1961 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1962 #define SURF_SET_AT(p_color, p_surf, p_x, p_y, p_pixels, p_format, p_byte_buf) \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1963 switch (p_format->BytesPerPixel) \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1964 { \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1965 case 1: \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1966 *((Uint8 *) p_pixels + (p_y) * p_surf->pitch + (p_x)) = (Uint8) p_color; \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1967 break; \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1968 case 2: \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1969 *((Uint16 *) (p_pixels + (p_y) * p_surf->pitch) + (p_x)) = (Uint16) p_color; \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1970 break; \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1971 case 3: \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1972 p_byte_buf = (Uint8 *) (p_pixels + (p_y) * p_surf->pitch) + (p_x) * 3; \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1973 *(p_byte_buf + 2 - (p_format->Rshift >> 3)) = (Uint8) (p_color >> 16); \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1974 *(p_byte_buf + 2 - (p_format->Gshift >> 3)) = (Uint8) (p_color >> 8); \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1975 *(p_byte_buf + 2 - (p_format->Bshift >> 3)) = (Uint8) p_color; \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1976 break; \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1977 default: \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1978 *((Uint32 *) (p_pixels + (p_y) * p_surf->pitch) + (p_x)) = p_color; \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1979 break; \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1980 } \ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1981 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1982 #endif |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1983 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1984 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1985 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1986 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1987 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1988 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1989 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1990 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1991 /* |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1992 number to use for missing samples |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1993 */ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1994 #define LAPLACIAN_NUM 0xFFFFFFFF |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1995 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1996 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1997 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1998 void laplacian(SDL_Surface *surf, SDL_Surface *destsurf) { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
1999 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2000 int ii; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2001 int x,y,height,width; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2002 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2003 Uint32 sample[9]; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2004 //Uint32 total[4]; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2005 int total[4]; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2006 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2007 Uint8 c1r, c1g, c1b, c1a; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2008 //Uint32 c1r, c1g, c1b, c1a; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2009 Uint8 acolor[4]; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2010 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2011 Uint32 the_color; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2012 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2013 int atmp0; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2014 int atmp1; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2015 int atmp2; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2016 int atmp3; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2017 |
|
1330
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
2018 SDL_PixelFormat *format, *destformat; |
|
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
2019 Uint8 *pixels, *destpixels; |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2020 Uint8 *pix; |
|
1360
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
2021 |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2022 Uint8 *byte_buf; |
|
1360
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
2023 |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
2024 |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2025 height = surf->h; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2026 width = surf->w; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2027 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2028 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2029 pixels = (Uint8 *) surf->pixels; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2030 format = surf->format; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2031 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2032 destpixels = (Uint8 *) destsurf->pixels; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2033 destformat = destsurf->format; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2034 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2035 /* |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2036 -1 -1 -1 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2037 -1 8 -1 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2038 -1 -1 -1 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2039 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2040 col = (sample[4] * 8) - (sample[0] + sample[1] + sample[2] + |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2041 sample[3] + sample[5] + |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2042 sample[6] + sample[7] + sample[8]) |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2043 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2044 [(-1,-1), (0,-1), (1,-1), (-1,0), (0,0), (1,0), (-1,1), (0,1), (1,1)] |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2045 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2046 */ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2047 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2048 for(y=0;y<height;y++) { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2049 for(x=0;x<width;x++) { |
|
1360
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
2050 |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2051 // Need to bounds check these accesses. |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2052 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2053 if(y > 0) { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2054 if(x>0) { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2055 SURF_GET_AT(sample[0], surf, x+ -1, y+ -1, pixels, format, pix); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2056 } |
|
1360
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
2057 |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2058 SURF_GET_AT(sample[1], surf, x+ 0, y+ -1, pixels, format, pix); |
|
1360
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
2059 |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2060 if(x+1<width) { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2061 SURF_GET_AT(sample[2], surf, x+ 1, y+ -1, pixels, format, pix); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2062 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2063 } else { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2064 sample[0] = LAPLACIAN_NUM; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2065 sample[1] = LAPLACIAN_NUM; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2066 sample[2] = LAPLACIAN_NUM; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2067 } |
|
1360
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
2068 |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2069 if(x>0) { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2070 SURF_GET_AT(sample[3], surf, x+ -1, y+ 0, pixels, format, pix); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2071 } else { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2072 sample[3] = LAPLACIAN_NUM; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2073 } |
|
1360
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
2074 |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
2075 |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2076 //SURF_GET_AT(sample[4], surf, x+0 , y+0); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2077 sample[4] = 0; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2078 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2079 if(x+1<width) { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2080 SURF_GET_AT(sample[5], surf, x+ 1, y+ 0, pixels, format, pix); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2081 } else { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2082 sample[5] = LAPLACIAN_NUM; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2083 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2084 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2085 if(y+1 < height) { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2086 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2087 if(x>0) { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2088 SURF_GET_AT(sample[6], surf, x+ -1, y+ 1, pixels, format, pix); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2089 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2090 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2091 SURF_GET_AT(sample[7], surf, x+ 0, y+ 1, pixels, format, pix); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2092 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2093 if(x+1<width) { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2094 SURF_GET_AT(sample[8], surf, x+ 1, y+ 1, pixels, format, pix); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2095 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2096 } else { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2097 sample[6] = LAPLACIAN_NUM; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2098 sample[7] = LAPLACIAN_NUM; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2099 sample[8] = LAPLACIAN_NUM; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2100 } |
|
1360
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
2101 |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
2102 |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2103 total[0] = 0; total[1] = 0; total[2] = 0; total[3] = 0; |
|
1360
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
2104 |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2105 for(ii =0; ii<9; ii++) { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2106 SDL_GetRGBA (sample[ii], format, &c1r, &c1g, &c1b, &c1a); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2107 total[0] += c1r; total[1] += c1g; total[2] += c1b; total[3] += c1a; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2108 } |
|
1360
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
2109 |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
2110 |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2111 SURF_GET_AT(sample[4], surf, x, y, pixels, format, pix); |
|
1360
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
2112 |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2113 SDL_GetRGBA (sample[4], format, &c1r, &c1g, &c1b, &c1a); |
|
1360
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
2114 |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2115 // cast on the right to a signed int, and then clamp to 0-255. |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2116 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2117 //atmp = c1r * 8 |
|
1360
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
2118 |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2119 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2120 atmp0 = c1r * 8; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2121 acolor[0] = MIN(MAX(atmp0 - total[0], 0), 255); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2122 atmp1 = c1g * 8; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2123 acolor[1] = MIN(MAX(atmp1 - total[1], 0), 255); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2124 atmp2 = c1b * 8; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2125 acolor[2] = MIN(MAX(atmp2 - total[2], 0), 255); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2126 atmp3 = c1a * 8; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2127 acolor[3] = MIN(MAX(atmp3 - total[3], 0), 255); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2128 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2129 //printf("%d;;%d;;%d;; ", atmp0, acolor[0],total[0]); |
|
1360
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
2130 |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
2131 |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2132 //printf("%d,%d,%d,%d;; \n", acolor[0], acolor[1], acolor[2], acolor[3]); |
|
1360
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
2133 |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2134 //the_color = (Uint32)acolor; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2135 //the_color = 0x00000000; |
|
1360
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
2136 |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
2137 |
|
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
2138 |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2139 // cast on the right to Uint32, and then clamp to 255. |
|
1360
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
2140 |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2141 the_color = SDL_MapRGBA (surf->format, acolor[0], acolor[1], acolor[2], acolor[3]); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2142 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2143 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2144 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2145 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2146 // set_at(destsurf, color, x,y); |
|
1360
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
2147 |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2148 switch (destformat->BytesPerPixel) |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2149 { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2150 case 1: |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2151 *((Uint8 *) destpixels + y * destsurf->pitch + x) = (Uint8) the_color; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2152 break; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2153 case 2: |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2154 *((Uint16 *) (destpixels + y * destsurf->pitch) + x) = (Uint16) the_color; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2155 break; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2156 case 3: |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2157 byte_buf = (Uint8 *) (destpixels + y * destsurf->pitch) + x * 3; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2158 #if (SDL_BYTEORDER == SDL_LIL_ENDIAN) |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2159 *(byte_buf + (destformat->Rshift >> 3)) = (Uint8) (the_color >> 16); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2160 *(byte_buf + (destformat->Gshift >> 3)) = (Uint8) (the_color >> 8); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2161 *(byte_buf + (destformat->Bshift >> 3)) = (Uint8) the_color; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2162 #else |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2163 *(byte_buf + 2 - (destformat->Rshift >> 3)) = (Uint8) (the_color >> 16); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2164 *(byte_buf + 2 - (destformat->Gshift >> 3)) = (Uint8) (the_color >> 8); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2165 *(byte_buf + 2 - (destformat->Bshift >> 3)) = (Uint8) the_color; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2166 #endif |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2167 break; |
|
1360
7b18b561457f
Changed pygame.transform.threshold to behave like pygame 1.8 again.
Rene Dudfield <renesd@gmail.com>
parents:
1337
diff
changeset
|
2168 default: |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2169 *((Uint32 *) (destpixels + y * destsurf->pitch) + x) = the_color; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2170 break; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2171 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2172 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2173 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2174 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2175 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2176 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2177 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2178 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2179 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2180 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2181 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2182 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2183 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2184 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2185 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2186 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2187 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2188 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2189 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2190 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2191 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2192 static PyObject* |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2193 surf_laplacian (PyObject* self, PyObject* arg) |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2194 { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2195 PyObject *surfobj, *surfobj2; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2196 SDL_Surface *surf; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2197 SDL_Surface *newsurf; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2198 int width, height; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2199 surfobj2 = NULL; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2200 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2201 /*get all the arguments*/ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2202 if (!PyArg_ParseTuple (arg, "O!|O!", &PySurface_Type, &surfobj, |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2203 &PySurface_Type, &surfobj2)) |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2204 return NULL; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2205 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2206 surf = PySurface_AsSurface (surfobj); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2207 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2208 /* if the second surface is not there, then make a new one. */ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2209 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2210 if (!surfobj2) |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2211 { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2212 width = surf->w; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2213 height = surf->h; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2214 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2215 newsurf = newsurf_fromsurf (surf, width, height); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2216 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2217 if (!newsurf) |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2218 return NULL; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2219 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2220 else |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2221 newsurf = PySurface_AsSurface (surfobj2); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2222 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2223 /* check to see if the size is the correct size. */ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2224 if (newsurf->w != (surf->w) || newsurf->h != (surf->h)) |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2225 return RAISE (PyExc_ValueError, "Destination surface not the same size."); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2226 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2227 /* check to see if the format of the surface is the same. */ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2228 if (surf->format->BytesPerPixel != newsurf->format->BytesPerPixel) |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2229 return RAISE (PyExc_ValueError, |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2230 "Source and destination surfaces need the same format."); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2231 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2232 SDL_LockSurface (newsurf); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2233 SDL_LockSurface (surf); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2234 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2235 Py_BEGIN_ALLOW_THREADS; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2236 laplacian (surf, newsurf); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2237 Py_END_ALLOW_THREADS; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2238 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2239 SDL_UnlockSurface (surf); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2240 SDL_UnlockSurface (newsurf); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2241 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2242 if (surfobj2) |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2243 { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2244 Py_INCREF (surfobj2); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2245 return surfobj2; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2246 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2247 else |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2248 return PySurface_New (newsurf); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2249 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2250 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2251 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2252 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2253 |
|
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:
1804
diff
changeset
|
2254 int average_surfaces(SDL_Surface **surfaces, |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2255 int num_surfaces, |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2256 SDL_Surface *destsurf, |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2257 int palette_colors) { |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2258 /* |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2259 returns the average surface from the ones given. |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2260 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2261 All surfaces need to be the same size. |
|
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:
1804
diff
changeset
|
2262 |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2263 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:
1804
diff
changeset
|
2264 average the pixel values. This is useful if the surface is |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2265 actually greyscale 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:
1804
diff
changeset
|
2266 |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2267 */ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2268 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2269 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2270 Uint32 *accumulate; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2271 Uint32 *the_idx; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2272 Uint32 the_color; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2273 SDL_Surface *surf; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2274 int height, width, x, y, surf_idx; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2275 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2276 float div_inv; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2277 |
|
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:
1804
diff
changeset
|
2278 |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2279 |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2280 |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2281 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2282 SDL_PixelFormat *format, *destformat; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2283 Uint8 *pixels, *destpixels; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2284 Uint8 *pix; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2285 Uint8 *byte_buf; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2286 |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2287 Uint32 rmask, gmask, bmask; |
|
1267
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
2288 int rshift, gshift, bshift, rloss, gloss, bloss; |
|
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:
1804
diff
changeset
|
2289 int num_elements; |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2290 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2291 if(!num_surfaces) { return 0; } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2292 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2293 height = surfaces[0]->h; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2294 width = surfaces[0]->w; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2295 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2296 destpixels = (Uint8 *) destsurf->pixels; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2297 destformat = destsurf->format; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2298 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2299 |
|
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:
1804
diff
changeset
|
2300 /* allocate an array to accumulate them all. |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2301 |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2302 If we're using 1 byte per pixel, then only need to average on that much. |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2303 */ |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2304 |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2305 if((destformat->BytesPerPixel == 1) && |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2306 (destformat->palette) && |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2307 (!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:
1804
diff
changeset
|
2308 num_elements = 1; |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2309 } else { |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2310 num_elements = 3; |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2311 } |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2312 |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2313 accumulate = (Uint32 *) calloc(1, sizeof(Uint32) * height * width * num_elements ); |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2314 |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2315 |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2316 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2317 if(!accumulate) { return -1; } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2318 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2319 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2320 /* add up the r,g,b from all the surfaces. */ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2321 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2322 for(surf_idx=0;surf_idx < num_surfaces;surf_idx++) { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2323 surf = surfaces[surf_idx]; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2324 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2325 pixels = (Uint8 *) surf->pixels; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2326 format = surf->format; |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2327 rmask = format->Rmask; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2328 gmask = format->Gmask; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2329 bmask = format->Bmask; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2330 rshift = format->Rshift; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2331 gshift = format->Gshift; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2332 bshift = format->Bshift; |
|
1267
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
2333 rloss = format->Rloss; |
|
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
2334 gloss = format->Gloss; |
|
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
2335 bloss = format->Bloss; |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2336 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2337 the_idx = accumulate; |
|
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:
1804
diff
changeset
|
2338 /* If palette surface, we use a different code path... */ |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2339 |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2340 if((format->BytesPerPixel == 1 && destformat->BytesPerPixel == 1) |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2341 && (format->palette) && (destformat->palette) && (!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:
1804
diff
changeset
|
2342 ) { |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2343 /* |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2344 This is useful if the surface is actually greyscale 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:
1804
diff
changeset
|
2345 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:
1804
diff
changeset
|
2346 */ |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2347 for(y=0;y<height;y++) { |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2348 for(x=0;x<width;x++) { |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2349 SURF_GET_AT(the_color, surf, x, y, pixels, format, pix); |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2350 *(the_idx) += the_color; |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2351 the_idx++; |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2352 } |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2353 } |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2354 |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2355 |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2356 } else { |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2357 /* TODO: This doesn't work correctly for palette surfaces yet, when the |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2358 source is paletted. Probably need to use something |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2359 like GET_PIXELVALS_1 from surface.h |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2360 */ |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2361 |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2362 |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2363 /* for non palette surfaces, we do this... */ |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2364 for(y=0;y<height;y++) { |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2365 for(x=0;x<width;x++) { |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2366 SURF_GET_AT(the_color, surf, x, y, pixels, format, pix); |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2367 |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2368 *(the_idx) += ((the_color & rmask) >> rshift) << rloss; |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2369 *(the_idx + 1) += ((the_color & gmask) >> gshift) << gloss; |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2370 *(the_idx + 2) += ((the_color & bmask) >> bshift) << bloss; |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2371 the_idx += 3; |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2372 } |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2373 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2374 } |
|
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:
1804
diff
changeset
|
2375 |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2376 |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2377 |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2378 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2379 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2380 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2381 /* blit the accumulated array back to the destination surface. */ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2382 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2383 |
|
1337
3f0a06cc1e4a
Yet again with that MacOSX and transform
Lenard Lindstrom <len-l@telus.net>
parents:
1330
diff
changeset
|
2384 div_inv = (float) (1.0L / (num_surfaces)); |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2385 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2386 the_idx = accumulate; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2387 |
|
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:
1804
diff
changeset
|
2388 if(num_elements == 1 && (!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:
1804
diff
changeset
|
2389 /* this is where we are using the palette surface without using its |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2390 colors from the palette. |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2391 */ |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2392 for(y=0;y<height;y++) { |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2393 for(x=0;x<width;x++) { |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2394 the_color = (*(the_idx) * div_inv + .5f); |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2395 SURF_SET_AT(the_color, destsurf, x, y, destpixels, destformat, byte_buf); |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2396 the_idx++; |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2397 } |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2398 } |
|
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:
1804
diff
changeset
|
2399 /* TODO: will need to handle 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:
1804
diff
changeset
|
2400 */ |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2401 |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2402 } else if (num_elements == 3) { |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2403 for(y=0;y<height;y++) { |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2404 for(x=0;x<width;x++) { |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2405 |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2406 the_color = SDL_MapRGB (destformat, |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2407 (Uint8) (*(the_idx) * div_inv + .5f), |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2408 (Uint8) (*(the_idx + 1) * div_inv + .5f), |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2409 (Uint8) (*(the_idx + 2) * div_inv + .5f)); |
|
1822
1ea8ab9129a0
Added palette_colors to mask.from_threshold. TODO notes to some functions.
Rene Dudfield <renesd@gmail.com>
parents:
1813
diff
changeset
|
2410 |
|
1ea8ab9129a0
Added palette_colors to mask.from_threshold. TODO notes to some functions.
Rene Dudfield <renesd@gmail.com>
parents:
1813
diff
changeset
|
2411 /* TODO: should it take into consideration the output |
|
1ea8ab9129a0
Added palette_colors to mask.from_threshold. TODO notes to some functions.
Rene Dudfield <renesd@gmail.com>
parents:
1813
diff
changeset
|
2412 shifts/masks/losses? Or does SDL_MapRGB do that correctly? |
|
1ea8ab9129a0
Added palette_colors to mask.from_threshold. TODO notes to some functions.
Rene Dudfield <renesd@gmail.com>
parents:
1813
diff
changeset
|
2413 |
|
1ea8ab9129a0
Added palette_colors to mask.from_threshold. TODO notes to some functions.
Rene Dudfield <renesd@gmail.com>
parents:
1813
diff
changeset
|
2414 *(the_idx) += ((the_color & rmask) >> rshift) << rloss; |
|
1ea8ab9129a0
Added palette_colors to mask.from_threshold. TODO notes to some functions.
Rene Dudfield <renesd@gmail.com>
parents:
1813
diff
changeset
|
2415 *(the_idx + 1) += ((the_color & gmask) >> gshift) << gloss; |
|
1ea8ab9129a0
Added palette_colors to mask.from_threshold. TODO notes to some functions.
Rene Dudfield <renesd@gmail.com>
parents:
1813
diff
changeset
|
2416 *(the_idx + 2) += ((the_color & bmask) >> bshift) << bloss; |
|
1ea8ab9129a0
Added palette_colors to mask.from_threshold. TODO notes to some functions.
Rene Dudfield <renesd@gmail.com>
parents:
1813
diff
changeset
|
2417 */ |
|
1ea8ab9129a0
Added palette_colors to mask.from_threshold. TODO notes to some functions.
Rene Dudfield <renesd@gmail.com>
parents:
1813
diff
changeset
|
2418 |
|
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:
1804
diff
changeset
|
2419 SURF_SET_AT(the_color, destsurf, x, y, destpixels, destformat, byte_buf); |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2420 |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2421 the_idx += 3; |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2422 } |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2423 } |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2424 } else { |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2425 free(accumulate); |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2426 return -4; |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2427 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2428 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2429 free(accumulate); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2430 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2431 return 1; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2432 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2433 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2434 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2435 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2436 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2437 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2438 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2439 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2440 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2441 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2442 |
|
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:
1804
diff
changeset
|
2443 /* |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2444 returns the average surface from the ones given. |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2445 |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2446 All surfaces need to be the same size. |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2447 |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2448 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:
1804
diff
changeset
|
2449 average the pixel values. This is useful if the surface is |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2450 actually greyscale 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:
1804
diff
changeset
|
2451 |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2452 */ |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2453 static PyObject* |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2454 surf_average_surfaces (PyObject* self, PyObject* arg) |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2455 { |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2456 PyObject *surfobj2; |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2457 SDL_Surface *surf; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2458 SDL_Surface *newsurf; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2459 SDL_Surface **surfaces; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2460 int width, height; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2461 int an_error; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2462 size_t size, loop, loop_up_to; |
|
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:
1804
diff
changeset
|
2463 int palette_colors = 1; |
|
3e6eb68af370
Added a palette_colors option to average_surfaces... which doesn't handle palette using surfaces correctly(yet).
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
2464 |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2465 PyObject* list, *obj; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2466 PyObject* ret = NULL; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2467 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2468 an_error = 0; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2469 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2470 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2471 surfobj2 = NULL; |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2472 newsurf = NULL; |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2473 |
|
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:
1804
diff
changeset
|
2474 if (!PyArg_ParseTuple (arg, "O|O!i", &list, &PySurface_Type, &surfobj2, &palette_colors )) |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2475 return NULL; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2476 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2477 if (!PySequence_Check (list)) |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2478 return RAISE (PyExc_TypeError, "Argument must be a sequence of surface objects."); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2479 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2480 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2481 size = PySequence_Length (list); /*warning, size could be -1 on error?*/ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2482 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2483 if(size < 1) |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2484 return RAISE (PyExc_TypeError, "Needs to be given at least one surface."); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2485 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2486 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2487 /* Allocate an array of surface pointers. */ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2488 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2489 surfaces = (SDL_Surface **) calloc(1, sizeof(SDL_Surface *) * size); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2490 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2491 if(!surfaces) { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2492 return RAISE (PyExc_MemoryError, "Not enough memory to store surfaces.\n"); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2493 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2494 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2495 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2496 /* Iterate over 'surfaces' passed in. */ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2497 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2498 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2499 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2500 /* need to get the first surface to see how big it is */ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2501 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2502 loop = 0; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2503 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2504 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2505 for (loop = 0; loop < size; ++loop) |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2506 { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2507 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2508 obj = PySequence_GetItem (list, loop); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2509 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2510 if(!obj) { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2511 Py_XDECREF (obj); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2512 ret = RAISE (PyExc_TypeError, "Needs to be a surface object."); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2513 an_error = 1; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2514 break; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2515 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2516 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2517 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2518 if (!PySurface_Check (obj)) { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2519 Py_XDECREF (obj); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2520 ret = RAISE (PyExc_TypeError, "Needs to be a surface object."); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2521 an_error = 1; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2522 break; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2523 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2524 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2525 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2526 surf = PySurface_AsSurface (obj); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2527 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2528 if(!surf) { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2529 Py_XDECREF (obj); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2530 ret = RAISE (PyExc_TypeError, "Needs to be a surface object."); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2531 an_error = 1; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2532 break; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2533 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2534 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2535 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2536 if(loop == 0) { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2537 /* if the second surface is not there, then make a new one. */ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2538 if (!surfobj2) { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2539 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2540 width = surf->w; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2541 height = surf->h; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2542 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2543 newsurf = newsurf_fromsurf (surf, width, height); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2544 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2545 if (!newsurf) { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2546 Py_XDECREF (obj); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2547 ret = RAISE (PyExc_ValueError, "Could not create new surface."); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2548 an_error = 1; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2549 break; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2550 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2551 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2552 else |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2553 newsurf = PySurface_AsSurface (surfobj2); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2554 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2555 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2556 /* check to see if the size is the correct size. */ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2557 if (newsurf->w != (surf->w) || newsurf->h != (surf->h)) { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2558 Py_XDECREF (obj); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2559 ret = RAISE (PyExc_ValueError, "Destination surface not the same size."); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2560 an_error = 1; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2561 break; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2562 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2563 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2564 /* check to see if the format of the surface is the same. */ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2565 if (surf->format->BytesPerPixel != newsurf->format->BytesPerPixel) { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2566 Py_XDECREF (obj); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2567 ret = RAISE (PyExc_ValueError, "Source and destination surfaces need the same format."); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2568 an_error = 1; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2569 break; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2570 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2571 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2572 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2573 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2574 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2575 /* Copy surface pointer, and also lock surface. */ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2576 SDL_LockSurface (surf); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2577 surfaces[loop] = surf; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2578 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2579 Py_DECREF (obj); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2580 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2581 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2582 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2583 loop_up_to = loop; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2584 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2585 if(!an_error) { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2586 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2587 /* Process images, get average surface. */ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2588 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2589 SDL_LockSurface (newsurf); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2590 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2591 Py_BEGIN_ALLOW_THREADS; |
|
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:
1804
diff
changeset
|
2592 average_surfaces (surfaces, size, newsurf, palette_colors); |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2593 Py_END_ALLOW_THREADS; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2594 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2595 SDL_UnlockSurface (newsurf); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2596 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2597 if (surfobj2) |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2598 { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2599 Py_INCREF (surfobj2); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2600 ret = surfobj2; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2601 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2602 else { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2603 ret = PySurface_New (newsurf); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2604 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2605 } else { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2606 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2607 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2608 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2609 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2610 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2611 /* cleanup */ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2612 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2613 /* unlock the surfaces we got up to. */ |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2614 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2615 for (loop = 0; loop < loop_up_to; loop++) { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2616 if(surfaces[loop]) { |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2617 SDL_UnlockSurface (surfaces[loop]); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2618 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2619 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2620 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2621 free(surfaces); |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2622 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2623 return ret; |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2624 } |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2625 |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2626 |
|
1267
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
2627 void average_color(SDL_Surface* surf, int x, int y, int width, int height, Uint8* r, Uint8* g, Uint8* b, Uint8* a) { |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2628 Uint32 color, rmask, gmask, bmask, amask; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2629 Uint8 *pixels, *pix; |
|
1267
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
2630 unsigned int rtot, gtot, btot, atot, size, rshift, gshift, bshift, ashift; |
|
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
2631 unsigned int rloss, gloss, bloss, aloss; |
|
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
2632 int row, col; |
|
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
2633 |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2634 SDL_PixelFormat *format; |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2635 |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2636 format = surf->format; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2637 rmask = format->Rmask; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2638 gmask = format->Gmask; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2639 bmask = format->Bmask; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2640 amask = format->Amask; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2641 rshift = format->Rshift; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2642 gshift = format->Gshift; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2643 bshift = format->Bshift; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2644 ashift = format->Ashift; |
|
1267
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
2645 rloss = format->Rloss; |
|
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
2646 gloss = format->Gloss; |
|
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
2647 bloss = format->Bloss; |
|
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
2648 aloss = format->Aloss; |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2649 rtot = gtot = btot = atot = 0; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2650 |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2651 /* make sure the area specified is within the Surface */ |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2652 if ((x + width) > surf->w) |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2653 width = surf->w - x; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2654 if ((y + height) > surf->h) |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2655 height = surf->h - y; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2656 if (x < 0) |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2657 { |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2658 width -= (-x); |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2659 x = 0; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2660 } |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2661 if (y < 0) |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2662 { |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2663 height -= (-y); |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2664 y = 0; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2665 } |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2666 |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2667 size = width*height; |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2668 |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2669 switch (format->BytesPerPixel) { |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2670 case 1: |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2671 for (row = y; row < y+height; row++) { |
|
1267
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
2672 pixels = (Uint8 *) surf->pixels + row*surf->pitch + x; |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2673 for (col = x; col < x+width; col++) { |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2674 color = (Uint32)*((Uint8 *) pixels); |
|
1267
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
2675 rtot += ((color & rmask) >> rshift) << rloss; |
|
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
2676 gtot += ((color & gmask) >> gshift) << gloss; |
|
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
2677 btot += ((color & bmask) >> bshift) << bloss; |
|
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
2678 atot += ((color & amask) >> ashift) << aloss; |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2679 pixels++; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2680 } |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2681 } |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2682 break; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2683 case 2: |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2684 for (row = y; row < y+height; row++) { |
|
1267
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
2685 pixels = (Uint8 *) surf->pixels + row*surf->pitch + x*2; |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2686 for (col = x; col < x+width; col++) { |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2687 color = (Uint32)*((Uint16 *) pixels); |
|
1267
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
2688 rtot += ((color & rmask) >> rshift) << rloss; |
|
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
2689 gtot += ((color & gmask) >> gshift) << gloss; |
|
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
2690 btot += ((color & bmask) >> bshift) << bloss; |
|
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
2691 atot += ((color & amask) >> ashift) << aloss; |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2692 pixels += 2; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2693 } |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2694 } |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2695 break; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2696 case 3: |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2697 for (row = y; row < y+height; row++) { |
|
1267
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
2698 pixels = (Uint8 *) surf->pixels + row*surf->pitch + x*3; |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2699 for (col = x; col < x+width; col++) { |
|
1267
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
2700 pix = pixels; |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2701 #if SDL_BYTEORDER == SDL_LIL_ENDIAN |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2702 color = (pix[0]) + (pix[1] << 8) + (pix[2] << 16); |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2703 #else |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2704 color = (pix[2]) + (pix[1] << 8) + (pix[0] << 16); |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2705 #endif |
|
1267
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
2706 rtot += ((color & rmask) >> rshift) << rloss; |
|
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
2707 gtot += ((color & gmask) >> gshift) << gloss; |
|
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
2708 btot += ((color & bmask) >> bshift) << bloss; |
|
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
2709 atot += ((color & amask) >> ashift) << aloss; |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2710 pixels += 3; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2711 } |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2712 } |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2713 break; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2714 default: /* case 4: */ |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2715 for (row = y; row < y+height; row++) { |
|
1267
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
2716 pixels = (Uint8 *) surf->pixels + row*surf->pitch + x*4; |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2717 for (col = x; col < x+width; col++) { |
|
1267
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
2718 color = *(Uint32 *)pixels; |
|
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
2719 rtot += ((color & rmask) >> rshift) << rloss; |
|
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
2720 gtot += ((color & gmask) >> gshift) << gloss; |
|
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
2721 btot += ((color & bmask) >> bshift) << bloss; |
|
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
2722 atot += ((color & amask) >> ashift) << aloss; |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2723 pixels += 4; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2724 } |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2725 } |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2726 break; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2727 } |
|
1267
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
2728 *r = rtot/size; |
|
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
2729 *g = gtot/size; |
|
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
2730 *b = btot/size; |
|
9be0ea33a1dd
fixed bugs with transform and mask
Nirav Patel <nrp@eclecti.cc>
parents:
1264
diff
changeset
|
2731 *a = atot/size; |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2732 } |
|
834
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
2733 |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2734 static PyObject* surf_average_color(PyObject* self, PyObject* arg) |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2735 { |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2736 PyObject *surfobj, *rectobj = NULL; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2737 SDL_Surface* surf; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2738 GAME_Rect* rect, temp; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2739 Uint8 r, g, b, a; |
|
1301
c16f9561fb32
fixing threading in average_color
Nirav Patel <nrp@eclecti.cc>
parents:
1267
diff
changeset
|
2740 int x, y, w, h; |
|
834
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
2741 |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2742 if (!PyArg_ParseTuple (arg, "O!|O", &PySurface_Type, &surfobj, &rectobj)) |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2743 return NULL; |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2744 |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2745 surf = PySurface_AsSurface (surfobj); |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2746 PySurface_Lock (surfobj); |
|
1301
c16f9561fb32
fixing threading in average_color
Nirav Patel <nrp@eclecti.cc>
parents:
1267
diff
changeset
|
2747 |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2748 if (!rectobj) { |
|
1301
c16f9561fb32
fixing threading in average_color
Nirav Patel <nrp@eclecti.cc>
parents:
1267
diff
changeset
|
2749 x = 0; |
|
c16f9561fb32
fixing threading in average_color
Nirav Patel <nrp@eclecti.cc>
parents:
1267
diff
changeset
|
2750 y = 0; |
|
c16f9561fb32
fixing threading in average_color
Nirav Patel <nrp@eclecti.cc>
parents:
1267
diff
changeset
|
2751 w = surf->w; |
|
c16f9561fb32
fixing threading in average_color
Nirav Patel <nrp@eclecti.cc>
parents:
1267
diff
changeset
|
2752 h = surf->h; |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2753 } else { |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2754 if (!(rect = GameRect_FromObject (rectobj, &temp))) |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2755 return RAISE (PyExc_TypeError, "Rect argument is invalid"); |
|
1301
c16f9561fb32
fixing threading in average_color
Nirav Patel <nrp@eclecti.cc>
parents:
1267
diff
changeset
|
2756 x = rect->x; |
|
c16f9561fb32
fixing threading in average_color
Nirav Patel <nrp@eclecti.cc>
parents:
1267
diff
changeset
|
2757 y = rect->y; |
|
c16f9561fb32
fixing threading in average_color
Nirav Patel <nrp@eclecti.cc>
parents:
1267
diff
changeset
|
2758 w = rect->w; |
|
c16f9561fb32
fixing threading in average_color
Nirav Patel <nrp@eclecti.cc>
parents:
1267
diff
changeset
|
2759 h = rect->h; |
|
c16f9561fb32
fixing threading in average_color
Nirav Patel <nrp@eclecti.cc>
parents:
1267
diff
changeset
|
2760 } |
|
c16f9561fb32
fixing threading in average_color
Nirav Patel <nrp@eclecti.cc>
parents:
1267
diff
changeset
|
2761 |
|
c16f9561fb32
fixing threading in average_color
Nirav Patel <nrp@eclecti.cc>
parents:
1267
diff
changeset
|
2762 Py_BEGIN_ALLOW_THREADS; |
|
c16f9561fb32
fixing threading in average_color
Nirav Patel <nrp@eclecti.cc>
parents:
1267
diff
changeset
|
2763 average_color(surf, x, y, w, h, &r, &g, &b, &a); |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2764 Py_END_ALLOW_THREADS; |
|
1301
c16f9561fb32
fixing threading in average_color
Nirav Patel <nrp@eclecti.cc>
parents:
1267
diff
changeset
|
2765 |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2766 PySurface_Unlock (surfobj); |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2767 return Py_BuildValue ("(bbbb)", r, g, b, a); |
|
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2768 } |
|
834
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
2769 |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
2770 static PyMethodDef _transform_methods[] = |
| 190 | 2771 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
2772 { "scale", surf_scale, METH_VARARGS, DOC_PYGAMETRANSFORMSCALE }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
2773 { "rotate", surf_rotate, METH_VARARGS, DOC_PYGAMETRANSFORMROTATE }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
2774 { "flip", surf_flip, METH_VARARGS, DOC_PYGAMETRANSFORMFLIP }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
2775 { "rotozoom", surf_rotozoom, METH_VARARGS, DOC_PYGAMETRANSFORMROTOZOOM}, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
2776 { "chop", surf_chop, METH_VARARGS, DOC_PYGAMETRANSFORMCHOP }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
2777 { "scale2x", surf_scale2x, METH_VARARGS, DOC_PYGAMETRANSFORMSCALE2X }, |
|
834
714963434e23
Added smoothscale function from Richard Goedeken.
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
2778 { "smoothscale", surf_scalesmooth, METH_VARARGS, DOC_PYGAMETRANSFORMSMOOTHSCALE }, |
|
1364
9198ad97ce33
transform.c: add surf_ prefix to get_smoothscale_backend()
Lenard Lindstrom <len-l@telus.net>
parents:
1360
diff
changeset
|
2779 { "get_smoothscale_backend", (PyCFunction) surf_get_smoothscale_backend, METH_NOARGS, |
|
1330
67fd4fb4bf12
Allow the VC build of transform.c use the MMX/SSE enhanced smoothscale code.
Lenard Lindstrom <len-l@telus.net>
parents:
1301
diff
changeset
|
2780 DOC_PYGAMETRANSFORMGETSMOOTHSCALEBACKEND }, |
|
1367
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
2781 { "set_smoothscale_backend", (PyCFunction) surf_set_smoothscale_backend, |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
2782 METH_VARARGS | METH_KEYWORDS, |
|
4be2e6337c3f
add additional smoothscale testing capability to transform
Lenard Lindstrom <len-l@telus.net>
parents:
1364
diff
changeset
|
2783 DOC_PYGAMETRANSFORMSETSMOOTHSCALEBACKEND }, |
|
862
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2784 { "threshold", surf_threshold, METH_VARARGS, DOC_PYGAMETRANSFORMTHRESHOLD }, |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2785 { "laplacian", surf_laplacian, METH_VARARGS, DOC_PYGAMETRANSFORMTHRESHOLD }, |
|
57ac2edacc4d
Mask can now get bounding rects of set bits.
Rene Dudfield <renesd@gmail.com>
parents:
857
diff
changeset
|
2786 { "average_surfaces", surf_average_surfaces, METH_VARARGS, DOC_PYGAMETRANSFORMAVERAGESURFACES }, |
|
1264
eeaeedcd46b8
transform module additions and changes
Nirav Patel <nrp@eclecti.cc>
parents:
1248
diff
changeset
|
2787 { "average_color", surf_average_color, METH_VARARGS, DOC_PYGAMETRANSFORMAVERAGECOLOR }, |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
2788 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
2789 { NULL, NULL, 0, NULL } |
| 190 | 2790 }; |
| 2791 | |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
2792 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
2793 MODINIT_DEFINE (transform) |
| 190 | 2794 { |
|
813
fd421ea279ae
Thanks Christopher Stone, John Myers, John Poppleweel, and Marcus!
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
2795 PyObject *module; |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
2796 struct _module_state *st; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
2797 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
2798 #if PY3 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
2799 static struct PyModuleDef _module = { |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
2800 PyModuleDef_HEAD_INIT, |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
2801 "transform", |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
2802 DOC_PYGAMETRANSFORM, |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
2803 sizeof (struct _module_state), |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
2804 _transform_methods, |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
2805 NULL, NULL, NULL, NULL |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
2806 }; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
2807 #endif |
|
1499
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1367
diff
changeset
|
2808 |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1367
diff
changeset
|
2809 /* imported needed apis; Do this first so if there is an error |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1367
diff
changeset
|
2810 the module is not loaded. |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1367
diff
changeset
|
2811 */ |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1367
diff
changeset
|
2812 import_pygame_base (); |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1367
diff
changeset
|
2813 if (PyErr_Occurred ()) { |
|
1804
7444350a233c
in init functions: fix minor Python 3.x related memory leaks and clean up indentation
Lenard Lindstrom <len-l@telus.net>
parents:
1604
diff
changeset
|
2814 MODINIT_ERROR; |
|
1499
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1367
diff
changeset
|
2815 } |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1367
diff
changeset
|
2816 import_pygame_color (); |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1367
diff
changeset
|
2817 if (PyErr_Occurred ()) { |
|
1804
7444350a233c
in init functions: fix minor Python 3.x related memory leaks and clean up indentation
Lenard Lindstrom <len-l@telus.net>
parents:
1604
diff
changeset
|
2818 MODINIT_ERROR; |
|
1499
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1367
diff
changeset
|
2819 } |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1367
diff
changeset
|
2820 import_pygame_rect (); |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1367
diff
changeset
|
2821 if (PyErr_Occurred ()) { |
|
1804
7444350a233c
in init functions: fix minor Python 3.x related memory leaks and clean up indentation
Lenard Lindstrom <len-l@telus.net>
parents:
1604
diff
changeset
|
2822 MODINIT_ERROR; |
|
1499
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1367
diff
changeset
|
2823 } |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1367
diff
changeset
|
2824 import_pygame_surface (); |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1367
diff
changeset
|
2825 if (PyErr_Occurred ()) { |
|
1804
7444350a233c
in init functions: fix minor Python 3.x related memory leaks and clean up indentation
Lenard Lindstrom <len-l@telus.net>
parents:
1604
diff
changeset
|
2826 MODINIT_ERROR; |
|
1499
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1367
diff
changeset
|
2827 } |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1367
diff
changeset
|
2828 |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1367
diff
changeset
|
2829 /* create the module */ |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
2830 #if PY3 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
2831 module = PyModule_Create (&_module); |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
2832 #else |
| 1596 | 2833 module = Py_InitModule3 (MODPREFIX "transform", |
| 2834 _transform_methods, | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
2835 DOC_PYGAMETRANSFORM); |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
2836 #endif |
| 190 | 2837 |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
2838 if (module == 0) { |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
2839 MODINIT_ERROR; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
2840 } |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
2841 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
2842 st = GETSTATE (module); |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
2843 if (st->filter_type == 0) { |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
2844 smoothscale_init (st); |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
2845 } |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
2846 MODINIT_RETURN (module); |
| 190 | 2847 } |
