Skip to content
Permalink
Browse files

Update C++ binding and function list

The generators use the new Introspect class of pyvips.
  • Loading branch information
kleisauke committed Nov 29, 2019
1 parent d88ce97 commit 2499b38403db3f196ffb1886d41be33b8ac67de7
@@ -596,20 +596,20 @@ VImage::new_from_buffer( const std::string &buf, const char *option_string,
}

VImage
VImage::new_from_stream( const VStreamI &input, const char *option_string,
VImage::new_from_stream( VStreamI streami, const char *option_string,
VOption *options )
{
const char *operation_name;
VImage out;

if( !(operation_name = vips_foreign_find_load_stream(
input.get_stream() )) ) {
streami.get_stream() )) ) {
delete options;
throw( VError() );
}

options = (options ? options : VImage::option())->
set( "input", input )->
set( "streami", streami )->
set( "out", &out );

call_option_string( operation_name, option_string, options );
@@ -702,7 +702,7 @@ VImage::write_to_buffer( const char *suffix, void **buf, size_t *size,
}

void
VImage::write_to_stream( const char *suffix, const VStreamO &output,
VImage::write_to_stream( const char *suffix, VStreamO streamo,
VOption *options ) const
{
char filename[VIPS_PATH_MAX];
@@ -718,7 +718,7 @@ VImage::write_to_stream( const char *suffix, const VStreamO &output,
call_option_string( operation_name, option_string,
(options ? options : VImage::option())->
set( "in", *this )->
set( "output", output ) );
set( "streamo", streamo ) );
}

#include "vips-operators.cpp"
@@ -25,7 +25,7 @@

import argparse

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

# TODO Move to pyvips.GValue
@@ -41,8 +41,8 @@
GValue.refstr_type: 'char *',
GValue.gflags_type: 'int',
GValue.image_type: 'VImage',
stream_input_type: 'const VStreamI &',
stream_output_type: 'const VStreamO &',
stream_input_type: 'VStreamI',
stream_output_type: 'VStreamO',
GValue.array_int_type: 'std::vector<int>',
GValue.array_double_type: 'std::vector<double>',
GValue.array_image_type: 'std::vector<VImage>',
@@ -87,66 +87,42 @@ def cppize(name):


def generate_operation(operation_name, declaration_only=False):
op = Operation.new_from_name(operation_name)

# we are only interested in non-deprecated args
args = [[name, flags] for name, flags in op.get_args()
if not flags & _DEPRECATED]

# find the first required input image arg, if any ... that will be self
member_x = None
for name, flags in args:
if ((flags & _INPUT) != 0 and
(flags & _REQUIRED) != 0 and
op.get_typeof(name) == GValue.image_type):
member_x = name
break

required_input = [name for name, flags in args
if (flags & _INPUT) != 0 and
(flags & _REQUIRED) != 0 and
name != member_x]

required_output = [name for name, flags in args
if ((flags & _OUTPUT) != 0 and
(flags & _REQUIRED) != 0) or
((flags & _INPUT) != 0 and
(flags & _REQUIRED) != 0 and
(flags & _MODIFY) != 0) and
name != member_x]
intro = Introspect.get(operation_name)

required_output = [name for name in intro.required_output if name != intro.member_x]

has_output = len(required_output) >= 1

# Add a C++ style comment block with some additional markings (@param,
# Add a C++ style comment block with some additional markings (@param,
# @return)
if declaration_only:
result = '\n/**\n * {}.'.format(op.get_description().capitalize())
result = '\n/**\n * {}.'.format(intro.description.capitalize())

for name in required_input:
for name in intro.method_args:
result += '\n * @param {} {}.' \
.format(cppize(name), op.get_blurb(name))
.format(cppize(name), intro.details[name]['blurb'])

if has_output:
# skip the first element
for name in required_output[1:]:
result += '\n * @param {} {}.' \
.format(cppize(name), op.get_blurb(name))
.format(cppize(name), intro.details[name]['blurb'])

result += '\n * @param options Optional options.'

if has_output:
result += '\n * @return {}.' \
.format(op.get_blurb(required_output[0]))
.format(intro.details[required_output[0]]['blurb'])

result += '\n */\n'
else:
result = '\n'

if member_x is None and declaration_only:
if intro.member_x is None and declaration_only:
result += 'static '
if has_output:
# the first output arg will be used as the result
cpp_type = get_cpp_type(op.get_typeof(required_output[0]))
cpp_type = get_cpp_type(intro.details[required_output[0]]['type'])
spacing = '' if cpp_type.endswith(cplusplus_suffixes) else ' '
result += '{0}{1}'.format(cpp_type, spacing)
else:
@@ -160,8 +136,9 @@ def generate_operation(operation_name, declaration_only=False):
cplusplus_operation += '_image'

result += '{0}( '.format(cplusplus_operation)
for name in required_input:
gtype = op.get_typeof(name)
for name in intro.method_args:
details = intro.details[name]
gtype = details['type']
cpp_type = get_cpp_type(gtype)
spacing = '' if cpp_type.endswith(cplusplus_suffixes) else ' '
result += '{0}{1}{2}, '.format(cpp_type, spacing, cppize(name))
@@ -170,15 +147,16 @@ def generate_operation(operation_name, declaration_only=False):
if has_output:
# skip the first element
for name in required_output[1:]:
gtype = op.get_typeof(name)
details = intro.details[name]
gtype = details['type']
cpp_type = get_cpp_type(gtype)
spacing = '' if cpp_type.endswith(cplusplus_suffixes) else ' '
result += '{0}{1}*{2}, '.format(cpp_type, spacing, cppize(name))

result += 'VOption *options {0})'.format('= 0 ' if declaration_only else '')

# if no 'this' available, it's a class method and they are all const
if member_x is not None:
if intro.member_x is not None:
result += ' const'

if declaration_only:
@@ -191,17 +169,17 @@ def generate_operation(operation_name, declaration_only=False):
if has_output:
# the first output arg will be used as the result
name = required_output[0]
cpp_type = get_cpp_type(op.get_typeof(name))
cpp_type = get_cpp_type(intro.details[name]['type'])
spacing = '' if cpp_type.endswith(cplusplus_suffixes) else ' '
result += ' {0}{1}{2};\n\n'.format(cpp_type, spacing, cppize(name))

result += ' call( "{0}",\n'.format(operation_name)
result += ' (options ? options : VImage::option())'
if member_x is not None:
if intro.member_x is not None:
result += '->\n'
result += ' set( "{0}", *this )'.format(member_x)
result += ' set( "{0}", *this )'.format(intro.member_x)

all_required = required_input
all_required = intro.method_args

if has_output:
# first element needs to be passed by reference
@@ -236,10 +214,10 @@ def add_nickname(gtype, a, b):
nickname = nickname_find(gtype)
try:
# can fail for abstract types
op = Operation.new_from_name(nickname)
intro = Introspect.get(nickname)

# we are only interested in non-deprecated operations
if (op.get_flags() & _OPERATION_DEPRECATED) == 0:
if (intro.flags & _OPERATION_DEPRECATED) == 0:
all_nicknames.append(nickname)
except Error:
pass
@@ -514,7 +514,7 @@ class VImage : VObject
static VImage new_from_buffer( const std::string &buf,
const char *option_string, VOption *options = 0 );

static VImage new_from_stream( const VStreamI &input,
static VImage new_from_stream( VStreamI streami,
const char *option_string, VOption *options = 0 );

static VImage new_matrix( int width, int height );
@@ -569,8 +569,8 @@ class VImage : VObject
void write_to_buffer( const char *suffix, void **buf, size_t *size,
VOption *options = 0 ) const;

void write_to_stream( const char *suffix,
const VStreamO &output, VOption *options = 0 ) const;
void write_to_stream( const char *suffix, VStreamO streamo,
VOption *options = 0 ) const;

void *
write_to_memory( size_t *size ) const
@@ -1,5 +1,5 @@
// headers for vips operations
// Mon 11 Nov 09:21:14 GMT 2019
// Fri 29 Nov 2019 02:46:41 PM CET
// this file is generated automatically, do not edit!

/**
@@ -1039,11 +1039,11 @@ static VImage jpegload_buffer( VipsBlob *buffer, VOption *options = 0 );

/**
* Load image from jpeg stream.
* @param input Stream to load from.
* @param streami Stream to load from.
* @param options Optional options.
* @return Output image.
*/
static VImage jpegload_stream( const VStreamI &input, VOption *options = 0 );
static VImage jpegload_stream( VStreamI streami, VOption *options = 0 );

/**
* Save image to jpeg file.
@@ -1070,7 +1070,7 @@ void jpegsave_mime( VOption *options = 0 ) const;
* @param streamo Stream to save to.
* @param options Optional options.
*/
void jpegsave_stream( const VStreamO &streamo, VOption *options = 0 ) const;
void jpegsave_stream( VStreamO streamo, VOption *options = 0 ) const;

/**
* Label regions in an image.
@@ -1521,7 +1521,7 @@ static VImage pngload_buffer( VipsBlob *buffer, VOption *options = 0 );
* @param options Optional options.
* @return Output image.
*/
static VImage pngload_stream( const VStreamI &streami, VOption *options = 0 );
static VImage pngload_stream( VStreamI streami, VOption *options = 0 );

/**
* Save image to png file.
@@ -1542,7 +1542,7 @@ VipsBlob *pngsave_buffer( VOption *options = 0 ) const;
* @param streamo Stream to save to.
* @param options Optional options.
*/
void pngsave_stream( const VStreamO &streamo, VOption *options = 0 ) const;
void pngsave_stream( VStreamO streamo, VOption *options = 0 ) const;

/**
* Load ppm from file.
@@ -1627,7 +1627,7 @@ static VImage radload_buffer( VipsBlob *buffer, VOption *options = 0 );
* @param options Optional options.
* @return Output image.
*/
static VImage radload_stream( const VStreamI &streami, VOption *options = 0 );
static VImage radload_stream( VStreamI streami, VOption *options = 0 );

/**
* Save image to radiance file.
@@ -1648,7 +1648,7 @@ VipsBlob *radsave_buffer( VOption *options = 0 ) const;
* @param streamo Stream to save to.
* @param options Optional options.
*/
void radsave_stream( const VStreamO &streamo, VOption *options = 0 ) const;
void radsave_stream( VStreamO streamo, VOption *options = 0 ) const;

/**
* Rank filter.
@@ -1998,7 +1998,7 @@ static VImage svgload_buffer( VipsBlob *buffer, VOption *options = 0 );
* @param options Optional options.
* @return Output image.
*/
static VImage svgload_stream( const VStreamI &streami, VOption *options = 0 );
static VImage svgload_stream( VStreamI streami, VOption *options = 0 );

/**
* Find the index of the first non-zero pixel in tests.
@@ -2056,7 +2056,7 @@ VImage thumbnail_image( int width, VOption *options = 0 ) const;
* @param options Optional options.
* @return Output image.
*/
static VImage thumbnail_stream( const VStreamI &streami, int width, VOption *options = 0 );
static VImage thumbnail_stream( VStreamI streami, int width, VOption *options = 0 );

/**
* Load tiff from file.
@@ -2080,7 +2080,7 @@ static VImage tiffload_buffer( VipsBlob *buffer, VOption *options = 0 );
* @param options Optional options.
* @return Output image.
*/
static VImage tiffload_stream( const VStreamI &streami, VOption *options = 0 );
static VImage tiffload_stream( VStreamI streami, VOption *options = 0 );

/**
* Save image to tiff file.
@@ -2161,7 +2161,7 @@ static VImage webpload_buffer( VipsBlob *buffer, VOption *options = 0 );
* @param options Optional options.
* @return Output image.
*/
static VImage webpload_stream( const VStreamI &streami, VOption *options = 0 );
static VImage webpload_stream( VStreamI streami, VOption *options = 0 );

/**
* Save image to webp file.
@@ -2182,7 +2182,7 @@ VipsBlob *webpsave_buffer( VOption *options = 0 ) const;
* @param streamo Stream to save to.
* @param options Optional options.
*/
void webpsave_stream( const VStreamO &streamo, VOption *options = 0 ) const;
void webpsave_stream( VStreamO streamo, VOption *options = 0 ) const;

/**
* Make a worley noise image.

0 comments on commit 2499b38

Please sign in to comment.
You can’t perform that action at this time.