add VInterpolate wrapper class

to cplusplus, see https://github.com/jcupitt/libvips/issues/230
This commit is contained in:
John Cupitt 2015-01-30 21:19:58 +00:00
parent 230a939521
commit ce557ba6de
8 changed files with 202 additions and 0 deletions

View File

@ -14,6 +14,7 @@
- rename vipsthumbnail -o as -f, -o stays as a hidden flag
- fix some small leaks
- faster openslide load, thanks Benjamin
- add VInterpolate class to cplusplus binding, thanks Lovell
24/12/14 started 7.42.1
- add gobject-2.0 to Requires: in vips and vips-cpp .pc files

View File

@ -10,6 +10,7 @@ lib_LTLIBRARIES = libvips-cpp.la
libvips_cpp_la_SOURCES = \
VImage.cpp \
VInterpolate.cpp \
VError.cpp
libvips_cpp_la_LDFLAGS = \

View File

@ -0,0 +1,77 @@
/* Object part of VInterpolate class
*/
/*
Copyright (C) 1991-2001 The National Gallery
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
/*
These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /*HAVE_CONFIG_H*/
#include <vips/intl.h>
#include <vips/vips8>
#include <vips/debug.h>
/*
#define VIPS_DEBUG
#define VIPS_DEBUG_VERBOSE
*/
VIPS_NAMESPACE_START
VInterpolate
VInterpolate::new_from_name( const char *name, VOption *options )
throw( VError )
{
VipsInterpolate *interp;
if( !(interp = vips_interpolate_new( name )) ) {
delete options;
throw VError();
}
delete options;
VInterpolate out( interp );
return( out );
}
VOption *
VOption::set( const char *name, VInterpolate value )
{
Pair *pair = new Pair( name );
pair->input = true;
g_value_init( &pair->value, VIPS_TYPE_INTERPOLATE );
g_value_set_object( &pair->value, value.get_interpolate() );
options.push_back( pair );
return( this );
}
VIPS_NAMESPACE_END

View File

@ -0,0 +1,54 @@
/*
* compile with:
*
* g++ -g -Wall resize.cpp `pkg-config vips-cpp --cflags --libs`
*
*/
#define DEBUG
#include <vips/vips8>
using namespace vips;
int
main( int argc, char **argv )
{
GOptionContext *context;
GOptionGroup *main_group;
GError *error = NULL;
if( vips_init( argv[0] ) )
vips_error_exit( NULL );
context = g_option_context_new( "" );
main_group = g_option_group_new( NULL, NULL, NULL, NULL, NULL );
g_option_context_set_main_group( context, main_group );
g_option_context_add_group( context, vips_get_option_group() );
if( !g_option_context_parse( context, &argc, &argv, &error ) ) {
if( error ) {
fprintf( stderr, "%s\n", error->message );
g_error_free( error );
}
vips_error_exit( NULL );
}
{
VImage in = VImage::new_from_file( argv[1],
VImage::option()->set( "access", VIPS_ACCESS_SEQUENTIAL ) );
VInterpolate interp = VInterpolate::new_from_name( "nohalo" );
VImage out;
out = in.resize( 0.2, VImage::option()->set( "interpolate", interp ) );
out.write_to_file( argv[2] );
}
vips_shutdown();
return( 0 );
}

View File

@ -1,6 +1,7 @@
pkginclude_HEADERS = \
VError8.h \
VImage8.h \
VInterpolate8.h \
vips8 \
vips-operators.h

View File

@ -163,6 +163,7 @@ public:
};
class VImage;
class VInterpolate;
class VOption;
class VOption
@ -215,6 +216,7 @@ public:
VOption *set( const char *name, double value );
VOption *set( const char *name, const char *value );
VOption *set( const char *name, VImage value );
VOption *set( const char *name, VInterpolate value );
VOption *set( const char *name, std::vector<VImage> value );
VOption *set( const char *name, std::vector<double> value );
VOption *set( const char *name, VipsBlob *value );

View File

@ -0,0 +1,65 @@
// VIPS interpolate wrapper
/*
This file is part of VIPS.
VIPS is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
/*
These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
*/
#ifndef VIPS_VINTERPOLATE_H
#define VIPS_VINTERPOLATE_H
#include <list>
#include <complex>
#include <vector>
#include <string.h>
#include <vips/vips.h>
VIPS_NAMESPACE_START
class VInterpolate : VObject
{
public:
VInterpolate( VipsInterpolate *interpolate, VSteal steal = STEAL ) :
VObject( (VipsObject *) interpolate, steal )
{
}
static
VInterpolate new_from_name( const char *name, VOption *options = 0 )
throw( VError );
VipsInterpolate *
get_interpolate()
{
return( (VipsInterpolate *) VObject::get_object() );
}
};
VIPS_NAMESPACE_END
#endif /*VIPS_VIMAGE_H*/

View File

@ -39,5 +39,6 @@
#include "VError8.h"
#include "VImage8.h"
#include "VInterpolate8.h"
#endif /*VIPS_CPLUSPLUS*/