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

« back to all changes in this revision

Viewing changes to plug-ins/pygimp/pygimp-drawable.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
 
5
5
    This program is free software; you can redistribute it and/or modify
6
 
    it under the terms of the GNU General Public License as published 
 
6
    it under the terms of the GNU General Public License as published
7
7
    the Free Software Foundation; either version 2 of the License, or
8
8
    (at your option) any later version.
9
9
 
20
20
#ifdef HAVE_CONFIG_H
21
21
#  include <config.h>
22
22
#endif
 
23
 
 
24
#define NO_IMPORT_PYGOBJECT
 
25
#include <pygobject.h>
 
26
 
23
27
#include "pygimp.h"
24
28
 
 
29
#define NO_IMPORT_PYGIMPCOLOR
 
30
#include "pygimpcolor-api.h"
 
31
 
 
32
#include <glib-object.h>
 
33
 
25
34
static void
26
35
ensure_drawable(PyGimpDrawable *self)
27
36
{
33
42
drw_flush(PyGimpDrawable *self)
34
43
{
35
44
    ensure_drawable(self);
 
45
 
36
46
    gimp_drawable_flush(self->drawable);
 
47
 
37
48
    Py_INCREF(Py_None);
38
49
    return Py_None;
39
50
}
44
55
{
45
56
    int x, y;
46
57
    unsigned int w, h;
 
58
 
47
59
    if (!PyArg_ParseTuple(args, "iiii:update", &x, &y, &w, &h))
48
60
        return NULL;
49
 
    gimp_drawable_update(self->ID, x, y, w, h);
50
 
    Py_INCREF(Py_None);
51
 
    return Py_None;
52
 
}
53
 
 
54
 
 
55
 
static PyObject *
56
 
drw_merge_shadow(PyGimpDrawable *self, PyObject *args)
57
 
{
58
 
    int u;
59
 
    if (!PyArg_ParseTuple(args, "i:merge_shadow", &u))
60
 
        return NULL;
61
 
    gimp_drawable_merge_shadow(self->ID, u);
62
 
    Py_INCREF(Py_None);
63
 
    return Py_None;
64
 
}
65
 
 
66
 
 
67
 
static PyObject *
68
 
drw_fill(PyGimpDrawable *self, PyObject *args)
69
 
{
70
 
    int f;
71
 
    if (!PyArg_ParseTuple(args, "i:fill", &f))
72
 
        return NULL;
73
 
    gimp_drawable_fill(self->ID, f);
74
 
    Py_INCREF(Py_None);
75
 
    return Py_None;
76
 
}
77
 
 
78
 
 
79
 
static PyObject *
80
 
drw_get_tile(PyGimpDrawable *self, PyObject *args)
 
61
 
 
62
    if (!gimp_drawable_update(self->ID, x, y, w, h)) {
 
63
        PyErr_Format(pygimp_error,
 
64
                     "could not update drawable (ID %d): "
 
65
                     "x=%d, y=%d, w=%d, h=%d",
 
66
                     self->ID, x, y, (int)w, (int)h);
 
67
        return NULL;
 
68
    }
 
69
 
 
70
    Py_INCREF(Py_None);
 
71
    return Py_None;
 
72
}
 
73
 
 
74
 
 
75
static PyObject *
 
76
drw_merge_shadow(PyGimpDrawable *self, PyObject *args, PyObject *kwargs)
 
77
{
 
78
    gboolean undo = FALSE;
 
79
 
 
80
    static char *kwlist[] = { "undo", NULL };
 
81
 
 
82
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i:merge_shadow", kwlist,
 
83
                                     &undo))
 
84
        return NULL;
 
85
 
 
86
    if (!gimp_drawable_merge_shadow(self->ID, undo)) {
 
87
        PyErr_Format(pygimp_error,
 
88
                     "could not merge the shadow buffer on drawable (ID %d)",
 
89
                     self->ID);
 
90
        return NULL;
 
91
    }
 
92
 
 
93
    Py_INCREF(Py_None);
 
94
    return Py_None;
 
95
}
 
96
 
 
97
 
 
98
static PyObject *
 
99
drw_fill(PyGimpDrawable *self, PyObject *args, PyObject *kwargs)
 
100
{
 
101
    int fill = GIMP_FOREGROUND_FILL;
 
102
 
 
103
    static char *kwlist[] = { "fill", NULL };
 
104
 
 
105
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i:fill", kwlist, &fill))
 
106
        return NULL;
 
107
 
 
108
    if (!gimp_drawable_fill(self->ID, fill)) {
 
109
        PyErr_Format(pygimp_error,
 
110
                     "could not fill drawable (ID %d) with fill mode %d",
 
111
                     self->ID, fill);
 
112
        return NULL;
 
113
    }
 
114
 
 
115
    Py_INCREF(Py_None);
 
116
    return Py_None;
 
117
}
 
118
 
 
119
 
 
120
static PyObject *
 
121
drw_get_tile(PyGimpDrawable *self, PyObject *args, PyObject *kwargs)
81
122
{
82
123
    GimpTile *t;
83
 
    int shadow, r, c;
84
 
    if (!PyArg_ParseTuple(args, "iii:get_tile", &shadow, &r, &c))
 
124
    int shadow, row, col;
 
125
 
 
126
    static char *kwlist[] = { "shadow", "row", "col", NULL };
 
127
 
 
128
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "iii:get_tile", kwlist,
 
129
                                     &shadow, &row, &col))
85
130
        return NULL;
 
131
 
86
132
    ensure_drawable(self);
87
 
    t = gimp_drawable_get_tile(self->drawable, shadow, r, c);
 
133
 
 
134
    t = gimp_drawable_get_tile(self->drawable, shadow, row, col);
88
135
    return pygimp_tile_new(t, self);
89
136
}
90
137
 
91
138
static PyObject *
92
 
drw_get_tile2(PyGimpDrawable *self, PyObject *args)
 
139
drw_get_tile2(PyGimpDrawable *self, PyObject *args, PyObject *kwargs)
93
140
{
94
141
    GimpTile *t;
95
142
    int shadow, x, y;
96
 
    if (!PyArg_ParseTuple(args, "iii:get_tile2", &shadow, &x ,&y))
 
143
 
 
144
    static char *kwlist[] = { "shadow", "x", "y", NULL };
 
145
 
 
146
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "iii:get_tile2", kwlist,
 
147
                                     &shadow, &x ,&y))
97
148
        return NULL;
 
149
 
98
150
    ensure_drawable(self);
 
151
 
99
152
    t = gimp_drawable_get_tile2(self->drawable, shadow, x, y);
100
153
    return pygimp_tile_new(t, self);
101
154
}
102
155
 
103
156
static PyObject *
104
 
drw_get_pixel_rgn(PyGimpDrawable *self, PyObject *args)
 
157
drw_get_pixel_rgn(PyGimpDrawable *self, PyObject *args, PyObject *kwargs)
105
158
{
106
 
    int x, y, w, h, dirty = 1, shadow = 0;
107
 
    if (!PyArg_ParseTuple(args, "iiii|ii:get_pixel_rgn", &x,&y,
108
 
                          &w,&h, &dirty,&shadow))
 
159
    int x, y, width, height, dirty = 1, shadow = 0;
 
160
 
 
161
    static char *kwlist[] = { "x", "y", "width", "height", "dirty", "shadow",
 
162
                              NULL };
 
163
 
 
164
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
165
                                     "iiii|ii:get_pixel_rgn", kwlist,
 
166
                                     &x, &y, &width, &height, &dirty, &shadow))
109
167
        return NULL;
 
168
 
110
169
    ensure_drawable(self);
111
 
    return pygimp_pixel_rgn_new(self, x, y, w, h, dirty, shadow);
 
170
 
 
171
    return pygimp_pixel_rgn_new(self, x, y, width, height, dirty, shadow);
112
172
}
113
173
 
114
174
static PyObject *
115
 
drw_offset(PyGimpDrawable *self, PyObject *args)
 
175
drw_offset(PyGimpDrawable *self, PyObject *args, PyObject *kwargs)
116
176
{
117
 
    gboolean wrap_around;
 
177
    int wrap_around;
118
178
    GimpOffsetType fill_type;
119
 
    gint offset_x, offset_y;
120
 
 
121
 
    if (!PyArg_ParseTuple(args, "iiii:offset", &wrap_around, &fill_type,
122
 
                           &offset_x, &offset_y))
123
 
        return NULL;
124
 
    return PyInt_FromLong(gimp_drawable_offset(self->ID, wrap_around,
125
 
                                               fill_type, offset_x, offset_y));
 
179
    int offset_x, offset_y;
 
180
 
 
181
    static char *kwlist[] = { "wrap_around", "fill_type",
 
182
                              "offset_x", "offset_y",
 
183
                              NULL };
 
184
 
 
185
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "iiii:offset", kwlist,
 
186
                                     &wrap_around, &fill_type,
 
187
                                     &offset_x, &offset_y))
 
188
        return NULL;
 
189
 
 
190
    if (!gimp_drawable_offset(self->ID, wrap_around, fill_type,
 
191
                              offset_x, offset_y)) {
 
192
        PyErr_Format(pygimp_error,
 
193
                     "could not offset drawable (ID %d) by x: %d, y: %d",
 
194
                     self->ID, offset_x, offset_y);
 
195
        return NULL;
 
196
    }
 
197
 
 
198
    Py_INCREF(Py_None);
 
199
    return Py_None;
126
200
}
127
201
 
128
202
static PyObject *
129
203
drw_parasite_find(PyGimpDrawable *self, PyObject *args)
130
204
{
131
205
    char *name;
 
206
 
132
207
    if (!PyArg_ParseTuple(args, "s:parasite_find", &name))
133
208
        return NULL;
 
209
 
134
210
    return pygimp_parasite_new(gimp_drawable_parasite_find(self->ID, name));
135
211
}
136
212
 
138
214
drw_parasite_attach(PyGimpDrawable *self, PyObject *args)
139
215
{
140
216
    PyGimpParasite *parasite;
 
217
 
141
218
    if (!PyArg_ParseTuple(args, "O!:parasite_attach", &PyGimpParasite_Type,
142
219
                          &parasite))
143
220
        return NULL;
144
 
    gimp_drawable_parasite_attach(self->ID, parasite->para);
 
221
 
 
222
    if (!gimp_drawable_parasite_attach(self->ID, parasite->para)) {
 
223
        PyErr_Format(pygimp_error,
 
224
                     "could not attach parasite '%s' on drawable (ID %d)",
 
225
                     gimp_parasite_name(parasite->para), self->ID);
 
226
        return NULL;
 
227
    }
 
228
 
145
229
    Py_INCREF(Py_None);
146
230
    return Py_None;
147
231
}
148
232
 
149
233
static PyObject *
150
 
drw_attach_new_parasite(PyGimpDrawable *self, PyObject *args)
 
234
drw_attach_new_parasite(PyGimpDrawable *self, PyObject *args, PyObject *kwargs)
151
235
{
152
 
    char *name, *data;
 
236
    char *name;
153
237
    int flags, size;
154
 
    if (!PyArg_ParseTuple(args, "sis#:attach_new_parasite", &name, &flags,
155
 
                          &data, &size))
156
 
        return NULL;
157
 
    gimp_drawable_attach_new_parasite(self->ID, name, flags, size, data);
 
238
    guint8 *data;
 
239
 
 
240
    static char *kwlist[] = { "name", "flags", "data", NULL };
 
241
 
 
242
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
243
                                     "sis#:attach_new_parasite", kwlist,
 
244
                                     &name, &flags, &data, &size))
 
245
        return NULL;
 
246
 
 
247
    if (!gimp_drawable_attach_new_parasite(self->ID, name, flags, size, data)) {
 
248
        PyErr_Format(pygimp_error,
 
249
                     "could not attach new parasite '%s' to drawable (ID %d)",
 
250
                     name, self->ID);
 
251
        return NULL;
 
252
    }
 
253
 
158
254
    Py_INCREF(Py_None);
159
255
    return Py_None;
160
256
}
165
261
    char *name;
166
262
    if (!PyArg_ParseTuple(args, "s:detach_parasite", &name))
167
263
        return NULL;
168
 
    gimp_drawable_parasite_detach(self->ID, name);
 
264
 
 
265
    if (!gimp_drawable_parasite_detach(self->ID, name)) {
 
266
        PyErr_Format(pygimp_error,
 
267
                     "could not detach parasite '%s' from drawable (ID %d)",
 
268
                     name, self->ID);
 
269
        return NULL;
 
270
    }
 
271
 
169
272
    Py_INCREF(Py_None);
170
273
    return Py_None;
171
274
}
172
275
 
173
276
static PyObject *
174
 
drw_parasite_list(PyGimpImage *self)
 
277
drw_parasite_list(PyGimpDrawable *self)
175
278
{
176
279
    gint num_parasites;
177
280
    gchar **parasites;
181
284
        gint i;
182
285
 
183
286
        ret = PyTuple_New(num_parasites);
 
287
 
184
288
        for (i = 0; i < num_parasites; i++) {
185
289
            PyTuple_SetItem(ret, i, PyString_FromString(parasites[i]));
186
290
            g_free(parasites[i]);
187
291
        }
 
292
 
188
293
        g_free(parasites);
189
294
        return ret;
190
295
    }
191
 
    PyErr_SetString(pygimp_error, "could not list parasites");
 
296
 
 
297
    PyErr_Format(pygimp_error, "could not list parasites on drawable (ID %d)",
 
298
                 self->ID);
192
299
    return NULL;
193
300
}
194
301
 
 
302
static PyObject *
 
303
drw_get_pixel(PyGimpDrawable *self, PyObject *args)
 
304
{
 
305
    int x, y;
 
306
    int num_channels, i;
 
307
    guint8 *pixel;
 
308
    PyObject *ret;
 
309
 
 
310
    if (!PyArg_ParseTuple(args, "(ii):get_pixel", &x, &y)) {
 
311
        PyErr_Clear();
 
312
        if (!PyArg_ParseTuple(args, "ii:get_pixel", &x, &y))
 
313
            return NULL;
 
314
    }
 
315
 
 
316
    pixel = gimp_drawable_get_pixel(self->ID, x, y, &num_channels);
 
317
 
 
318
    if (!pixel) {
 
319
        PyErr_Format(pygimp_error,
 
320
                     "could not get pixel (%d, %d) on drawable (ID %d)",
 
321
                     x, y, self->ID);
 
322
        return NULL;
 
323
    }
 
324
 
 
325
    ret = PyTuple_New(num_channels);
 
326
 
 
327
    for (i = 0; i < num_channels; i++)
 
328
        PyTuple_SetItem(ret, i, PyInt_FromLong(pixel[i]));
 
329
 
 
330
    g_free(pixel);
 
331
 
 
332
    return ret;
 
333
}
 
334
 
 
335
static PyObject *
 
336
drw_set_pixel(PyGimpDrawable *self, PyObject *args)
 
337
{
 
338
    int x, y;
 
339
    int num_channels, i, val;
 
340
    guint8 *pixel;
 
341
    PyObject *seq, *item;
 
342
    gboolean is_string, error = TRUE;
 
343
 
 
344
    if (!PyArg_ParseTuple(args, "(ii)O:set_pixel", &x, &y, &seq)) {
 
345
        PyErr_Clear();
 
346
        if (!PyArg_ParseTuple(args, "iiO:set_pixel", &x, &y, &seq))
 
347
            return NULL;
 
348
    }
 
349
 
 
350
    if (!PyString_Check(seq)) {
 
351
        if (!PySequence_Check(seq)) {
 
352
            PyErr_SetString(PyExc_TypeError,
 
353
                            "pixel values must be a sequence");
 
354
            return NULL;
 
355
        }
 
356
 
 
357
        is_string = FALSE;
 
358
 
 
359
        num_channels = PySequence_Length(seq);
 
360
        pixel = g_new(guint8, num_channels);
 
361
 
 
362
        for (i = 0; i < num_channels; i++) {
 
363
            item = PySequence_GetItem(seq, i);
 
364
 
 
365
            if (!PyInt_Check(item)) {
 
366
                PyErr_SetString(PyExc_TypeError,
 
367
                                "pixel values must be a sequence of ints");
 
368
                goto out;
 
369
            }
 
370
 
 
371
            val = PyInt_AsLong(item);
 
372
 
 
373
            if (val < 0 || val > 255) {
 
374
                PyErr_SetString(PyExc_TypeError,
 
375
                                "pixel values must be between 0 and 255");
 
376
                goto out;
 
377
            }
 
378
 
 
379
            pixel[i] = val;
 
380
        }
 
381
    } else {
 
382
        is_string = TRUE;
 
383
 
 
384
        num_channels = PyString_Size(seq);
 
385
        pixel = PyString_AsString(seq);
 
386
    }
 
387
 
 
388
    error = !gimp_drawable_set_pixel(self->ID, x, y, num_channels, pixel);
 
389
 
 
390
    if (error)
 
391
        PyErr_Format(pygimp_error,
 
392
                     "could not set %d-element pixel (%d, %d) on "
 
393
                     "drawable (ID %d)",
 
394
                     num_channels, x, y, self->ID);
 
395
 
 
396
out:
 
397
    if (!is_string)
 
398
        g_free(pixel);
 
399
 
 
400
    if (!error) {
 
401
        Py_INCREF(Py_None);
 
402
        return Py_None;
 
403
    } else
 
404
        return NULL;
 
405
}
 
406
 
 
407
static PyObject *
 
408
drw_mask_intersect(PyGimpDrawable *self)
 
409
{
 
410
    int x, y, width, height;
 
411
 
 
412
    if (!gimp_drawable_mask_intersect(self->ID, &x, &y, &width, &height)) {
 
413
        PyErr_Format(pygimp_error,
 
414
                     "could not get selection bounds of drawable (ID %d)",
 
415
                     self->ID);
 
416
        return NULL;
 
417
    }
 
418
 
 
419
    return Py_BuildValue("(iiii)", x, y, width, height);
 
420
}
 
421
 
 
422
static PyObject *
 
423
transform_result(PyGimpDrawable *self, gint32 id, const char *err_desc)
 
424
{
 
425
    if (id == self->ID) {
 
426
        Py_INCREF(self);
 
427
        return (PyObject *)self;
 
428
    } else if (id != -1) {
 
429
        return pygimp_drawable_new(NULL, id);
 
430
    } else {
 
431
        PyErr_Format(pygimp_error, "could not %s drawable (ID %d)",
 
432
                     err_desc, self->ID);
 
433
        return NULL;
 
434
    }
 
435
}
 
436
 
 
437
static PyObject *
 
438
drw_transform_flip(PyGimpDrawable *self, PyObject *args, PyObject *kwargs)
 
439
{
 
440
    double x0, y0, x1, y1;
 
441
    int transform_direction, interpolation, recursion_level = 3;
 
442
    gboolean supersample = FALSE, clip_result = FALSE;
 
443
    gint32 id;
 
444
 
 
445
    static char *kwlist[] = { "x0", "y0", "x1", "y1",
 
446
                              "transform_direction", "interpolation",
 
447
                              "supersample", "recursion_level",
 
448
                              "clip_result", NULL };
 
449
 
 
450
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
451
                                     "ddddii|iii:transform_flip", kwlist,
 
452
                                     &x0, &y0, &x1, &y1, &transform_direction,
 
453
                                     &interpolation, &supersample,
 
454
                                     &recursion_level, &clip_result))
 
455
        return NULL;
 
456
 
 
457
    id = gimp_drawable_transform_flip(self->ID, x0, y0, x1, y1,
 
458
                                      transform_direction, interpolation,
 
459
                                      supersample, recursion_level,
 
460
                                      clip_result);
 
461
 
 
462
    return transform_result(self, id, "flip");
 
463
}
 
464
 
 
465
static PyObject *
 
466
drw_transform_flip_simple(PyGimpDrawable *self, PyObject *args, PyObject *kwargs)
 
467
{
 
468
    int flip_type;
 
469
    gboolean auto_center, clip_result = FALSE;
 
470
    double axis;
 
471
    gint32 id;
 
472
 
 
473
    static char *kwlist[] = { "flip_type", "auto_center", "axis",
 
474
                              "clip_result", NULL };
 
475
 
 
476
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
477
                                     "iid|:transform_flip_simple", kwlist,
 
478
                                     &flip_type, &auto_center, &axis,
 
479
                                     &clip_result))
 
480
        return NULL;
 
481
 
 
482
    id = gimp_drawable_transform_flip_simple(self->ID, flip_type, auto_center,
 
483
                                             axis, clip_result);
 
484
 
 
485
    return transform_result(self, id, "flip");
 
486
}
 
487
 
 
488
static PyObject *
 
489
drw_transform_flip_default(PyGimpDrawable *self, PyObject *args, PyObject *kwargs)
 
490
{
 
491
    double x0, y0, x1, y1;
 
492
    gboolean interpolate = FALSE, clip_result = FALSE;
 
493
    gint32 id;
 
494
 
 
495
    static char *kwlist[] = { "x0", "y0", "x1", "y1", "interpolate",
 
496
                              "clip_result", NULL };
 
497
 
 
498
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
499
                                     "dddd|ii:transform_flip_default", kwlist,
 
500
                                     &x0, &y0, &x1, &y1, &interpolate,
 
501
                                     &clip_result))
 
502
        return NULL;
 
503
 
 
504
    id = gimp_drawable_transform_flip_default(self->ID, x0, y0, x1, y1,
 
505
                                              interpolate, clip_result);
 
506
 
 
507
    return transform_result(self, id, "flip");
 
508
}
 
509
 
 
510
static PyObject *
 
511
drw_transform_perspective(PyGimpDrawable *self, PyObject *args, PyObject *kwargs)
 
512
{
 
513
    double x0, y0, x1, y1, x2, y2, x3, y3;
 
514
    int transform_direction, interpolation, recursion_level = 3;
 
515
    gboolean supersample = FALSE, clip_result = FALSE;
 
516
    gint32 id;
 
517
 
 
518
    static char *kwlist[] = { "x0", "y0", "x1", "y1", "x2", "y2", "x3", "y3",
 
519
                              "transform_direction", "interpolation",
 
520
                              "supersample", "recursion_level",
 
521
                              "clip_result", NULL };
 
522
 
 
523
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
524
                                     "ddddddddii|iii:transform_perspective",
 
525
                                     kwlist,
 
526
                                     &x0, &y0, &x1, &y1, &x2, &y2, &x3, &y3,
 
527
                                     &transform_direction, &interpolation,
 
528
                                     &supersample, &recursion_level,
 
529
                                     &clip_result))
 
530
        return NULL;
 
531
 
 
532
    id = gimp_drawable_transform_perspective(self->ID,
 
533
                                             x0, y0, x1, y1, x2, y2, x3, y3,
 
534
                                             transform_direction, interpolation,
 
535
                                             supersample, recursion_level,
 
536
                                             clip_result);
 
537
 
 
538
    return transform_result(self, id, "apply perspective transform to");
 
539
}
 
540
 
 
541
static PyObject *
 
542
drw_transform_perspective_default(PyGimpDrawable *self, PyObject *args, PyObject *kwargs)
 
543
{
 
544
    double x0, y0, x1, y1, x2, y2, x3, y3;
 
545
    gboolean interpolate = FALSE, clip_result = FALSE;
 
546
    gint32 id;
 
547
 
 
548
    static char *kwlist[] = { "x0", "y0", "x1", "y1", "x2", "y2", "x3", "y3",
 
549
                              "interpolate", "clip_result", NULL };
 
550
 
 
551
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
552
                                     "dddddddd|ii:transform_perspective_default",
 
553
                                     kwlist,
 
554
                                     &x0, &y0, &x1, &y1, &x2, &y2, &x3, &y3,
 
555
                                     &interpolate, &clip_result))
 
556
        return NULL;
 
557
 
 
558
    id = gimp_drawable_transform_perspective_default(self->ID,
 
559
                                                     x0, y0, x1, y1,
 
560
                                                     x2, y2, x3, y3,
 
561
                                                     interpolate, clip_result);
 
562
 
 
563
    return transform_result(self, id, "apply perspective transform to");
 
564
}
 
565
 
 
566
static PyObject *
 
567
drw_transform_rotate(PyGimpDrawable *self, PyObject *args, PyObject *kwargs)
 
568
{
 
569
    double angle;
 
570
    gboolean auto_center, supersample = FALSE, clip_result = FALSE;
 
571
    int center_x, center_y, transform_direction, interpolation,
 
572
        recursion_level = 3;
 
573
    gint32 id;
 
574
 
 
575
    static char *kwlist[] = { "angle", "auto_center", "center_x", "center_y",
 
576
                              "transform_direction", "interpolation",
 
577
                              "supersample", "recursion_level",
 
578
                              "clip_result", NULL };
 
579
 
 
580
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
581
                                     "diiii|iii:transform_rotate", kwlist,
 
582
                                     &angle, &auto_center, &center_x, &center_y,
 
583
                                     &transform_direction, &interpolation,
 
584
                                     &supersample, &recursion_level,
 
585
                                     &clip_result))
 
586
        return NULL;
 
587
 
 
588
    id = gimp_drawable_transform_rotate(self->ID, angle, auto_center,
 
589
                                        center_x, center_y,
 
590
                                        transform_direction, interpolation,
 
591
                                        supersample, recursion_level,
 
592
                                        clip_result);
 
593
 
 
594
    return transform_result(self, id, "rotate");
 
595
}
 
596
 
 
597
static PyObject *
 
598
drw_transform_rotate_simple(PyGimpDrawable *self, PyObject *args, PyObject *kwargs)
 
599
{
 
600
    int rotate_type, center_x, center_y;
 
601
    gboolean auto_center, clip_result = FALSE;
 
602
    gint32 id;
 
603
 
 
604
    static char *kwlist[] = { "rotate_type", "auto_center",
 
605
                              "center_x", "center_y",
 
606
                              "clip_result", NULL };
 
607
 
 
608
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
609
                                     "iiii|i:transform_rotate_simple", kwlist,
 
610
                                     &rotate_type, &auto_center,
 
611
                                     &center_x, &center_y,
 
612
                                     &clip_result))
 
613
        return NULL;
 
614
 
 
615
    id = gimp_drawable_transform_rotate_simple(self->ID, rotate_type,
 
616
                                               auto_center,
 
617
                                               center_x, center_y,
 
618
                                               clip_result);
 
619
 
 
620
    return transform_result(self, id, "rotate");
 
621
}
 
622
 
 
623
static PyObject *
 
624
drw_transform_rotate_default(PyGimpDrawable *self, PyObject *args, PyObject *kwargs)
 
625
{
 
626
    double angle;
 
627
    gboolean auto_center, interpolate = FALSE, clip_result = FALSE;
 
628
    int center_x, center_y;
 
629
    gint32 id;
 
630
 
 
631
    static char *kwlist[] = { "angle", "auto_center", "center_x", "center_y",
 
632
                              "interpolate", "clip_result", NULL };
 
633
 
 
634
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
635
                                     "dddd|ii:transform_rotate_default", kwlist,
 
636
                                     &angle, &auto_center, &center_x, &center_y,
 
637
                                     &interpolate, &clip_result))
 
638
        return NULL;
 
639
 
 
640
    id = gimp_drawable_transform_rotate_default(self->ID, angle, auto_center,
 
641
                                                center_x, center_y,
 
642
                                                interpolate, clip_result);
 
643
 
 
644
    return transform_result(self, id, "rotate");
 
645
}
 
646
 
 
647
static PyObject *
 
648
drw_transform_scale(PyGimpDrawable *self, PyObject *args, PyObject *kwargs)
 
649
{
 
650
    double x0, y0, x1, y1;
 
651
    int transform_direction, interpolation, recursion_level = 3;
 
652
    gboolean supersample = FALSE, clip_result = FALSE;
 
653
    gint32 id;
 
654
 
 
655
    static char *kwlist[] = { "x0", "y0", "x1", "y1",
 
656
                              "transform_direction", "interpolation",
 
657
                              "supersample", "recursion_level",
 
658
                              "clip_result", NULL };
 
659
 
 
660
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
661
                                     "ddddii|iii:transform_scale", kwlist,
 
662
                                     &x0, &y0, &x1, &y1, &transform_direction,
 
663
                                     &interpolation, &supersample,
 
664
                                     &recursion_level, &clip_result))
 
665
        return NULL;
 
666
 
 
667
    id = gimp_drawable_transform_scale(self->ID, x0, y0, x1, y1,
 
668
                                       transform_direction, interpolation,
 
669
                                       supersample, recursion_level,
 
670
                                       clip_result);
 
671
 
 
672
    return transform_result(self, id, "scale");
 
673
}
 
674
 
 
675
static PyObject *
 
676
drw_transform_scale_default(PyGimpDrawable *self, PyObject *args, PyObject *kwargs)
 
677
{
 
678
    double x0, y0, x1, y1;
 
679
    gboolean interpolate = FALSE, clip_result = FALSE;
 
680
    gint32 id;
 
681
 
 
682
    static char *kwlist[] = { "x0", "y0", "x1", "y1", "interpolate",
 
683
                              "clip_result", NULL };
 
684
 
 
685
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
686
                                     "dddd|ii:transform_scale_default", kwlist,
 
687
                                     &x0, &y0, &x1, &y1, &interpolate,
 
688
                                     &clip_result))
 
689
        return NULL;
 
690
 
 
691
    id = gimp_drawable_transform_scale_default(self->ID, x0, y0, x1, y1,
 
692
                                               interpolate, clip_result);
 
693
 
 
694
    return transform_result(self, id, "scale");
 
695
}
 
696
 
 
697
static PyObject *
 
698
drw_transform_shear(PyGimpDrawable *self, PyObject *args, PyObject *kwargs)
 
699
{
 
700
    int shear_type, transform_direction, interpolation, recursion_level = 3;
 
701
    double magnitude;
 
702
    gboolean supersample = FALSE, clip_result = FALSE;
 
703
    gint32 id;
 
704
 
 
705
    static char *kwlist[] = { "shear_type", "magnitude",
 
706
                              "transform_direction", "interpolation",
 
707
                              "supersample", "recursion_level",
 
708
                              "clip_result", NULL };
 
709
 
 
710
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
711
                                     "idii|iii:transform_shear", kwlist,
 
712
                                     &shear_type, &magnitude,
 
713
                                     &transform_direction, &interpolation,
 
714
                                     &supersample, &recursion_level,
 
715
                                     &clip_result))
 
716
        return NULL;
 
717
 
 
718
    id = gimp_drawable_transform_shear(self->ID, shear_type, magnitude,
 
719
                                       transform_direction, interpolation,
 
720
                                       supersample, recursion_level,
 
721
                                       clip_result);
 
722
 
 
723
    return transform_result(self, id, "shear");
 
724
}
 
725
 
 
726
static PyObject *
 
727
drw_transform_shear_default(PyGimpDrawable *self, PyObject *args, PyObject *kwargs)
 
728
{
 
729
    int shear_type;
 
730
    double magnitude;
 
731
    gboolean interpolate = FALSE, clip_result = FALSE;
 
732
    gint32 id;
 
733
 
 
734
    static char *kwlist[] = { "shear_type", "magnitude", "interpolate",
 
735
                              "clip_result", NULL };
 
736
 
 
737
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
738
                                     "id|ii:transform_shear_default", kwlist,
 
739
                                     &shear_type, &magnitude, &interpolate,
 
740
                                     &clip_result))
 
741
        return NULL;
 
742
 
 
743
    id = gimp_drawable_transform_shear_default(self->ID, shear_type,
 
744
                                               magnitude, interpolate,
 
745
                                               clip_result);
 
746
 
 
747
    return transform_result(self, id, "shear");
 
748
}
 
749
 
 
750
static PyObject *
 
751
drw_transform_2d(PyGimpDrawable *self, PyObject *args, PyObject *kwargs)
 
752
{
 
753
    double source_x, source_y, scale_x, scale_y, angle, dest_x, dest_y;
 
754
    int transform_direction, interpolation, recursion_level = 3;
 
755
    gboolean supersample = FALSE, clip_result = FALSE;
 
756
    gint32 id;
 
757
 
 
758
    static char *kwlist[] = { "source_x", "source_y", "scale_x", "scale_y",
 
759
                              "angle", "dest_x", "dest_y",
 
760
                              "transform_direction", "interpolation",
 
761
                              "supersample", "recursion_level",
 
762
                              "clip_result", NULL };
 
763
 
 
764
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
765
                                     "dddddddii|iii:transform_2d", kwlist,
 
766
                                     &source_x, &source_y, &scale_x, &scale_y,
 
767
                                     &angle, &dest_x, &dest_y,
 
768
                                     &transform_direction, &interpolation,
 
769
                                     &supersample, &recursion_level,
 
770
                                     &clip_result))
 
771
        return NULL;
 
772
 
 
773
    id = gimp_drawable_transform_2d(self->ID, source_x, source_y,
 
774
                                    scale_x, scale_y, angle, dest_x, dest_y,
 
775
                                    transform_direction, interpolation,
 
776
                                    supersample, recursion_level, clip_result);
 
777
 
 
778
    return transform_result(self, id, "apply 2d transform to");
 
779
}
 
780
 
 
781
static PyObject *
 
782
drw_transform_2d_default(PyGimpDrawable *self, PyObject *args, PyObject *kwargs)
 
783
{
 
784
    double source_x, source_y, scale_x, scale_y, angle, dest_x, dest_y;
 
785
    gboolean interpolate = FALSE, clip_result = FALSE;
 
786
    gint32 id;
 
787
 
 
788
    static char *kwlist[] = { "source_x", "source_y", "scale_x", "scale_y",
 
789
                              "angle", "dest_x", "dest_y", "interpolate",
 
790
                              "clip_result", NULL };
 
791
 
 
792
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
793
                                     "ddddddd|ii:transform_2d_default", kwlist,
 
794
                                     &source_x, &source_y, &scale_x, &scale_y,
 
795
                                     &angle, &dest_x, &dest_y, &interpolate,
 
796
                                     &clip_result))
 
797
        return NULL;
 
798
 
 
799
    id = gimp_drawable_transform_2d_default(self->ID, source_x, source_y,
 
800
                                            scale_x, scale_y, angle,
 
801
                                            dest_x, dest_y, interpolate,
 
802
                                            clip_result);
 
803
 
 
804
    return transform_result(self, id, "apply 2d transform to");
 
805
}
 
806
 
 
807
static PyObject *
 
808
drw_transform_matrix(PyGimpDrawable *self, PyObject *args, PyObject *kwargs)
 
809
{
 
810
    double coeff_0_0, coeff_0_1, coeff_0_2,
 
811
           coeff_1_0, coeff_1_1, coeff_1_2,
 
812
           coeff_2_0, coeff_2_1, coeff_2_2;
 
813
    int transform_direction, interpolation, recursion_level = 3;
 
814
    gboolean supersample = FALSE, clip_result = FALSE;
 
815
    gint32 id;
 
816
 
 
817
    static char *kwlist[] = { "coeff_0_0", "coeff_0_1", "coeff_0_2",
 
818
                              "coeff_1_0", "coeff_1_1", "coeff_1_2",
 
819
                              "coeff_2_0", "coeff_2_1", "coeff_2_2",
 
820
                              "transform_direction", "interpolation",
 
821
                              "supersample", "recursion_level",
 
822
                              "clip_result", NULL };
 
823
 
 
824
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
825
                                     "dddddddddii|iii:transform_matrix", kwlist,
 
826
                                     &coeff_0_0, &coeff_0_1, &coeff_0_2,
 
827
                                     &coeff_1_0, &coeff_1_1, &coeff_1_2,
 
828
                                     &coeff_2_0, &coeff_2_1, &coeff_2_2,
 
829
                                     &transform_direction, &interpolation,
 
830
                                     &supersample, &recursion_level,
 
831
                                     &clip_result))
 
832
        return NULL;
 
833
 
 
834
    id = gimp_drawable_transform_matrix(self->ID,
 
835
                                        coeff_0_0, coeff_0_1, coeff_0_2,
 
836
                                        coeff_1_0, coeff_1_1, coeff_1_2,
 
837
                                        coeff_2_0, coeff_2_1, coeff_2_2,
 
838
                                        transform_direction, interpolation,
 
839
                                        supersample, recursion_level,
 
840
                                        clip_result);
 
841
 
 
842
    return transform_result(self, id, "apply 2d matrix transform to");
 
843
}
 
844
 
 
845
static PyObject *
 
846
drw_transform_matrix_default(PyGimpDrawable *self, PyObject *args, PyObject *kwargs)
 
847
{
 
848
    double coeff_0_0, coeff_0_1, coeff_0_2,
 
849
           coeff_1_0, coeff_1_1, coeff_1_2,
 
850
           coeff_2_0, coeff_2_1, coeff_2_2;
 
851
    gboolean interpolate = FALSE, clip_result = FALSE;
 
852
    gint32 id;
 
853
 
 
854
    static char *kwlist[] = { "coeff_0_0", "coeff_0_1", "coeff_0_2",
 
855
                              "coeff_1_0", "coeff_1_1", "coeff_1_2",
 
856
                              "coeff_2_0", "coeff_2_1", "coeff_2_2",
 
857
                              "interpolate", "clip_result", NULL };
 
858
 
 
859
    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
 
860
                                     "ddddddddd|ii:transform_matrix_default",
 
861
                                     kwlist,
 
862
                                     &coeff_0_0, &coeff_0_1, &coeff_0_2,
 
863
                                     &coeff_1_0, &coeff_1_1, &coeff_1_2,
 
864
                                     &coeff_2_0, &coeff_2_1, &coeff_2_2,
 
865
                                     &interpolate, &clip_result))
 
866
        return NULL;
 
867
 
 
868
    id = gimp_drawable_transform_matrix_default(self->ID,
 
869
                                                coeff_0_0, coeff_0_1, coeff_0_2,
 
870
                                                coeff_1_0, coeff_1_1, coeff_1_2,
 
871
                                                coeff_2_0, coeff_2_1, coeff_2_2,
 
872
                                                interpolate, clip_result);
 
873
 
 
874
    return transform_result(self, id, "apply 2d matrix transform to");
 
875
}
 
876
 
195
877
/* for inclusion with the methods of layer and channel objects */
196
878
static PyMethodDef drw_methods[] = {
197
879
    {"flush",   (PyCFunction)drw_flush, METH_NOARGS},
198
880
    {"update",  (PyCFunction)drw_update,        METH_VARARGS},
199
 
    {"merge_shadow",    (PyCFunction)drw_merge_shadow,  METH_VARARGS},
200
 
    {"fill",    (PyCFunction)drw_fill,  METH_VARARGS},
201
 
    {"get_tile",        (PyCFunction)drw_get_tile,      METH_VARARGS},
202
 
    {"get_tile2",       (PyCFunction)drw_get_tile2,     METH_VARARGS},
203
 
    {"get_pixel_rgn", (PyCFunction)drw_get_pixel_rgn, METH_VARARGS},
204
 
    {"offset", (PyCFunction)drw_offset, METH_VARARGS},
 
881
    {"merge_shadow",    (PyCFunction)drw_merge_shadow,  METH_VARARGS | METH_KEYWORDS},
 
882
    {"fill",    (PyCFunction)drw_fill,  METH_VARARGS | METH_KEYWORDS},
 
883
    {"get_tile",        (PyCFunction)drw_get_tile,      METH_VARARGS | METH_KEYWORDS},
 
884
    {"get_tile2",       (PyCFunction)drw_get_tile2,     METH_VARARGS | METH_KEYWORDS},
 
885
    {"get_pixel_rgn", (PyCFunction)drw_get_pixel_rgn, METH_VARARGS | METH_KEYWORDS},
 
886
    {"offset", (PyCFunction)drw_offset, METH_VARARGS | METH_KEYWORDS},
205
887
    {"parasite_find",       (PyCFunction)drw_parasite_find, METH_VARARGS},
206
888
    {"parasite_attach",     (PyCFunction)drw_parasite_attach, METH_VARARGS},
207
 
    {"attach_new_parasite",(PyCFunction)drw_attach_new_parasite,METH_VARARGS},
 
889
    {"attach_new_parasite",(PyCFunction)drw_attach_new_parasite,METH_VARARGS | METH_KEYWORDS},
208
890
    {"parasite_detach",     (PyCFunction)drw_parasite_detach, METH_VARARGS},
209
891
    {"parasite_list",     (PyCFunction)drw_parasite_list, METH_VARARGS},
 
892
    {"get_pixel",       (PyCFunction)drw_get_pixel, METH_VARARGS},
 
893
    {"set_pixel",       (PyCFunction)drw_set_pixel, METH_VARARGS},
 
894
    {"mask_intersect",  (PyCFunction)drw_mask_intersect, METH_NOARGS},
 
895
    {"transform_flip",  (PyCFunction)drw_transform_flip, METH_VARARGS | METH_KEYWORDS},
 
896
    {"transform_flip_simple",   (PyCFunction)drw_transform_flip_simple, METH_VARARGS | METH_KEYWORDS},
 
897
    {"transform_flip_default",  (PyCFunction)drw_transform_flip_default, METH_VARARGS | METH_KEYWORDS},
 
898
    {"transform_perspective",   (PyCFunction)drw_transform_perspective, METH_VARARGS | METH_KEYWORDS},
 
899
    {"transform_perspective_default",   (PyCFunction)drw_transform_perspective_default, METH_VARARGS | METH_KEYWORDS},
 
900
    {"transform_rotate",        (PyCFunction)drw_transform_rotate, METH_VARARGS | METH_KEYWORDS},
 
901
    {"transform_rotate_simple", (PyCFunction)drw_transform_rotate_simple, METH_VARARGS | METH_KEYWORDS},
 
902
    {"transform_rotate_default",        (PyCFunction)drw_transform_rotate_default, METH_VARARGS | METH_KEYWORDS},
 
903
    {"transform_scale", (PyCFunction)drw_transform_scale, METH_VARARGS | METH_KEYWORDS},
 
904
    {"transform_scale_default", (PyCFunction)drw_transform_scale_default, METH_VARARGS | METH_KEYWORDS},
 
905
    {"transform_shear", (PyCFunction)drw_transform_shear, METH_VARARGS | METH_KEYWORDS},
 
906
    {"transform_shear_default", (PyCFunction)drw_transform_shear_default, METH_VARARGS | METH_KEYWORDS},
 
907
    {"transform_2d",    (PyCFunction)drw_transform_2d, METH_VARARGS | METH_KEYWORDS},
 
908
    {"transform_2d_default",    (PyCFunction)drw_transform_2d_default, METH_VARARGS | METH_KEYWORDS},
 
909
    {"transform_matrix",        (PyCFunction)drw_transform_matrix, METH_VARARGS | METH_KEYWORDS},
 
910
    {"transform_matrix_default",        (PyCFunction)drw_transform_matrix_default, METH_VARARGS | METH_KEYWORDS},
210
911
    {NULL, NULL, 0}
211
912
};
212
913
 
229
930
        PyErr_SetString(PyExc_TypeError, "cannot delete name");
230
931
        return -1;
231
932
    }
232
 
    if (!PyString_Check(value)) {
 
933
 
 
934
    if (!PyString_Check(value) && !PyUnicode_Check(value)) {
233
935
        PyErr_SetString(PyExc_TypeError, "type mismatch");
234
936
        return -1;
235
937
    }
 
938
 
236
939
    gimp_drawable_set_name(self->ID, PyString_AsString(value));
 
940
 
237
941
    return 0;
238
942
}
239
943
 
246
950
static PyObject *
247
951
drw_get_has_alpha(PyGimpDrawable *self, void *closure)
248
952
{
249
 
    return PyInt_FromLong(gimp_drawable_has_alpha(self->ID));
 
953
    return PyBool_FromLong(gimp_drawable_has_alpha(self->ID));
250
954
}
251
955
 
252
956
static PyObject *
264
968
static PyObject *
265
969
drw_get_is_rgb(PyGimpDrawable *self, void *closure)
266
970
{
267
 
    return PyInt_FromLong(gimp_drawable_is_rgb(self->ID));
 
971
    return PyBool_FromLong(gimp_drawable_is_rgb(self->ID));
268
972
}
269
973
 
270
974
static PyObject *
271
975
drw_get_is_gray(PyGimpDrawable *self, void *closure)
272
976
{
273
 
    return PyInt_FromLong(gimp_drawable_is_gray(self->ID));
 
977
    return PyBool_FromLong(gimp_drawable_is_gray(self->ID));
274
978
}
275
979
 
276
980
static PyObject *
277
981
drw_get_is_indexed(PyGimpDrawable *self, void *closure)
278
982
{
279
 
    return PyInt_FromLong(gimp_drawable_is_indexed(self->ID));
 
983
    return PyBool_FromLong(gimp_drawable_is_indexed(self->ID));
280
984
}
281
985
 
282
986
static PyObject *
283
987
drw_get_is_layer_mask(PyGimpDrawable *self, void *closure)
284
988
{
285
 
    return PyInt_FromLong(gimp_drawable_is_layer_mask(self->ID));
 
989
    return PyBool_FromLong(gimp_drawable_is_layer_mask(self->ID));
286
990
}
287
991
 
288
992
static PyObject *
300
1004
    gint x, y;
301
1005
 
302
1006
    gimp_drawable_offsets(self->ID, &x, &y);
 
1007
 
303
1008
    return Py_BuildValue("(ii)", x, y);
304
1009
}
305
1010
 
324
1029
static PyObject *
325
1030
drw_get_linked(PyGimpDrawable *self, void *closure)
326
1031
{
327
 
    return PyInt_FromLong(gimp_drawable_get_linked(self->ID));
 
1032
    return PyBool_FromLong(gimp_drawable_get_linked(self->ID));
328
1033
}
329
1034
 
330
1035
static int
334
1039
        PyErr_SetString(PyExc_TypeError, "cannot delete linked");
335
1040
        return -1;
336
1041
    }
 
1042
 
337
1043
    if (!PyInt_Check(value)) {
338
1044
        PyErr_SetString(PyExc_TypeError, "type mismatch");
339
1045
        return -1;
340
1046
    }
 
1047
 
341
1048
    gimp_drawable_set_linked(self->ID, PyInt_AsLong(value));
 
1049
 
342
1050
    return 0;
343
1051
}
344
1052
 
355
1063
        PyErr_SetString(PyExc_TypeError, "cannot delete tattoo");
356
1064
        return -1;
357
1065
    }
 
1066
 
358
1067
    if (!PyInt_Check(value)) {
359
1068
        PyErr_SetString(PyExc_TypeError, "type mismatch");
360
1069
        return -1;
361
1070
    }
 
1071
 
362
1072
    gimp_drawable_set_tattoo(self->ID, PyInt_AsLong(value));
 
1073
 
363
1074
    return 0;
364
1075
}
365
1076
 
366
1077
static PyObject *
367
1078
drw_get_visible(PyGimpDrawable *self, void *closure)
368
1079
{
369
 
    return PyInt_FromLong(gimp_drawable_get_visible(self->ID));
 
1080
    return PyBool_FromLong(gimp_drawable_get_visible(self->ID));
370
1081
}
371
 
                                                                                
 
1082
 
372
1083
static int
373
1084
drw_set_visible(PyGimpDrawable *self, PyObject *value, void *closure)
374
1085
{
376
1087
        PyErr_SetString(PyExc_TypeError, "cannot delete visible");
377
1088
        return -1;
378
1089
    }
 
1090
 
379
1091
    if (!PyInt_Check(value)) {
380
1092
        PyErr_SetString(PyExc_TypeError, "type mismatch");
381
1093
        return -1;
382
1094
    }
 
1095
 
383
1096
    gimp_drawable_set_visible(self->ID, PyInt_AsLong(value));
 
1097
 
384
1098
    return 0;
385
1099
}
386
1100
 
412
1126
{
413
1127
    if (self->drawable)
414
1128
        gimp_drawable_detach(self->drawable);
 
1129
 
415
1130
    PyObject_DEL(self);
416
1131
}
417
1132
 
422
1137
    gchar *name;
423
1138
 
424
1139
    name = gimp_drawable_get_name(self->ID);
425
 
    s = PyString_FromFormat("<gimp.Drawable '%s'>", name?name:"(null)");
 
1140
    s = PyString_FromFormat("<gimp.Drawable '%s'>", name ? name : "(null)");
426
1141
    g_free(name);
 
1142
 
427
1143
    return s;
428
1144
}
429
1145
 
430
1146
static int
431
1147
drw_cmp(PyGimpDrawable *self, PyGimpDrawable *other)
432
1148
{
433
 
    if (self->ID == other->ID) return 0;
434
 
    if (self->ID > other->ID) return -1;
 
1149
    if (self->ID == other->ID)
 
1150
        return 0;
 
1151
    if (self->ID > other->ID)
 
1152
        return -1;
435
1153
    return 1;
436
1154
}
437
1155
 
488
1206
        Py_INCREF(Py_None);
489
1207
        return Py_None;
490
1208
    }
 
1209
 
491
1210
    if (drawable != NULL)
492
1211
        ID = drawable->drawable_id;
 
1212
 
493
1213
    /* create the appropriate object type */
494
1214
    if (gimp_drawable_is_layer(ID))
495
1215
        self = pygimp_layer_new(ID);
509
1229
 
510
1230
 
511
1231
static PyObject *
512
 
lay_copy(PyGimpLayer *self, PyObject *args)
 
1232
lay_copy(PyGimpLayer *self, PyObject *args, PyObject *kwargs)
513
1233
{
514
 
    int add_alpha = 0, nreturn_vals;
 
1234
    int nreturn_vals;
515
1235
    GimpParam *return_vals;
516
 
    gint32 id;
517
 
 
518
 
    /* start of long convoluted (working) layer_copy */
519
 
    if (!PyArg_ParseTuple(args, "|i:copy", &add_alpha))
 
1236
    gboolean add_alpha = FALSE;
 
1237
    gint32 id = -1;
 
1238
 
 
1239
    static char *kwlist[] = { "add_alpha", NULL };
 
1240
 
 
1241
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i:copy", kwlist,
 
1242
                                     &add_alpha))
520
1243
        return NULL;
521
1244
 
522
 
    return_vals = gimp_run_procedure("gimp_layer_copy",
523
 
                                     &nreturn_vals, 
 
1245
    return_vals = gimp_run_procedure("gimp-layer-copy",
 
1246
                                     &nreturn_vals,
524
1247
                                     GIMP_PDB_LAYER, self->ID,
525
1248
                                     GIMP_PDB_INT32, add_alpha,
526
1249
                                     GIMP_PDB_END);
527
 
    if (return_vals[0].data.d_status != GIMP_PDB_SUCCESS) {
528
 
        PyErr_SetString(pygimp_error, "can't create new layer");
529
 
        return NULL;
530
 
    }   
531
 
    id = return_vals[1].data.d_layer;
 
1250
 
 
1251
    if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
 
1252
        id = return_vals[1].data.d_layer;
 
1253
    else
 
1254
        PyErr_Format(pygimp_error,
 
1255
                     "could not create new layer copy from layer (ID %d)",
 
1256
                     self->ID);
 
1257
 
532
1258
    gimp_destroy_params(return_vals, nreturn_vals);
533
 
    return pygimp_layer_new(id);
534
1259
 
535
 
    /* This simple version of the code doesn't seem to work */
536
 
    /* return (PyObject *)newlayobject(gimp_layer_copy(self->ID));*/
 
1260
    return id != -1 ? pygimp_layer_new(id) : NULL;
537
1261
}
538
1262
 
539
1263
 
540
1264
static PyObject *
541
1265
lay_add_alpha(PyGimpLayer *self)
542
1266
{
543
 
    gimp_layer_add_alpha(self->ID);
 
1267
    if (!gimp_layer_add_alpha(self->ID)) {
 
1268
        PyErr_Format(pygimp_error, "could not add alpha to layer (ID %d)",
 
1269
                     self->ID);
 
1270
        return NULL;
 
1271
    }
 
1272
 
544
1273
    Py_INCREF(Py_None);
545
1274
    return Py_None;
546
1275
}
553
1282
 
554
1283
    if (!PyArg_ParseTuple(args, "O!:add_mask", &PyGimpChannel_Type, &mask))
555
1284
        return NULL;
556
 
    return PyInt_FromLong(gimp_layer_add_mask(self->ID, mask->ID));
 
1285
 
 
1286
    if (!gimp_layer_add_mask(self->ID, mask->ID)) {
 
1287
        PyErr_Format(pygimp_error,
 
1288
                     "could not add mask (ID %d) to layer (ID %d)",
 
1289
                     mask->ID, self->ID);
 
1290
        return NULL;
 
1291
    }
 
1292
 
 
1293
    Py_INCREF(Py_None);
 
1294
    return Py_None;
557
1295
}
558
1296
 
559
1297
static PyObject *
560
1298
lay_create_mask(PyGimpLayer *self, PyObject *args)
561
1299
{
562
1300
    int type;
 
1301
    gint32 id;
563
1302
 
564
1303
    if (!PyArg_ParseTuple(args, "i:create_mask", &type))
565
1304
        return NULL;
566
 
    return pygimp_channel_new(gimp_layer_create_mask(self->ID,type));
 
1305
 
 
1306
    id = gimp_layer_create_mask(self->ID, type);
 
1307
 
 
1308
    if (id == -1) {
 
1309
        PyErr_Format(pygimp_error,
 
1310
                     "could not create mask of type %d on layer (ID %d)",
 
1311
                     type, self->ID);
 
1312
        return NULL;
 
1313
    }
 
1314
 
 
1315
    return pygimp_channel_new(id);
567
1316
}
568
1317
 
569
1318
static PyObject *
573
1322
 
574
1323
    if (!PyArg_ParseTuple(args, "i:remove_mask", &mode))
575
1324
        return NULL;
576
 
    return PyInt_FromLong(gimp_layer_remove_mask(self->ID, mode));
 
1325
 
 
1326
    if (!gimp_layer_remove_mask(self->ID, mode)) {
 
1327
        PyErr_Format(pygimp_error,
 
1328
                     "could not remove mask from layer (ID %d) with mode %d",
 
1329
                      self->ID, mode);
 
1330
        return NULL;
 
1331
    }
 
1332
 
 
1333
    Py_INCREF(Py_None);
 
1334
    return Py_None;
577
1335
}
578
1336
 
579
1337
 
580
1338
static PyObject *
581
 
lay_resize(PyGimpLayer *self, PyObject *args)
 
1339
lay_resize(PyGimpLayer *self, PyObject *args, PyObject *kwargs)
582
1340
{
583
1341
    unsigned int new_h, new_w;
584
 
    int offs_x, offs_y;
585
 
    if (!PyArg_ParseTuple(args, "iiii:resize", &new_w, &new_h,
586
 
                          &offs_x, &offs_y))
587
 
        return NULL;
588
 
    gimp_layer_resize(self->ID, new_w, new_h, offs_x, offs_y);
589
 
    Py_INCREF(Py_None);
590
 
    return Py_None;
591
 
}
592
 
 
593
 
 
594
 
static PyObject *
595
 
lay_scale(PyGimpLayer *self, PyObject *args)
 
1342
    int offs_x = 0, offs_y = 0;
 
1343
 
 
1344
    static char *kwlist[] = { "width", "height", "offset_x", "offset_y", NULL };
 
1345
 
 
1346
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii|ii:resize", kwlist,
 
1347
                                     &new_w, &new_h, &offs_x, &offs_y))
 
1348
        return NULL;
 
1349
 
 
1350
    if (!gimp_layer_resize(self->ID, new_w, new_h, offs_x, offs_y)) {
 
1351
        PyErr_Format(pygimp_error,
 
1352
                     "could not resize layer (ID %d) to size %dx%d "
 
1353
                     "(offset %d, %d)",
 
1354
                     self->ID, new_w, new_h, offs_x, offs_y);
 
1355
        return NULL;
 
1356
    }
 
1357
 
 
1358
    Py_INCREF(Py_None);
 
1359
    return Py_None;
 
1360
}
 
1361
 
 
1362
static PyObject *
 
1363
lay_resize_to_image_size(PyGimpLayer *self)
 
1364
{
 
1365
    if (!gimp_layer_resize_to_image_size(self->ID)) {
 
1366
        PyErr_Format(pygimp_error,
 
1367
                     "could not resize layer (ID %d) to image size",
 
1368
                     self->ID);
 
1369
        return NULL;
 
1370
    }
 
1371
 
 
1372
    Py_INCREF(Py_None);
 
1373
    return Py_None;
 
1374
}
 
1375
 
 
1376
static PyObject *
 
1377
lay_scale(PyGimpLayer *self, PyObject *args, PyObject *kwargs)
596
1378
{
597
1379
    unsigned int new_w, new_h;
598
 
    int local_origin;
599
 
    if (!PyArg_ParseTuple(args, "iii:scale", &new_w, &new_h,
600
 
                          &local_origin))
601
 
        return NULL;
602
 
    gimp_layer_scale(self->ID, new_w, new_h, local_origin);
603
 
    Py_INCREF(Py_None);
604
 
    return Py_None;
605
 
}
606
 
 
607
 
 
608
 
static PyObject *
609
 
lay_translate(PyGimpLayer *self, PyObject *args)
610
 
{
611
 
    int offs_x, offs_y;
612
 
    if (!PyArg_ParseTuple(args, "ii:translate", &offs_x, &offs_y))
613
 
        return NULL;
614
 
    gimp_layer_translate(self->ID, offs_x, offs_y);
615
 
    Py_INCREF(Py_None);
616
 
    return Py_None;
617
 
}
618
 
 
619
 
 
620
 
static PyObject *
621
 
lay_set_offsets(PyGimpLayer *self, PyObject *args)
622
 
{
623
 
    int offs_x, offs_y;
624
 
    if (!PyArg_ParseTuple(args, "ii:set_offsets", &offs_x, &offs_y))
625
 
        return NULL;
626
 
    gimp_layer_set_offsets(self->ID, offs_x, offs_y);
 
1380
    gboolean local_origin = FALSE;
 
1381
 
 
1382
    static char *kwlist[] = { "width", "height", "local_origin", NULL };
 
1383
 
 
1384
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii|i:scale", kwlist,
 
1385
                                     &new_w, &new_h, &local_origin))
 
1386
        return NULL;
 
1387
 
 
1388
    if (!gimp_layer_scale(self->ID, new_w, new_h, local_origin)) {
 
1389
        PyErr_Format(pygimp_error,
 
1390
                     "could not scale layer (ID %d) to size %dx%d",
 
1391
                     self->ID, new_w, new_h);
 
1392
        return NULL;
 
1393
    }
 
1394
 
 
1395
    Py_INCREF(Py_None);
 
1396
    return Py_None;
 
1397
}
 
1398
 
 
1399
 
 
1400
static PyObject *
 
1401
lay_translate(PyGimpLayer *self, PyObject *args, PyObject *kwargs)
 
1402
{
 
1403
    int offs_x, offs_y;
 
1404
 
 
1405
    static char *kwlist[] = { "offset_x", "offset_y", NULL };
 
1406
 
 
1407
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii:translate", kwlist,
 
1408
                                     &offs_x, &offs_y))
 
1409
        return NULL;
 
1410
 
 
1411
    if (!gimp_layer_translate(self->ID, offs_x, offs_y)) {
 
1412
        PyErr_Format(pygimp_error,
 
1413
                     "could not translate layer (ID %d) to offset %d, %d",
 
1414
                     self->ID, offs_x, offs_y);
 
1415
        return NULL;
 
1416
    }
 
1417
 
 
1418
    Py_INCREF(Py_None);
 
1419
    return Py_None;
 
1420
}
 
1421
 
 
1422
 
 
1423
static PyObject *
 
1424
lay_set_offsets(PyGimpLayer *self, PyObject *args, PyObject *kwargs)
 
1425
{
 
1426
    int offs_x, offs_y;
 
1427
 
 
1428
    static char *kwlist[] = { "offset_x", "offset_y", NULL };
 
1429
 
 
1430
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii:set_offsets", kwlist,
 
1431
                                     &offs_x, &offs_y))
 
1432
        return NULL;
 
1433
 
 
1434
    if (!gimp_layer_set_offsets(self->ID, offs_x, offs_y)) {
 
1435
        PyErr_Format(pygimp_error,
 
1436
                     "could not set offset %d, %d on layer (ID %d)",
 
1437
                     offs_x, offs_y, self->ID);
 
1438
        return NULL;
 
1439
    }
 
1440
 
627
1441
    Py_INCREF(Py_None);
628
1442
    return Py_None;
629
1443
}
630
1444
 
631
1445
static PyMethodDef lay_methods[] = {
632
 
    {"copy",    (PyCFunction)lay_copy,  METH_VARARGS},
 
1446
    {"copy",    (PyCFunction)lay_copy,  METH_VARARGS | METH_KEYWORDS},
633
1447
    {"add_alpha",       (PyCFunction)lay_add_alpha,     METH_NOARGS},
634
1448
    {"add_mask",        (PyCFunction)lay_add_mask,      METH_VARARGS},
635
1449
    {"create_mask",     (PyCFunction)lay_create_mask,   METH_VARARGS},
636
1450
    {"remove_mask",     (PyCFunction)lay_remove_mask,   METH_VARARGS},
637
 
    {"resize",  (PyCFunction)lay_resize,        METH_VARARGS},
638
 
    {"scale",   (PyCFunction)lay_scale, METH_VARARGS},
639
 
    {"translate",       (PyCFunction)lay_translate,     METH_VARARGS},
640
 
    {"set_offsets",     (PyCFunction)lay_set_offsets,   METH_VARARGS},
 
1451
    {"resize",  (PyCFunction)lay_resize,        METH_VARARGS | METH_KEYWORDS},
 
1452
    {"resize_to_image_size",    (PyCFunction)lay_resize_to_image_size,  METH_NOARGS},
 
1453
    {"scale",   (PyCFunction)lay_scale, METH_VARARGS | METH_KEYWORDS},
 
1454
    {"translate",       (PyCFunction)lay_translate,     METH_VARARGS | METH_KEYWORDS},
 
1455
    {"set_offsets",     (PyCFunction)lay_set_offsets,   METH_VARARGS | METH_KEYWORDS},
641
1456
    {NULL,              NULL}           /* sentinel */
642
1457
};
643
1458
 
644
1459
static PyObject *
645
1460
lay_get_is_floating_sel(PyGimpLayer *self, void *closure)
646
1461
{
647
 
    return PyInt_FromLong(gimp_layer_is_floating_sel(self->ID));
 
1462
    return PyBool_FromLong(gimp_layer_is_floating_sel(self->ID));
648
1463
}
649
1464
 
650
1465
static PyObject *
651
1466
lay_get_mask(PyGimpLayer *self, void *closure)
652
1467
{
653
1468
    gint32 id = gimp_layer_get_mask(self->ID);
 
1469
 
654
1470
    if (id == -1) {
655
1471
        Py_INCREF(Py_None);
656
1472
        return Py_None;
657
1473
    }
 
1474
 
658
1475
    return pygimp_channel_new(id);
659
1476
}
660
1477
 
661
1478
static PyObject *
662
1479
lay_get_apply_mask(PyGimpLayer *self, void *closure)
663
1480
{
664
 
    return PyInt_FromLong(gimp_layer_get_apply_mask(self->ID));
 
1481
    return PyBool_FromLong(gimp_layer_get_apply_mask(self->ID));
665
1482
}
666
1483
 
667
1484
static int
671
1488
        PyErr_SetString(PyExc_TypeError, "cannot delete apply_mask");
672
1489
        return -1;
673
1490
    }
 
1491
 
674
1492
    if (!PyInt_Check(value)) {
675
1493
        PyErr_SetString(PyExc_TypeError, "type mismatch");
676
1494
        return -1;
677
1495
    }
678
 
    gimp_layer_set_apply_mask(self->ID, PyInt_AsLong(value));
 
1496
 
 
1497
    if (!gimp_layer_set_apply_mask(self->ID, PyInt_AsLong(value))) {
 
1498
        PyErr_Format(pygimp_error,
 
1499
                     "could not set layer mask on layer (ID %d)",
 
1500
                     self->ID);
 
1501
        return -1;
 
1502
    }
 
1503
 
679
1504
    return 0;
680
1505
}
681
1506
 
682
1507
static PyObject *
683
1508
lay_get_edit_mask(PyGimpLayer *self, void *closure)
684
1509
{
685
 
    return PyInt_FromLong(gimp_layer_get_edit_mask(self->ID));}
 
1510
    return PyBool_FromLong(gimp_layer_get_edit_mask(self->ID));
 
1511
}
686
1512
 
687
1513
static int
688
1514
lay_set_edit_mask(PyGimpLayer *self, PyObject *value, void *closure)
691
1517
        PyErr_SetString(PyExc_TypeError, "cannot delete edit_mask");
692
1518
        return -1;
693
1519
    }
 
1520
 
694
1521
    if (!PyInt_Check(value)) {
695
1522
        PyErr_SetString(PyExc_TypeError, "type mismatch");
696
1523
        return -1;
697
1524
    }
698
 
    gimp_layer_set_edit_mask(self->ID, PyInt_AsLong(value));
 
1525
 
 
1526
    if (!gimp_layer_set_edit_mask(self->ID, PyInt_AsLong(value))) {
 
1527
        PyErr_Format(pygimp_error,
 
1528
                     "could not set layer mask active on layer (ID %d)",
 
1529
                     self->ID);
 
1530
        return -1;
 
1531
    }
 
1532
 
699
1533
    return 0;
700
1534
}
701
1535
 
712
1546
        PyErr_SetString(PyExc_TypeError, "cannot delete mode");
713
1547
        return -1;
714
1548
    }
 
1549
 
715
1550
    if (!PyInt_Check(value)) {
716
1551
        PyErr_SetString(PyExc_TypeError, "type mismatch");
717
1552
        return -1;
718
1553
    }
719
 
    gimp_layer_set_mode(self->ID, (GimpLayerModeEffects)PyInt_AsLong(value));
 
1554
 
 
1555
    if (!gimp_layer_set_mode(self->ID, PyInt_AsLong(value))) {
 
1556
        PyErr_Format(pygimp_error, "could not set mode on layer (ID %d)",
 
1557
                     self->ID);
 
1558
        return -1;
 
1559
    }
 
1560
 
720
1561
    return 0;
721
1562
}
722
1563
 
733
1574
        PyErr_SetString(PyExc_TypeError, "cannot delete opacity");
734
1575
        return -1;
735
1576
    }
 
1577
 
736
1578
    if (!PyFloat_Check(value)) {
737
1579
        PyErr_SetString(PyExc_TypeError, "type mismatch");
738
1580
        return -1;
739
1581
    }
740
 
    gimp_layer_set_opacity(self->ID, PyFloat_AsDouble(value));
 
1582
 
 
1583
    if (!gimp_layer_set_opacity(self->ID, PyFloat_AsDouble(value))) {
 
1584
        PyErr_Format(pygimp_error, "could not set opacity on layer (ID %d)",
 
1585
                     self->ID);
 
1586
        return -1;
 
1587
    }
 
1588
 
741
1589
    return 0;
742
1590
}
743
1591
 
744
1592
static PyObject *
745
 
lay_get_preserve_trans(PyGimpLayer *self, void *closure)
 
1593
lay_get_lock_alpha(PyGimpLayer *self, void *closure)
746
1594
{
747
 
    return PyInt_FromLong(gimp_layer_get_preserve_trans(self->ID));
 
1595
    return PyBool_FromLong(gimp_layer_get_lock_alpha(self->ID));
748
1596
}
749
1597
 
750
1598
static int
751
 
lay_set_preserve_trans(PyGimpLayer *self, PyObject *value, void *closure)
 
1599
lay_set_lock_alpha(PyGimpLayer *self, PyObject *value, void *closure)
752
1600
{
753
1601
    if (value == NULL) {
754
1602
        PyErr_SetString(PyExc_TypeError,
755
 
                        "cannot delete preserve_transparency");
 
1603
                        "cannot delete lock_alpha");
756
1604
        return -1;
757
1605
    }
 
1606
 
758
1607
    if (!PyInt_Check(value)) {
759
1608
        PyErr_SetString(PyExc_TypeError, "type mismatch");
760
1609
        return -1;
761
1610
    }
762
 
    gimp_layer_set_preserve_trans(self->ID, PyInt_AsLong(value));
 
1611
 
 
1612
    if (!gimp_layer_set_lock_alpha(self->ID, PyInt_AsLong(value))) {
 
1613
        PyErr_Format(pygimp_error,
 
1614
                     "could not set lock alpha setting on layer (ID %d)",
 
1615
                     self->ID);
 
1616
        return -1;
 
1617
    }
 
1618
 
763
1619
    return 0;
764
1620
}
765
1621
 
766
1622
static PyObject *
767
1623
lay_get_show_mask(PyGimpLayer *self, void *closure)
768
1624
{
769
 
    return PyInt_FromLong(gimp_layer_get_show_mask(self->ID));
 
1625
    return PyBool_FromLong(gimp_layer_get_show_mask(self->ID));
770
1626
}
771
1627
 
772
1628
static int
776
1632
        PyErr_SetString(PyExc_TypeError, "cannot delete show_mask");
777
1633
        return -1;
778
1634
    }
 
1635
 
779
1636
    if (!PyInt_Check(value)) {
780
1637
        PyErr_SetString(PyExc_TypeError, "type mismatch");
781
1638
        return -1;
782
1639
    }
783
 
    gimp_layer_set_show_mask(self->ID, PyInt_AsLong(value));
 
1640
 
 
1641
    if (!gimp_layer_set_show_mask(self->ID, PyInt_AsLong(value))) {
 
1642
        PyErr_Format(pygimp_error,
 
1643
                     "could not set mask visibility on layer (ID %d)",
 
1644
                     self->ID);
 
1645
        return -1;
 
1646
    }
 
1647
 
784
1648
    return 0;
785
1649
}
786
1650
 
 
1651
static PyObject *
 
1652
lay_get_preserve_trans(PyGimpLayer *self, void *closure)
 
1653
{
 
1654
    if (PyErr_Warn(PyExc_DeprecationWarning, "use lock_alpha attribute") < 0)
 
1655
        return NULL;
 
1656
 
 
1657
    return lay_get_lock_alpha(self, closure);
 
1658
}
 
1659
 
 
1660
static int
 
1661
lay_set_preserve_trans(PyGimpLayer *self, PyObject *value, void *closure)
 
1662
{
 
1663
    if (PyErr_Warn(PyExc_DeprecationWarning, "use lock_alpha attribute") < 0)
 
1664
        return -1;
 
1665
 
 
1666
    return lay_set_lock_alpha(self, value, closure);
 
1667
}
 
1668
 
787
1669
static PyGetSetDef lay_getsets[] = {
788
1670
    { "is_floating_sel", (getter)lay_get_is_floating_sel, (setter)0 },
789
1671
    { "mask", (getter)lay_get_mask, (setter)0 },
791
1673
    { "edit_mask", (getter)lay_get_edit_mask, (setter)lay_set_edit_mask },
792
1674
    { "mode", (getter)lay_get_mode, (setter)lay_set_mode },
793
1675
    { "opacity", (getter)lay_get_opacity, (setter)lay_set_opacity },
 
1676
    { "lock_alpha", (getter)lay_get_lock_alpha, (setter)lay_set_lock_alpha },
 
1677
    { "show_mask", (getter)lay_get_show_mask, (setter)lay_set_show_mask },
794
1678
    { "preserve_trans", (getter)lay_get_preserve_trans,
795
1679
      (setter)lay_set_preserve_trans },
796
 
    { "show_mask", (getter)lay_get_show_mask, (setter)lay_set_show_mask },
797
1680
    { NULL, (getter)0, (setter)0 }
798
1681
};
799
1682
 
806
1689
    name = gimp_drawable_get_name(self->ID);
807
1690
    s = PyString_FromFormat("<gimp.Layer '%s'>", name);
808
1691
    g_free(name);
 
1692
 
809
1693
    return s;
810
1694
}
811
1695
 
815
1699
    PyGimpImage *img;
816
1700
    char *name;
817
1701
    unsigned int width, height;
818
 
    GimpImageType type;
819
 
    double opacity;
820
 
    GimpLayerModeEffects mode;
821
 
        
822
 
 
823
 
    if (!PyArg_ParseTuple(args, "O!siiidi:gimp.Layer.__init__",
 
1702
    GimpImageType type = GIMP_RGB_IMAGE;
 
1703
    double opacity = 100.0;
 
1704
    GimpLayerModeEffects mode = GIMP_NORMAL_MODE;
 
1705
 
 
1706
 
 
1707
    if (!PyArg_ParseTuple(args, "O!sii|idi:gimp.Layer.__init__",
824
1708
                          &PyGimpImage_Type, &img, &name, &width, &height,
825
1709
                          &type, &opacity, &mode))
826
1710
        return -1;
827
 
    self->ID = gimp_layer_new(img->ID, name, width,
828
 
                              height, type, opacity, mode);
 
1711
 
 
1712
    self->ID = gimp_layer_new(img->ID, name, width, height,
 
1713
                              type, opacity, mode);
 
1714
 
829
1715
    self->drawable = NULL;
 
1716
 
830
1717
    if (self->ID < 0) {
831
 
        PyErr_SetString(pygimp_error, "could not create layer");
 
1718
        PyErr_Format(pygimp_error,
 
1719
                     "could not create %dx%d layer '%s' of type %d on "
 
1720
                     "image (ID %d)",
 
1721
                     width, height, name, type, img->ID);
832
1722
        return -1;
833
1723
    }
 
1724
 
834
1725
    return 0;
835
1726
}
836
1727
 
886
1777
        Py_INCREF(Py_None);
887
1778
        return Py_None;
888
1779
    }
 
1780
 
889
1781
    self = PyObject_NEW(PyGimpLayer, &PyGimpLayer_Type);
 
1782
 
890
1783
    if (self == NULL)
891
1784
        return NULL;
 
1785
 
892
1786
    self->ID = ID;
893
1787
    self->drawable = NULL;
 
1788
 
894
1789
    return (PyObject *)self;
895
1790
}
896
1791
 
902
1797
chn_copy(PyGimpChannel *self)
903
1798
{
904
1799
    gint32 id;
905
 
        
 
1800
 
906
1801
    id = gimp_channel_copy(self->ID);
 
1802
 
907
1803
    if (id == -1) {
908
 
        PyErr_SetString(pygimp_error, "can't copy channel");
 
1804
        PyErr_Format(pygimp_error,
 
1805
                     "could not create new channel copy from channel (ID %d)",
 
1806
                     self->ID);
909
1807
        return NULL;
910
1808
    }
 
1809
 
911
1810
    return pygimp_channel_new(id);
912
1811
}
913
1812
 
914
1813
static PyObject *
915
 
chn_combine_masks(PyGimpChannel *self, PyObject *args)
 
1814
chn_combine_masks(PyGimpChannel *self, PyObject *args, PyObject *kwargs)
916
1815
{
917
1816
    PyGimpChannel *channel2;
918
1817
    GimpChannelOps operation;
919
 
    gint offx, offy;
920
 
 
921
 
    if (!PyArg_ParseTuple(args, "O!iii:combine_masks", &PyGimpChannel_Type,
922
 
                          &channel2, &operation, &offx, &offy))
923
 
        return NULL;
924
 
    return PyInt_FromLong(gimp_channel_combine_masks(self->ID, channel2->ID,
925
 
                                                     operation, offx, offy));
 
1818
    int offx = 0, offy = 0;
 
1819
 
 
1820
    static char *kwlist[] = { "channel", "operation", "offset_x", "offset_y",
 
1821
                              NULL };
 
1822
 
 
1823
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!i|ii:combine_masks",
 
1824
                                     kwlist,
 
1825
                                     &PyGimpChannel_Type, &channel2,
 
1826
                                     &operation, &offx, &offy))
 
1827
        return NULL;
 
1828
 
 
1829
    if (!gimp_channel_combine_masks(self->ID, channel2->ID, operation,
 
1830
                                    offx, offy)) {
 
1831
        PyErr_Format(pygimp_error,
 
1832
                     "could not combine masks with channels (ID %d and ID %d) "
 
1833
                     "with operation %d, offset %d, %d",
 
1834
                     self->ID, channel2->ID, operation, offx, offy);
 
1835
        return NULL;
 
1836
    }
 
1837
 
 
1838
    Py_INCREF(Py_None);
 
1839
    return Py_None;
926
1840
}
927
1841
 
928
1842
static PyMethodDef chn_methods[] = {
934
1848
static PyObject *
935
1849
chn_get_color(PyGimpChannel *self, void *closure)
936
1850
{
937
 
    GimpRGB colour;
938
 
    guchar r, g, b;
939
 
 
940
 
    gimp_channel_get_color(self->ID, &colour);
941
 
    gimp_rgb_get_uchar(&colour, &r, &g, &b);
942
 
    return Py_BuildValue("(iii)", (long)r, (long)g, (long)b);
 
1851
    GimpRGB rgb;
 
1852
 
 
1853
    if (!gimp_channel_get_color(self->ID, &rgb)) {
 
1854
        PyErr_Format(pygimp_error,
 
1855
                     "could not get compositing color of channel (ID %d)",
 
1856
                     self->ID);
 
1857
        return NULL;
 
1858
    }
 
1859
 
 
1860
    return pygimp_rgb_new(&rgb);
943
1861
}
944
1862
 
945
1863
static int
946
1864
chn_set_color(PyGimpChannel *self, PyObject *value, void *closure)
947
1865
{
948
1866
    guchar r, g, b;
949
 
    GimpRGB colour;
 
1867
    GimpRGB tmprgb, *rgb;
950
1868
 
951
1869
    if (value == NULL) {
952
 
        PyErr_SetString(PyExc_TypeError, "cannot delete colour");
 
1870
        PyErr_SetString(PyExc_TypeError, "cannot delete color");
953
1871
        return -1;
954
1872
    }
955
 
    if (!PyTuple_Check(value) || !PyArg_ParseTuple(value, "(BBB)", &r,&g,&b)) {
 
1873
 
 
1874
    if (pygimp_rgb_check(value)) {
 
1875
        rgb = pyg_boxed_get(value, GimpRGB);
 
1876
    } else if (PyTuple_Check(value) &&
 
1877
               PyArg_ParseTuple(value, "(BBB)", &r, &g, &b)) {
 
1878
        gimp_rgb_set_uchar(&tmprgb, r, g, b);
 
1879
        rgb = &tmprgb;
 
1880
    } else {
956
1881
        PyErr_Clear();
957
1882
        PyErr_SetString(PyExc_TypeError, "type mismatch");
958
1883
        return -1;
959
1884
    }
960
 
    gimp_rgb_set_uchar(&colour, r, g, b);
961
 
    gimp_channel_set_color(self->ID, &colour);
 
1885
 
 
1886
    if (!gimp_channel_set_color(self->ID, rgb)) {
 
1887
        PyErr_Format(pygimp_error,
 
1888
                     "could not set compositing color on channel (ID %d)",
 
1889
                     self->ID);
 
1890
        return -1;
 
1891
    }
 
1892
 
962
1893
    return 0;
963
1894
}
964
1895
 
975
1906
        PyErr_SetString(PyExc_TypeError, "cannot delete opacity");
976
1907
        return -1;
977
1908
    }
 
1909
 
978
1910
    if (!PyFloat_Check(value)) {
979
1911
        PyErr_SetString(PyExc_TypeError, "type mismatch");
980
1912
        return -1;
981
1913
    }
982
 
    gimp_channel_set_opacity(self->ID, PyFloat_AsDouble(value));
 
1914
 
 
1915
    if (!gimp_channel_set_opacity(self->ID, PyFloat_AsDouble(value))) {
 
1916
        PyErr_Format(pygimp_error,
 
1917
                     "could not set opacity on channel (ID %d)",
 
1918
                     self->ID);
 
1919
        return -1;
 
1920
    }
 
1921
 
983
1922
    return 0;
984
1923
}
985
1924
 
986
1925
static PyObject *
987
1926
chn_get_show_masked(PyGimpLayer *self, void *closure)
988
1927
{
989
 
    return PyInt_FromLong(gimp_channel_get_show_masked(self->ID));
 
1928
    return PyBool_FromLong(gimp_channel_get_show_masked(self->ID));
990
1929
}
991
1930
 
992
1931
static int
996
1935
        PyErr_SetString(PyExc_TypeError, "cannot delete show_masked");
997
1936
        return -1;
998
1937
    }
 
1938
 
999
1939
    if (!PyInt_Check(value)) {
1000
1940
        PyErr_SetString(PyExc_TypeError, "type mismatch");
1001
1941
        return -1;
1002
1942
    }
1003
 
    gimp_channel_set_show_masked(self->ID, PyInt_AsLong(value));
 
1943
 
 
1944
    if (!gimp_channel_set_show_masked(self->ID, PyInt_AsLong(value))) {
 
1945
        PyErr_Format(pygimp_error,
 
1946
                     "could not set composite method on channel (ID %d)",
 
1947
                     self->ID);
 
1948
        return -1;
 
1949
    }
 
1950
 
1004
1951
    return 0;
1005
1952
}
1006
1953
 
1021
1968
    name = gimp_drawable_get_name(self->ID);
1022
1969
    s = PyString_FromFormat("<gimp.Channel '%s'>", name);
1023
1970
    g_free(name);
 
1971
 
1024
1972
    return s;
1025
1973
}
1026
1974
 
1028
1976
chn_init(PyGimpChannel *self, PyObject *args, PyObject *kwargs)
1029
1977
{
1030
1978
    PyGimpImage *img;
 
1979
    PyObject *color;
1031
1980
    char *name;
1032
1981
    unsigned int width, height, r, g, b;
1033
1982
    double opacity;
1034
 
    GimpRGB colour;
 
1983
    GimpRGB tmprgb, *rgb;
1035
1984
 
1036
 
    if (!PyArg_ParseTuple(args, "O!siid(iii):gimp.Channel.__init__",
 
1985
    if (!PyArg_ParseTuple(args, "O!siidO:gimp.Channel.__init__",
1037
1986
                          &PyGimpImage_Type, &img, &name, &width,
1038
 
                          &height, &opacity, &r, &g, &b))
1039
 
        return -1;
1040
 
    gimp_rgb_set_uchar(&colour, r & 0xff, g & 0xff, b & 0xff);
1041
 
    self->ID = gimp_channel_new(img->ID, name, width, height,
1042
 
                                opacity, &colour);
 
1987
                          &height, &opacity, &color))
 
1988
        return -1;
 
1989
 
 
1990
    if (pygimp_rgb_check(color)) {
 
1991
        rgb = pyg_boxed_get(color, GimpRGB);
 
1992
    } else if (PyTuple_Check(color) &&
 
1993
               PyArg_ParseTuple(color, "(BBB)", &r, &g, &b)) {
 
1994
        gimp_rgb_set_uchar(&tmprgb, r, g, b);
 
1995
        rgb = &tmprgb;
 
1996
    } else {
 
1997
        PyErr_Clear();
 
1998
        PyErr_SetString(PyExc_TypeError, "type mismatch");
 
1999
        return -1;
 
2000
    }
 
2001
 
 
2002
    self->ID = gimp_channel_new(img->ID, name, width, height, opacity, rgb);
 
2003
 
1043
2004
    self->drawable = NULL;
 
2005
 
1044
2006
    if (self->ID < 0) {
1045
 
        PyErr_SetString(pygimp_error, "could not create layer");
 
2007
        PyErr_Format(pygimp_error,
 
2008
                     "could not create %dx%d channel '%s' on image (ID %d)",
 
2009
                     width, height, name, img->ID);
1046
2010
        return -1;
1047
2011
    }
 
2012
 
1048
2013
    return 0;
1049
2014
}
1050
2015
 
1100
2065
        Py_INCREF(Py_None);
1101
2066
        return Py_None;
1102
2067
    }
 
2068
 
1103
2069
    self = PyObject_NEW(PyGimpChannel, &PyGimpChannel_Type);
 
2070
 
1104
2071
    if (self == NULL)
1105
2072
        return NULL;
 
2073
 
1106
2074
    self->ID = ID;
1107
2075
    self->drawable = NULL;
 
2076
 
1108
2077
    return (PyObject *)self;
1109
2078
}