~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to plug-ins/pygimp/pygimp-image.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C; c-basic-offset: 4 -*- 
 
1
/* -*- Mode: C; c-basic-offset: 4 -*-
2
2
    Gimp-Python - allows the writing of Gimp plugins in Python.
3
3
    Copyright (C) 1997-2002  James Henstridge <james@daa.com.au>
4
4
 
20
20
#ifdef HAVE_CONFIG_H
21
21
#  include <config.h>
22
22
#endif
 
23
 
23
24
#include "pygimp.h"
24
25
 
25
26
static PyObject *
28
29
    PyGimpChannel *chn;
29
30
    int pos = -1;
30
31
        
31
 
    if (!PyArg_ParseTuple(args, "O!|i:add_channel", &PyGimpChannel_Type, &chn, &pos))
32
 
        return NULL;
33
 
    return PyInt_FromLong(gimp_image_add_channel(self->ID, chn->ID, pos));
 
32
    if (!PyArg_ParseTuple(args, "O!|i:add_channel",
 
33
                                &PyGimpChannel_Type, &chn, &pos))
 
34
        return NULL;
 
35
 
 
36
    if (!gimp_image_add_channel(self->ID, chn->ID, pos)) {
 
37
        PyErr_Format(pygimp_error,
 
38
                     "could not add channel (ID %d) to image (ID %d)",
 
39
                     chn->ID, self->ID);
 
40
        return NULL;
 
41
    }
 
42
 
 
43
    Py_INCREF(Py_None);
 
44
    return Py_None;
34
45
}
35
46
 
36
 
 
37
47
static PyObject *
38
48
img_add_layer(PyGimpImage *self, PyObject *args)
39
49
{
43
53
    if (!PyArg_ParseTuple(args, "O!|i:add_layer", &PyGimpLayer_Type, &lay,
44
54
                          &pos))
45
55
        return NULL;
46
 
    return PyInt_FromLong(gimp_image_add_layer(self->ID, lay->ID, pos));
 
56
 
 
57
    if (!gimp_image_add_layer(self->ID, lay->ID, pos)) {
 
58
        PyErr_Format(pygimp_error,
 
59
                     "could not add layer (ID %d) to image (ID %d)",
 
60
                     lay->ID, self->ID);
 
61
        return NULL;
 
62
    }
 
63
 
 
64
    Py_INCREF(Py_None);
 
65
    return Py_None;
47
66
}
48
67
 
49
 
 
50
68
static PyObject *
51
69
img_clean_all(PyGimpImage *self)
52
70
{
53
 
    return PyInt_FromLong(gimp_image_clean_all(self->ID));
 
71
    if (!gimp_image_clean_all(self->ID)) {
 
72
        PyErr_Format(pygimp_error, "could not clean all on image (ID %d)",
 
73
                     self->ID);
 
74
        return NULL;
 
75
    }
 
76
 
 
77
    Py_INCREF(Py_None);
 
78
    return Py_None;
54
79
}
55
80
 
56
 
 
57
81
static PyObject *
58
82
img_disable_undo(PyGimpImage *self)
59
83
{
60
 
 
61
 
    return PyInt_FromLong(gimp_image_undo_disable(self->ID));
 
84
    return PyBool_FromLong(gimp_image_undo_disable(self->ID));
62
85
}
63
86
 
64
 
 
65
87
static PyObject *
66
88
img_enable_undo(PyGimpImage *self)
67
89
{
68
 
    return PyInt_FromLong(gimp_image_undo_enable(self->ID));
 
90
    return PyBool_FromLong(gimp_image_undo_enable(self->ID));
69
91
}
70
92
 
71
 
 
72
93
static PyObject *
73
94
img_flatten(PyGimpImage *self)
74
95
{
75
96
    return pygimp_layer_new(gimp_image_flatten(self->ID));
76
97
}
77
98
 
78
 
 
79
99
static PyObject *
80
100
img_lower_channel(PyGimpImage *self, PyObject *args)
81
101
{
82
102
    PyGimpChannel *chn;
 
103
 
83
104
    if (!PyArg_ParseTuple(args, "O!:lower_channel", &PyGimpChannel_Type, &chn))
84
105
        return NULL;
85
 
    return PyInt_FromLong(gimp_image_lower_channel(self->ID, chn->ID));
 
106
 
 
107
    if (!gimp_image_lower_channel(self->ID, chn->ID)) {
 
108
        PyErr_Format(pygimp_error,
 
109
                     "could not lower channel (ID %d) on image (ID %d)",
 
110
                     chn->ID, self->ID);
 
111
        return NULL;
 
112
    }
 
113
 
 
114
    Py_INCREF(Py_None);
 
115
    return Py_None;
86
116
}
87
117
 
88
118
static PyObject *
89
119
img_lower_layer(PyGimpImage *self, PyObject *args)
90
120
{
91
121
    PyGimpLayer *lay;
 
122
 
92
123
    if (!PyArg_ParseTuple(args, "O!:lower_layer", &PyGimpLayer_Type, &lay))
93
124
        return NULL;
94
 
    return PyInt_FromLong(gimp_image_lower_layer(self->ID, lay->ID));
 
125
 
 
126
    if (!gimp_image_lower_layer(self->ID, lay->ID)) {
 
127
        PyErr_Format(pygimp_error,
 
128
                     "could not lower layer (ID %d) on image (ID %d)",
 
129
                     lay->ID, self->ID);
 
130
        return NULL;
 
131
    }
 
132
 
 
133
    Py_INCREF(Py_None);
 
134
    return Py_None;
95
135
}
96
136
 
97
137
static PyObject *
98
138
img_lower_layer_to_bottom(PyGimpImage *self, PyObject *args)
99
139
{
100
140
    PyGimpLayer *lay;
 
141
 
101
142
    if (!PyArg_ParseTuple(args, "O!:lower_layer_to_bottom",
102
143
                          &PyGimpLayer_Type, &lay))
103
144
        return NULL;
104
 
    return PyInt_FromLong(gimp_image_lower_layer_to_bottom(self->ID, lay->ID));
 
145
 
 
146
    if (!gimp_image_lower_layer_to_bottom(self->ID, lay->ID)) {
 
147
        PyErr_Format(pygimp_error,
 
148
                     "could not lower layer (ID %d) to bottom on image (ID %d)",
 
149
                     lay->ID, self->ID);
 
150
        return NULL;
 
151
    }
 
152
 
 
153
    Py_INCREF(Py_None);
 
154
    return Py_None;
105
155
}
106
156
 
107
157
static PyObject *
112
162
 
113
163
    if (!PyArg_ParseTuple(args, "i:merge_visible_layers", &merge))
114
164
        return NULL;
 
165
 
115
166
    id = gimp_image_merge_visible_layers(self->ID, merge);
 
167
 
116
168
    if (id == -1) {
117
 
        PyErr_SetString(pygimp_error, "Can't merge layers");
 
169
        PyErr_Format(pygimp_error,
 
170
                     "could not merge visible layers on image (ID %d) "
 
171
                     "with merge type %d",
 
172
                     self->ID, merge);
118
173
        return NULL;
119
174
    }
 
175
 
120
176
    return pygimp_layer_new(id);
121
177
}
122
178
 
127
183
    PyGimpLayer *layer;
128
184
    int merge;
129
185
 
130
 
    if (!PyArg_ParseTuple(args, "O!i:merge_visible_layers",
 
186
    if (!PyArg_ParseTuple(args, "O!i:merge_down",
131
187
                          &PyGimpLayer_Type, &layer, &merge))
132
188
        return NULL;
 
189
 
133
190
    id = gimp_image_merge_down(self->ID, layer->ID, merge);
 
191
 
134
192
    if (id == -1) {
135
 
        PyErr_SetString(pygimp_error, "Can't merge layers");
 
193
        PyErr_Format(pygimp_error,
 
194
                     "could not merge down layer (ID %d) on image (ID %d) "
 
195
                     "with merge type %d",
 
196
                     layer->ID, self->ID, merge);
136
197
        return NULL;
137
198
    }
 
199
 
138
200
    return pygimp_layer_new(id);
139
201
}
140
202
 
146
208
        
147
209
    if (!PyArg_ParseTuple(args, "ii:pick_correlate_layer", &x, &y))
148
210
        return NULL;
 
211
 
149
212
    id = gimp_image_pick_correlate_layer(self->ID, x, y);
 
213
 
150
214
    if (id == -1) {
151
215
        Py_INCREF(Py_None);
152
216
        return Py_None;
153
217
    }
 
218
 
154
219
    return pygimp_layer_new(id);
155
220
}
156
221
 
157
 
 
158
222
static PyObject *
159
223
img_raise_channel(PyGimpImage *self, PyObject *args)
160
224
{
162
226
        
163
227
    if (!PyArg_ParseTuple(args, "O!:raise_channel", &PyGimpChannel_Type, &chn))
164
228
        return NULL;
165
 
    return PyInt_FromLong(gimp_image_raise_channel(self->ID, chn->ID));
 
229
 
 
230
    if (!gimp_image_raise_channel(self->ID, chn->ID)) {
 
231
        PyErr_Format(pygimp_error,
 
232
                     "could not raise channel (ID %d) on image (ID %d)",
 
233
                     chn->ID, self->ID);
 
234
        return NULL;
 
235
    }
 
236
 
 
237
    Py_INCREF(Py_None);
 
238
    return Py_None;
166
239
}
167
240
 
168
241
static PyObject *
169
242
img_raise_layer(PyGimpImage *self, PyObject *args)
170
243
{
171
244
    PyGimpLayer *lay;
 
245
 
172
246
    if (!PyArg_ParseTuple(args, "O!:raise_layer", &PyGimpLayer_Type, &lay))
173
247
        return NULL;
174
 
    return PyInt_FromLong(gimp_image_raise_layer(self->ID, lay->ID));
 
248
 
 
249
    if (!gimp_image_raise_layer(self->ID, lay->ID)) {
 
250
        PyErr_Format(pygimp_error,
 
251
                     "could not raise layer (ID %d) on image (ID %d)",
 
252
                     lay->ID, self->ID);
 
253
        return NULL;
 
254
    }
 
255
 
 
256
    Py_INCREF(Py_None);
 
257
    return Py_None;
175
258
}
176
259
 
177
260
static PyObject *
178
261
img_raise_layer_to_top(PyGimpImage *self, PyObject *args)
179
262
{
180
263
    PyGimpLayer *lay;
 
264
 
181
265
    if (!PyArg_ParseTuple(args, "O!:raise_layer_to_top",
182
266
                          &PyGimpLayer_Type, &lay))
183
267
        return NULL;
184
 
    return PyInt_FromLong(gimp_image_raise_layer_to_top(self->ID, lay->ID));
 
268
 
 
269
    if (!gimp_image_raise_layer_to_top(self->ID, lay->ID)) {
 
270
        PyErr_Format(pygimp_error,
 
271
                     "could not raise layer (ID %d) to top on image (ID %d)",
 
272
                     lay->ID, self->ID);
 
273
        return NULL;
 
274
    }
 
275
 
 
276
    Py_INCREF(Py_None);
 
277
    return Py_None;
185
278
}
186
279
 
187
280
static PyObject *
188
281
img_remove_channel(PyGimpImage *self, PyObject *args)
189
282
{
190
283
    PyGimpChannel *chn;
 
284
 
191
285
    if (!PyArg_ParseTuple(args, "O!:remove_channel", &PyGimpChannel_Type, &chn))
192
286
        return NULL;
193
 
    return PyInt_FromLong(gimp_image_remove_channel(self->ID, chn->ID));
 
287
 
 
288
    if (!gimp_image_remove_channel(self->ID, chn->ID)) {
 
289
        PyErr_Format(pygimp_error,
 
290
                     "could not remove channel (ID %d) from image (ID %d)",
 
291
                     chn->ID, self->ID);
 
292
        return NULL;
 
293
    }
 
294
 
 
295
    Py_INCREF(Py_None);
 
296
    return Py_None;
194
297
}
195
298
 
196
 
 
197
299
static PyObject *
198
300
img_remove_layer(PyGimpImage *self, PyObject *args)
199
301
{
200
302
    PyGimpLayer *lay;
 
303
 
201
304
    if (!PyArg_ParseTuple(args, "O!:remove_layer", &PyGimpLayer_Type, &lay))
202
305
        return NULL;
203
 
    return PyInt_FromLong(gimp_image_remove_layer(self->ID, lay->ID));
204
 
}
205
 
 
206
 
 
207
 
static PyObject *
208
 
img_resize(PyGimpImage *self, PyObject *args)
209
 
{
210
 
    int new_w, new_h;
211
 
    int offs_x, offs_y;
212
 
 
213
 
    if (!PyArg_ParseTuple(args, "iiii:resize", &new_w, &new_h,
214
 
                          &offs_x, &offs_y))
215
 
        return NULL;
216
 
    return PyInt_FromLong(gimp_image_resize(self->ID, new_w, new_h,
217
 
                                            offs_x, offs_y));
218
 
}
219
 
 
220
 
static PyObject *
221
 
img_scale(PyGimpImage *self, PyObject *args)
222
 
{
223
 
    gint new_width, new_height;
224
 
 
225
 
    if (!PyArg_ParseTuple(args, "ii:scale", &new_width, &new_height))
226
 
        return NULL;
227
 
    return PyInt_FromLong(gimp_image_scale(self->ID, new_width, new_height));
228
 
}
229
 
 
230
 
static PyObject *
231
 
img_crop(PyGimpImage *self, PyObject *args)
232
 
{
233
 
    int new_w, new_h;
234
 
    int offs_x, offs_y;
235
 
    if (!PyArg_ParseTuple(args, "iiii:crop", &new_w, &new_h,
236
 
                          &offs_x, &offs_y))
237
 
        return NULL;
238
 
    return PyInt_FromLong(gimp_image_crop(self->ID, new_w, new_h,
239
 
                                          offs_x, offs_y));
 
306
 
 
307
    if (!gimp_image_remove_layer(self->ID, lay->ID)) {
 
308
        PyErr_Format(pygimp_error,
 
309
                     "could not remove layer (ID %d) from image (ID %d)",
 
310
                     lay->ID, self->ID);
 
311
        return NULL;
 
312
    }
 
313
 
 
314
    Py_INCREF(Py_None);
 
315
    return Py_None;
 
316
}
 
317
 
 
318
static PyObject *
 
319
img_resize(PyGimpImage *self, PyObject *args, PyObject *kwargs)
 
320
{
 
321
    int new_w, new_h;
 
322
    int offs_x = 0, offs_y = 0;
 
323
 
 
324
    static char *kwlist[] = { "width", "height", "offset_x", "offset_y",
 
325
                              NULL };
 
326
 
 
327
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii|ii:resize", kwlist,
 
328
                                     &new_w, &new_h, &offs_x, &offs_y))
 
329
        return NULL;
 
330
 
 
331
    if (!gimp_image_resize(self->ID, new_w, new_h, offs_x, offs_y)) {
 
332
        PyErr_Format(pygimp_error,
 
333
                     "could not resize image (ID %d) to %dx%d, offset %d, %d",
 
334
                     self->ID, new_w, new_h, offs_x, offs_y);
 
335
        return NULL;
 
336
    }
 
337
 
 
338
    Py_INCREF(Py_None);
 
339
    return Py_None;
 
340
}
 
341
 
 
342
static PyObject *
 
343
img_scale(PyGimpImage *self, PyObject *args, PyObject *kwargs)
 
344
{
 
345
    int new_width, new_height;
 
346
 
 
347
    static char *kwlist[] = { "width", "height", NULL };
 
348
 
 
349
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii:scale", kwlist,
 
350
                                     &new_width, &new_height))
 
351
        return NULL;
 
352
 
 
353
    if (!gimp_image_scale(self->ID, new_width, new_height)) {
 
354
        PyErr_Format(pygimp_error, "could not scale image (ID %d) to %dx%d",
 
355
                     self->ID, new_width, new_height);
 
356
        return NULL;
 
357
    }
 
358
 
 
359
    Py_INCREF(Py_None);
 
360
    return Py_None;
 
361
}
 
362
 
 
363
static PyObject *
 
364
img_crop(PyGimpImage *self, PyObject *args, PyObject *kwargs)
 
365
{
 
366
    int new_w, new_h;
 
367
    int offs_x = 0, offs_y = 0;
 
368
 
 
369
    static char *kwlist[] = { "width", "height", "offset_x", "offset_y",
 
370
                              NULL };
 
371
 
 
372
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii|ii:crop", kwlist,
 
373
                                     &new_w, &new_h, &offs_x, &offs_y))
 
374
        return NULL;
 
375
 
 
376
    if (!gimp_image_crop(self->ID, new_w, new_h, offs_x, offs_y)) {
 
377
        PyErr_Format(pygimp_error,
 
378
                     "could not crop image (ID %d) to %dx%d, offset %d, %d",
 
379
                     self->ID, new_w, new_h, offs_x, offs_y);
 
380
        return NULL;
 
381
    }
 
382
 
 
383
    Py_INCREF(Py_None);
 
384
    return Py_None;
240
385
}
241
386
 
242
387
static PyObject *
243
388
img_free_shadow(PyGimpImage *self)
244
389
{
245
 
    return PyInt_FromLong(gimp_image_free_shadow(self->ID));
 
390
    if (!gimp_image_free_shadow(self->ID)) {
 
391
        PyErr_Format(pygimp_error, "could not free shadow on image (ID %d)",
 
392
                     self->ID);
 
393
        return NULL;
 
394
    }
 
395
 
 
396
    Py_INCREF(Py_None);
 
397
    return Py_None;
246
398
}
247
399
 
248
400
static PyObject *
249
401
img_unset_active_channel(PyGimpImage *self)
250
402
{
251
 
    return PyInt_FromLong(gimp_image_unset_active_channel(self->ID));
 
403
    if (!gimp_image_unset_active_channel(self->ID)) {
 
404
        PyErr_Format(pygimp_error,
 
405
                     "could not unset active channel on image (ID %d)",
 
406
                     self->ID);
 
407
        return NULL;
 
408
    }
 
409
 
 
410
    Py_INCREF(Py_None);
 
411
    return Py_None;
252
412
}
253
413
 
254
414
static PyObject *
255
415
img_get_component_active(PyGimpImage *self, PyObject *args)
256
416
{
257
417
    int comp;
 
418
 
258
419
    if (!PyArg_ParseTuple(args, "i:get_component_active", &comp))
259
420
        return NULL;
260
 
    return PyInt_FromLong(gimp_image_get_component_active(self->ID, comp));
 
421
 
 
422
    return PyBool_FromLong(gimp_image_get_component_active(self->ID, comp));
261
423
}
262
424
 
263
425
 
269
431
    if (!PyArg_ParseTuple(args, "i:get_component_visible", &comp))
270
432
        return NULL;
271
433
        
272
 
    return PyInt_FromLong(gimp_image_get_component_visible(self->ID, comp));
 
434
    return PyBool_FromLong(gimp_image_get_component_visible(self->ID, comp));
273
435
}
274
436
 
275
437
 
277
439
img_set_component_active(PyGimpImage *self, PyObject *args)
278
440
{
279
441
    int comp, a;
 
442
 
280
443
    if (!PyArg_ParseTuple(args, "ii:set_component_active", &comp, &a))
281
444
        return NULL;
282
 
    return PyInt_FromLong(gimp_image_set_component_active(self->ID, comp, a));
 
445
 
 
446
    if (!gimp_image_set_component_active(self->ID, comp, a)) {
 
447
        PyErr_Format(pygimp_error,
 
448
                     "could not set component (%d) %sactive on image (ID %d)",
 
449
                     comp, a ? "" : "in", self->ID);
 
450
        return NULL;
 
451
    }
 
452
 
 
453
    Py_INCREF(Py_None);
 
454
    return Py_None;
283
455
}
284
456
 
285
 
 
286
457
static PyObject *
287
458
img_set_component_visible(PyGimpImage *self, PyObject *args)
288
459
{
289
460
    int comp, v;
 
461
 
290
462
    if (!PyArg_ParseTuple(args, "ii:set_component_visible", &comp, &v))
291
463
        return NULL;
292
 
    return PyInt_FromLong(gimp_image_set_component_visible(self->ID, comp, v));
 
464
 
 
465
    if (!gimp_image_set_component_visible(self->ID, comp, v)) {
 
466
        PyErr_Format(pygimp_error,
 
467
                     "could not set component (%d) %svisible on image (ID %d)",
 
468
                     comp, v ? "" : "in", self->ID);
 
469
        return NULL;
 
470
    }
 
471
 
 
472
    Py_INCREF(Py_None);
 
473
    return Py_None;
293
474
}
294
475
 
295
476
static PyObject *
296
477
img_parasite_find(PyGimpImage *self, PyObject *args)
297
478
{
298
479
    char *name;
 
480
 
299
481
    if (!PyArg_ParseTuple(args, "s:parasite_find", &name))
300
482
        return NULL;
 
483
 
301
484
    return pygimp_parasite_new(gimp_image_parasite_find(self->ID, name));
302
485
}
303
486
 
305
488
img_parasite_attach(PyGimpImage *self, PyObject *args)
306
489
{
307
490
    PyGimpParasite *parasite;
 
491
 
308
492
    if (!PyArg_ParseTuple(args, "O!:parasite_attach", &PyGimpParasite_Type,
309
493
                          &parasite))
310
494
        return NULL;
311
 
    return PyInt_FromLong(gimp_image_parasite_attach(self->ID,parasite->para));
 
495
 
 
496
    if (!gimp_image_parasite_attach(self->ID, parasite->para)) {
 
497
        PyErr_Format(pygimp_error,
 
498
                     "could not attach parasite '%s' to image (ID %d)",
 
499
                     parasite->para->name, self->ID);
 
500
        return NULL;
 
501
    }
 
502
 
 
503
    Py_INCREF(Py_None);
 
504
    return Py_None;
312
505
}
313
506
 
314
507
static PyObject *
315
 
img_attach_new_parasite(PyGimpImage *self, PyObject *args)
 
508
img_attach_new_parasite(PyGimpImage *self, PyObject *args, PyObject *kwargs)
316
509
{
317
 
    char *name, *data;
 
510
    char *name;
318
511
    int flags, size;
319
 
    if (!PyArg_ParseTuple(args, "sis#:attach_new_parasite", &name, &flags,
320
 
                          &data, &size))
321
 
        return NULL;
322
 
    gimp_image_attach_new_parasite(self->ID, name, flags, size, data);
 
512
    guint8 *data;
 
513
 
 
514
    static char *kwlist[] = { "name", "flags", "data", NULL };
 
515
 
 
516
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
517
                                     "sis#:attach_new_parasite", kwlist,
 
518
                                     &name, &flags, &data, &size))
 
519
        return NULL;
 
520
 
 
521
    if (!gimp_image_attach_new_parasite(self->ID, name, flags, size, data)) {
 
522
        PyErr_Format(pygimp_error,
 
523
                     "could not attach new parasite '%s' to image (ID %d)",
 
524
                     name, self->ID);
 
525
        return NULL;
 
526
    }
 
527
 
323
528
    Py_INCREF(Py_None);
324
529
    return Py_None;
325
530
}
328
533
img_parasite_detach(PyGimpImage *self, PyObject *args)
329
534
{
330
535
    char *name;
 
536
 
331
537
    if (!PyArg_ParseTuple(args, "s:parasite_detach", &name))
332
538
        return NULL;
333
 
    return PyInt_FromLong(gimp_image_parasite_detach(self->ID, name));
 
539
 
 
540
    if (!gimp_image_parasite_detach(self->ID, name)) {
 
541
        PyErr_Format(pygimp_error,
 
542
                     "could not detach parasite '%s' from image (ID %d)",
 
543
                     name, self->ID);
 
544
        return NULL;
 
545
    }
 
546
 
 
547
    Py_INCREF(Py_None);
 
548
    return Py_None;
334
549
}
335
550
 
336
551
static PyObject *
344
559
        gint i;
345
560
 
346
561
        ret = PyTuple_New(num_parasites);
 
562
 
347
563
        for (i = 0; i < num_parasites; i++) {
348
564
            PyTuple_SetItem(ret, i, PyString_FromString(parasites[i]));
349
565
            g_free(parasites[i]);
350
566
        }
 
567
 
351
568
        g_free(parasites);
352
569
        return ret;
353
570
    }
354
 
    PyErr_SetString(pygimp_error, "could not list parasites");
 
571
 
 
572
    PyErr_Format(pygimp_error, "could not list parasites on image (ID %d)",
 
573
                 self->ID);
355
574
    return NULL;
356
575
}
357
576
 
359
578
img_get_layer_by_tattoo(PyGimpImage *self, PyObject *args)
360
579
{
361
580
    int tattoo;
 
581
 
362
582
    if (!PyArg_ParseTuple(args, "i:get_layer_by_tattoo", &tattoo))
363
583
        return NULL;
 
584
 
364
585
    return pygimp_layer_new(gimp_image_get_layer_by_tattoo(self->ID, tattoo));
365
586
}
366
587
 
368
589
img_get_channel_by_tattoo(PyGimpImage *self, PyObject *args)
369
590
{
370
591
    int tattoo;
 
592
 
371
593
    if (!PyArg_ParseTuple(args, "i:get_channel_by_tattoo", &tattoo))
372
594
        return NULL;
 
595
 
373
596
    return pygimp_channel_new(gimp_image_get_channel_by_tattoo(self->ID,
374
597
                                                               tattoo));
375
598
}
378
601
img_add_hguide(PyGimpImage *self, PyObject *args)
379
602
{
380
603
    int ypos;
 
604
 
381
605
    if (!PyArg_ParseTuple(args, "i:add_hguide", &ypos))
382
606
        return NULL;
 
607
 
383
608
    return PyInt_FromLong(gimp_image_add_hguide(self->ID, ypos));
384
609
}
385
610
 
387
612
img_add_vguide(PyGimpImage *self, PyObject *args)
388
613
{
389
614
    int xpos;
 
615
 
390
616
    if (!PyArg_ParseTuple(args, "i:add_vguide", &xpos))
391
617
        return NULL;
 
618
 
392
619
    return PyInt_FromLong(gimp_image_add_vguide(self->ID, xpos));
393
620
}
394
621
 
396
623
img_delete_guide(PyGimpImage *self, PyObject *args)
397
624
{
398
625
    int guide;
 
626
 
399
627
    if (!PyArg_ParseTuple(args, "i:delete_guide", &guide))
400
628
        return NULL;
401
 
    return PyInt_FromLong(gimp_image_delete_guide(self->ID, guide));
 
629
 
 
630
    if (!gimp_image_delete_guide(self->ID, guide)) {
 
631
        PyErr_Format(pygimp_error,
 
632
                     "could not delete guide (ID %d) from image (ID %d)",
 
633
                     guide, self->ID);
 
634
        return NULL;
 
635
    }
 
636
 
 
637
    Py_INCREF(Py_None);
 
638
    return Py_None;
402
639
}
403
640
 
404
641
static PyObject *
405
642
img_find_next_guide(PyGimpImage *self, PyObject *args)
406
643
{
407
644
    int guide;
 
645
 
408
646
    if (!PyArg_ParseTuple(args, "i:find_next_guide", &guide))
409
647
        return NULL;
 
648
 
410
649
    return PyInt_FromLong(gimp_image_find_next_guide(self->ID, guide));
411
650
}
412
651
 
414
653
img_get_guide_orientation(PyGimpImage *self, PyObject *args)
415
654
{
416
655
    int guide;
 
656
 
417
657
    if (!PyArg_ParseTuple(args, "i:get_guide_orientation", &guide))
418
658
        return NULL;
 
659
 
419
660
    return PyInt_FromLong(gimp_image_get_guide_orientation(self->ID, guide));
420
661
}
421
662
 
423
664
img_get_guide_position(PyGimpImage *self, PyObject *args)
424
665
{
425
666
    int guide;
 
667
 
426
668
    if (!PyArg_ParseTuple(args, "i:get_guide_position", &guide))
427
669
        return NULL;
 
670
 
428
671
    return PyInt_FromLong(gimp_image_get_guide_position(self->ID, guide));
429
672
}
430
673
 
431
674
static PyObject *
432
675
img_undo_is_enabled(PyGimpImage *self)
433
676
{
434
 
    return PyInt_FromLong(gimp_image_undo_is_enabled(self->ID));
 
677
    return PyBool_FromLong(gimp_image_undo_is_enabled(self->ID));
435
678
}
436
679
 
437
680
static PyObject *
438
681
img_undo_freeze(PyGimpImage *self)
439
682
{
440
 
    return PyInt_FromLong(gimp_image_undo_freeze(self->ID));
 
683
    return PyBool_FromLong(gimp_image_undo_freeze(self->ID));
441
684
}
442
685
 
443
686
static PyObject *
444
687
img_undo_thaw(PyGimpImage *self)
445
688
{
446
 
    return PyInt_FromLong(gimp_image_undo_thaw(self->ID));
 
689
    return PyBool_FromLong(gimp_image_undo_thaw(self->ID));
447
690
}
448
691
 
449
692
static PyObject *
455
698
static PyObject *
456
699
img_undo_group_start(PyGimpImage *self)
457
700
{
458
 
    return PyInt_FromLong(gimp_image_undo_group_start(self->ID));
 
701
    if (!gimp_image_undo_group_start(self->ID)) {
 
702
        PyErr_Format(pygimp_error,
 
703
                     "could not start undo group on image (ID %d)",
 
704
                     self->ID);
 
705
        return NULL;
 
706
    }
 
707
 
 
708
    Py_INCREF(Py_None);
 
709
    return Py_None;
459
710
}
460
711
 
461
712
static PyObject *
462
713
img_undo_group_end(PyGimpImage *self)
463
714
{
464
 
    return PyInt_FromLong(gimp_image_undo_group_end(self->ID));
 
715
    if (!gimp_image_undo_group_end(self->ID)) {
 
716
        PyErr_Format(pygimp_error,
 
717
                     "could not end undo group on image (ID %d)",
 
718
                     self->ID);
 
719
        return NULL;
 
720
    }
 
721
 
 
722
    Py_INCREF(Py_None);
 
723
    return Py_None;
465
724
}
466
725
 
467
726
static PyMethodDef img_methods[] = {
482
741
    {"raise_layer_to_top",      (PyCFunction)img_raise_layer_to_top,    METH_VARARGS},
483
742
    {"remove_channel",  (PyCFunction)img_remove_channel,        METH_VARARGS},
484
743
    {"remove_layer",    (PyCFunction)img_remove_layer,  METH_VARARGS},
485
 
    {"resize",  (PyCFunction)img_resize,        METH_VARARGS},
 
744
    {"resize",  (PyCFunction)img_resize,        METH_VARARGS | METH_KEYWORDS},
486
745
    {"get_component_active",    (PyCFunction)img_get_component_active,  METH_VARARGS},
487
746
    {"get_component_visible",   (PyCFunction)img_get_component_visible, METH_VARARGS},
488
747
    {"set_component_active",    (PyCFunction)img_set_component_active,  METH_VARARGS},
489
748
    {"set_component_visible",   (PyCFunction)img_set_component_visible, METH_VARARGS},
490
749
    {"parasite_find",       (PyCFunction)img_parasite_find,      METH_VARARGS},
491
750
    {"parasite_attach",     (PyCFunction)img_parasite_attach,    METH_VARARGS},
492
 
    {"attach_new_parasite", (PyCFunction)img_attach_new_parasite,METH_VARARGS},
 
751
    {"attach_new_parasite", (PyCFunction)img_attach_new_parasite,       METH_VARARGS | METH_KEYWORDS},
493
752
    {"parasite_detach",     (PyCFunction)img_parasite_detach,    METH_VARARGS},
494
753
    {"parasite_list", (PyCFunction)img_parasite_list, METH_NOARGS},
495
754
    {"get_layer_by_tattoo",(PyCFunction)img_get_layer_by_tattoo,METH_VARARGS},
500
759
    {"find_next_guide", (PyCFunction)img_find_next_guide, METH_VARARGS},
501
760
    {"get_guide_orientation",(PyCFunction)img_get_guide_orientation,METH_VARARGS},
502
761
    {"get_guide_position", (PyCFunction)img_get_guide_position, METH_VARARGS},
503
 
    {"scale", (PyCFunction)img_scale, METH_VARARGS},
504
 
    {"crop", (PyCFunction)img_crop, METH_VARARGS},
 
762
    {"scale", (PyCFunction)img_scale, METH_VARARGS | METH_KEYWORDS},
 
763
    {"crop", (PyCFunction)img_crop, METH_VARARGS | METH_KEYWORDS},
505
764
    {"free_shadow", (PyCFunction)img_free_shadow, METH_NOARGS},
506
765
    {"unset_active_channel", (PyCFunction)img_unset_active_channel, METH_NOARGS},
507
766
    {"undo_is_enabled", (PyCFunction)img_undo_is_enabled, METH_NOARGS},
528
787
        Py_INCREF(Py_None);
529
788
        return Py_None;
530
789
    }
 
790
 
531
791
    return pygimp_channel_new(id);
532
792
}
533
793
 
534
794
static int
535
795
img_set_active_channel(PyGimpImage *self, PyObject *value, void *closure)
536
796
{
 
797
    PyGimpChannel *chn;
 
798
 
537
799
    if (value == NULL) {
538
800
        PyErr_SetString(PyExc_TypeError, "cannot delete active_channel");
539
801
        return -1;
540
802
    }
 
803
 
541
804
    if (!pygimp_channel_check(value)) {
542
805
        PyErr_SetString(PyExc_TypeError, "type mismatch");
543
806
        return -1;
544
807
    }
545
 
    gimp_image_set_active_channel(self->ID, ((PyGimpChannel *)value)->ID);
 
808
 
 
809
    chn = (PyGimpChannel *)value;
 
810
 
 
811
    if (!gimp_image_set_active_channel(self->ID, chn->ID)) {
 
812
        PyErr_Format(pygimp_error,
 
813
                     "could not set active channel (ID %d) on image (ID %d)",
 
814
                     chn->ID, self->ID);
 
815
        return -1;
 
816
    }
 
817
 
546
818
    return 0;
547
819
}
548
820
 
555
827
        Py_INCREF(Py_None);
556
828
        return Py_None;
557
829
    }
 
830
 
558
831
    return pygimp_drawable_new(NULL, id);
559
832
}
560
833
 
567
840
        Py_INCREF(Py_None);
568
841
        return Py_None;
569
842
    }
 
843
 
570
844
    return pygimp_layer_new(id);
571
845
}
572
846
 
573
847
static int
574
848
img_set_active_layer(PyGimpImage *self, PyObject *value, void *closure)
575
849
{
 
850
    PyGimpLayer *lay;
 
851
 
576
852
    if (value == NULL) {
577
853
        PyErr_SetString(PyExc_TypeError, "cannot delete active_layer");
578
854
        return -1;
579
855
    }
 
856
 
580
857
    if (!pygimp_layer_check(value)) {
581
858
        PyErr_SetString(PyExc_TypeError, "type mismatch");
582
859
        return -1;
583
860
    }
584
 
    gimp_image_set_active_layer(self->ID, ((PyGimpLayer *)value)->ID);
 
861
 
 
862
    lay = (PyGimpLayer *)value;
 
863
 
 
864
    if (!gimp_image_set_active_layer(self->ID, lay->ID)) {
 
865
        PyErr_Format(pygimp_error,
 
866
                     "could not set active layer (ID %d) on image (ID %d)",
 
867
                     lay->ID, self->ID);
 
868
        return -1;
 
869
    }
 
870
 
585
871
    return 0;
586
872
}
587
873
 
597
883
    gint32 *channels;
598
884
    gint n_channels, i;
599
885
    PyObject *ret;
600
 
    
 
886
 
601
887
    channels = gimp_image_get_channels(self->ID, &n_channels);
 
888
 
602
889
    ret = PyList_New(n_channels);
 
890
 
603
891
    for (i = 0; i < n_channels; i++)
604
892
        PyList_SetItem(ret, i, pygimp_channel_new(channels[i]));
 
893
 
605
894
    g_free(channels);
 
895
 
606
896
    return ret;
607
897
}
608
898
 
612
902
    guchar *cmap;
613
903
    gint n_colours;
614
904
    PyObject *ret;
615
 
    
 
905
 
616
906
    cmap = gimp_image_get_colormap(self->ID, &n_colours);
 
907
 
 
908
    if (cmap == NULL) {
 
909
        PyErr_Format(pygimp_error, "could not get colormap for image (ID %d)",
 
910
                     self->ID);
 
911
        return NULL;
 
912
    }
 
913
        
617
914
    ret = PyString_FromStringAndSize(cmap, n_colours * 3);
618
915
    g_free(cmap);
 
916
 
619
917
    return ret;
620
918
}
621
919
 
623
921
img_set_colormap(PyGimpImage *self, PyObject *value, void *closure)
624
922
{
625
923
    if (value == NULL) {
626
 
        PyErr_SetString(PyExc_TypeError, "cannot delete cmap");
 
924
        PyErr_SetString(PyExc_TypeError, "cannot delete colormap");
627
925
        return -1;
628
926
    }
 
927
 
629
928
    if (!PyString_Check(value)) {
630
929
        PyErr_SetString(PyExc_TypeError, "type mismatch");
631
930
        return -1;
632
931
    }
633
 
    gimp_image_set_colormap(self->ID, PyString_AsString(value),
634
 
                            PyString_Size(value) / 3);
 
932
 
 
933
    if (!gimp_image_set_colormap(self->ID, PyString_AsString(value),
 
934
                                 PyString_Size(value) / 3)) {
 
935
        PyErr_Format(pygimp_error, "could not set colormap on image (ID %d)",
 
936
                     self->ID);
 
937
        return -1;
 
938
    }
 
939
 
635
940
    return 0;
636
941
}
637
942
 
638
943
static PyObject *
 
944
img_get_is_dirty(PyGimpImage *self, void *closure)
 
945
{
 
946
    return PyBool_FromLong(gimp_image_is_dirty(self->ID));
 
947
}
 
948
 
 
949
static PyObject *
639
950
img_get_filename(PyGimpImage *self, void *closure)
640
951
{
641
952
    gchar *filename;
642
953
 
643
954
    filename = gimp_image_get_filename(self->ID);
 
955
 
644
956
    if (filename) {
645
957
        PyObject *ret = PyString_FromString(filename);
646
958
        g_free(filename);
647
959
        return ret;
648
960
    }
 
961
 
649
962
    Py_INCREF(Py_None);
650
963
    return Py_None;
651
964
}
657
970
        PyErr_SetString(PyExc_TypeError, "cannot delete filename");
658
971
        return -1;
659
972
    }
 
973
 
660
974
    if (!PyString_Check(value)) {
661
975
        PyErr_SetString(PyExc_TypeError, "type mismatch");
662
976
        return -1;
663
977
    }
664
 
    gimp_image_set_filename(self->ID, PyString_AsString(value));
 
978
 
 
979
    if (!gimp_image_set_filename(self->ID, PyString_AsString(value))) {
 
980
        PyErr_SetString(PyExc_TypeError, "could not set filename "
 
981
                                         "(possibly bad encoding)");
 
982
        return -1;
 
983
    }
 
984
 
665
985
    return 0;
666
986
}
667
987
 
671
991
    gint32 id;
672
992
 
673
993
    id = gimp_image_get_floating_sel(self->ID);
 
994
 
674
995
    if (id == -1) {
675
996
        Py_INCREF(Py_None);
676
997
        return Py_None;
677
998
    }
 
999
 
678
1000
    return pygimp_layer_new(id);
679
1001
}
680
1002
 
684
1006
    gint32 id;
685
1007
 
686
1008
    id = gimp_image_floating_sel_attached_to(self->ID);
 
1009
 
687
1010
    if (id == -1) {
688
1011
        Py_INCREF(Py_None);
689
1012
        return Py_None;
690
1013
    }
 
1014
 
691
1015
    return pygimp_layer_new(id);
692
1016
}
693
1017
 
697
1021
    gint32 *layers;
698
1022
    gint n_layers, i;
699
1023
    PyObject *ret;
700
 
    
 
1024
 
701
1025
    layers = gimp_image_get_layers(self->ID, &n_layers);
 
1026
 
702
1027
    ret = PyList_New(n_layers);
 
1028
 
703
1029
    for (i = 0; i < n_layers; i++)
704
1030
        PyList_SetItem(ret, i, pygimp_layer_new(layers[i]));
 
1031
 
705
1032
    g_free(layers);
 
1033
 
706
1034
    return ret;
707
1035
}
708
1036
 
712
1040
    gchar *name;
713
1041
 
714
1042
    name = gimp_image_get_name(self->ID);
 
1043
 
715
1044
    if (name) {
716
1045
        PyObject *ret = PyString_FromString(name);
717
1046
        g_free(name);
718
1047
        return ret;
719
1048
    }
 
1049
 
720
1050
    Py_INCREF(Py_None);
721
1051
    return Py_None;
722
1052
}
740
1070
        PyErr_SetString(PyExc_TypeError, "cannot delete tattoo_state");
741
1071
        return -1;
742
1072
    }
 
1073
 
743
1074
    if (!PyInt_Check(value)) {
744
1075
        PyErr_SetString(PyExc_TypeError, "type mismatch");
745
1076
        return -1;
746
1077
    }
 
1078
 
747
1079
    gimp_image_set_tattoo_state(self->ID, PyInt_AsLong(value));
 
1080
 
748
1081
    return 0;
749
1082
}
750
1083
 
766
1099
    double xres, yres;
767
1100
 
768
1101
    gimp_image_get_resolution(self->ID, &xres, &yres);
 
1102
 
769
1103
    return Py_BuildValue("(dd)", xres, yres);
770
1104
}
771
1105
 
778
1112
        PyErr_SetString(PyExc_TypeError, "cannot delete resolution");
779
1113
        return -1;
780
1114
    }
 
1115
 
781
1116
    if (!PySequence_Check(value) ||
782
1117
        !PyArg_ParseTuple(value, "dd", &xres, &yres)) {
783
1118
        PyErr_Clear();
784
1119
        PyErr_SetString(PyExc_TypeError, "type mismatch");
785
1120
        return -1;
786
1121
    }
787
 
    gimp_image_set_resolution(self->ID, xres, yres);
 
1122
 
 
1123
    if (!gimp_image_set_resolution(self->ID, xres, yres)) {
 
1124
        PyErr_SetString(PyExc_TypeError, "could not set resolution");
 
1125
        return -1;
 
1126
    }
 
1127
 
788
1128
    return 0;
789
1129
}
790
1130
 
801
1141
        PyErr_SetString(PyExc_TypeError, "cannot delete unit");
802
1142
        return -1;
803
1143
    }
 
1144
 
804
1145
    if (!PyInt_Check(value)) {
805
1146
        PyErr_SetString(PyExc_TypeError, "type mismatch");
806
1147
        return -1;
807
1148
    }
808
 
    gimp_image_set_unit(self->ID, PyInt_AsLong(value));
 
1149
 
 
1150
    if (!gimp_image_set_unit(self->ID, PyInt_AsLong(value))) {
 
1151
        PyErr_SetString(PyExc_TypeError, "could not set unit");
 
1152
        return -1;
 
1153
    }
 
1154
 
809
1155
    return 0;
810
1156
}
811
1157
 
 
1158
static PyObject *
 
1159
img_get_vectors(PyGimpImage *self, void *closure)
 
1160
{
 
1161
    int *vectors;
 
1162
    int i, num_vectors;
 
1163
    PyObject *ret;
 
1164
 
 
1165
    vectors = gimp_image_get_vectors(self->ID, &num_vectors);
 
1166
 
 
1167
    ret = PyList_New(num_vectors);
 
1168
 
 
1169
    for (i = 0; i < num_vectors; i++)
 
1170
        PyList_SetItem(ret, i, pygimp_vectors_new(vectors[i]));
 
1171
 
 
1172
    g_free(vectors);
 
1173
 
 
1174
    return ret;
 
1175
}
 
1176
 
812
1177
static PyGetSetDef img_getsets[] = {
813
1178
    { "ID", (getter)img_get_ID, (setter)0 },
814
1179
    { "active_channel", (getter)img_get_active_channel,
819
1184
    { "base_type", (getter)img_get_base_type, (setter)0 },
820
1185
    { "channels", (getter)img_get_channels, (setter)0 },
821
1186
    { "colormap", (getter)img_get_colormap, (setter)img_set_colormap },
 
1187
    { "dirty", (getter)img_get_is_dirty, (setter)0 },
822
1188
    { "filename", (getter)img_get_filename, (setter)img_set_filename },
823
1189
    { "floating_selection", (getter)img_get_floating_selection, (setter)0 },
824
1190
    { "floating_sel_attached_to", (getter)img_get_floating_sel_attached_to,
831
1197
    { "tattoo_state", (getter)img_get_tattoo_state,
832
1198
      (setter)img_set_tattoo_state },
833
1199
    { "unit", (getter)img_get_unit, (setter)img_set_unit },
 
1200
    { "vectors", (getter)img_get_vectors, (setter)0 },
834
1201
    { "width", (getter)img_get_width, (setter)0 },
835
1202
    { NULL, (getter)0, (setter)0 }
836
1203
};
847
1214
        Py_INCREF(Py_None);
848
1215
        return Py_None;
849
1216
    }
 
1217
 
850
1218
    self = PyObject_NEW(PyGimpImage, &PyGimpImage_Type);
 
1219
 
851
1220
    if (self == NULL)
852
1221
        return NULL;
 
1222
 
853
1223
    self->ID = ID;
 
1224
 
854
1225
    return (PyObject *)self;
855
1226
}
856
1227
 
869
1240
    gchar *name;
870
1241
 
871
1242
    name = gimp_image_get_name(self->ID);
872
 
    s = PyString_FromFormat("<gimp.image '%s'>", name?name:"(null)");
 
1243
    s = PyString_FromFormat("<gimp.Image '%s'>", name ? name : "(null)");
873
1244
    g_free(name);
 
1245
 
874
1246
    return s;
875
1247
}
876
1248
 
877
1249
static int
878
1250
img_cmp(PyGimpImage *self, PyGimpImage *other)
879
1251
{
880
 
    if (self->ID == other->ID) return 0;
881
 
    if (self->ID > other->ID) return -1;
 
1252
    if (self->ID == other->ID)
 
1253
        return 0;
 
1254
 
 
1255
    if (self->ID > other->ID)
 
1256
        return -1;
 
1257
 
882
1258
    return 1;
883
1259
}
884
1260
 
886
1262
img_init(PyGimpImage *self, PyObject *args, PyObject *kwargs)
887
1263
{
888
1264
    guint width, height;
889
 
    GimpImageBaseType type;
890
 
 
891
 
    if (!PyArg_ParseTuple(args, "iii:gimp.Image.__init__",
892
 
                          &width, &height, &type))
 
1265
    GimpImageBaseType type = GIMP_RGB;
 
1266
 
 
1267
    static char *kwlist[] = { "width", "height", "type", NULL };
 
1268
 
 
1269
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
1270
                                     "ii|i:gimp.Image.__init__", kwlist,
 
1271
                                     &width, &height, &type))
893
1272
        return -1;
 
1273
 
894
1274
    self->ID = gimp_image_new(width, height, type);
 
1275
 
895
1276
    if (self->ID < 0) {
896
 
        PyErr_SetString(pygimp_error, "could not create image");
 
1277
        PyErr_Format(pygimp_error,
 
1278
                     "could not create image (width: %d, height: %d, type: %d)",
 
1279
                     width, height, type);
897
1280
        return -1;
898
1281
    }
 
1282
 
899
1283
    return 0;
900
1284
}
901
1285