Mercurial > pygame
annotate src/image.c @ 3172:d1b367fc08bc tests-returncode
Use a return code of 1 when the tests fail.
| author | Thomas Kluyver <takowl@gmail.com> |
|---|---|
| date | Wed, 09 Jan 2013 10:13:57 +0000 |
| parents | 5c3f0f965568 |
| children |
| rev | line source |
|---|---|
| 7 | 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 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
4 Copyright (C) 2006 Rene Dudfield |
| 7 | 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. |
| 7 | 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. |
| 7 | 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 |
| 7 | 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 |
| 7 | 22 */ |
| 23 | |
| 24 /* | |
| 29 | 25 * image module for pygame |
| 7 | 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/image_doc.h" |
|
1114
e7317210f112
opengl save segfault: moved __stdcall again
Lenard Lindstrom <len-l@telus.net>
parents:
1110
diff
changeset
|
30 #include "pgopengl.h" |
| 7 | 31 |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
32 struct _module_state { |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
33 int is_extended; |
|
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 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
36 #if PY3 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
37 #define GETSTATE(m) PY3_GETSTATE (_module_state, m) |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
38 #else |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
39 static struct _module_state _state = { 0 }; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
40 #define GETSTATE(m) PY2_GETSTATE (_state) |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
41 #endif |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
42 |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
43 static int SaveTGA (SDL_Surface *surface, const char *file, int rle); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
44 static int SaveTGA_RW (SDL_Surface *surface, SDL_RWops *out, int rle); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
45 static SDL_Surface* opengltosdl (void); |
| 7 | 46 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
47 #define DATAROW(data, row, width, height, flipped) \ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
48 ((flipped) ? (((char*) data) + (height - row - 1) * width) : \ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
49 (((char*) data) + row * width)) |
| 7 | 50 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
51 static PyObject* |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
52 image_load_basic(PyObject *self, PyObject *arg) |
| 7 | 53 { |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
54 PyObject *obj; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
55 PyObject *final; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
56 PyObject *oencoded; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
57 const char *name = NULL; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
58 SDL_Surface* surf; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
59 SDL_RWops *rw; |
| 7 | 60 |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
61 if (!PyArg_ParseTuple(arg, "O|s", &obj, &name)) { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
62 return NULL; |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
63 } |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
64 |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
65 oencoded = RWopsEncodeFilePath(obj, PyExc_SDLError); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
66 if (oencoded == NULL) { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
67 return NULL; |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
68 } |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
69 if (oencoded != Py_None) { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
70 Py_BEGIN_ALLOW_THREADS; |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
71 surf = SDL_LoadBMP(Bytes_AS_STRING(oencoded)); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
72 Py_END_ALLOW_THREADS; |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
73 Py_DECREF(oencoded); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
74 } |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
75 else { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
76 Py_DECREF(oencoded); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
77 rw = RWopsFromFileObject(obj); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
78 if (rw == NULL) { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
79 return NULL; |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
80 } |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
81 if (RWopsCheckObject(rw)) { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
82 surf = SDL_LoadBMP_RW (rw, 1); |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
83 } |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
84 else { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
85 Py_BEGIN_ALLOW_THREADS; |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
86 surf = SDL_LoadBMP_RW(rw, 1); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
87 Py_END_ALLOW_THREADS; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
88 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
89 } |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
90 |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
91 if (surf == NULL) { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
92 return RAISE(PyExc_SDLError, SDL_GetError()); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
93 } |
| 7 | 94 |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
95 final = PySurface_New(surf); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
96 if (final == NULL) { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
97 SDL_FreeSurface(surf); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
98 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
99 return final; |
| 7 | 100 } |
| 101 | |
|
1056
5c105664999f
Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents:
1047
diff
changeset
|
102 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
103 static SDL_Surface* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
104 opengltosdl () |
| 454 | 105 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
106 /*we need to get ahold of the pyopengl glReadPixels function*/ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
107 /*we use pyopengl's so we don't need to link with opengl at compiletime*/ |
|
1374
9f3f2a16f498
Remove compiler warnings from image.c
Lenard Lindstrom <len-l@telus.net>
parents:
1114
diff
changeset
|
108 SDL_Surface *surf = NULL; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
109 Uint32 rmask, gmask, bmask; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
110 int i; |
|
1374
9f3f2a16f498
Remove compiler warnings from image.c
Lenard Lindstrom <len-l@telus.net>
parents:
1114
diff
changeset
|
111 unsigned char *pixels = NULL; |
|
1056
5c105664999f
Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents:
1047
diff
changeset
|
112 |
|
1374
9f3f2a16f498
Remove compiler warnings from image.c
Lenard Lindstrom <len-l@telus.net>
parents:
1114
diff
changeset
|
113 GL_glReadPixels_Func p_glReadPixels = NULL; |
|
1056
5c105664999f
Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents:
1047
diff
changeset
|
114 |
|
5c105664999f
Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents:
1047
diff
changeset
|
115 p_glReadPixels = (GL_glReadPixels_Func) SDL_GL_GetProcAddress("glReadPixels"); |
| 455 | 116 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
117 surf = SDL_GetVideoSurface (); |
| 484 | 118 |
|
1056
5c105664999f
Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents:
1047
diff
changeset
|
119 if(!surf) { |
|
5c105664999f
Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents:
1047
diff
changeset
|
120 RAISE (PyExc_RuntimeError, "Cannot get video surface."); |
|
5c105664999f
Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents:
1047
diff
changeset
|
121 return NULL; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
122 } |
|
1056
5c105664999f
Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents:
1047
diff
changeset
|
123 |
|
5c105664999f
Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents:
1047
diff
changeset
|
124 |
|
5c105664999f
Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents:
1047
diff
changeset
|
125 if(!p_glReadPixels) { |
|
5c105664999f
Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents:
1047
diff
changeset
|
126 RAISE (PyExc_RuntimeError, "Cannot find glReadPixels function."); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
127 return NULL; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
128 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
129 |
|
1056
5c105664999f
Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents:
1047
diff
changeset
|
130 /* |
|
5c105664999f
Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents:
1047
diff
changeset
|
131 GL_UNSIGNED_BYTE = 5121 |
|
5c105664999f
Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents:
1047
diff
changeset
|
132 GL_RGB = 6407 |
|
5c105664999f
Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents:
1047
diff
changeset
|
133 */ |
|
5c105664999f
Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents:
1047
diff
changeset
|
134 |
|
5c105664999f
Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents:
1047
diff
changeset
|
135 pixels = (unsigned char*) malloc(surf->w * surf->h * 3); |
|
5c105664999f
Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents:
1047
diff
changeset
|
136 |
|
5c105664999f
Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents:
1047
diff
changeset
|
137 if(!pixels) { |
|
5c105664999f
Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents:
1047
diff
changeset
|
138 RAISE (PyExc_MemoryError, "Cannot allocate enough memory for pixels."); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
139 return NULL; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
140 } |
|
1056
5c105664999f
Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents:
1047
diff
changeset
|
141 //p_glReadPixels(0, 0, surf->w, surf->h, 6407, 5121, pixels); |
|
5c105664999f
Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents:
1047
diff
changeset
|
142 //glReadPixels(0, 0, surf->w, surf->h, 0x1907, 0x1401, pixels); |
|
5c105664999f
Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents:
1047
diff
changeset
|
143 p_glReadPixels(0, 0, surf->w, surf->h, 0x1907, 0x1401, pixels); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
144 |
|
1056
5c105664999f
Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents:
1047
diff
changeset
|
145 if (SDL_BYTEORDER == SDL_LIL_ENDIAN) { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
146 rmask=0x000000FF; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
147 gmask=0x0000FF00; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
148 bmask=0x00FF0000; |
|
1056
5c105664999f
Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents:
1047
diff
changeset
|
149 } else { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
150 rmask=0x00FF0000; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
151 gmask=0x0000FF00; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
152 bmask=0x000000FF; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
153 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
154 surf = SDL_CreateRGBSurface (SDL_SWSURFACE, surf->w, surf->h, 24, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
155 rmask, gmask, bmask, 0); |
|
1056
5c105664999f
Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents:
1047
diff
changeset
|
156 if (!surf) { |
|
5c105664999f
Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents:
1047
diff
changeset
|
157 free(pixels); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
158 RAISE (PyExc_SDLError, SDL_GetError ()); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
159 return NULL; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
160 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
161 |
|
1056
5c105664999f
Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents:
1047
diff
changeset
|
162 for (i = 0; i < surf->h; ++i) { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
163 memcpy (((char *) surf->pixels) + surf->pitch * i, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
164 pixels + 3 * surf->w * (surf->h - i - 1), surf->w * 3); |
|
1056
5c105664999f
Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents:
1047
diff
changeset
|
165 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
166 |
|
1056
5c105664999f
Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents:
1047
diff
changeset
|
167 |
|
5c105664999f
Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents:
1047
diff
changeset
|
168 free(pixels); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
169 return surf; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
170 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
171 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
172 PyObject* |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
173 image_save(PyObject *self, PyObject *arg) |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
174 { |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
175 PyObject *surfobj; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
176 PyObject *obj; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
177 PyObject *oencoded; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
178 PyObject *imgext = NULL; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
179 SDL_Surface *surf; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
180 SDL_Surface *temp = NULL; |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
181 int result = 1; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
182 |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
183 if (!PyArg_ParseTuple(arg, "O!O", &PySurface_Type, &surfobj, &obj)) { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
184 return NULL; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
185 } |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
186 |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
187 surf = PySurface_AsSurface(surfobj); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
188 if (surf->flags & SDL_OPENGL) { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
189 temp = surf = opengltosdl(); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
190 if (surf == NULL) { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
191 return NULL; |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
192 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
193 } |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
194 else { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
195 PySurface_Prep(surfobj); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
196 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
197 |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
198 oencoded = RWopsEncodeFilePath(obj, PyExc_SDLError); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
199 if (oencoded == Py_None) { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
200 SDL_RWops *rw = RWopsFromFileObject(obj); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
201 if (rw != NULL) { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
202 result = SaveTGA_RW(surf, rw, 1); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
203 } |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
204 else { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
205 result = -2; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
206 } |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
207 } |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
208 else if (oencoded != NULL) { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
209 const char *name = Bytes_AS_STRING(oencoded); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
210 Py_ssize_t namelen = Bytes_GET_SIZE(oencoded); |
| 905 | 211 int written = 0; |
| 212 | |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
213 if (namelen > 3) { |
| 905 | 214 if ((name[namelen - 1]=='p' || name[namelen - 1]=='P') && |
| 215 (name[namelen - 2]=='m' || name[namelen - 2]=='M') && | |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
216 (name[namelen - 3]=='b' || name[namelen - 3]=='B')) { |
| 905 | 217 Py_BEGIN_ALLOW_THREADS; |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
218 result = SDL_SaveBMP(surf, name); |
| 905 | 219 Py_END_ALLOW_THREADS; |
| 220 written = 1; | |
| 221 } | |
| 222 else if (((name[namelen - 1]=='g' || name[namelen - 1]=='G') && | |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
223 (name[namelen - 2]=='n' || name[namelen - 2]=='N') && |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
224 (name[namelen - 3]=='p' || name[namelen - 3]=='P')) || |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
225 ((name[namelen - 1]=='g' || name[namelen - 1]=='G') && |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
226 (name[namelen - 2]=='e' || name[namelen - 2]=='E') && |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
227 (name[namelen - 3]=='p' || name[namelen - 3]=='P') && |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
228 (name[namelen - 4]=='j' || name[namelen - 4]=='J')) || |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
229 ((name[namelen - 1]=='g' || name[namelen - 1]=='G') && |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
230 (name[namelen - 2]=='p' || name[namelen - 2]=='P') && |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
231 (name[namelen - 3]=='j' || name[namelen - 3]=='J'))) { |
| 905 | 232 /* If it is .png .jpg .jpeg use the extended module. */ |
| 233 /* try to get extended formats */ | |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
234 imgext = PyImport_ImportModule(IMPPREFIX "imageext"); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
235 if (imgext != NULL) |
| 905 | 236 { |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
237 PyObject *extsave = |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
238 PyObject_GetAttrString(imgext, "save_extended"); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
239 PyObject *data; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
240 |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
241 Py_DECREF(imgext); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
242 if (extsave != NULL) { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
243 data = PyObject_CallObject(extsave, arg); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
244 Py_DECREF(extsave); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
245 if (data == NULL) { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
246 result = -2; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
247 } |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
248 else { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
249 Py_DECREF(data); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
250 result = 0; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
251 } |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
252 } |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
253 else { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
254 result = -2; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
255 } |
| 905 | 256 } |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
257 else { |
| 905 | 258 result = -2; |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
259 } |
| 905 | 260 written = 1; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
261 } |
| 454 | 262 } |
| 905 | 263 |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
264 if (!written) { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
265 Py_BEGIN_ALLOW_THREADS; |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
266 result = SaveTGA(surf, name, 1); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
267 Py_END_ALLOW_THREADS; |
| 454 | 268 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
269 } |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
270 else { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
271 result = -2; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
272 } |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
273 Py_XDECREF(oencoded); |
| 175 | 274 |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
275 if (temp) { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
276 SDL_FreeSurface (temp); |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
277 } |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
278 else { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
279 PySurface_Unprep (surfobj); |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
280 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
281 |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
282 if (result == -2) { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
283 /* Python error raised elsewhere */ |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
284 return NULL; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
285 } |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
286 if (result == -1) { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
287 /* SDL error: translate to Python error */ |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
288 return RAISE(PyExc_SDLError, SDL_GetError()); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
289 } |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
290 if (result == 1) { |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
291 /* Should never get here */ |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
292 return RAISE(PyExc_SDLError, "Unrecognized image type"); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
293 } |
|
704
fdd76aeca73b
Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents:
627
diff
changeset
|
294 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
295 Py_RETURN_NONE; |
| 175 | 296 } |
| 297 | |
| 298 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
299 PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
300 image_get_extended (PyObject* self, PyObject* arg) |
| 184 | 301 { |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
302 return PyInt_FromLong (GETSTATE (self)->is_extended); |
| 184 | 303 } |
| 304 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
305 PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
306 image_tostring (PyObject* self, PyObject* arg) |
| 184 | 307 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
308 PyObject *surfobj, *string = NULL; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
309 char *format, *data, *pixels; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
310 SDL_Surface *surf, *temp = NULL; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
311 int w, h, color, flipped = 0; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
312 Py_ssize_t len; |
|
855
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
313 Uint32 Rmask, Gmask, Bmask, Amask, Rshift, Gshift, Bshift, Ashift, Rloss, |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
314 Gloss, Bloss, Aloss; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
315 int hascolorkey, colorkey; |
|
855
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
316 Uint32 alpha; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
317 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
318 if (!PyArg_ParseTuple (arg, "O!s|i", &PySurface_Type, &surfobj, &format, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
319 &flipped)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
320 return NULL; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
321 surf = PySurface_AsSurface (surfobj); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
322 if (surf->flags & SDL_OPENGL) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
323 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
324 temp = surf = opengltosdl (); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
325 if (!surf) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
326 return NULL; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
327 } |
| 184 | 328 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
329 Rmask = surf->format->Rmask; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
330 Gmask = surf->format->Gmask; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
331 Bmask = surf->format->Bmask; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
332 Amask = surf->format->Amask; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
333 Rshift = surf->format->Rshift; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
334 Gshift = surf->format->Gshift; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
335 Bshift = surf->format->Bshift; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
336 Ashift = surf->format->Ashift; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
337 Rloss = surf->format->Rloss; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
338 Gloss = surf->format->Gloss; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
339 Bloss = surf->format->Bloss; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
340 Aloss = surf->format->Aloss; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
341 hascolorkey = (surf->flags & SDL_SRCCOLORKEY) && !Amask; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
342 colorkey = surf->format->colorkey; |
| 184 | 343 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
344 if (!strcmp (format, "P")) |
|
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 if (surf->format->BytesPerPixel != 1) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
347 return RAISE |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
348 (PyExc_ValueError, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
349 "Can only create \"P\" format data with 8bit Surfaces"); |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
350 string = Bytes_FromStringAndSize (NULL, surf->w * surf->h); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
351 if (!string) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
352 return NULL; |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
353 Bytes_AsStringAndSize (string, &data, &len); |
| 544 | 354 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
355 PySurface_Lock (surfobj); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
356 pixels = (char*) surf->pixels; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
357 for (h = 0; h < surf->h; ++h) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
358 memcpy (DATAROW (data, h, surf->w, surf->h, flipped), |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
359 pixels + (h * surf->pitch), surf->w); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
360 PySurface_Unlock (surfobj); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
361 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
362 else if (!strcmp (format, "RGB")) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
363 { |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
364 string = Bytes_FromStringAndSize (NULL, surf->w * surf->h * 3); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
365 if (!string) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
366 return NULL; |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
367 Bytes_AsStringAndSize (string, &data, &len); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
368 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
369 if (!temp) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
370 PySurface_Lock (surfobj); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
371 pixels = (char*) surf->pixels; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
372 switch (surf->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 (h = 0; h < surf->h; ++h) |
|
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* ptr = (Uint8*) DATAROW (surf->pixels, h, surf->pitch, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
378 surf->h, flipped); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
379 for (w = 0; w < surf->w; ++w) |
|
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 color = *ptr++; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
382 data[0] = (char) surf->format->palette->colors[color].r; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
383 data[1] = (char) surf->format->palette->colors[color].g; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
384 data[2] = (char) surf->format->palette->colors[color].b; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
385 data += 3; |
|
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 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
388 break; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
389 case 2: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
390 for (h = 0; h < surf->h; ++h) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
391 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
392 Uint16* ptr = (Uint16*) DATAROW (surf->pixels, h, surf->pitch, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
393 surf->h, flipped); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
394 for(w = 0; w < surf->w; ++w) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
395 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
396 color = *ptr++; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
397 data[0] = (char) (((color & Rmask) >> Rshift) << Rloss); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
398 data[1] = (char) (((color & Gmask) >> Gshift) << Gloss); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
399 data[2] = (char) (((color & Bmask) >> Bshift) << Bloss); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
400 data += 3; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
401 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
402 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
403 break; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
404 case 3: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
405 for (h = 0; h < surf->h; ++h) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
406 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
407 Uint8* ptr = (Uint8*) DATAROW (surf->pixels, h, surf->pitch, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
408 surf->h, flipped); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
409 for(w = 0; w < surf->w; ++w) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
410 { |
| 184 | 411 #if SDL_BYTEORDER == SDL_LIL_ENDIAN |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
412 color = ptr[0] + (ptr[1]<<8) + (ptr[2]<<16); |
| 184 | 413 #else |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
414 color = ptr[2] + (ptr[1]<<8) + (ptr[0]<<16); |
| 184 | 415 #endif |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
416 ptr += 3; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
417 data[0] = (char) (((color & Rmask) >> Rshift) << Rloss); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
418 data[1] = (char) (((color & Gmask) >> Gshift) << Gloss); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
419 data[2] = (char) (((color & Bmask) >> Bshift) << Bloss); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
420 data += 3; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
421 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
422 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
423 break; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
424 case 4: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
425 for (h = 0; h < surf->h; ++h) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
426 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
427 Uint32* ptr = (Uint32*) DATAROW (surf->pixels, h, surf->pitch, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
428 surf->h, flipped); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
429 for (w = 0; w < surf->w; ++w) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
430 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
431 color = *ptr++; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
432 data[0] = (char) (((color & Rmask) >> Rshift) << Rloss); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
433 data[1] = (char) (((color & Gmask) >> Gshift) << Rloss); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
434 data[2] = (char) (((color & Bmask) >> Bshift) << Rloss); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
435 data += 3; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
436 } |
|
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 break; |
|
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 if (!temp) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
441 PySurface_Unlock (surfobj); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
442 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
443 else if (!strcmp (format, "RGBX") || !strcmp (format, "RGBA")) |
|
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 if (strcmp (format, "RGBA")) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
446 hascolorkey = 0; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
447 |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
448 string = Bytes_FromStringAndSize (NULL, surf->w * surf->h * 4); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
449 if (!string) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
450 return NULL; |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
451 Bytes_AsStringAndSize (string, &data, &len); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
452 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
453 PySurface_Lock (surfobj); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
454 pixels = (char*) surf->pixels; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
455 switch (surf->format->BytesPerPixel) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
456 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
457 case 1: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
458 for(h = 0; h < surf->h; ++h) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
459 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
460 Uint8* ptr = (Uint8*) DATAROW (surf->pixels, h, surf->pitch, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
461 surf->h, flipped); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
462 for(w = 0; w < surf->w; ++w) |
|
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 color = *ptr++; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
465 data[0] = (char) surf->format->palette->colors[color].r; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
466 data[1] = (char) surf->format->palette->colors[color].g; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
467 data[2] = (char) surf->format->palette->colors[color].b; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
468 data[3] = hascolorkey ? (char)(color != colorkey) * 255 : |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
469 (char)255; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
470 data += 4; |
|
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 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
473 break; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
474 case 2: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
475 for (h = 0; h < surf->h; ++h) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
476 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
477 Uint16* ptr = (Uint16*) DATAROW (surf->pixels, h, surf->pitch, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
478 surf->h, flipped); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
479 for(w = 0; w < surf->w; ++w) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
480 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
481 color = *ptr++; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
482 data[0] = (char) (((color & Rmask) >> Rshift) << Rloss); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
483 data[1] = (char) (((color & Gmask) >> Gshift) << Gloss); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
484 data[2] = (char) (((color & Bmask) >> Bshift) << Bloss); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
485 data[3] = hascolorkey ? (char)(color!=colorkey) * 255 : |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
486 (char)(Amask ? (((color & Amask) >> Ashift) << Aloss) : |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
487 255); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
488 data += 4; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
489 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
490 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
491 break; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
492 case 3: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
493 for (h = 0; h < surf->h; ++h) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
494 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
495 Uint8* ptr = (Uint8*) DATAROW (surf->pixels, h, surf->pitch, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
496 surf->h, flipped); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
497 for (w = 0; w < surf->w; ++w) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
498 { |
| 273 | 499 #if SDL_BYTEORDER == SDL_LIL_ENDIAN |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
500 color = ptr[0] + (ptr[1]<<8) + (ptr[2]<<16); |
| 273 | 501 #else |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
502 color = ptr[2] + (ptr[1]<<8) + (ptr[0]<<16); |
| 273 | 503 #endif |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
504 ptr += 3; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
505 data[0] = (char) (((color & Rmask) >> Rshift) << Rloss); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
506 data[1] = (char) (((color & Gmask) >> Gshift) << Gloss); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
507 data[2] = (char) (((color & Bmask) >> Bshift) << Bloss); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
508 data[3] = hascolorkey ? (char)(color!=colorkey)*255 : |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
509 (char)(Amask ? (((color & Amask) >> Ashift) << Aloss) : |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
510 255); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
511 data += 4; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
512 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
513 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
514 break; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
515 case 4: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
516 for (h = 0; h < surf->h; ++h) |
|
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 Uint32* ptr = (Uint32*) DATAROW (surf->pixels, h, surf->pitch, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
519 surf->h, flipped); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
520 for(w = 0; w < surf->w; ++w) |
|
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 color = *ptr++; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
523 data[0] = (char) (((color & Rmask) >> Rshift) << Rloss); |
|
855
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
524 data[1] = (char) (((color & Gmask) >> Gshift) << Gloss); |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
525 data[2] = (char) (((color & Bmask) >> Bshift) << Bloss); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
526 data[3] = hascolorkey ? (char)(color!=colorkey)*255 : |
|
855
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
527 (char)(Amask ? (((color & Amask) >> Ashift) << Aloss) : |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
528 255); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
529 data += 4; |
|
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 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
532 break; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
533 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
534 PySurface_Unlock (surfobj); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
535 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
536 else if (!strcmp (format, "ARGB")) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
537 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
538 hascolorkey = 0; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
539 |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
540 string = Bytes_FromStringAndSize (NULL, surf->w * surf->h * 4); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
541 if (!string) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
542 return NULL; |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
543 Bytes_AsStringAndSize (string, &data, &len); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
544 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
545 PySurface_Lock (surfobj); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
546 pixels = (char*) surf->pixels; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
547 switch (surf->format->BytesPerPixel) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
548 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
549 case 1: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
550 for (h = 0; h < surf->h; ++h) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
551 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
552 Uint8* ptr = (Uint8*) DATAROW (surf->pixels, h, surf->pitch, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
553 surf->h, flipped); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
554 for (w = 0; w < surf->w; ++w) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
555 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
556 color = *ptr++; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
557 data[1] = (char)surf->format->palette->colors[color].r; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
558 data[2] = (char)surf->format->palette->colors[color].g; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
559 data[3] = (char)surf->format->palette->colors[color].b; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
560 data[0] = hascolorkey ? (char)(color!=colorkey)*255 : |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
561 (char)255; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
562 data += 4; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
563 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
564 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
565 break; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
566 case 2: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
567 for(h = 0; h < surf->h; ++h) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
568 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
569 Uint16* ptr = (Uint16*) DATAROW (surf->pixels, h, surf->pitch, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
570 surf->h, flipped); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
571 for(w = 0; w < surf->w; ++w) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
572 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
573 color = *ptr++; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
574 data[1] = (char) (((color & Rmask) >> Rshift) << Rloss); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
575 data[2] = (char) (((color & Gmask) >> Gshift) << Gloss); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
576 data[3] = (char) (((color & Bmask) >> Bshift) << Bloss); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
577 data[0] = hascolorkey ? (char)(color!=colorkey)*255 : |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
578 (char)(Amask ? (((color & Amask) >> Ashift) << Aloss) : |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
579 255); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
580 data += 4; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
581 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
582 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
583 break; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
584 case 3: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
585 for (h = 0; h < surf->h; ++h) |
|
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 Uint8* ptr = (Uint8*) DATAROW (surf->pixels, h, surf->pitch, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
588 surf->h, flipped); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
589 for (w = 0; w < surf->w; ++w) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
590 { |
| 490 | 591 #if SDL_BYTEORDER == SDL_LIL_ENDIAN |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
592 color = ptr[0] + (ptr[1]<<8) + (ptr[2]<<16); |
| 490 | 593 #else |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
594 color = ptr[2] + (ptr[1]<<8) + (ptr[0]<<16); |
| 490 | 595 #endif |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
596 ptr += 3; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
597 data[1] = (char) (((color & Rmask) >> Rshift) << Rloss); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
598 data[2] = (char) (((color & Gmask) >> Gshift) << Gloss); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
599 data[3] = (char) (((color & Bmask) >> Bshift) << Bloss); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
600 data[0] = hascolorkey ? (char)(color!=colorkey)*255 : |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
601 (char)(Amask ? (((color & Amask) >> Ashift) << Aloss) : |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
602 255); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
603 data += 4; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
604 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
605 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
606 break; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
607 case 4: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
608 for (h = 0; h < surf->h; ++h) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
609 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
610 Uint32* ptr = (Uint32*) DATAROW (surf->pixels, h, surf->pitch, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
611 surf->h, flipped); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
612 for (w = 0; w < surf->w; ++w) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
613 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
614 color = *ptr++; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
615 data[1] = (char) (((color & Rmask) >> Rshift) << Rloss); |
|
855
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
616 data[2] = (char) (((color & Gmask) >> Gshift) << Gloss); |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
617 data[3] = (char) (((color & Bmask) >> Bshift) << Bloss); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
618 data[0] = hascolorkey ? (char)(color!=colorkey)*255 : |
|
855
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
619 (char)(Amask ? (((color & Amask) >> Ashift) << Aloss) : |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
620 255); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
621 data += 4; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
622 } |
|
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 break; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
625 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
626 PySurface_Unlock (surfobj); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
627 } |
|
855
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
628 else if (!strcmp (format, "RGBA_PREMULT")) |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
629 { |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
630 if (surf->format->BytesPerPixel == 1 || surf->format->Amask == 0) |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
631 return RAISE |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
632 (PyExc_ValueError, |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
633 "Can only create pre-multiplied alpha strings if the surface has per-pixel alpha"); |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
634 |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
635 hascolorkey = 0; |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
636 |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
637 string = Bytes_FromStringAndSize (NULL, surf->w * surf->h * 4); |
|
855
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
638 if (!string) |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
639 return NULL; |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
640 Bytes_AsStringAndSize (string, &data, &len); |
|
855
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
641 |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
642 PySurface_Lock (surfobj); |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
643 pixels = (char*) surf->pixels; |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
644 switch (surf->format->BytesPerPixel) |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
645 { |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
646 case 2: |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
647 for (h = 0; h < surf->h; ++h) |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
648 { |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
649 Uint16* ptr = (Uint16*) DATAROW (surf->pixels, h, surf->pitch, |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
650 surf->h, flipped); |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
651 for(w = 0; w < surf->w; ++w) |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
652 { |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
653 color = *ptr++; |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
654 alpha = ((color & Amask) >> Ashift) << Aloss; |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
655 data[0] = (char) ((((color & Rmask) >> Rshift) << Rloss)*alpha/255); |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
656 data[1] = (char) ((((color & Gmask) >> Gshift) << Gloss)*alpha/255); |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
657 data[2] = (char) ((((color & Bmask) >> Bshift) << Bloss)*alpha/255); |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
658 data[3] = (char) alpha; |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
659 data += 4; |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
660 } |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
661 } |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
662 break; |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
663 case 3: |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
664 for (h = 0; h < surf->h; ++h) |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
665 { |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
666 Uint8* ptr = (Uint8*) DATAROW (surf->pixels, h, surf->pitch, |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
667 surf->h, flipped); |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
668 for (w = 0; w < surf->w; ++w) |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
669 { |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
670 #if SDL_BYTEORDER == SDL_LIL_ENDIAN |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
671 color = ptr[0] + (ptr[1]<<8) + (ptr[2]<<16); |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
672 #else |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
673 color = ptr[2] + (ptr[1]<<8) + (ptr[0]<<16); |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
674 #endif |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
675 ptr += 3; |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
676 alpha = ((color & Amask) >> Ashift) << Aloss; |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
677 data[0] = (char) ((((color & Rmask) >> Rshift) << Rloss)*alpha/255); |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
678 data[1] = (char) ((((color & Gmask) >> Gshift) << Gloss)*alpha/255); |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
679 data[2] = (char) ((((color & Bmask) >> Bshift) << Bloss)*alpha/255); |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
680 data[3] = (char) alpha; |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
681 data += 4; |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
682 } |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
683 } |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
684 break; |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
685 case 4: |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
686 for (h = 0; h < surf->h; ++h) |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
687 { |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
688 Uint32* ptr = (Uint32*) DATAROW (surf->pixels, h, surf->pitch, |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
689 surf->h, flipped); |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
690 for(w = 0; w < surf->w; ++w) |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
691 { |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
692 color = *ptr++; |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
693 alpha = ((color & Amask) >> Ashift) << Aloss; |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
694 if (alpha == 0) |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
695 { |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
696 data[0] = data[1] = data[2] = 0; |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
697 } |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
698 else |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
699 { |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
700 data[0] = (char) ((((color & Rmask) >> Rshift) << Rloss)*alpha/255); |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
701 data[1] = (char) ((((color & Gmask) >> Gshift) << Gloss)*alpha/255); |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
702 data[2] = (char) ((((color & Bmask) >> Bshift) << Bloss)*alpha/255); |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
703 } |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
704 data[3] = (char) alpha; |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
705 data += 4; |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
706 } |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
707 } |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
708 break; |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
709 } |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
710 PySurface_Unlock (surfobj); |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
711 } |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
712 else if (!strcmp (format, "ARGB_PREMULT")) |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
713 { |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
714 if (surf->format->BytesPerPixel == 1 || surf->format->Amask == 0) |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
715 return RAISE |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
716 (PyExc_ValueError, |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
717 "Can only create pre-multiplied alpha strings if the surface has per-pixel alpha"); |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
718 |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
719 hascolorkey = 0; |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
720 |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
721 string = Bytes_FromStringAndSize (NULL, surf->w * surf->h * 4); |
|
855
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
722 if (!string) |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
723 return NULL; |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
724 Bytes_AsStringAndSize (string, &data, &len); |
|
855
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
725 |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
726 PySurface_Lock (surfobj); |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
727 pixels = (char*) surf->pixels; |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
728 switch (surf->format->BytesPerPixel) |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
729 { |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
730 case 2: |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
731 for (h = 0; h < surf->h; ++h) |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
732 { |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
733 Uint16* ptr = (Uint16*) DATAROW (surf->pixels, h, surf->pitch, |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
734 surf->h, flipped); |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
735 for(w = 0; w < surf->w; ++w) |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
736 { |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
737 color = *ptr++; |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
738 alpha = ((color & Amask) >> Ashift) << Aloss; |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
739 data[1] = (char) ((((color & Rmask) >> Rshift) << Rloss)*alpha/255); |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
740 data[2] = (char) ((((color & Gmask) >> Gshift) << Gloss)*alpha/255); |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
741 data[3] = (char) ((((color & Bmask) >> Bshift) << Bloss)*alpha/255); |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
742 data[0] = (char) alpha; |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
743 data += 4; |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
744 } |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
745 } |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
746 break; |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
747 case 3: |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
748 for (h = 0; h < surf->h; ++h) |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
749 { |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
750 Uint8* ptr = (Uint8*) DATAROW (surf->pixels, h, surf->pitch, |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
751 surf->h, flipped); |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
752 for (w = 0; w < surf->w; ++w) |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
753 { |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
754 #if SDL_BYTEORDER == SDL_LIL_ENDIAN |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
755 color = ptr[0] + (ptr[1]<<8) + (ptr[2]<<16); |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
756 #else |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
757 color = ptr[2] + (ptr[1]<<8) + (ptr[0]<<16); |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
758 #endif |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
759 ptr += 3; |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
760 alpha = ((color & Amask) >> Ashift) << Aloss; |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
761 data[1] = (char) ((((color & Rmask) >> Rshift) << Rloss)*alpha/255); |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
762 data[2] = (char) ((((color & Gmask) >> Gshift) << Gloss)*alpha/255); |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
763 data[3] = (char) ((((color & Bmask) >> Bshift) << Bloss)*alpha/255); |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
764 data[0] = (char) alpha; |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
765 data += 4; |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
766 } |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
767 } |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
768 break; |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
769 case 4: |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
770 for (h = 0; h < surf->h; ++h) |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
771 { |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
772 Uint32* ptr = (Uint32*) DATAROW (surf->pixels, h, surf->pitch, |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
773 surf->h, flipped); |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
774 for(w = 0; w < surf->w; ++w) |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
775 { |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
776 color = *ptr++; |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
777 alpha = ((color & Amask) >> Ashift) << Aloss; |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
778 if (alpha == 0) |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
779 { |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
780 data[1] = data[2] = data[3] = 0; |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
781 } |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
782 else |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
783 { |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
784 data[1] = (char) ((((color & Rmask) >> Rshift) << Rloss)*alpha/255); |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
785 data[2] = (char) ((((color & Gmask) >> Gshift) << Gloss)*alpha/255); |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
786 data[3] = (char) ((((color & Bmask) >> Bshift) << Bloss)*alpha/255); |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
787 } |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
788 data[0] = (char) alpha; |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
789 data += 4; |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
790 } |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
791 } |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
792 break; |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
793 } |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
794 PySurface_Unlock (surfobj); |
|
5eba2232e6d1
Changes from Brian Fisher to add RGBA_PREMULT & ARGB_PREMULT type to
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
795 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
796 else |
|
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 if (temp) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
799 SDL_FreeSurface (temp); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
800 return RAISE (PyExc_ValueError, "Unrecognized type of format"); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
801 } |
| 184 | 802 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
803 if (temp) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
804 SDL_FreeSurface (temp); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
805 return string; |
| 184 | 806 } |
| 807 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
808 PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
809 image_fromstring (PyObject* self, PyObject* arg) |
| 544 | 810 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
811 PyObject *string; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
812 char *format, *data; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
813 SDL_Surface *surf = NULL; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
814 int w, h, flipped=0; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
815 Py_ssize_t len; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
816 int loopw, looph; |
| 544 | 817 |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
818 if (!PyArg_ParseTuple (arg, "O!(ii)s|i", &Bytes_Type, &string, &w, &h, |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
819 &format, &flipped)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
820 return NULL; |
| 544 | 821 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
822 if (w < 1 || h < 1) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
823 return RAISE (PyExc_ValueError, "Resolution must be positive values"); |
| 544 | 824 |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
825 Bytes_AsStringAndSize (string, &data, &len); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
826 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
827 if (!strcmp (format, "P")) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
828 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
829 if (len != w * h) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
830 return RAISE |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
831 (PyExc_ValueError, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
832 "String length does not equal format and resolution size"); |
| 544 | 833 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
834 surf = SDL_CreateRGBSurface (0, w, h, 8, 0, 0, 0, 0); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
835 if (!surf) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
836 return RAISE (PyExc_SDLError, SDL_GetError ()); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
837 SDL_LockSurface (surf); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
838 for (looph = 0; looph < h; ++looph) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
839 memcpy(((char*) surf->pixels) + looph * surf->pitch, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
840 DATAROW (data, looph, w, h, flipped), w); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
841 SDL_UnlockSurface (surf); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
842 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
843 else if (!strcmp (format, "RGB")) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
844 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
845 if (len != w * h * 3) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
846 return RAISE |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
847 (PyExc_ValueError, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
848 "String length does not equal format and resolution size"); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
849 surf = SDL_CreateRGBSurface (0, w, h, 24, 0xFF<<16, 0xFF<<8, 0xFF, 0); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
850 if (!surf) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
851 return RAISE (PyExc_SDLError, SDL_GetError ()); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
852 SDL_LockSurface (surf); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
853 for (looph = 0; looph < h; ++looph) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
854 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
855 Uint8* pix = (Uint8*) DATAROW (surf->pixels, looph, surf->pitch, h, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
856 flipped); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
857 for (loopw = 0; loopw < w; ++loopw) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
858 { |
| 544 | 859 #if SDL_BYTEORDER == SDL_LIL_ENDIAN |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
860 pix[2] = data[0]; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
861 pix[1] = data[1]; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
862 pix[0] = data[2]; |
| 544 | 863 #else |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
864 pix[0] = data[0]; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
865 pix[1] = data[1]; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
866 pix[2] = data[2]; |
| 544 | 867 #endif |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
868 pix += 3; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
869 data += 3; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
870 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
871 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
872 SDL_UnlockSurface (surf); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
873 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
874 else if (!strcmp (format, "RGBA") || !strcmp (format, "RGBX")) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
875 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
876 int alphamult = !strcmp (format, "RGBA"); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
877 if (len != w * h * 4) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
878 return RAISE |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
879 (PyExc_ValueError, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
880 "String length does not equal format and resolution size"); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
881 surf = SDL_CreateRGBSurface ((alphamult ? SDL_SRCALPHA : 0), w, h, 32, |
| 544 | 882 #if SDL_BYTEORDER == SDL_LIL_ENDIAN |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
883 0xFF, 0xFF<<8, 0xFF<<16, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
884 (alphamult ? 0xFF << 24 : 0)); |
| 544 | 885 #else |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
886 0xFF<<24, 0xFF<<16, 0xFF<<8, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
887 (alphamult ? 0xFF : 0)); |
| 544 | 888 #endif |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
889 if (!surf) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
890 return RAISE (PyExc_SDLError, SDL_GetError ()); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
891 SDL_LockSurface (surf); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
892 for (looph = 0; looph < h; ++looph) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
893 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
894 Uint32* pix = (Uint32*) DATAROW (surf->pixels, looph, surf->pitch, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
895 h, flipped); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
896 for (loopw = 0; loopw < w; ++loopw) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
897 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
898 *pix++ = *((Uint32*) data); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
899 data += 4; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
900 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
901 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
902 SDL_UnlockSurface (surf); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
903 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
904 else if (!strcmp (format, "ARGB")) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
905 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
906 if (len != w * h * 4) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
907 return RAISE |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
908 (PyExc_ValueError, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
909 "String length does not equal format and resolution size"); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
910 surf = SDL_CreateRGBSurface (SDL_SRCALPHA, w, h, 32, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
911 #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
|
912 0xFF<<8, 0xFF<<16, 0xFF<<24, 0xFF); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
913 #else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
914 0xFF<<16, 0xFF<<8, 0xFF, 0xFF<<24); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
915 #endif |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
916 if (!surf) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
917 return RAISE (PyExc_SDLError, SDL_GetError ()); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
918 SDL_LockSurface (surf); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
919 for (looph = 0; looph < h; ++looph) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
920 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
921 Uint32* pix = (Uint32*) DATAROW (surf->pixels, looph, surf->pitch, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
922 h, flipped); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
923 for (loopw = 0; loopw < w; ++loopw) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
924 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
925 *pix++ = *((Uint32*) data); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
926 data += 4; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
927 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
928 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
929 SDL_UnlockSurface (surf); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
930 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
931 else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
932 return RAISE (PyExc_ValueError, "Unrecognized type of format"); |
| 544 | 933 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
934 if (!surf) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
935 return NULL; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
936 return PySurface_New (surf); |
| 544 | 937 } |
| 938 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
939 PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
940 image_frombuffer (PyObject* self, PyObject* arg) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
941 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
942 PyObject *buffer; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
943 char *format, *data; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
944 SDL_Surface *surf = NULL; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
945 int w, h; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
946 Py_ssize_t len; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
947 PyObject *surfobj; |
| 544 | 948 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
949 if (!PyArg_ParseTuple (arg, "O(ii)s|i", &buffer, &w, &h, &format)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
950 return NULL; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
951 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
952 if (w < 1 || h < 1) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
953 return RAISE (PyExc_ValueError, "Resolution must be positive values"); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
954 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
955 /* breaking constness here, we should really not change this string */ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
956 if (PyObject_AsCharBuffer (buffer, (const char**)&data, &len) == -1) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
957 return NULL; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
958 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
959 if (!strcmp (format, "P")) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
960 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
961 if (len != w * h) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
962 return RAISE |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
963 (PyExc_ValueError, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
964 "Buffer length does not equal format and resolution size"); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
965 |
| 926 | 966 surf = SDL_CreateRGBSurfaceFrom (data, w, h, 8, w, 0, 0, 0, 0); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
967 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
968 else if (!strcmp (format, "RGB")) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
969 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
970 if (len != w * h * 3) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
971 return RAISE |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
972 (PyExc_ValueError, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
973 "Buffer length does not equal format and resolution size"); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
974 surf = SDL_CreateRGBSurfaceFrom (data, w, h, 24, w * 3, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
975 0xFF, 0xFF<<8, 0xFF<<16, 0); |
|
1822
1ea8ab9129a0
Added palette_colors to mask.from_threshold. TODO notes to some functions.
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
976 /* |
|
1ea8ab9129a0
Added palette_colors to mask.from_threshold. TODO notes to some functions.
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
977 #if SDL_BYTEORDER == SDL_LIL_ENDIAN |
|
1ea8ab9129a0
Added palette_colors to mask.from_threshold. TODO notes to some functions.
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
978 0xFF, 0xFF<<8, 0xFF<<16, 0xFF<<24 |
|
1ea8ab9129a0
Added palette_colors to mask.from_threshold. TODO notes to some functions.
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
979 #else |
|
1ea8ab9129a0
Added palette_colors to mask.from_threshold. TODO notes to some functions.
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
980 0xFF<<24, 0xFF<<16, 0xFF<<8, 0xFF |
|
1ea8ab9129a0
Added palette_colors to mask.from_threshold. TODO notes to some functions.
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
981 #endif |
|
1ea8ab9129a0
Added palette_colors to mask.from_threshold. TODO notes to some functions.
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
982 ); |
|
1ea8ab9129a0
Added palette_colors to mask.from_threshold. TODO notes to some functions.
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
983 |
|
1ea8ab9129a0
Added palette_colors to mask.from_threshold. TODO notes to some functions.
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
984 */ |
|
1ea8ab9129a0
Added palette_colors to mask.from_threshold. TODO notes to some functions.
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
985 |
|
1ea8ab9129a0
Added palette_colors to mask.from_threshold. TODO notes to some functions.
Rene Dudfield <renesd@gmail.com>
parents:
1804
diff
changeset
|
986 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
987 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
988 else if (!strcmp (format, "RGBA") || !strcmp (format, "RGBX")) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
989 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
990 int alphamult = !strcmp (format, "RGBA"); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
991 if (len != w * h * 4) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
992 return RAISE |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
993 (PyExc_ValueError, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
994 "Buffer length does not equal format and resolution size"); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
995 surf = SDL_CreateRGBSurfaceFrom (data, w, h, 32, w * 4, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
996 #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
|
997 0xFF, 0xFF<<8, 0xFF<<16, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
998 (alphamult ? 0xFF << 24 : 0)); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
999 #else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1000 0xFF<<24, 0xFF<<16, 0xFF<<8, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1001 (alphamult ? 0xFF : 0)); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1002 #endif |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1003 if(alphamult) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1004 surf->flags |= SDL_SRCALPHA; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1005 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1006 else if (!strcmp (format, "ARGB")) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1007 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1008 if (len != w * h * 4) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1009 return RAISE |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1010 (PyExc_ValueError, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1011 "Buffer length does not equal format and resolution size"); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1012 surf = SDL_CreateRGBSurfaceFrom (data, w, h, 32, w*4, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1013 #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
|
1014 0xFF<<24, 0xFF, 0xFF<<8, 0xFF<<16); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1015 #else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1016 0xFF, 0xFF<<24, 0xFF<<16, 0xFF<<8); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1017 #endif |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1018 surf->flags |= SDL_SRCALPHA; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1019 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1020 else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1021 return RAISE(PyExc_ValueError, "Unrecognized type of format"); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1022 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1023 if (!surf) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1024 return RAISE (PyExc_SDLError, SDL_GetError ()); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1025 surfobj = PySurface_New (surf); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1026 Py_INCREF (buffer); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1027 ((PySurfaceObject*) surfobj)->dependency = buffer; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1028 return surfobj; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1029 } |
| 544 | 1030 |
| 376 | 1031 /*******************************************************/ |
|
1581
9f910eda60c5
Starting to merge in sybian_s60 branch... still going... you like break? Well then try and build this!
Rene Dudfield <renesd@gmail.com>
parents:
1553
diff
changeset
|
1032 /* tga code by Mattias Engdegard, in the public domain */ |
| 376 | 1033 /*******************************************************/ |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1034 struct TGAheader |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1035 { |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1036 Uint8 infolen; /* length of info field */ |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1037 Uint8 has_cmap; /* 1 if image has colormap, 0 otherwise */ |
| 376 | 1038 Uint8 type; |
| 1039 | |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1040 Uint8 cmap_start[2]; /* index of first colormap entry */ |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1041 Uint8 cmap_len[2]; /* number of entries in colormap */ |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1042 Uint8 cmap_bits; /* bits per colormap entry */ |
| 376 | 1043 |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1044 Uint8 yorigin[2]; /* image origin (ignored here) */ |
| 376 | 1045 Uint8 xorigin[2]; |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1046 Uint8 width[2]; /* image size */ |
| 376 | 1047 Uint8 height[2]; |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1048 Uint8 pixel_bits; /* bits/pixel */ |
| 376 | 1049 Uint8 flags; |
| 1050 }; | |
| 1051 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1052 enum tga_type |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1053 { |
| 376 | 1054 TGA_TYPE_INDEXED = 1, |
| 1055 TGA_TYPE_RGB = 2, | |
| 1056 TGA_TYPE_BW = 3, | |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1057 TGA_TYPE_RLE = 8 /* additive */ |
| 376 | 1058 }; |
| 1059 | |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1060 #define TGA_INTERLEAVE_MASK 0xc0 |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1061 #define TGA_INTERLEAVE_NONE 0x00 |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1062 #define TGA_INTERLEAVE_2WAY 0x40 |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1063 #define TGA_INTERLEAVE_4WAY 0x80 |
| 376 | 1064 |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1065 #define TGA_ORIGIN_MASK 0x30 |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1066 #define TGA_ORIGIN_LEFT 0x00 |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1067 #define TGA_ORIGIN_RIGHT 0x10 |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1068 #define TGA_ORIGIN_LOWER 0x00 |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1069 #define TGA_ORIGIN_UPPER 0x20 |
| 376 | 1070 |
| 1071 /* read/write unaligned little-endian 16-bit ints */ | |
| 1072 #define LE16(p) ((p)[0] + ((p)[1] << 8)) | |
| 1073 #define SETLE16(p, v) ((p)[0] = (v), (p)[1] = (v) >> 8) | |
| 1074 | |
| 1075 #ifndef MIN | |
| 1076 #define MIN(a, b) ((a) < (b) ? (a) : (b)) | |
| 1077 #endif | |
| 1078 | |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1079 #define TGA_RLE_MAX 128 /* max length of a TGA RLE chunk */ |
| 376 | 1080 /* return the number of bytes in the resulting buffer after RLE-encoding |
| 1081 a line of TGA data */ | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1082 static int |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1083 rle_line (Uint8 *src, Uint8 *dst, int w, int bpp) |
| 376 | 1084 { |
| 1085 int x = 0; | |
| 1086 int out = 0; | |
| 1087 int raw = 0; | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1088 while (x < w) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1089 { |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1090 Uint32 pix; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1091 int x0 = x; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1092 memcpy (&pix, src + x * bpp, bpp); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1093 x++; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1094 while (x < w && memcmp (&pix, src + x * bpp, bpp) == 0 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1095 && x - x0 < TGA_RLE_MAX) |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1096 x++; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1097 /* use a repetition chunk iff the repeated pixels would consume |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1098 two bytes or more */ |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1099 if ((x - x0 - 1) * bpp >= 2 || x == w) |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1100 { |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1101 /* output previous raw chunks */ |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1102 while (raw < x0) |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1103 { |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1104 int n = MIN (TGA_RLE_MAX, x0 - raw); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1105 dst[out++] = n - 1; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1106 memcpy (dst + out, src + raw * bpp, n * bpp); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1107 out += n * bpp; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1108 raw += n; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1109 } |
| 376 | 1110 |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1111 if (x - x0 > 0) |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1112 { |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1113 /* output new repetition chunk */ |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1114 dst[out++] = 0x7f + x - x0; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1115 memcpy (dst + out, &pix, bpp); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1116 out += bpp; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1117 } |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1118 raw = x; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1119 } |
| 376 | 1120 } |
| 1121 return out; | |
| 1122 } | |
| 1123 | |
| 1124 /* | |
| 1125 * Save a surface to an output stream in TGA format. | |
| 1126 * 8bpp surfaces are saved as indexed images with 24bpp palette, or with | |
| 1127 * 32bpp palette if colourkeying is used. | |
| 1128 * 15, 16, 24 and 32bpp surfaces are saved as 24bpp RGB images, | |
| 1129 * or as 32bpp RGBA images if alpha channel is used. | |
| 1130 * | |
| 1131 * RLE compression is not used in the output file. | |
| 1132 * | |
| 1133 * Returns -1 upon error, 0 if success | |
| 1134 */ | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1135 static int |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1136 SaveTGA_RW (SDL_Surface *surface, SDL_RWops *out, int rle) |
| 376 | 1137 { |
| 1138 SDL_Surface *linebuf = NULL; | |
| 1139 int alpha = 0; | |
| 1140 int ckey = -1; | |
| 1141 struct TGAheader h; | |
| 1142 int srcbpp; | |
| 1143 unsigned surf_flags; | |
| 1144 unsigned surf_alpha; | |
| 1145 Uint32 rmask, gmask, bmask, amask; | |
| 1146 SDL_Rect r; | |
| 1147 int bpp; | |
| 1148 Uint8 *rlebuf = NULL; | |
| 1149 | |
| 1150 h.infolen = 0; | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1151 SETLE16 (h.cmap_start, 0); |
| 376 | 1152 |
| 1153 srcbpp = surface->format->BitsPerPixel; | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1154 if (srcbpp < 8) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1155 { |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1156 SDL_SetError ("cannot save <8bpp images as TGA"); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1157 return -1; |
| 376 | 1158 } |
| 1159 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1160 if (srcbpp == 8) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1161 { |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1162 h.has_cmap = 1; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1163 h.type = TGA_TYPE_INDEXED; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1164 if (surface->flags & SDL_SRCCOLORKEY) |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1165 { |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1166 ckey = surface->format->colorkey; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1167 h.cmap_bits = 32; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1168 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1169 else |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1170 h.cmap_bits = 24; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1171 SETLE16 (h.cmap_len, surface->format->palette->ncolors); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1172 h.pixel_bits = 8; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1173 rmask = gmask = bmask = amask = 0; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1174 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1175 else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1176 { |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1177 h.has_cmap = 0; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1178 h.type = TGA_TYPE_RGB; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1179 h.cmap_bits = 0; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1180 SETLE16 (h.cmap_len, 0); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1181 if (surface->format->Amask) |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1182 { |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1183 alpha = 1; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1184 h.pixel_bits = 32; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1185 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1186 else |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1187 h.pixel_bits = 24; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1188 if (SDL_BYTEORDER == SDL_BIG_ENDIAN) |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1189 { |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1190 int s = alpha ? 0 : 8; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1191 amask = 0x000000ff >> s; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1192 rmask = 0x0000ff00 >> s; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1193 gmask = 0x00ff0000 >> s; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1194 bmask = 0xff000000 >> s; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1195 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1196 else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1197 { |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1198 amask = alpha ? 0xff000000 : 0; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1199 rmask = 0x00ff0000; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1200 gmask = 0x0000ff00; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1201 bmask = 0x000000ff; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1202 } |
| 376 | 1203 } |
| 1204 bpp = h.pixel_bits >> 3; | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1205 if (rle) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1206 h.type += TGA_TYPE_RLE; |
| 376 | 1207 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1208 SETLE16 (h.yorigin, 0); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1209 SETLE16 (h.xorigin, 0); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1210 SETLE16 (h.width, surface->w); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1211 SETLE16 (h.height, surface->h); |
| 376 | 1212 h.flags = TGA_ORIGIN_UPPER | (alpha ? 8 : 0); |
| 1213 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1214 if (!SDL_RWwrite (out, &h, sizeof (h), 1)) |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1215 return -1; |
| 376 | 1216 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1217 if (h.has_cmap) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1218 { |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1219 int i; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1220 SDL_Palette *pal = surface->format->palette; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1221 Uint8 entry[4]; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1222 for (i = 0; i < pal->ncolors; i++) |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1223 { |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1224 entry[0] = pal->colors[i].b; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1225 entry[1] = pal->colors[i].g; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1226 entry[2] = pal->colors[i].r; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1227 entry[3] = (i == ckey) ? 0 : 0xff; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1228 if (!SDL_RWwrite (out, entry, h.cmap_bits >> 3, 1)) |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1229 return -1; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1230 } |
| 376 | 1231 } |
| 1232 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1233 linebuf = SDL_CreateRGBSurface (SDL_SWSURFACE, surface->w, 1, h.pixel_bits, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1234 rmask, gmask, bmask, amask); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1235 if (!linebuf) |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1236 return -1; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1237 if (h.has_cmap) |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1238 SDL_SetColors (linebuf, surface->format->palette->colors, 0, |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1239 surface->format->palette->ncolors); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1240 if (rle) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1241 { |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1242 rlebuf = malloc (bpp * surface->w + 1 + surface->w / TGA_RLE_MAX); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1243 if (!rlebuf) |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1244 { |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1245 SDL_SetError ("out of memory"); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1246 goto error; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1247 } |
| 376 | 1248 } |
| 1249 | |
| 1250 /* Temporarily remove colourkey and alpha from surface so copies are | |
| 1251 opaque */ | |
| 1252 surf_flags = surface->flags & (SDL_SRCALPHA | SDL_SRCCOLORKEY); | |
| 1253 surf_alpha = surface->format->alpha; | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1254 if (surf_flags & SDL_SRCALPHA) |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1255 SDL_SetAlpha (surface, 0, 255); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1256 if (surf_flags & SDL_SRCCOLORKEY) |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1257 SDL_SetColorKey (surface, 0, surface->format->colorkey); |
| 376 | 1258 |
| 1259 r.x = 0; | |
| 1260 r.w = surface->w; | |
| 1261 r.h = 1; | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1262 for (r.y = 0; r.y < surface->h; r.y++) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1263 { |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1264 int n; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1265 void *buf; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1266 if (SDL_BlitSurface (surface, &r, linebuf, NULL) < 0) |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1267 break; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1268 if (rle) |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1269 { |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1270 buf = rlebuf; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1271 n = rle_line (linebuf->pixels, rlebuf, surface->w, bpp); |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1272 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1273 else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1274 { |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1275 buf = linebuf->pixels; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1276 n = surface->w * bpp; |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1277 } |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1278 if (!SDL_RWwrite (out, buf, n, 1)) |
|
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1279 break; |
| 376 | 1280 } |
| 1281 | |
| 1282 /* restore flags */ | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1283 if (surf_flags & SDL_SRCALPHA) |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1284 SDL_SetAlpha (surface, SDL_SRCALPHA, (Uint8)surf_alpha); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1285 if (surf_flags & SDL_SRCCOLORKEY) |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1286 SDL_SetColorKey (surface, SDL_SRCCOLORKEY, surface->format->colorkey); |
| 376 | 1287 |
| 1288 error: | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1289 free (rlebuf); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1290 SDL_FreeSurface (linebuf); |
| 376 | 1291 return 0; |
| 1292 } | |
| 1293 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1294 static int |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1295 SaveTGA (SDL_Surface *surface, const char *file, int rle) |
| 376 | 1296 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1297 SDL_RWops *out = SDL_RWFromFile (file, "wb"); |
| 376 | 1298 int ret; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1299 if (!out) |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1300 return -1; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1301 ret = SaveTGA_RW (surface, out, rle); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1302 SDL_RWclose (out); |
| 376 | 1303 return ret; |
| 1304 } | |
| 1305 | |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1306 static PyMethodDef _image_methods[] = |
| 7 | 1307 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1308 { "load_basic", image_load_basic, METH_VARARGS, DOC_PYGAMEIMAGELOAD }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1309 { "save", image_save, METH_VARARGS, DOC_PYGAMEIMAGESAVE }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1310 { "get_extended", (PyCFunction) image_get_extended, METH_NOARGS, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1311 DOC_PYGAMEIMAGEGETEXTENDED }, |
| 7 | 1312 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1313 { "tostring", image_tostring, METH_VARARGS, DOC_PYGAMEIMAGETOSTRING }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1314 { "fromstring", image_fromstring, METH_VARARGS, DOC_PYGAMEIMAGEFROMSTRING }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1315 { "frombuffer", image_frombuffer, METH_VARARGS, DOC_PYGAMEIMAGEFROMBUFFER }, |
| 184 | 1316 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1317 { NULL, NULL, 0, NULL } |
| 7 | 1318 }; |
| 1319 | |
| 1320 | |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1321 MODINIT_DEFINE (image) |
| 7 | 1322 { |
|
2196
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1323 PyObject *module; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1324 PyObject *extmodule; |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1325 struct _module_state *st; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1326 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1327 #if PY3 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1328 static struct PyModuleDef _module = { |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1329 PyModuleDef_HEAD_INIT, |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1330 "image", |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1331 DOC_PYGAMEIMAGE, |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1332 sizeof (struct _module_state), |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1333 _image_methods, |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1334 NULL, NULL, NULL, NULL |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1335 }; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1336 #endif |
| 7 | 1337 |
|
1499
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1374
diff
changeset
|
1338 /* 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:
1374
diff
changeset
|
1339 the module is not loaded. |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1374
diff
changeset
|
1340 */ |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1374
diff
changeset
|
1341 import_pygame_base (); |
|
2196
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1342 if (PyErr_Occurred ()) |
|
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1343 { |
|
1804
7444350a233c
in init functions: fix minor Python 3.x related memory leaks and clean up indentation
Lenard Lindstrom <len-l@telus.net>
parents:
1581
diff
changeset
|
1344 MODINIT_ERROR; |
|
1499
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1374
diff
changeset
|
1345 } |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1374
diff
changeset
|
1346 import_pygame_surface (); |
|
2196
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1347 if (PyErr_Occurred ()) |
|
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1348 { |
|
1804
7444350a233c
in init functions: fix minor Python 3.x related memory leaks and clean up indentation
Lenard Lindstrom <len-l@telus.net>
parents:
1581
diff
changeset
|
1349 MODINIT_ERROR; |
|
1499
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1374
diff
changeset
|
1350 } |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1374
diff
changeset
|
1351 import_pygame_rwobject (); |
|
2196
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1352 if (PyErr_Occurred ()) |
|
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1353 { |
|
1804
7444350a233c
in init functions: fix minor Python 3.x related memory leaks and clean up indentation
Lenard Lindstrom <len-l@telus.net>
parents:
1581
diff
changeset
|
1354 MODINIT_ERROR; |
|
1499
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1374
diff
changeset
|
1355 } |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1374
diff
changeset
|
1356 |
| 7 | 1357 /* create the module */ |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1358 #if PY3 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1359 module = PyModule_Create (&_module); |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1360 #else |
|
1581
9f910eda60c5
Starting to merge in sybian_s60 branch... still going... you like break? Well then try and build this!
Rene Dudfield <renesd@gmail.com>
parents:
1553
diff
changeset
|
1361 module = Py_InitModule3 (MODPREFIX "image", _image_methods, DOC_PYGAMEIMAGE); |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1362 #endif |
|
2196
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1363 if (module == NULL) |
|
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1364 { |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1365 MODINIT_ERROR; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1366 } |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1367 st = GETSTATE (module); |
| 7 | 1368 |
| 175 | 1369 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1370 /* try to get extended formats */ |
|
1581
9f910eda60c5
Starting to merge in sybian_s60 branch... still going... you like break? Well then try and build this!
Rene Dudfield <renesd@gmail.com>
parents:
1553
diff
changeset
|
1371 extmodule = PyImport_ImportModule (IMPPREFIX "imageext"); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1372 if (extmodule) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1373 { |
|
2196
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1374 PyObject *extload; |
|
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1375 PyObject *extsave; |
|
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1376 |
|
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1377 extload = PyObject_GetAttrString (extmodule, "load_extended"); |
|
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1378 if (!extload) |
|
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1379 { |
|
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1380 Py_DECREF (extmodule); |
|
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1381 MODINIT_ERROR; |
|
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1382 } |
|
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1383 extsave = PyObject_GetAttrString (extmodule, "save_extended"); |
|
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1384 if (!extsave) |
|
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1385 { |
|
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1386 Py_DECREF (extload); |
|
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1387 Py_DECREF (extmodule); |
|
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1388 MODINIT_ERROR; |
|
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1389 } |
|
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1390 if (PyModule_AddObject (module, "load_extended", extload)) |
|
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1391 { |
|
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1392 Py_DECREF (extload); |
|
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1393 Py_DECREF (extsave); |
|
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1394 Py_DECREF (extmodule); |
|
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1395 MODINIT_ERROR; |
|
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1396 } |
|
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1397 if (PyModule_AddObject (module, "save_extended", extsave)) |
|
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1398 { |
|
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1399 Py_DECREF(extsave); |
|
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1400 Py_DECREF(extmodule); |
|
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1401 MODINIT_ERROR; |
|
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1402 } |
|
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1403 Py_INCREF (extload); |
|
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1404 if (PyModule_AddObject (module, "load", extload)) |
|
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1405 { |
|
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1406 Py_DECREF (extload); |
|
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1407 Py_DECREF (extmodule); |
|
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1408 MODINIT_ERROR; |
|
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1409 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1410 Py_DECREF (extmodule); |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1411 st->is_extended = 1; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1412 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1413 else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1414 { |
|
2196
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1415 PyObject* basicload = PyObject_GetAttrString (module, "load_basic"); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1416 PyErr_Clear (); |
|
2196
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1417 PyModule_AddObject (module, "load_extended", Py_None); |
|
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1418 PyModule_AddObject (module, "save_extended", Py_None); |
|
5c3f0f965568
remove direct module dict accesses in init function
Lenard Lindstrom <len-l@telus.net>
parents:
2105
diff
changeset
|
1419 PyModule_AddObject (module, "load", basicload); |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1420 st->is_extended = 0; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1421 } |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
1422 MODINIT_RETURN (module); |
| 7 | 1423 } |
