annotate src/imageext.c @ 3194:9fcb7abf3185 default tip

Remove some gcc 4.7.2 compiler warnings
author Lenard Lindstrom <len-l@telus.net>
date Tue, 23 Apr 2013 19:53:36 -0700
parents 82b87373acb9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
175
7a9d787f2316 image module redone
pygame
parents:
diff changeset
1 /*
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
2 pygame - Python Game Library
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
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: 798
diff changeset
4 Copyright (C) 2006 Rene Dudfield
175
7a9d787f2316 image module redone
pygame
parents:
diff changeset
5
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
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: 798
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: 798
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: 798
diff changeset
9 version 2 of the License, or (at your option) any later version.
175
7a9d787f2316 image module redone
pygame
parents:
diff changeset
10
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
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: 798
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: 798
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: 798
diff changeset
14 Library General Public License for more details.
175
7a9d787f2316 image module redone
pygame
parents:
diff changeset
15
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
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: 798
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: 798
diff changeset
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
175
7a9d787f2316 image module redone
pygame
parents:
diff changeset
19
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
20 Pete Shinners
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
21 pete@shinners.org
175
7a9d787f2316 image module redone
pygame
parents:
diff changeset
22 */
7a9d787f2316 image module redone
pygame
parents:
diff changeset
23
7a9d787f2316 image module redone
pygame
parents:
diff changeset
24 /*
7a9d787f2316 image module redone
pygame
parents:
diff changeset
25 * extended image module for pygame, note this only has
704
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
26 * the extended load and save functions, which are autmatically used
175
7a9d787f2316 image module redone
pygame
parents:
diff changeset
27 * by the normal pygame.image module if it is available.
7a9d787f2316 image module redone
pygame
parents:
diff changeset
28 */
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
29 // This is temporal until PNG support is done for Symbian
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
30 #ifdef __SYMBIAN32__
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
31 #include <stdio.h>
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
32 #else
704
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
33 #include <png.h>
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
34 #endif
708
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
35 #include <jpeglib.h>
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1550
diff changeset
36 /* Keep a stray macro from conflicting with python.h */
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1550
diff changeset
37 #if defined(HAVE_PROTOTYPES)
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1550
diff changeset
38 #undef HAVE_PROTOTYPES
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1550
diff changeset
39 #endif
1329
f016741318a4 resolve several macro redefines (GCC warnings)
Lenard Lindstrom <len-l@telus.net>
parents: 1114
diff changeset
40 /* Remove GCC macro redefine warnings. */
f016741318a4 resolve several macro redefines (GCC warnings)
Lenard Lindstrom <len-l@telus.net>
parents: 1114
diff changeset
41 #if defined(HAVE_STDDEF_H) /* also defined in pygame.h (python.h) */
f016741318a4 resolve several macro redefines (GCC warnings)
Lenard Lindstrom <len-l@telus.net>
parents: 1114
diff changeset
42 #undef HAVE_STDDEF_H
f016741318a4 resolve several macro redefines (GCC warnings)
Lenard Lindstrom <len-l@telus.net>
parents: 1114
diff changeset
43 #endif
f016741318a4 resolve several macro redefines (GCC warnings)
Lenard Lindstrom <len-l@telus.net>
parents: 1114
diff changeset
44 #if defined(HAVE_STDLIB_H) /* also defined in pygame.h (SDL.h) */
f016741318a4 resolve several macro redefines (GCC warnings)
Lenard Lindstrom <len-l@telus.net>
parents: 1114
diff changeset
45 #undef HAVE_STDLIB_H
f016741318a4 resolve several macro redefines (GCC warnings)
Lenard Lindstrom <len-l@telus.net>
parents: 1114
diff changeset
46 #endif
175
7a9d787f2316 image module redone
pygame
parents:
diff changeset
47 #include "pygame.h"
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1550
diff changeset
48 #include "pgcompat.h"
1937
0d661c00c1aa Merged FreeType branch into trunk.
tanoku
parents: 1804
diff changeset
49 #include "doc/image_doc.h"
1114
e7317210f112 opengl save segfault: moved __stdcall again
Lenard Lindstrom <len-l@telus.net>
parents: 1110
diff changeset
50 #include "pgopengl.h"
175
7a9d787f2316 image module redone
pygame
parents:
diff changeset
51 #include <SDL_image.h>
7a9d787f2316 image module redone
pygame
parents:
diff changeset
52
2105
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
53 static const char*
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
54 find_extension(const char *fullname)
175
7a9d787f2316 image module redone
pygame
parents:
diff changeset
55 {
2105
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
56 const char *dot;
175
7a9d787f2316 image module redone
pygame
parents:
diff changeset
57
2105
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
58 if (fullname == NULL) {
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
59 return NULL;
2105
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
60 }
175
7a9d787f2316 image module redone
pygame
parents:
diff changeset
61
2105
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
62 dot = strrchr(fullname, '.');
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
63 if (dot == NULL) {
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
64 return fullname;
2105
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
65 }
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
66 return dot + 1;
175
7a9d787f2316 image module redone
pygame
parents:
diff changeset
67 }
7a9d787f2316 image module redone
pygame
parents:
diff changeset
68
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
69 static PyObject*
2105
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
70 image_load_ext(PyObject *self, PyObject *arg)
175
7a9d787f2316 image module redone
pygame
parents:
diff changeset
71 {
2105
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
72 PyObject *obj;
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
73 PyObject *final;
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
74 PyObject *oencoded;
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
75 PyObject *oname;
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
76 const char *name = NULL;
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
77 const char *cext;
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
78 char *ext = NULL;
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
79 SDL_Surface *surf;
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
80 SDL_RWops *rw;
2105
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
81
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
82 if (!PyArg_ParseTuple(arg, "O|s", &obj, &name)) {
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
83 return NULL;
2105
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
84 }
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
85
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
86 oencoded = RWopsEncodeFilePath(obj, PyExc_SDLError);
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
87 if (oencoded == NULL) {
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
88 return NULL;
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
89 }
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
90 if (oencoded != Py_None) {
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
91 Py_BEGIN_ALLOW_THREADS;
2105
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
92 surf = IMG_Load(Bytes_AS_STRING(oencoded));
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
93 Py_END_ALLOW_THREADS;
2105
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
94 Py_DECREF(oencoded);
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
95 }
2105
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
96 else {
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
97 Py_DECREF(oencoded);
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
98 oencoded = NULL;
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
99 #if PY2
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
100 if (name == NULL && PyFile_Check(obj)) {
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
101 oencoded = PyFile_Name(obj);
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
102 if (oencoded == NULL) {
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
103 /* This should never happen */
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
104 return NULL;
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
105 }
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
106 Py_INCREF(oencoded);
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
107 name = Bytes_AS_STRING(oencoded);
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
108 }
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1550
diff changeset
109 #endif
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1550
diff changeset
110 if (name == NULL) {
2105
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
111 oname = PyObject_GetAttrString(obj, "name");
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
112 if (oname != NULL) {
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
113 oencoded = RWopsEncodeFilePath(oname, NULL);
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
114 Py_DECREF(oname);
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
115 if (oencoded == NULL) {
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
116 return NULL;
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
117 }
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
118 if (oencoded != Py_None) {
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
119 name = Bytes_AS_STRING(oencoded);
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
120 }
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1550
diff changeset
121 }
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1550
diff changeset
122 else {
2105
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
123 PyErr_Clear();
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
124 }
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
125 }
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
126 rw = RWopsFromFileObject(obj);
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
127 if (rw == NULL) {
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
128 Py_XDECREF(oencoded);
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
129 return NULL;
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1550
diff changeset
130 }
2105
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
131
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
132 cext = find_extension(name);
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
133 if (cext != NULL) {
2112
9d4e31c20a7e minor changes to merged fsencoding files that may fix the Mac GCC error
Lenard Lindstrom <len-l@telus.net>
parents: 2105
diff changeset
134 ext = (char *)PyMem_Malloc(strlen(cext) + 1);
2105
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
135 if (ext == NULL) {
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
136 Py_XDECREF(oencoded);
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
137 return PyErr_NoMemory();
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
138 }
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
139 strcpy(ext, cext);
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
140 }
2105
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
141 Py_XDECREF(oencoded);
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
142 if (RWopsCheckObject(rw)) {
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
143 surf = IMG_LoadTyped_RW(rw, 1, ext);
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
144 }
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
145 else {
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
146 Py_BEGIN_ALLOW_THREADS;
2105
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
147 surf = IMG_LoadTyped_RW(rw, 1, ext);
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
148 Py_END_ALLOW_THREADS;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
149 }
2105
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
150 PyMem_Free(ext);
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
151 }
175
7a9d787f2316 image module redone
pygame
parents:
diff changeset
152
2105
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
153 if (surf == NULL) {
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
154 return RAISE(PyExc_SDLError, IMG_GetError());
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
155 }
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
156 final = PySurface_New(surf);
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
157 if (final == NULL) {
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
158 SDL_FreeSurface(surf);
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
159 }
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
160 return final;
175
7a9d787f2316 image module redone
pygame
parents:
diff changeset
161 }
7a9d787f2316 image module redone
pygame
parents:
diff changeset
162
704
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
163 #ifdef PNG_H
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
164
876
e8926413cb3e Minor compiler warning fixes
marcus
parents: 831
diff changeset
165 static int
3025
2cd6d1ced383 Fixes #43. Memory leak in pygame.image.save with png files,
Rene Dudfield <renesd@gmail.com>
parents: 2112
diff changeset
166 write_png (const char *file_name,
2cd6d1ced383 Fixes #43. Memory leak in pygame.image.save with png files,
Rene Dudfield <renesd@gmail.com>
parents: 2112
diff changeset
167 png_bytep *rows,
2cd6d1ced383 Fixes #43. Memory leak in pygame.image.save with png files,
Rene Dudfield <renesd@gmail.com>
parents: 2112
diff changeset
168 int w,
2cd6d1ced383 Fixes #43. Memory leak in pygame.image.save with png files,
Rene Dudfield <renesd@gmail.com>
parents: 2112
diff changeset
169 int h,
2cd6d1ced383 Fixes #43. Memory leak in pygame.image.save with png files,
Rene Dudfield <renesd@gmail.com>
parents: 2112
diff changeset
170 int colortype,
2cd6d1ced383 Fixes #43. Memory leak in pygame.image.save with png files,
Rene Dudfield <renesd@gmail.com>
parents: 2112
diff changeset
171 int bitdepth)
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
172 {
3025
2cd6d1ced383 Fixes #43. Memory leak in pygame.image.save with png files,
Rene Dudfield <renesd@gmail.com>
parents: 2112
diff changeset
173 png_structp png_ptr = NULL;
2cd6d1ced383 Fixes #43. Memory leak in pygame.image.save with png files,
Rene Dudfield <renesd@gmail.com>
parents: 2112
diff changeset
174 png_infop info_ptr = NULL;
704
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
175 FILE *fp = NULL;
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
176 char *doing = "open for writing";
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
177
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
178 if (!(fp = fopen (file_name, "wb")))
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
179 goto fail;
704
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
180
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
181 doing = "create png write struct";
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
182 if (!(png_ptr = png_create_write_struct
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
183 (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL)))
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
184 goto fail;
704
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
185
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
186 doing = "create png info struct";
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
187 if (!(info_ptr = png_create_info_struct (png_ptr)))
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
188 goto fail;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
189 if (setjmp (png_jmpbuf (png_ptr)))
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
190 goto fail;
704
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
191
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
192 doing = "init IO";
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
193 png_init_io (png_ptr, fp);
704
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
194
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
195 doing = "write header";
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
196 png_set_IHDR (png_ptr, info_ptr, w, h, bitdepth, colortype,
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
197 PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE,
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
198 PNG_FILTER_TYPE_BASE);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
199
704
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
200 doing = "write info";
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
201 png_write_info (png_ptr, info_ptr);
704
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
202
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
203 doing = "write image";
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
204 png_write_image (png_ptr, rows);
704
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
205
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
206 doing = "write end";
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
207 png_write_end (png_ptr, NULL);
704
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
208
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
209 doing = "closing file";
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
210 if(0 != fclose (fp))
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
211 goto fail;
3025
2cd6d1ced383 Fixes #43. Memory leak in pygame.image.save with png files,
Rene Dudfield <renesd@gmail.com>
parents: 2112
diff changeset
212 png_destroy_write_struct(&png_ptr, &info_ptr);
704
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
213 return 0;
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
214
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
215 fail:
3025
2cd6d1ced383 Fixes #43. Memory leak in pygame.image.save with png files,
Rene Dudfield <renesd@gmail.com>
parents: 2112
diff changeset
216 /*
2cd6d1ced383 Fixes #43. Memory leak in pygame.image.save with png files,
Rene Dudfield <renesd@gmail.com>
parents: 2112
diff changeset
217 * I don't see how to handle the case where png_ptr
2cd6d1ced383 Fixes #43. Memory leak in pygame.image.save with png files,
Rene Dudfield <renesd@gmail.com>
parents: 2112
diff changeset
218 * was allocated but info_ptr was not. However, those
2cd6d1ced383 Fixes #43. Memory leak in pygame.image.save with png files,
Rene Dudfield <renesd@gmail.com>
parents: 2112
diff changeset
219 * calls should only fail if memory is out and you are
2cd6d1ced383 Fixes #43. Memory leak in pygame.image.save with png files,
Rene Dudfield <renesd@gmail.com>
parents: 2112
diff changeset
220 * probably screwed regardless then. The resulting memory
2cd6d1ced383 Fixes #43. Memory leak in pygame.image.save with png files,
Rene Dudfield <renesd@gmail.com>
parents: 2112
diff changeset
221 * leak is the least of your concerns.
2cd6d1ced383 Fixes #43. Memory leak in pygame.image.save with png files,
Rene Dudfield <renesd@gmail.com>
parents: 2112
diff changeset
222 */
2cd6d1ced383 Fixes #43. Memory leak in pygame.image.save with png files,
Rene Dudfield <renesd@gmail.com>
parents: 2112
diff changeset
223 if( png_ptr && info_ptr ) {
2cd6d1ced383 Fixes #43. Memory leak in pygame.image.save with png files,
Rene Dudfield <renesd@gmail.com>
parents: 2112
diff changeset
224 png_destroy_write_struct(&png_ptr, &info_ptr);
2cd6d1ced383 Fixes #43. Memory leak in pygame.image.save with png files,
Rene Dudfield <renesd@gmail.com>
parents: 2112
diff changeset
225 }
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
226 SDL_SetError ("SavePNG: could not %s", doing);
704
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
227 return -1;
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
228 }
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
229
876
e8926413cb3e Minor compiler warning fixes
marcus
parents: 831
diff changeset
230 static int
2105
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
231 SavePNG (SDL_Surface *surface, const char *file)
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
232 {
704
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
233 static unsigned char** ss_rows;
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
234 static int ss_size;
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
235 static int ss_w, ss_h;
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
236 SDL_Surface *ss_surface;
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
237 SDL_Rect ss_rect;
708
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
238 int r, i;
704
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
239 int alpha = 0;
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
240 int pixel_bits = 32;
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
241
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
242 unsigned surf_flags;
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
243 unsigned surf_alpha;
2014
40072b4f596d pygame.image.save was not resetting color key correctly.
Rene Dudfield <renesd@gmail.com>
parents: 1937
diff changeset
244 unsigned surf_colorkey;
704
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
245
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
246 ss_rows = 0;
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
247 ss_size = 0;
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
248 ss_surface = NULL;
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
249
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
250 ss_w = surface->w;
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
251 ss_h = surface->h;
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
252
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
253 if (surface->format->Amask)
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
254 {
704
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
255 alpha = 1;
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
256 pixel_bits = 32;
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
257 }
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
258 else
704
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
259 pixel_bits = 24;
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
260
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
261 ss_surface = SDL_CreateRGBSurface (SDL_SWSURFACE|SDL_SRCALPHA,
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
262 ss_w, ss_h, pixel_bits,
704
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
263 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
264 0xff0000, 0xff00, 0xff, 0x000000ff
704
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
265 #else
3116
82b87373acb9 Fixed SDL_BIG_ENDIAN bug for png write. Fixes and closes #39
Rene Dudfield <renesd@gmail.com>
parents: 3025
diff changeset
266 0xff00, 0xff, 0xff0000, 0xff000000
704
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
267 #endif
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
268 );
704
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
269
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
270 if (ss_surface == NULL)
704
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
271 return -1;
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
272
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
273 surf_flags = surface->flags & (SDL_SRCALPHA | SDL_SRCCOLORKEY);
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
274 surf_alpha = surface->format->alpha;
2014
40072b4f596d pygame.image.save was not resetting color key correctly.
Rene Dudfield <renesd@gmail.com>
parents: 1937
diff changeset
275 surf_colorkey = surface->format->colorkey;
40072b4f596d pygame.image.save was not resetting color key correctly.
Rene Dudfield <renesd@gmail.com>
parents: 1937
diff changeset
276
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
277 if (surf_flags & SDL_SRCALPHA)
954
3e7d2a8a17f5 disable gil release for image save with png, and jpeg on windows.
Rene Dudfield <renesd@gmail.com>
parents: 913
diff changeset
278 SDL_SetAlpha (surface, 0, 255);
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
279 if (surf_flags & SDL_SRCCOLORKEY)
954
3e7d2a8a17f5 disable gil release for image save with png, and jpeg on windows.
Rene Dudfield <renesd@gmail.com>
parents: 913
diff changeset
280 SDL_SetColorKey (surface, 0, surface->format->colorkey);
704
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
281
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
282 ss_rect.x = 0;
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
283 ss_rect.y = 0;
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
284 ss_rect.w = ss_w;
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
285 ss_rect.h = ss_h;
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
286 SDL_BlitSurface (surface, &ss_rect, ss_surface, NULL);
704
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
287
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
288 if (ss_size == 0)
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
289 {
704
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
290 ss_size = ss_h;
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
291 ss_rows = (unsigned char**) malloc (sizeof (unsigned char*) * ss_size);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
292 if (ss_rows == NULL)
704
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
293 return -1;
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
294 }
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
295 if (surf_flags & SDL_SRCALPHA)
954
3e7d2a8a17f5 disable gil release for image save with png, and jpeg on windows.
Rene Dudfield <renesd@gmail.com>
parents: 913
diff changeset
296 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: 798
diff changeset
297 if (surf_flags & SDL_SRCCOLORKEY)
2014
40072b4f596d pygame.image.save was not resetting color key correctly.
Rene Dudfield <renesd@gmail.com>
parents: 1937
diff changeset
298 SDL_SetColorKey (surface, SDL_SRCCOLORKEY, surf_colorkey);
704
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
299
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
300 for (i = 0; i < ss_h; i++)
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
301 {
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
302 ss_rows[i] = ((unsigned char*)ss_surface->pixels) +
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
303 i * ss_surface->pitch;
704
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
304 }
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
305
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
306 if (alpha)
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
307 {
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
308 r = write_png (file, ss_rows, surface->w, surface->h,
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
309 PNG_COLOR_TYPE_RGB_ALPHA, 8);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
310 }
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
311 else
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
312 {
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
313 r = write_png (file, ss_rows, surface->w, surface->h,
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
314 PNG_COLOR_TYPE_RGB, 8);
704
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
315 }
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
316
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
317 free (ss_rows);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
318 SDL_FreeSurface (ss_surface);
704
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
319 ss_surface = NULL;
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
320 return r;
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
321 }
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
322
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
323 #endif /* end if PNG_H */
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
324
708
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
325 #ifdef JPEGLIB_H
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
326
1414
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
327 #define NUM_LINES_TO_WRITE 500
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
328
1415
085d62dd1965 Made saving jpeg release the GIL. seems ok on windows.
Rene Dudfield <renesd@gmail.com>
parents: 1414
diff changeset
329
2105
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
330 int write_jpeg (const char *file_name, unsigned char** image_buffer,
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
331 int image_width, int image_height, int quality) {
1415
085d62dd1965 Made saving jpeg release the GIL. seems ok on windows.
Rene Dudfield <renesd@gmail.com>
parents: 1414
diff changeset
332
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
333 struct jpeg_compress_struct cinfo;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
334 struct jpeg_error_mgr jerr;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
335 FILE * outfile;
1414
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
336 JSAMPROW row_pointer[NUM_LINES_TO_WRITE];
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
337 int row_stride;
1414
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
338 int num_lines_to_write;
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
339 int lines_written;
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
340 int i;
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
341
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
342 row_stride = image_width * 3;
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
343
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
344 num_lines_to_write = NUM_LINES_TO_WRITE;
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
345
708
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
346
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
347 cinfo.err = jpeg_std_error (&jerr);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
348 jpeg_create_compress (&cinfo);
708
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
349
1414
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
350 if ((outfile = fopen (file_name, "wb")) == NULL) {
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
351
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
352 SDL_SetError ("SaveJPEG: could not open %s", file_name);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
353 return -1;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
354 }
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
355 jpeg_stdio_dest (&cinfo, outfile);
708
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
356
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
357 cinfo.image_width = image_width;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
358 cinfo.image_height = image_height;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
359 cinfo.input_components = 3;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
360 cinfo.in_color_space = JCS_RGB;
1414
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
361 /* cinfo.optimize_coding = FALSE;
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
362 */
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
363 /* cinfo.optimize_coding = FALSE;
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
364 */
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
365
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
366 jpeg_set_defaults (&cinfo);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
367 jpeg_set_quality (&cinfo, quality, TRUE);
708
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
368
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
369 jpeg_start_compress (&cinfo, TRUE);
1414
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
370
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
371
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
372
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
373 /* try and write many scanlines at once. */
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
374 while (cinfo.next_scanline < cinfo.image_height) {
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
375 if (num_lines_to_write > (cinfo.image_height - cinfo.next_scanline) -1) {
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
376 num_lines_to_write = (cinfo.image_height - cinfo.next_scanline);
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
377 }
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
378 /* copy the memory from the buffers */
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
379 for(i =0; i < num_lines_to_write; i++) {
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
380 row_pointer[i] = image_buffer[cinfo.next_scanline + i];
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
381 }
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
382
708
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
383
1414
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
384 /*
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
385 num_lines_to_write = 1;
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
386 row_pointer[0] = image_buffer[cinfo.next_scanline];
1414
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
387 printf("num_lines_to_write:%d: cinfo.image_height:%d: cinfo.next_scanline:%d:\n", num_lines_to_write, cinfo.image_height, cinfo.next_scanline);
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
388 */
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
389
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
390
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
391 lines_written = jpeg_write_scanlines (&cinfo, row_pointer, num_lines_to_write);
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
392
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
393 /*
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
394 printf("lines_written:%d:\n", lines_written);
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
395 */
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
396
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
397 }
708
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
398
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
399 jpeg_finish_compress (&cinfo);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
400 fclose (outfile);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
401 jpeg_destroy_compress (&cinfo);
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
402 return 0;
708
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
403 }
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
404
1415
085d62dd1965 Made saving jpeg release the GIL. seems ok on windows.
Rene Dudfield <renesd@gmail.com>
parents: 1414
diff changeset
405
085d62dd1965 Made saving jpeg release the GIL. seems ok on windows.
Rene Dudfield <renesd@gmail.com>
parents: 1414
diff changeset
406
2105
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
407 int SaveJPEG (SDL_Surface *surface, const char *file) {
1415
085d62dd1965 Made saving jpeg release the GIL. seems ok on windows.
Rene Dudfield <renesd@gmail.com>
parents: 1414
diff changeset
408
708
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
409 static unsigned char** ss_rows;
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
410 static int ss_size;
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
411 static int ss_w, ss_h;
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
412 SDL_Surface *ss_surface;
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
413 SDL_Rect ss_rect;
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
414 int r, i;
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
415 int alpha = 0;
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
416 int pixel_bits = 32;
1414
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
417 int free_ss_surface = 1;
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
418
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
419
704
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
420
708
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
421 ss_rows = 0;
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
422 ss_size = 0;
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
423 ss_surface = NULL;
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
424
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
425 ss_w = surface->w;
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
426 ss_h = surface->h;
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
427
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
428 alpha = 0;
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
429 pixel_bits = 24;
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
430
1414
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
431 if(!surface) {
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
432 return -1;
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
433 }
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
434
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
435 /* See if the Surface is suitable for using directly.
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
436 So no conversion is needed. 24bit, RGB
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
437 */
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
438
1550
1fc9ed0cd01e A quick fix for jpeg saving not checking color order in 24 bit surfaces
Nirav Patel <nrp@eclecti.cc>
parents: 1499
diff changeset
439 if((surface->format->BytesPerPixel == 3) && !(surface->flags & SDL_SRCALPHA) && (surface->format->Rshift == 0)) {
1414
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
440 /*
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
441 printf("not creating...\n");
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
442 */
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
443 ss_surface = surface;
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
444
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
445 free_ss_surface = 0;
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
446 } else {
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
447 /*
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
448 printf("creating...\n");
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
449 */
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
450
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
451 /* If it is not, then we need to make a new surface.
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
452 */
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
453
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
454
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
455 ss_surface = SDL_CreateRGBSurface (SDL_SWSURFACE,
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
456 ss_w, ss_h, pixel_bits,
708
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
457 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
3116
82b87373acb9 Fixed SDL_BIG_ENDIAN bug for png write. Fixes and closes #39
Rene Dudfield <renesd@gmail.com>
parents: 3025
diff changeset
458 0xff00, 0xff, 0xff0000, 0xff000000
708
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
459 #else
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
460 0xff, 0xff00, 0xff0000, 0xff000000
708
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
461 #endif
1414
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
462 );
708
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
463
1414
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
464 if (ss_surface == NULL) {
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
465 return -1;
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
466 }
708
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
467
1414
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
468 ss_rect.x = 0;
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
469 ss_rect.y = 0;
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
470 ss_rect.w = ss_w;
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
471 ss_rect.h = ss_h;
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
472 SDL_BlitSurface (surface, &ss_rect, ss_surface, NULL);
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
473
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
474 free_ss_surface = 1;
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
475 }
708
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
476
1387
b59e8a5b89b4 missed freeing surface on malloc out of memory error for saving jpegs.
Rene Dudfield <renesd@gmail.com>
parents: 1372
diff changeset
477
b59e8a5b89b4 missed freeing surface on malloc out of memory error for saving jpegs.
Rene Dudfield <renesd@gmail.com>
parents: 1372
diff changeset
478 ss_size = ss_h;
b59e8a5b89b4 missed freeing surface on malloc out of memory error for saving jpegs.
Rene Dudfield <renesd@gmail.com>
parents: 1372
diff changeset
479 ss_rows = (unsigned char**) malloc (sizeof (unsigned char*) * ss_size);
b59e8a5b89b4 missed freeing surface on malloc out of memory error for saving jpegs.
Rene Dudfield <renesd@gmail.com>
parents: 1372
diff changeset
480 if(ss_rows == NULL) {
b59e8a5b89b4 missed freeing surface on malloc out of memory error for saving jpegs.
Rene Dudfield <renesd@gmail.com>
parents: 1372
diff changeset
481 /* clean up the allocated surface too */
1414
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
482 if(free_ss_surface) {
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
483 SDL_FreeSurface (ss_surface);
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
484 }
1387
b59e8a5b89b4 missed freeing surface on malloc out of memory error for saving jpegs.
Rene Dudfield <renesd@gmail.com>
parents: 1372
diff changeset
485 return -1;
708
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
486 }
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
487
1414
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
488 /* copy pointers to the scanlines... since they might not be packed.
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
489 */
1387
b59e8a5b89b4 missed freeing surface on malloc out of memory error for saving jpegs.
Rene Dudfield <renesd@gmail.com>
parents: 1372
diff changeset
490 for (i = 0; i < ss_h; i++) {
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
491 ss_rows[i] = ((unsigned char*)ss_surface->pixels) +
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
492 i * ss_surface->pitch;
708
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
493 }
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
494 r = write_jpeg (file, ss_rows, surface->w, surface->h, 85);
708
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
495
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
496
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
497 free (ss_rows);
1414
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
498
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
499 if(free_ss_surface) {
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
500 SDL_FreeSurface (ss_surface);
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
501 ss_surface = NULL;
120512179936 Some optimizations for jpeg saving.
Rene Dudfield <renesd@gmail.com>
parents: 1387
diff changeset
502 }
708
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
503 return r;
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
504 }
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
505
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
506 #endif /* end if JPEGLIB_H */
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
507
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
508 /* NOTE XX HACK TODO FIXME: this opengltosdl is also in image.c
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
509 need to share it between both.
708
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
510 */
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
511
1056
5c105664999f Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents: 1010
diff changeset
512
5c105664999f Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents: 1010
diff changeset
513 static SDL_Surface*
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1550
diff changeset
514 opengltosdl (void)
704
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
515 {
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
516 /*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: 798
diff changeset
517 /*we use pyopengl's so we don't need to link with opengl at compiletime*/
1372
04fa64ae38c1 Remove some compiler warnings
Lenard Lindstrom <len-l@telus.net>
parents: 1329
diff changeset
518 SDL_Surface *surf = NULL;
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
519 Uint32 rmask, gmask, bmask;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
520 int i;
1372
04fa64ae38c1 Remove some compiler warnings
Lenard Lindstrom <len-l@telus.net>
parents: 1329
diff changeset
521 unsigned char *pixels = NULL;
1056
5c105664999f Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents: 1010
diff changeset
522
5c105664999f Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents: 1010
diff changeset
523 GL_glReadPixels_Func p_glReadPixels= NULL;
5c105664999f Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents: 1010
diff changeset
524
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
525 p_glReadPixels = (GL_glReadPixels_Func) SDL_GL_GetProcAddress("glReadPixels");
704
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
526
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
527 surf = SDL_GetVideoSurface ();
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
528
1056
5c105664999f Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents: 1010
diff changeset
529 if(!surf) {
5c105664999f Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents: 1010
diff changeset
530 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: 1010
diff changeset
531 return NULL;
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
532 }
1056
5c105664999f Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents: 1010
diff changeset
533 if(!p_glReadPixels) {
5c105664999f Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents: 1010
diff changeset
534 RAISE (PyExc_RuntimeError, "Cannot find glReadPixels function.");
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
535 return NULL;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
536 }
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
537
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
538 pixels = (unsigned char*) malloc(surf->w * surf->h * 3);
1056
5c105664999f Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents: 1010
diff changeset
539
5c105664999f Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents: 1010
diff changeset
540 if(!pixels) {
5c105664999f Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents: 1010
diff changeset
541 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: 798
diff changeset
542 return NULL;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
543 }
704
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
544
1056
5c105664999f Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents: 1010
diff changeset
545 /* GL_RGB, GL_UNSIGNED_BYTE */
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
546 p_glReadPixels(0, 0, surf->w, surf->h, 0x1907, 0x1401, pixels);
1056
5c105664999f Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents: 1010
diff changeset
547
5c105664999f Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents: 1010
diff changeset
548 if (SDL_BYTEORDER == SDL_LIL_ENDIAN) {
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
549 rmask=0x000000FF;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
550 gmask=0x0000FF00;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
551 bmask=0x00FF0000;
1056
5c105664999f Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents: 1010
diff changeset
552 } else {
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
553 rmask=0x00FF0000;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
554 gmask=0x0000FF00;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
555 bmask=0x000000FF;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
556 }
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
557 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: 798
diff changeset
558 rmask, gmask, bmask, 0);
1056
5c105664999f Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents: 1010
diff changeset
559 if (!surf) {
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
560 free(pixels);
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
561 RAISE (PyExc_SDLError, SDL_GetError ());
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
562 return NULL;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
563 }
704
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
564
1056
5c105664999f Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents: 1010
diff changeset
565 for (i = 0; i < surf->h; ++i) {
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
566 memcpy (((char *) surf->pixels) + surf->pitch * i,
1056
5c105664999f Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents: 1010
diff changeset
567 pixels + 3 * surf->w * (surf->h - i - 1), surf->w * 3);
5c105664999f Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents: 1010
diff changeset
568 }
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
569
1056
5c105664999f Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents: 1010
diff changeset
570
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
571 free(pixels);
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
572 return surf;
704
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
573 }
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
574
1056
5c105664999f Made image.save use glReadPixels loaded by SDL, dropped pyopengl dependency.
Rene Dudfield <renesd@gmail.com>
parents: 1010
diff changeset
575
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
576 static PyObject*
2105
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
577 image_save_ext(PyObject *self, PyObject *arg)
699
a4ebfbe11a5b Put a stub function in for saving images. This is where the jpg, and png
Rene Dudfield <renesd@gmail.com>
parents: 627
diff changeset
578 {
2105
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
579 PyObject *surfobj;
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
580 PyObject *obj;
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
581 PyObject *oencoded;
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
582 SDL_Surface *surf;
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
583 SDL_Surface *temp = NULL;
2105
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
584 int result = 1;
704
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
585
2105
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
586 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: 2014
diff changeset
587 return NULL;
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
588 }
2105
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
589 surf = PySurface_AsSurface(surfobj);
704
fdd76aeca73b Added saving as png function. Since often imageext will have libpng
Rene Dudfield <renesd@gmail.com>
parents: 699
diff changeset
590
2105
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
591 surf = PySurface_AsSurface(surfobj);
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
592 if (surf->flags & SDL_OPENGL) {
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
593 temp = surf = opengltosdl();
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
594 if (surf == NULL) {
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
595 return NULL;
2105
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
596 }
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
597 }
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
598 else {
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
599 PySurface_Prep(surfobj);
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
600 }
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
601
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
602 oencoded = RWopsEncodeFilePath(obj, PyExc_SDLError);
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
603 if (oencoded == Py_None) {
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
604 PyErr_Format(PyExc_TypeError,
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
605 "Expected a string for the file argument: got %.1024s",
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
606 Py_TYPE(obj)->tp_name);
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
607 result = -2;
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
608 }
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
609 else if (oencoded != NULL) {
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
610 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: 2014
diff changeset
611 Py_ssize_t namelen = Bytes_GET_SIZE(oencoded);
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
612
1010
aef9d98ddd0e fixing png saving, and saving jpeg with capital letter extensions
brian
parents: 955
diff changeset
613 if ((namelen >= 4) &&
913
63dd8719801d Fixed ambiguous parenthesis for image type detection in imageext.save.
marcus
parents: 909
diff changeset
614 (((name[namelen - 1]=='g' || name[namelen - 1]=='G') &&
1010
aef9d98ddd0e fixing png saving, and saving jpeg with capital letter extensions
brian
parents: 955
diff changeset
615 (name[namelen - 2]=='e' || name[namelen - 2]=='E') &&
aef9d98ddd0e fixing png saving, and saving jpeg with capital letter extensions
brian
parents: 955
diff changeset
616 (name[namelen - 3]=='p' || name[namelen - 3]=='P') &&
aef9d98ddd0e fixing png saving, and saving jpeg with capital letter extensions
brian
parents: 955
diff changeset
617 (name[namelen - 4]=='j' || name[namelen - 4]=='J')) ||
aef9d98ddd0e fixing png saving, and saving jpeg with capital letter extensions
brian
parents: 955
diff changeset
618 ((name[namelen - 1]=='g' || name[namelen - 1]=='G') &&
aef9d98ddd0e fixing png saving, and saving jpeg with capital letter extensions
brian
parents: 955
diff changeset
619 (name[namelen - 2]=='p' || name[namelen - 2]=='P') &&
2105
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
620 (name[namelen - 3]=='j' || name[namelen - 3]=='J')))) {
708
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
621 #ifdef JPEGLIB_H
1443
0e566d4679ac jpeg image saving is not thread safe on windows after all.
Rene Dudfield <renesd@gmail.com>
parents: 1415
diff changeset
622 /* jpg save functions seem *NOT* thread safe at least on windows. */
0e566d4679ac jpeg image saving is not thread safe on windows after all.
Rene Dudfield <renesd@gmail.com>
parents: 1415
diff changeset
623 /*
1415
085d62dd1965 Made saving jpeg release the GIL. seems ok on windows.
Rene Dudfield <renesd@gmail.com>
parents: 1414
diff changeset
624 Py_BEGIN_ALLOW_THREADS;
1443
0e566d4679ac jpeg image saving is not thread safe on windows after all.
Rene Dudfield <renesd@gmail.com>
parents: 1415
diff changeset
625 */
2105
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
626 result = SaveJPEG(surf, name);
1443
0e566d4679ac jpeg image saving is not thread safe on windows after all.
Rene Dudfield <renesd@gmail.com>
parents: 1415
diff changeset
627 /*
1415
085d62dd1965 Made saving jpeg release the GIL. seems ok on windows.
Rene Dudfield <renesd@gmail.com>
parents: 1414
diff changeset
628 Py_END_ALLOW_THREADS;
1443
0e566d4679ac jpeg image saving is not thread safe on windows after all.
Rene Dudfield <renesd@gmail.com>
parents: 1415
diff changeset
629 */
777
e5f57903301d Some fixes from John Popplewell. Thanks!
Rene Dudfield <renesd@gmail.com>
parents: 708
diff changeset
630 #else
2105
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
631 RAISE(PyExc_SDLError, "No support for jpg compiled in.");
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
632 result = -2;
708
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
633 #endif
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
634
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
635 }
1010
aef9d98ddd0e fixing png saving, and saving jpeg with capital letter extensions
brian
parents: 955
diff changeset
636 else if ((namelen >= 3) &&
aef9d98ddd0e fixing png saving, and saving jpeg with capital letter extensions
brian
parents: 955
diff changeset
637 ((name[namelen - 1]=='g' || name[namelen - 1]=='G') &&
aef9d98ddd0e fixing png saving, and saving jpeg with capital letter extensions
brian
parents: 955
diff changeset
638 (name[namelen - 2]=='n' || name[namelen - 2]=='N') &&
2105
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
639 (name[namelen - 3]=='p' || name[namelen - 3]=='P'))) {
708
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
640 #ifdef PNG_H
955
e2651d31d119 disable gil release for image save for all platforms.
Rene Dudfield <renesd@gmail.com>
parents: 954
diff changeset
641 /*Py_BEGIN_ALLOW_THREADS; */
2105
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
642 result = SavePNG(surf, name);
955
e2651d31d119 disable gil release for image save for all platforms.
Rene Dudfield <renesd@gmail.com>
parents: 954
diff changeset
643 /*Py_END_ALLOW_THREADS; */
777
e5f57903301d Some fixes from John Popplewell. Thanks!
Rene Dudfield <renesd@gmail.com>
parents: 708
diff changeset
644 #else
2105
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
645 RAISE(PyExc_SDLError, "No support for png compiled in.");
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
646 result = -2;
708
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
647 #endif
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
648 }
2105
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
649 }
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
650 else {
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
651 result = -2;
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
652 }
708
58a68cb639ae Cleaned up the png code a little. Made it error out more nicely.
Rene Dudfield <renesd@gmail.com>
parents: 704
diff changeset
653
2105
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
654 if (temp != NULL) {
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
655 SDL_FreeSurface(temp);
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
656 }
2105
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
657 else {
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
658 PySurface_Unprep(surfobj);
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
659 }
699
a4ebfbe11a5b Put a stub function in for saving images. This is where the jpg, and png
Rene Dudfield <renesd@gmail.com>
parents: 627
diff changeset
660
2105
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
661 if (result == -2) {
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
662 /* Python error raised elsewhere */
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
663 return NULL;
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
664 }
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
665 if (result == -1) {
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
666 /* 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: 2014
diff changeset
667 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: 2014
diff changeset
668 }
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
669 if (result == 1) {
297803165311 merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents: 2014
diff changeset
670 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: 2014
diff changeset
671 }
699
a4ebfbe11a5b Put a stub function in for saving images. This is where the jpg, and png
Rene Dudfield <renesd@gmail.com>
parents: 627
diff changeset
672
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
673 Py_RETURN_NONE;
699
a4ebfbe11a5b Put a stub function in for saving images. This is where the jpg, and png
Rene Dudfield <renesd@gmail.com>
parents: 627
diff changeset
674 }
a4ebfbe11a5b Put a stub function in for saving images. This is where the jpg, and png
Rene Dudfield <renesd@gmail.com>
parents: 627
diff changeset
675
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1550
diff changeset
676 static PyMethodDef _imageext_methods[] =
175
7a9d787f2316 image module redone
pygame
parents:
diff changeset
677 {
831
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
678 { "load_extended", image_load_ext, METH_VARARGS, DOC_PYGAMEIMAGE },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
679 { "save_extended", image_save_ext, METH_VARARGS, DOC_PYGAMEIMAGE },
8749d7c235f8 Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents: 798
diff changeset
680 { NULL, NULL, 0, NULL }
175
7a9d787f2316 image module redone
pygame
parents:
diff changeset
681 };
7a9d787f2316 image module redone
pygame
parents:
diff changeset
682
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1550
diff changeset
683
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1550
diff changeset
684 /*DOC*/ static char _imageext_doc[] =
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1550
diff changeset
685 /*DOC*/ "additional image loaders";
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1550
diff changeset
686
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1550
diff changeset
687 MODINIT_DEFINE (imageext)
175
7a9d787f2316 image module redone
pygame
parents:
diff changeset
688 {
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1550
diff changeset
689 PyObject *module;
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1550
diff changeset
690
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1550
diff changeset
691 #if PY3
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1550
diff changeset
692 static struct PyModuleDef _module = {
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1550
diff changeset
693 PyModuleDef_HEAD_INIT,
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1550
diff changeset
694 "imageext",
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1550
diff changeset
695 _imageext_doc,
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1550
diff changeset
696 -1,
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1550
diff changeset
697 _imageext_methods,
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1550
diff changeset
698 NULL, NULL, NULL, NULL
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1550
diff changeset
699 };
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1550
diff changeset
700 #endif
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1550
diff changeset
701
1499
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1443
diff changeset
702 /* 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: 1443
diff changeset
703 the module is not loaded.
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1443
diff changeset
704 */
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1443
diff changeset
705 import_pygame_base ();
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1443
diff changeset
706 if (PyErr_Occurred ()) {
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1550
diff changeset
707 MODINIT_ERROR;
1499
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1443
diff changeset
708 }
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1443
diff changeset
709 import_pygame_surface ();
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1443
diff changeset
710 if (PyErr_Occurred ()) {
1804
7444350a233c in init functions: fix minor Python 3.x related memory leaks and clean up indentation
Lenard Lindstrom <len-l@telus.net>
parents: 1603
diff changeset
711 MODINIT_ERROR;
1499
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1443
diff changeset
712 }
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1443
diff changeset
713 import_pygame_rwobject ();
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
714
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
715
1499
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1443
diff changeset
716 if (PyErr_Occurred ()) {
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1550
diff changeset
717 MODINIT_ERROR;
1499
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1443
diff changeset
718 }
65e001d30448 bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents: 1443
diff changeset
719
175
7a9d787f2316 image module redone
pygame
parents:
diff changeset
720 /* create the module */
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1550
diff changeset
721 #if PY3
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1550
diff changeset
722 module = PyModule_Create (&_module);
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1550
diff changeset
723 #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
724 module = Py_InitModule3(MODPREFIX "imageext",
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
725 _imageext_methods,
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
726 _imageext_doc);
1553
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1550
diff changeset
727 #endif
ebd545641c8b merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents: 1550
diff changeset
728 MODINIT_RETURN (module);
175
7a9d787f2316 image module redone
pygame
parents:
diff changeset
729 }