File: gen-function-list.py

package info (click to toggle)
vips 8.17.3-2
  • links: PTS
  • area: main
  • in suites: sid
  • size: 52,228 kB
  • sloc: ansic: 169,684; cpp: 12,156; python: 4,887; sh: 733; perl: 40; makefile: 25; javascript: 6
file content (169 lines) | stat: -rwxr-xr-x 5,165 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/usr/bin/env python3

# walk vips and generate a list of all operators and their descriptions
# for docs

# this needs pyvips
#   pip install --user pyvips

# rebuild with:
#   ./gen-function-list.py > function-list.md

# sample output:
# | `gamma` | Gamma an image | [method@Image.gamma] |

from pyvips import Introspect, Operation, Error, \
    ffi, type_map, type_from_name, nickname_find

# for VipsOperationFlags
_OPERATION_DEPRECATED = 8


def gen_function(operation_name, overloads):
    intro = Introspect.get(operation_name)

    # Keep-in-sync with fixup-gir-for-doc.py
    image_funcs = [
        'arrayjoin',
        'bandjoin',
        'bandrank',
        'composite',
        'sum',
        'switch',
    ]

    if operation_name in image_funcs:
        c_operations = f'[func@Image.{operation_name}]'
    else:
        operation_type = 'ctor' if intro.member_x is None else 'method'
        operation_class = 'Blob' if operation_name == 'profile_load' else 'Image'
        c_operations = f'[{operation_type}@{operation_class}.{operation_name}]'

    if overloads:
        c_operations += ', ' + (', '.join(f'[method@Image.{n}]' for n in overloads))

    result = f"| `{operation_name}` | {intro.description.capitalize()} | {c_operations} |"

    return result


def gen_function_list():
    all_nicknames = []

    def add_nickname(gtype, a, b):
        nickname = nickname_find(gtype)
        try:
            # can fail for abstract types
            intro = Introspect.get(nickname)

            # we are only interested in non-deprecated operations
            if (intro.flags & _OPERATION_DEPRECATED) == 0:
                all_nicknames.append(nickname)
        except Error:
            pass

        type_map(gtype, add_nickname)

        return ffi.NULL

    type_map(type_from_name('VipsOperation'), add_nickname)

    # make list unique and sort
    all_nicknames = list(set(all_nicknames))
    all_nicknames.sort()

    # make dict with overloads
    overloads = {
        'bandbool': ['bandand', 'bandor', 'bandeor', 'bandmean'],
        'bandjoin': ['bandjoin2'],
        'bandjoin_const': ['bandjoin_const1'],
        'boolean': ['andimage', 'orimage', 'eorimage', 'lshift', 'rshift'],
        'cast': ['cast_uchar', 'cast_char', 'cast_ushort', 'cast_short',
            'cast_uint', 'cast_int', 'cast_float', 'cast_double', 
            'cast_complex', 'cast_dpcomplex'],
        'complex': ['polar', 'rect', 'conj'],
        'complex2': ['cross_phase'],
        'complexget': ['real', 'imag'],
        'draw_circle': ['draw_circle1'],
        'draw_flood': ['draw_flood1'],
        'draw_line': ['draw_line1'],
        'draw_mask': ['draw_mask1'],
        'draw_rect': ['draw_rect1', 'draw_point', 'draw_point1'],
        'extract_area': ['crop'],
        'linear': ['linear1'],
        'math': ['sin', 'cos', 'tan', 'asin', 'acos', 'atan', 'sinh', 
            'cosh', 'tanh', 'asinh', 'acosh', 'atanh', 'exp', 'exp10', 
            'log', 'log10'],
        'math2': ['pow', 'wop', 'atan2'],
        'rank': ['median'],
        'relational': ['equal', 'notequal', 'less', 'lesseq', 'more', 'moreeq'],
        'remainder_const': ['remainder_const1'],
        'round': ['floor', 'ceil', 'rint'],
    }

    overloads['boolean_const'] = \
            [o + '_const' for o in overloads['boolean']] \
            + ['boolean_const1'] \
            + [o + '_const1' for o in overloads['boolean']]

    overloads['math2_const'] = \
            [o + '_const' for o in overloads['boolean']] \
            + ['math2_const1'] \
            + [o + '_const1' for o in overloads['boolean']]

    overloads['relational_const'] = \
            [o + '_const' for o in overloads['relational']] \
            + ['relational_const1'] \
            + [o + '_const1' for o in overloads['relational']]

    for nickname in all_nicknames:
        result = gen_function(nickname, 
                overloads[nickname] if nickname in overloads else None)
        print(result)


if __name__ == '__main__':
    print("""Title: Operator index / Alphabetical

libvips has a set of operators, each of which computes some useful image
processing operation. Each operator is implemented as a [class@GObject.Object]
class, for example `VipsGamma`. Classes are identified by their unique
[property@VipsObject:nickname], in this case `gamma`.

From the command-line, C++ and most language bindings, you use the nickname
to call the operator. For example in C++:

```c++
vips::VImage fred = ...;
vips::VImage jim = fred.gamma();
```

or Python:

```python
fred = jim.gamma()
```

libvips has a set of C wrapper functions for calling operators, in this
case [method@Image.gamma]:

```c
VipsImage *fred = ...;
VipsImage *jim;

if (vips_gamma(fred, &jim, NULL))
    ...error;
```

Some operators have many C convenience functions.

# All libvips operators

This table lists all the libvips operators with their C convenience functions
and a short description. It's supposed to be useful for searching. See the
API docs each function links to for more details.

| Operator | Description | C functions |
| -------- | ----------- | ----------- |""")

    gen_function_list()