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

« back to all changes in this revision

Viewing changes to plug-ins/pygimp/pygimp-pdb.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
 
 
24
#define NO_IMPORT_PYGOBJECT
 
25
#include <pygobject.h>
 
26
 
23
27
#include "pygimp.h"
 
28
 
 
29
#define NO_IMPORT_PYGIMPCOLOR
 
30
#include "pygimpcolor-api.h"
 
31
 
24
32
#include <structmember.h>
25
33
 
 
34
#include <glib-object.h>
 
35
 
26
36
#ifndef PG_DEBUG
27
37
# define PG_DEBUG 0
28
38
#endif
66
76
    for (i = 0; i < nparams; i++) {
67
77
        switch(params[i].type) {
68
78
        case GIMP_PDB_INT32:
69
 
            fprintf(stderr, "%i. int %i\n", i,
70
 
                    params[i].data.d_int32);
 
79
            g_printerr("%i. int %i\n", i,
 
80
                       params[i].data.d_int32);
71
81
            break;
72
82
        case GIMP_PDB_INT16:
73
 
            fprintf(stderr, "%i. int %i\n", i,
74
 
                    params[i].data.d_int16);
 
83
            g_printerr("%i. int %i\n", i,
 
84
                       params[i].data.d_int16);
75
85
            break;
76
86
        case GIMP_PDB_INT8:
77
 
            fprintf(stderr, "%i. int %i\n", i,
78
 
                    params[i].data.d_int8);
 
87
            g_printerr("%i. int %u\n", i,
 
88
                       params[i].data.d_int8);
79
89
            break;
80
90
        case GIMP_PDB_FLOAT:
81
 
            fprintf(stderr, "%i. float %f\n", i,
82
 
                    params[i].data.d_float);
 
91
            g_printerr("%i. float %f\n", i,
 
92
                       params[i].data.d_float);
83
93
            break;
84
94
        case GIMP_PDB_STRING:
85
 
            fprintf(stderr, "%i. string %s\n", i,
86
 
                    params[i].data.d_string);
 
95
            g_printerr("%i. string %s\n", i,
 
96
                       params[i].data.d_string);
87
97
            break;
88
98
        case GIMP_PDB_INT32ARRAY:
89
99
        case GIMP_PDB_INT16ARRAY:
90
100
        case GIMP_PDB_INT8ARRAY:
91
101
        case GIMP_PDB_FLOATARRAY:
92
102
        case GIMP_PDB_STRINGARRAY:
93
 
            fprintf(stderr, "%i. array of type %i %s\n", i,
94
 
                    params[i].type, params[i].data.d_int32array
95
 
                    == NULL ? "(null)":"");
 
103
            g_printerr("%i. array of type %i %s\n", i,
 
104
                       params[i].type,
 
105
                       params[i].data.d_int32array == NULL ? "(null)":"");
96
106
            break;
97
107
        case GIMP_PDB_STATUS:
98
 
            fprintf(stderr, "%i. status %i\n", i,
99
 
                    params[i].data.d_status);
 
108
            g_printerr("%i. status %i\n", i,
 
109
                       params[i].data.d_status);
100
110
            break;
101
111
        default:
102
 
            fprintf(stderr, "%i. other %i\n", i,
103
 
                    params[i].data.d_int32);
 
112
            g_printerr("%i. other %i\n", i,
 
113
                       params[i].data.d_int32);
104
114
            break;
105
115
        }
106
116
    }
250
260
                        PyString_FromString(""));
251
261
            break;
252
262
        case GIMP_PDB_COLOR:
253
 
            {
254
 
                guchar r, g, b;
255
 
                gimp_rgb_get_uchar(&params[i].data.d_color, &r, &g, &b);
256
 
                value = Py_BuildValue("(iii)", (int)r, (int)g, (int)b);
257
 
            }
 
263
            value = pygimp_rgb_new(&params[i].data.d_color);
258
264
            break;
259
265
        case GIMP_PDB_REGION:
260
266
            value = Py_BuildValue("(iiii)",
284
290
        case GIMP_PDB_BOUNDARY:
285
291
            value = PyInt_FromLong(params[i].data.d_boundary);
286
292
            break;
287
 
        case GIMP_PDB_PATH:
288
 
            value = PyInt_FromLong(params[i].data.d_path);
 
293
        case GIMP_PDB_VECTORS:
 
294
            value = pygimp_vectors_new(params[i].data.d_vectors);
289
295
            break;
290
296
        case GIMP_PDB_PARASITE:
291
297
            value = pygimp_parasite_new(gimp_parasite_copy(
308
314
    PyObject *tuple, *item, *r, *g, *b, *x, *y, *w, *h;
309
315
    GimpParam *ret;
310
316
    int i, j, len;
311
 
    gint32 *i32a; gint16 *i16a; gint8 *i8a; gdouble *fa; gchar **sa;
 
317
    gint32 *i32a; gint16 *i16a; guint8 *i8a; gdouble *fa; gchar **sa;
312
318
 
313
319
    if (nparams == 0)
314
320
        tuple = PyTuple_New(0);
349
355
        switch (ptype[i-1].type) {
350
356
        case GIMP_PDB_INT32:
351
357
            check((x = PyNumber_Int(item)) == NULL);
352
 
            ret[i].data.d_int32 = PyInt_AsLong(x);
 
358
            ret[i].data.d_int32 = (gint32)PyInt_AsLong(x);
353
359
            Py_DECREF(x);
354
360
            break;
355
361
        case GIMP_PDB_INT16:
356
362
            check((x = PyNumber_Int(item)) == NULL);
357
 
            ret[i].data.d_int16 = PyInt_AsLong(x);
 
363
            ret[i].data.d_int16 = (gint16)PyInt_AsLong(x);
358
364
            Py_DECREF(x);
359
365
            break;
360
366
        case GIMP_PDB_INT8:
361
367
            check((x = PyNumber_Int(item)) == NULL);
362
 
            ret[i].data.d_int8 = PyInt_AsLong(x);
 
368
            ret[i].data.d_int8 = (guint8)PyInt_AsLong(x);
363
369
            Py_DECREF(x);
364
370
            break;
365
371
        case GIMP_PDB_FLOAT:
405
411
        case GIMP_PDB_INT8ARRAY:
406
412
            check(!PySequence_Check(item));
407
413
            len = PySequence_Length(item);
408
 
            i8a = g_new(gint8, len);
 
414
            i8a = g_new(guint8, len);
409
415
            for (j = 0; j < len; j++) {
410
416
                x = PySequence_GetItem(item, j);
411
417
                arraycheck((y=PyNumber_Int(x))==NULL,
446
452
            ret[i].data.d_stringarray = sa;
447
453
            break;
448
454
        case GIMP_PDB_COLOR:
449
 
            check(!PySequence_Check(item) || PySequence_Length(item) < 3);
450
 
            r = PySequence_GetItem(item, 0);
451
 
            g = PySequence_GetItem(item, 1);
452
 
            b = PySequence_GetItem(item, 2);
453
 
            check(!PyInt_Check(r) || !PyInt_Check(g) ||
454
 
                  !PyInt_Check(b));
455
 
            gimp_rgb_set_uchar(&ret[i].data.d_color, PyInt_AsLong(r),
456
 
                               PyInt_AsLong(g), PyInt_AsLong(b));
 
455
            {
 
456
                GimpRGB *rgb, tmprgb;
 
457
 
 
458
                if (!pygimp_rgb_check(item)) {
 
459
                    check(!PySequence_Check(item) ||
 
460
                          PySequence_Length(item) < 3);
 
461
                    r = PySequence_GetItem(item, 0);
 
462
                    g = PySequence_GetItem(item, 1);
 
463
                    b = PySequence_GetItem(item, 2);
 
464
                    check(!PyInt_Check(r) || !PyInt_Check(g) ||
 
465
                          !PyInt_Check(b));
 
466
                    gimp_rgba_set_uchar(&tmprgb, PyInt_AsLong(r),
 
467
                                        PyInt_AsLong(g), PyInt_AsLong(b), 255);
 
468
                    rgb = &tmprgb;
 
469
                } else {
 
470
                    rgb = pyg_boxed_get(item, GimpRGB);
 
471
                }
 
472
                ret[i].data.d_color = *rgb;
 
473
            }
457
474
            break;
458
475
        case GIMP_PDB_REGION:
459
476
            check(!PySequence_Check(item) ||
471
488
            break;
472
489
        case GIMP_PDB_DISPLAY:
473
490
            check(!pygimp_display_check(item));
474
 
            ret[i].data.d_display=((PyGimpDisplay *)item)->ID;
 
491
            ret[i].data.d_display = ((PyGimpDisplay *)item)->ID;
475
492
            break;
476
493
        case GIMP_PDB_IMAGE:
477
494
            if (item == Py_None) {
479
496
                break;
480
497
            }
481
498
            check(!pygimp_image_check(item));
482
 
            ret[i].data.d_image=((PyGimpImage *)item)->ID;
 
499
            ret[i].data.d_image = ((PyGimpImage *)item)->ID;
483
500
            break;
484
501
        case GIMP_PDB_LAYER:
485
502
            if (item == Py_None) {
487
504
                break;
488
505
            }
489
506
            check(!pygimp_layer_check(item));
490
 
            ret[i].data.d_layer=((PyGimpLayer *)item)->ID;
 
507
            ret[i].data.d_layer = ((PyGimpLayer *)item)->ID;
491
508
            break;
492
509
        case GIMP_PDB_CHANNEL:
493
510
            if (item == Py_None) {
495
512
                break;
496
513
            }
497
514
            check(!pygimp_channel_check(item));
498
 
            ret[i].data.d_channel=((PyGimpChannel *)item)->ID;
 
515
            ret[i].data.d_channel = ((PyGimpChannel *)item)->ID;
499
516
            break;
500
517
        case GIMP_PDB_DRAWABLE:
501
518
            if (item == Py_None) {
503
520
                break;
504
521
            }
505
522
            check(!pygimp_drawable_check(item));
506
 
            ret[i].data.d_channel=((PyGimpDrawable *)item)->ID;
 
523
            ret[i].data.d_channel = ((PyGimpDrawable *)item)->ID;
507
524
            break;
508
525
        case GIMP_PDB_SELECTION:
509
526
            check(!pygimp_layer_check(item));
510
 
            ret[i].data.d_selection=((PyGimpLayer *)item)->ID;
 
527
            ret[i].data.d_selection = ((PyGimpLayer *)item)->ID;
511
528
            break;
512
529
        case GIMP_PDB_BOUNDARY:
513
530
            check(!PyInt_Check(item));
514
531
            ret[i].data.d_boundary = PyInt_AsLong(item);
515
532
            break;
516
 
        case GIMP_PDB_PATH:
517
 
            check(!PyInt_Check(item));
518
 
            ret[i].data.d_path = PyInt_AsLong(item);
 
533
        case GIMP_PDB_VECTORS:
 
534
            check(!pygimp_vectors_check(item));
 
535
            ret[i].data.d_vectors = ((PyGimpVectors *)item)->ID;
519
536
            break;
520
537
        case GIMP_PDB_PARASITE:
521
538
            /* can't do anything, since size of GimpParasite is not known */
545
562
    int num, i;
546
563
    char **names;
547
564
    PyObject *ret;
 
565
 
548
566
    if (!PyArg_ParseTuple(args, "|zzzzzzz:gimp.pdb.query", &n, &b, &h, &a,
549
567
                          &c, &d, &t))
550
568
        return NULL;
 
569
 
551
570
    gimp_procedural_db_query(n, b, h, a, c, d, t, &num, &names);
 
571
 
552
572
    ret = PyList_New(num);
 
573
 
553
574
    for (i = 0; i < num; i++)
554
575
        PyList_SetItem(ret, i, PyString_FromString(names[i]));
 
576
 
555
577
    g_free(names);
 
578
 
556
579
    return ret;
557
580
}
558
581
 
570
593
    PyGimpPDB *self;
571
594
        
572
595
    self = PyObject_NEW(PyGimpPDB, &PyGimpPDB_Type);
 
596
 
573
597
    if (self == NULL)
574
598
        return NULL;
 
599
 
575
600
    return (PyObject *)self;
576
601
}
577
602
 
599
624
        PyErr_SetString(PyExc_TypeError, "Subscript must be a string");
600
625
        return NULL;
601
626
    }
 
627
 
602
628
    r = (PyObject *)pygimp_pdb_function_new_from_proc_db(PyString_AsString(key));
 
629
 
603
630
    if (r == NULL) {
604
631
        PyErr_Clear();
605
632
        PyErr_SetObject(PyExc_KeyError, key);
606
633
    }
 
634
 
607
635
    return r;
608
636
}
609
637
 
621
649
    PyObject *ret;
622
650
 
623
651
    ret = PyObject_GenericGetAttr((PyObject *)self, attr);
 
652
 
624
653
    if (ret)
625
654
        return ret;
 
655
 
626
656
    PyErr_Clear();
 
657
 
627
658
    return pygimp_pdb_function_new_from_proc_db(PyString_AsString(attr));
628
659
}
629
660
 
700
731
pf_dealloc(PyGimpPDBFunction *self)
701
732
{
702
733
    g_free(self->name);
 
734
 
703
735
    Py_DECREF(self->proc_name);
704
736
    Py_DECREF(self->proc_blurb);
705
737
    Py_DECREF(self->proc_help);
709
741
    Py_DECREF(self->proc_type);
710
742
    Py_DECREF(self->py_params);
711
743
    Py_DECREF(self->py_return_vals);
 
744
 
712
745
    gimp_destroy_paramdefs(self->params, self->nparams);
713
746
    gimp_destroy_paramdefs(self->return_vals, self->nreturn_vals);
 
747
 
714
748
    PyObject_DEL(self);
715
749
}
716
750
 
746
780
    PyObject *t = NULL, *r;
747
781
 
748
782
#if PG_DEBUG > 0
749
 
    fprintf(stderr, "--- %s --- ", PyString_AsString(self->proc_name));
 
783
    g_printerr("--- %s --- ", PyString_AsString(self->proc_name));
750
784
#endif
751
 
    if (self->nparams > 0 && !strcmp(self->params[0].name, "run_mode")) {
752
 
        params = pygimp_param_from_tuple(args, self->params+1, self->nparams-1);
 
785
 
 
786
    if (self->nparams > 0 && !strcmp(self->params[0].name, "run-mode")) {
 
787
        params = pygimp_param_from_tuple(args, self->params + 1,
 
788
                                         self->nparams - 1);
 
789
 
753
790
        if (params == NULL)
754
791
            return NULL;
 
792
 
755
793
        params[0].type = self->params[0].type;
756
794
        params[0].data.d_int32 = GIMP_RUN_NONINTERACTIVE;
 
795
 
757
796
#if PG_DEBUG > 1
758
797
        pygimp_param_print(self->nparams, params);
759
798
#endif
 
799
 
760
800
        ret = gimp_run_procedure2(self->name, &nret, self->nparams,
761
801
                                  params);
762
802
    } else {
763
803
        params = pygimp_param_from_tuple(args, self->params, self->nparams);
 
804
 
764
805
        if (params == NULL)
765
806
            return NULL;
 
807
 
766
808
#if PG_DEBUG > 1
767
809
        pygimp_param_print(self->nparams, params+1);
768
810
#endif
769
 
        ret = gimp_run_procedure2(self->name, &nret, self->nparams,
770
 
                                  params+1);
 
811
 
 
812
        ret = gimp_run_procedure2(self->name, &nret, self->nparams, params + 1);
771
813
    }
 
814
 
772
815
    gimp_destroy_params(params, self->nparams);
 
816
 
773
817
    if (!ret) {
774
818
        PyErr_SetString(pygimp_error, "no status returned");
775
819
#if PG_DEBUG >= 1
776
 
        fprintf(stderr, "ret == NULL\n");
 
820
        g_printerr("ret == NULL\n");
777
821
#endif
778
822
        return NULL;
779
823
    }
 
824
 
780
825
    switch(ret[0].data.d_status) {
781
826
    case GIMP_PDB_EXECUTION_ERROR:
782
827
#if PG_DEBUG > 0
783
 
        fprintf(stderr, "execution error\n");
 
828
        g_printerr("execution error\n");
784
829
#endif
785
830
        gimp_destroy_params(ret, nret);
786
831
        PyErr_SetString(PyExc_RuntimeError, "execution error");
787
832
        return NULL;
788
833
        break;
 
834
 
789
835
    case GIMP_PDB_CALLING_ERROR:
790
836
#if PG_DEBUG > 0
791
 
        fprintf(stderr, "calling error\n");
 
837
        g_printerr("calling error\n");
792
838
#endif
793
839
        gimp_destroy_params(ret, nret);
794
840
        PyErr_SetString(PyExc_TypeError, "invalid arguments");
795
841
        return NULL;
796
842
        break;
 
843
 
797
844
    case GIMP_PDB_SUCCESS:
798
845
#if PG_DEBUG > 0
799
 
        fprintf(stderr, "success\n");
 
846
        g_printerr("success\n");
800
847
#endif
801
848
        t = pygimp_param_to_tuple(nret-1, ret+1);
802
849
        gimp_destroy_params(ret, nret);
 
850
 
803
851
        if (t == NULL) {
804
 
            PyErr_SetString(pygimp_error,
805
 
                            "couldn't make return value");
 
852
            PyErr_SetString(pygimp_error, "could not make return value");
806
853
            return NULL;
807
854
        }
808
855
        break;
 
856
 
809
857
    default:
810
858
#if PG_DEBUG > 0
811
 
        fprintf(stderr, "unknown - %i (type %i)\n",
812
 
                ret[0].data.d_status, ret[0].type);
 
859
        g_printerr("unknown - %i (type %i)\n",
 
860
                   ret[0].data.d_status, ret[0].type);
813
861
#endif
814
862
        PyErr_SetString(pygimp_error, "unknown return code");
815
863
        return NULL;
816
864
        break;
817
865
    }
 
866
 
818
867
    if (PyTuple_Size(t) == 1) {
819
868
        r = PyTuple_GetItem(t, 0);
820
869
        Py_INCREF(r);
821
870
        Py_DECREF(t);
822
871
        return r;
823
872
    }
 
873
 
824
874
    if (PyTuple_Size(t) == 0) {
825
875
        r = Py_None;
826
876
        Py_INCREF(r);
827
877
        Py_DECREF(t);
828
878
        return r;
829
879
    }
 
880
 
830
881
    return t;
831
882
}
832
883
 
885
936
    int i;
886
937
 
887
938
    self = PyObject_NEW(PyGimpPDBFunction, &PyGimpPDBFunction_Type);
 
939
 
888
940
    if (self == NULL)
889
941
        return NULL;
890
942
 
916
968
                                      return_vals[i].type,
917
969
                                      return_vals[i].name,
918
970
                                      return_vals[i].description));
 
971
 
919
972
    return (PyObject *)self;
920
973
}