My favorites | Sign in
Project Logo
Project hosting will be READ-ONLY Wednesday at 8am PST due to brief network maintenance.
                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436

/**
* @file screen.c
*/

/**********************************************************************

Created: 30 Oct 2005

**********************************************************************/
// $Id: screen.cpp 1547 2005-12-09 12:25:07Z fraca7 $

#include "screen.h"
#include "image.h"
#include "color.h"
#include "font.h"

using namespace Imaging;

#define MIN(x, y) ((x) < (y) ? (x) : (y))

static void screen_dealloc(PyScreen *self)
{
self->ob_type->tp_free((PyObject*)self);
}

static PyObject* screen_new(PyTypeObject *type,
PyObject *args,
PyObject *kwargs)
{
PyScreen *self;

if (PyErr_CheckSignals())
return NULL;

self = (PyScreen*)type->tp_alloc(type, 0);

if (self)
self->scr = NULL;

return (PyObject*)self;
}

static int screen_init(PyScreen *self,
PyObject *args,
PyObject *kwargs)
{
if (!PyArg_ParseTuple(args, ":__init__"))
return -1;

if (PyErr_CheckSignals())
return -1;

self->scr = Screen::getInstance();

return 0;
}

static PyObject* screen_getwidth(PyImage *self, void *closure)
{
if (PyErr_CheckSignals())
return NULL;

return Py_BuildValue("i", 480);
}

static PyObject* screen_getheight(PyImage *self, void *closure)
{
if (PyErr_CheckSignals())
return NULL;

return Py_BuildValue("i", 272);
}

static PyObject* screen_getsize(PyImage *self, void *closure)
{
if (PyErr_CheckSignals())
return NULL;

return Py_BuildValue("ii", 480, 272);
}

static PyGetSetDef screen_getset[] = {
{ "width", (getter)screen_getwidth, NULL, "Width of the image", NULL },
{ "height", (getter)screen_getheight, NULL, "Height of the image", NULL },
{ "size", (getter)screen_getsize, NULL, "Size as a 2-tuple", NULL },

{ NULL }
};


static PyObject* screen_blit(PyScreen *self,
PyObject *args,
PyObject *kwargs)
{
int sx = 0, sy = 0, w = -1, h = -1, dx = 0, dy = 0, blend = 0, dw = -1, dh = -1;
double scaleX, scaleY;
PyImage *img;

static char* kwids[] = { "src", "sx", "sy", "w", "h", "dx", "dy", "blend", "dw", "dh", NULL };

if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"O|iiiiiiiii:blit", kwids,
&img,
&sx, &sy, &w, &h,
&dx, &dy,
&blend,
&dw, &dh))
return NULL;

if (PyErr_CheckSignals())
return NULL;

if (!PyType_IsSubtype(((PyObject*)img)->ob_type, PPyImageType))
{
PyErr_SetString(PyExc_TypeError, "Fifth argument must be an Image");
return NULL;
}

if (PyErr_CheckSignals())
return NULL;

if (w == -1)
w = (int)img->img->getWidth();

if (h == -1)
h = (int)img->img->getHeight();

if (dw < 0)
dw = w;

if (dh < 0)
dh = h;

scaleX = (double)dw / w;
scaleY = (double)dh / h;

// Sanity checks

if ((dx >= SCREEN_WIDTH) || (dy >= SCREEN_HEIGHT))
{
Py_INCREF(Py_None);
return Py_None;
}

w = MIN(w, (int)img->img->getWidth() - sx);
if (dx + scaleX * w >= SCREEN_WIDTH)
w = (int)((SCREEN_WIDTH - dx) / scaleX);

h = MIN(h, (int)img->img->getHeight() - sy);
if (dy + scaleY * h >= SCREEN_HEIGHT)
h = (int)((SCREEN_HEIGHT - dy) / scaleY);

if ((w <= 0) || (h <= 0))
{
Py_INCREF(Py_None);
return Py_None;
}

// OK

self->scr->blit(img->img, sx, sy, w, h, dx, dy, blend, scaleX, scaleY);

Py_INCREF(Py_None);
return Py_None;
}

static PyObject* screen_clear(PyScreen *self,
PyObject *args)
{
PyColor *color;

if (!PyArg_ParseTuple(args, "O:clear", &color))
return NULL;

if (PyErr_CheckSignals())
return NULL;

if (!PyType_IsSubtype(((PyObject*)color)->ob_type, PPyColorType))
{
PyErr_SetString(PyExc_TypeError, "Argument must be a Color.");
return NULL;
}

if (PyErr_CheckSignals())
return NULL;

self->scr->clear(color->color);

Py_INCREF(Py_None);
return Py_None;
}

static PyObject* screen_fillRect(PyScreen *self,
PyObject *args)
{
PyColor *color;
int x, y, w, h;

if (!PyArg_ParseTuple(args, "iiiiO:fillRect", &x, &y,
&w, &h, &color))
return NULL;

if (PyErr_CheckSignals())
return NULL;

if (!PyType_IsSubtype(((PyObject*)color)->ob_type, PPyColorType))
{
PyErr_SetString(PyExc_TypeError, "Fifth argument must be a Color.");
return NULL;
}

if (PyErr_CheckSignals())
return NULL;

self->scr->fillRect(color->color, x, y, w, h);

Py_INCREF(Py_None);
return Py_None;
}

static PyObject* screen_swap(PyScreen *self,
PyObject *args)
{
if (!PyArg_ParseTuple(args, ":swap"))
return NULL;

if (PyErr_CheckSignals())
return NULL;

self->scr->flip();

Py_INCREF(Py_None);
return Py_None;
}

static PyObject* screen_saveToFile(PyScreen *self,
PyObject *args)
{
char *filename;
int type = (int)IMG_PNG;
ImageType etype = IMG_PNG;

if (!PyArg_ParseTuple(args, "s|i:saveToFile", &filename, &type))
return NULL;

if (PyErr_CheckSignals())
return NULL;

switch (type)
{
case (int)IMG_PNG:
etype = IMG_PNG;
break;
case (int)IMG_JPEG:
etype = IMG_JPEG;
break;
}

self->scr->saveToFile(filename, etype);

Py_INCREF(Py_None);
return Py_None;
}

static PyObject* screen_putPixel(PyScreen *self,
PyObject *args)
{
int x, y;
PyColor *color;

if (!PyArg_ParseTuple(args, "iiO:putPixel", &x, &y, &color))
return NULL;

if (PyErr_CheckSignals())
return NULL;

if (!PyType_IsSubtype(((PyObject*)color)->ob_type, PPyColorType))
{
PyErr_SetString(PyExc_TypeError, "Third argument must be a Color.");
return NULL;
}

self->scr->putPixel(color->color, x, y);

Py_INCREF(Py_None);
return Py_None;
}

static PyObject* screen_getPixel(PyScreen *self,
PyObject *args)
{
int x, y;
PyColor *color;
PyObject *nargs;
u32 c;

if (!PyArg_ParseTuple(args, "ii:getPixel", &x, &y))
return NULL;

if (PyErr_CheckSignals())
return NULL;

c = self->scr->getPixel(x, y);
nargs = Py_BuildValue("iii", (int)(c & 0xFF), (int)((c >> 8) & 0xFF),
(int)((c >> 16) & 0xFF), (int)((c >> 24) & 0xFF));

color = (PyColor*)PyType_GenericNew(PPyColorType, nargs, NULL);
Py_DECREF(nargs);

color->color = c;
return (PyObject*)color;
}

static PyObject* screen_drawLine(PyScreen *self,
PyObject *args)
{
int x1, y1, x2, y2;
PyColor *colorobj = NULL;
u32 color = 0xFFFFFFFFU;

if (!PyArg_ParseTuple(args, "iiii|O:drawLine", &x1, &y1, &x2, &y2, &colorobj))
return NULL;

if (PyErr_CheckSignals())
return NULL;

if (colorobj)
{
if (!PyType_IsSubtype(((PyObject*)colorobj)->ob_type, PPyColorType))
{
PyErr_SetString(PyExc_TypeError, "Fifth argument must be a Color.");
return NULL;
}

color = colorobj->color;
}

self->scr->drawLine(x1, y1, x2, y2, color);

Py_INCREF(Py_None);
return Py_None;
}

static PyObject* screen_drawText(PyScreen *self,
PyObject *args)
{
int x, y;
char *text;
PyColor *colorobj = NULL;
u32 color = 0xFFFFFFFFU;

if (!PyArg_ParseTuple(args, "iis|O:drawText", &x, &y, &text, &colorobj))
return NULL;

if (PyErr_CheckSignals())
return NULL;

if (colorobj)
{
if (!PyType_IsSubtype(((PyObject*)colorobj)->ob_type, PPyColorType))
{
PyErr_SetString(PyExc_TypeError, "Fifth argument must be a Color.");
return NULL;
}

color = colorobj->color;
}

self->scr->printText(x, y, text, color);

Py_INCREF(Py_None);
return Py_None;
}

static PyMethodDef screen_methods[] = {
{ "blit", (PyCFunction)screen_blit, METH_VARARGS|METH_KEYWORDS, "" },
{ "clear", (PyCFunction)screen_clear, METH_VARARGS, "" },
{ "fillRect", (PyCFunction)screen_fillRect, METH_VARARGS, "" },
{ "swap", (PyCFunction)screen_swap, METH_VARARGS, "" },
{ "saveToFile", (PyCFunction)screen_saveToFile, METH_VARARGS, "" },
{ "putPixel", (PyCFunction)screen_putPixel, METH_VARARGS, "" },
{ "getPixel", (PyCFunction)screen_getPixel, METH_VARARGS, "" },
{ "drawLine", (PyCFunction)screen_drawLine, METH_VARARGS, "" },
{ "drawText", (PyCFunction)screen_drawText, METH_VARARGS, "" },

{ NULL }
};

static PyTypeObject PyScreenType = {
PyObject_HEAD_INIT(NULL)
0,
"pymaging.Screen",
sizeof(PyScreen),
0,
(destructor)screen_dealloc,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
"Screen objects",
0,
0,
0,
0,
0,
0,
screen_methods,
0,
screen_getset,
0,
0,
0,
0,
0,
(initproc)screen_init,
0,
screen_new,
};

PyTypeObject* PPyScreenType = &PyScreenType;

#ifdef _GNUC
static const char* _rcsid_screen __attribute__((unused)) = "$Id: screen.cpp 1547 2005-12-09 12:25:07Z fraca7 $";
#endif
Show details Hide details

Change log

r42 by carlosedp on Jul 01, 2008   Diff
Tagging PSP Stackless 2.5.2 Release 1
Go to: 
Project members, sign in to write a code review

Older revisions

r28 by carlosedp on Jun 27, 2008   Diff
- Updated to latest libs revision from
svn://www.fraca7.net/python/trunk/pyth
on revision 163.
- Added pach from MagerValp to fix
some issues on pspos, psp2d, pspnet.
...
r11 by carlosedp on Nov 21, 2007   Diff
- Merged to Revision 106 from Python
PSP repository.
- Ported to run on Kernel 3.XX
- Added some registers to
switch_mips_psp_gcc.h that prevented
...
r9 by carlosedp on Nov 20, 2007   Diff
Branch to keep PSP Stackless 2.5
maintenance
All revisions of this file

File info

Size: 9683 bytes, 436 lines
Hosted by Google Code