2021-11-15 12:17:36 +01:00
|
|
|
#!/usr/bin/python3
|
2015-01-02 13:39:20 +01:00
|
|
|
|
2019-04-24 16:02:52 +02:00
|
|
|
# walk vips and generate a list of all operators and their descriptions
|
2015-01-02 13:39:20 +01:00
|
|
|
# for docs
|
|
|
|
|
2019-04-24 16:02:52 +02:00
|
|
|
# this needs pyvips
|
|
|
|
#
|
|
|
|
# pip install --user pyvips
|
|
|
|
|
2015-01-02 13:39:20 +01:00
|
|
|
# sample output:
|
|
|
|
|
|
|
|
# <row>
|
|
|
|
# <entry>gamma</entry>
|
2019-04-24 16:02:52 +02:00
|
|
|
# <entry>Gamma an image</entry>
|
2015-01-02 13:39:20 +01:00
|
|
|
# <entry>vips_gamma()</entry>
|
|
|
|
# </row>
|
|
|
|
|
2019-11-29 14:51:03 +01:00
|
|
|
from pyvips import Introspect, Operation, Error, \
|
2019-04-24 16:02:52 +02:00
|
|
|
ffi, type_map, type_from_name, nickname_find
|
2015-01-02 13:39:20 +01:00
|
|
|
|
2019-04-24 16:02:52 +02:00
|
|
|
# for VipsOperationFlags
|
|
|
|
_OPERATION_DEPRECATED = 8
|
2015-01-02 13:39:20 +01:00
|
|
|
|
|
|
|
|
2020-01-01 12:28:18 +01:00
|
|
|
def gen_function(operation_name, overloads):
|
2019-11-29 14:51:03 +01:00
|
|
|
intro = Introspect.get(operation_name)
|
2015-01-02 13:39:20 +01:00
|
|
|
|
2020-01-01 12:28:18 +01:00
|
|
|
c_operations = 'vips_{}()'.format(operation_name)
|
|
|
|
|
|
|
|
if overloads:
|
|
|
|
c_operations += ', ' + (', '.join('vips_{}()'.format(n) for n in overloads))
|
|
|
|
|
2019-11-29 14:51:03 +01:00
|
|
|
result = '<row>\n'
|
|
|
|
result += ' <entry>{}</entry>\n'.format(operation_name)
|
|
|
|
result += ' <entry>{}</entry>\n'.format(intro.description.capitalize())
|
2020-01-01 12:28:18 +01:00
|
|
|
result += ' <entry>{}</entry>\n'.format(c_operations)
|
2019-11-29 14:51:03 +01:00
|
|
|
result += '</row>'
|
|
|
|
|
|
|
|
return result
|
2015-01-02 13:39:20 +01:00
|
|
|
|
|
|
|
|
2019-04-24 16:02:52 +02:00
|
|
|
def gen_function_list():
|
|
|
|
all_nicknames = []
|
2015-01-02 13:39:20 +01:00
|
|
|
|
2019-04-24 16:02:52 +02:00
|
|
|
def add_nickname(gtype, a, b):
|
|
|
|
nickname = nickname_find(gtype)
|
|
|
|
try:
|
|
|
|
# can fail for abstract types
|
2019-11-29 14:51:03 +01:00
|
|
|
intro = Introspect.get(nickname)
|
2019-04-24 16:02:52 +02:00
|
|
|
|
|
|
|
# we are only interested in non-deprecated operations
|
2019-11-29 14:51:03 +01:00
|
|
|
if (intro.flags & _OPERATION_DEPRECATED) == 0:
|
2019-04-24 16:02:52 +02:00
|
|
|
all_nicknames.append(nickname)
|
|
|
|
except Error:
|
|
|
|
pass
|
|
|
|
|
|
|
|
type_map(gtype, add_nickname)
|
|
|
|
|
|
|
|
return ffi.NULL
|
|
|
|
|
|
|
|
type_map(type_from_name('VipsOperation'), add_nickname)
|
2015-01-02 13:39:20 +01:00
|
|
|
|
2019-04-24 16:02:52 +02:00
|
|
|
# make list unique and sort
|
|
|
|
all_nicknames = list(set(all_nicknames))
|
|
|
|
all_nicknames.sort()
|
|
|
|
|
2019-11-29 14:51:03 +01:00
|
|
|
# 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'],
|
2020-01-01 12:28:18 +01:00
|
|
|
'draw_flood': ['draw_flood1'],
|
2019-11-29 14:51:03 +01:00
|
|
|
'draw_line': ['draw_line1'],
|
|
|
|
'draw_mask': ['draw_mask1'],
|
2020-01-01 12:28:18 +01:00
|
|
|
'draw_rect': ['draw_rect1', 'draw_point', 'draw_point1'],
|
2019-11-29 14:51:03 +01:00
|
|
|
'extract_area': ['crop'],
|
|
|
|
'linear': ['linear1'],
|
2021-11-02 16:05:37 +01:00
|
|
|
'math': ['sin', 'cos', 'tan', 'asin', 'acos', 'atan', 'sinh', 'cosh', 'tanh', 'asinh', 'acosh', 'atanh', 'exp', 'exp10', 'log', 'log10'],
|
2021-06-18 11:14:02 +02:00
|
|
|
'math2': ['pow', 'wop', 'atan2'],
|
2019-11-29 14:51:03 +01:00
|
|
|
'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']]
|
|
|
|
|
2019-04-24 16:02:52 +02:00
|
|
|
for nickname in all_nicknames:
|
2020-01-01 12:28:18 +01:00
|
|
|
result = gen_function(nickname, overloads[nickname] if nickname in overloads else None)
|
2019-11-29 14:51:03 +01:00
|
|
|
print(result)
|
2019-04-24 16:02:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
gen_function_list()
|