88 lines
2.1 KiB
XML
88 lines
2.1 KiB
XML
|
<?xml version="1.0"?>
|
||
|
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
|
||
|
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
|
||
|
]>
|
||
|
<refentry id="using-from-cpp">
|
||
|
<refmeta>
|
||
|
<refentrytitle>VIPS from C++</refentrytitle>
|
||
|
<manvolnum>3</manvolnum>
|
||
|
<refmiscinfo>VIPS Library</refmiscinfo>
|
||
|
</refmeta>
|
||
|
|
||
|
<refnamediv>
|
||
|
<refname>Using VIPS</refname>
|
||
|
<refpurpose>How to use the VIPS library from C++</refpurpose>
|
||
|
</refnamediv>
|
||
|
|
||
|
<refsect1 id="using-cpp">
|
||
|
<title>Using VIPS from C++</title>
|
||
|
<para>
|
||
|
VIPS comes with a convenient C++ API. It is a very thin wrapper over the
|
||
|
C API and provides automatic reference counting, exceptions, operator
|
||
|
overloads, and automatic constant expansion. You can drop down to the C
|
||
|
API at any point, so all the C API docs also work for C++.
|
||
|
</para>
|
||
|
|
||
|
<example>
|
||
|
<title>VIPS from C++ example</title>
|
||
|
<programlisting language="C++">
|
||
|
/* compile with:
|
||
|
* g++ -g -Wall try.cc `pkg-config vips-cc --cflags --libs`
|
||
|
*/
|
||
|
|
||
|
#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_UNBUFFERED ) );
|
||
|
|
||
|
double avg;
|
||
|
avg = in.avg();
|
||
|
|
||
|
printf( "avg = %g\n", avg );
|
||
|
|
||
|
VImage out = in.embed( 10, 10, 1000, 1000,
|
||
|
VImage::option()->
|
||
|
set( "extend", VIPS_EXTEND_BACKGROUND )->
|
||
|
set( "background", 128 ) );
|
||
|
|
||
|
out.write_to_file( argv[2] );
|
||
|
|
||
|
vips_shutdown();
|
||
|
|
||
|
return( 0 );
|
||
|
}
|
||
|
</programlisting>
|
||
|
</example>
|
||
|
|
||
|
</refsect1>
|
||
|
|
||
|
</refentry>
|