2011-09-29 14:34:14 +02:00
|
|
|
/* base class for all conversion operations
|
|
|
|
*
|
|
|
|
* properties:
|
|
|
|
* - unary, binary or binary with one arg a constant
|
|
|
|
* - cast binary args to match
|
|
|
|
* - not point-to-point
|
|
|
|
* - format, bands etc. can all change
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright (C) 1991-2005 The National Gallery
|
|
|
|
|
2012-09-17 12:52:32 +02:00
|
|
|
This library 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.1 of the License, or (at your option) any later version.
|
2011-09-29 14:34:14 +02:00
|
|
|
|
2012-09-17 12:52:32 +02:00
|
|
|
This library is distributed in the hope that it will be useful,
|
2011-09-29 14:34:14 +02:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-09-17 12:52:32 +02:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
2011-09-29 14:34:14 +02:00
|
|
|
|
2012-09-17 12:52:32 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
2013-03-07 06:40:19 +01:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
02110-1301 USA
|
2011-09-29 14:34:14 +02:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
#define DEBUG
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif /*HAVE_CONFIG_H*/
|
|
|
|
#include <vips/intl.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include <vips/vips.h>
|
2011-11-04 17:58:09 +01:00
|
|
|
#include <vips/internal.h>
|
2011-09-29 14:34:14 +02:00
|
|
|
|
|
|
|
#include "conversion.h"
|
|
|
|
|
|
|
|
G_DEFINE_ABSTRACT_TYPE( VipsConversion, vips_conversion, VIPS_TYPE_OPERATION );
|
|
|
|
|
|
|
|
static int
|
|
|
|
vips_conversion_build( VipsObject *object )
|
|
|
|
{
|
|
|
|
VipsConversion *conversion = VIPS_CONVERSION( object );
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf( "vips_conversion_build: " );
|
|
|
|
vips_object_print_name( object );
|
|
|
|
printf( "\n" );
|
|
|
|
#endif /*DEBUG*/
|
|
|
|
|
|
|
|
g_object_set( conversion, "out", vips_image_new(), NULL );
|
|
|
|
|
|
|
|
if( VIPS_OBJECT_CLASS( vips_conversion_parent_class )->build( object ) )
|
|
|
|
return( -1 );
|
|
|
|
|
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vips_conversion_class_init( VipsConversionClass *class )
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS( class );
|
|
|
|
VipsObjectClass *vobject_class = VIPS_OBJECT_CLASS( class );
|
|
|
|
|
|
|
|
gobject_class->set_property = vips_object_set_property;
|
|
|
|
gobject_class->get_property = vips_object_get_property;
|
|
|
|
|
|
|
|
vobject_class->nickname = "conversion";
|
|
|
|
vobject_class->description = _( "conversion operations" );
|
|
|
|
vobject_class->build = vips_conversion_build;
|
|
|
|
|
2011-10-16 15:48:47 +02:00
|
|
|
VIPS_ARG_IMAGE( class, "out", 1,
|
|
|
|
_( "Output" ),
|
2011-09-29 14:34:14 +02:00
|
|
|
_( "Output image" ),
|
|
|
|
VIPS_ARGUMENT_REQUIRED_OUTPUT,
|
2011-10-27 13:10:24 +02:00
|
|
|
G_STRUCT_OFFSET( VipsConversion, out ) );
|
2011-09-29 14:34:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vips_conversion_init( VipsConversion *conversion )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Called from iofuncs to init all operations in this dir. Use a plugin system
|
|
|
|
* instead?
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
vips_conversion_operation_init( void )
|
|
|
|
{
|
|
|
|
extern GType vips_copy_get_type( void );
|
2011-12-05 13:19:56 +01:00
|
|
|
extern GType vips_tile_cache_get_type( void );
|
2012-08-23 15:51:57 +02:00
|
|
|
extern GType vips_line_cache_get_type( void );
|
2012-02-15 16:47:43 +01:00
|
|
|
extern GType vips_sequential_get_type( void );
|
2012-01-13 14:15:56 +01:00
|
|
|
extern GType vips_cache_get_type( void );
|
2011-10-16 15:48:47 +02:00
|
|
|
extern GType vips_embed_get_type( void );
|
2011-10-17 08:15:51 +02:00
|
|
|
extern GType vips_flip_get_type( void );
|
2011-10-22 14:10:47 +02:00
|
|
|
extern GType vips_insert_get_type( void );
|
2011-10-26 14:26:20 +02:00
|
|
|
extern GType vips_join_get_type( void );
|
2011-10-26 16:09:01 +02:00
|
|
|
extern GType vips_extract_area_get_type( void );
|
|
|
|
extern GType vips_extract_band_get_type( void );
|
2011-10-26 17:51:27 +02:00
|
|
|
extern GType vips_replicate_get_type( void );
|
2011-10-27 13:10:24 +02:00
|
|
|
extern GType vips_cast_get_type( void );
|
2011-10-27 18:40:39 +02:00
|
|
|
extern GType vips_bandjoin_get_type( void );
|
2011-10-31 15:49:39 +01:00
|
|
|
extern GType vips_black_get_type( void );
|
2011-11-04 15:45:56 +01:00
|
|
|
extern GType vips_rot_get_type( void );
|
2011-11-15 22:49:49 +01:00
|
|
|
extern GType vips_ifthenelse_get_type( void );
|
2011-11-20 10:56:02 +01:00
|
|
|
extern GType vips_recomb_get_type( void );
|
|
|
|
extern GType vips_bandmean_get_type( void );
|
2012-06-18 15:49:39 +02:00
|
|
|
extern GType vips_flatten_get_type( void );
|
2012-12-07 12:17:09 +01:00
|
|
|
extern GType vips_bandbool_get_type( void );
|
2013-05-29 13:21:30 +02:00
|
|
|
extern GType vips_gaussnoise_get_type( void );
|
2013-05-30 16:52:36 +02:00
|
|
|
extern GType vips_grid_get_type( void );
|
2013-05-30 17:29:58 +02:00
|
|
|
extern GType vips_scale_get_type( void );
|
2013-05-31 19:12:39 +02:00
|
|
|
extern GType vips_wrap_get_type( void );
|
2013-06-01 11:56:16 +02:00
|
|
|
extern GType vips_zoom_get_type( void );
|
2013-06-01 22:31:45 +02:00
|
|
|
extern GType vips_subsample_get_type( void );
|
2013-06-03 11:26:09 +02:00
|
|
|
extern GType vips_msb_get_type( void );
|
2013-06-03 15:37:55 +02:00
|
|
|
#ifdef HAVE_PANGOFT2
|
|
|
|
extern GType vips_text_get_type( void );
|
|
|
|
#endif /*HAVE_PANGOFT2*/
|
2013-06-12 15:51:43 +02:00
|
|
|
extern GType vips_xyz_get_type( void );
|
2011-09-29 14:34:14 +02:00
|
|
|
|
|
|
|
vips_copy_get_type();
|
2011-12-05 13:19:56 +01:00
|
|
|
vips_tile_cache_get_type();
|
2012-08-23 15:51:57 +02:00
|
|
|
vips_line_cache_get_type();
|
2012-02-15 16:47:43 +01:00
|
|
|
vips_sequential_get_type();
|
2012-01-13 14:15:56 +01:00
|
|
|
vips_cache_get_type();
|
2011-10-16 15:48:47 +02:00
|
|
|
vips_embed_get_type();
|
2011-10-17 08:15:51 +02:00
|
|
|
vips_flip_get_type();
|
2011-10-22 14:10:47 +02:00
|
|
|
vips_insert_get_type();
|
2011-10-26 14:26:20 +02:00
|
|
|
vips_join_get_type();
|
2011-10-26 16:09:01 +02:00
|
|
|
vips_extract_area_get_type();
|
|
|
|
vips_extract_band_get_type();
|
2011-10-26 17:51:27 +02:00
|
|
|
vips_replicate_get_type();
|
2011-10-27 13:10:24 +02:00
|
|
|
vips_cast_get_type();
|
2011-10-27 18:40:39 +02:00
|
|
|
vips_bandjoin_get_type();
|
2011-10-31 15:49:39 +01:00
|
|
|
vips_black_get_type();
|
2011-11-04 15:45:56 +01:00
|
|
|
vips_rot_get_type();
|
2011-11-15 22:49:49 +01:00
|
|
|
vips_ifthenelse_get_type();
|
2011-11-20 10:56:02 +01:00
|
|
|
vips_recomb_get_type();
|
|
|
|
vips_bandmean_get_type();
|
2012-06-18 15:49:39 +02:00
|
|
|
vips_flatten_get_type();
|
2012-12-07 12:17:09 +01:00
|
|
|
vips_bandbool_get_type();
|
2013-05-29 13:21:30 +02:00
|
|
|
vips_gaussnoise_get_type();
|
2013-05-30 16:52:36 +02:00
|
|
|
vips_grid_get_type();
|
2013-05-30 17:29:58 +02:00
|
|
|
vips_scale_get_type();
|
2013-05-31 19:12:39 +02:00
|
|
|
vips_wrap_get_type();
|
2013-06-01 11:56:16 +02:00
|
|
|
vips_zoom_get_type();
|
2013-06-01 22:31:45 +02:00
|
|
|
vips_subsample_get_type();
|
2013-06-03 11:26:09 +02:00
|
|
|
vips_msb_get_type();
|
2013-06-03 15:37:55 +02:00
|
|
|
#ifdef HAVE_PANGOFT2
|
|
|
|
vips_text_get_type();
|
|
|
|
#endif /*HAVE_PANGOFT2*/
|
2013-06-12 15:51:43 +02:00
|
|
|
vips_xyz_get_type();
|
2011-09-29 14:34:14 +02:00
|
|
|
}
|
|
|
|
|
2011-11-04 17:58:09 +01:00
|
|
|
/* The common part of most binary conversion
|
|
|
|
* operators. We:
|
|
|
|
*
|
|
|
|
* - check in and out
|
|
|
|
* - cast in1 and in2 up to a common format
|
|
|
|
* - equalise bands
|
|
|
|
* - make an input array
|
|
|
|
* - return the matched images in vec[0] and vec[1]
|
|
|
|
*
|
|
|
|
* A left-over, remove soon.
|
|
|
|
*/
|
|
|
|
IMAGE **
|
|
|
|
im__insert_base( const char *domain,
|
|
|
|
IMAGE *in1, IMAGE *in2, IMAGE *out )
|
|
|
|
{
|
|
|
|
IMAGE *t[4];
|
|
|
|
IMAGE **vec;
|
|
|
|
|
|
|
|
if( im_piocheck( in1, out ) ||
|
|
|
|
im_pincheck( in2 ) ||
|
|
|
|
im_check_bands_1orn( domain, in1, in2 ) ||
|
|
|
|
im_check_coding_known( domain, in1 ) ||
|
|
|
|
im_check_coding_same( domain, in1, in2 ) )
|
|
|
|
return( NULL );
|
|
|
|
|
|
|
|
/* Cast our input images up to a common format and bands.
|
|
|
|
*/
|
|
|
|
if( im_open_local_array( out, t, 4, domain, "p" ) ||
|
|
|
|
im__formatalike( in1, in2, t[0], t[1] ) ||
|
|
|
|
im__bandalike( domain, t[0], t[1], t[2], t[3] ) ||
|
|
|
|
!(vec = im_allocate_input_array( out, t[2], t[3], NULL )) )
|
|
|
|
return( NULL );
|
|
|
|
|
|
|
|
/* Generate the output.
|
|
|
|
*/
|
|
|
|
if( im_cp_descv( out, vec[0], vec[1], NULL ) ||
|
|
|
|
im_demand_hint_array( out, IM_SMALLTILE, vec ) )
|
|
|
|
return( NULL );
|
|
|
|
|
|
|
|
return( vec );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* im_insertset:
|
|
|
|
* @main: big image
|
|
|
|
* @sub: small image
|
|
|
|
* @out: output image
|
|
|
|
* @n: number of positions
|
|
|
|
* @x: left positions of @sub
|
|
|
|
* @y: top positions of @sub
|
|
|
|
*
|
|
|
|
* Insert @sub repeatedly into @main at the positions listed in the arrays @x,
|
|
|
|
* @y of length @n. @out is the same
|
|
|
|
* size as @main. @sub is clipped against the edges of @main.
|
|
|
|
*
|
|
|
|
* This operation is fast for large @n, but will use a memory buffer the size
|
|
|
|
* of @out. It's useful for things like making scatter plots.
|
|
|
|
*
|
|
|
|
* If the number of bands differs, one of the images
|
|
|
|
* must have one band. In this case, an n-band image is formed from the
|
|
|
|
* one-band image by joining n copies of the one-band image together, and then
|
|
|
|
* the two n-band images are operated upon.
|
|
|
|
*
|
|
|
|
* The two input images are cast up to the smallest common type (see table
|
|
|
|
* Smallest common format in
|
|
|
|
* <link linkend="VIPS-arithmetic">arithmetic</link>).
|
|
|
|
*
|
|
|
|
* See also: im_insert(), im_lrjoin().
|
|
|
|
*
|
|
|
|
* Returns: 0 on success, -1 on error
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
im_insertset( IMAGE *main, IMAGE *sub, IMAGE *out, int n, int *x, int *y )
|
|
|
|
{
|
|
|
|
IMAGE **vec;
|
|
|
|
IMAGE *t;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if( !(vec = im__insert_base( "im_insert", main, sub, out )) )
|
|
|
|
return( -1 );
|
|
|
|
|
|
|
|
/* Copy to a memory image, zap that, then copy to out.
|
|
|
|
*/
|
|
|
|
if( !(t = im_open_local( out, "im_insertset", "t" )) ||
|
|
|
|
im_copy( vec[0], t ) )
|
|
|
|
return( -1 );
|
|
|
|
|
|
|
|
for( i = 0; i < n; i++ )
|
|
|
|
if( im_insertplace( t, vec[1], x[i], y[i] ) )
|
|
|
|
return( -1 );
|
|
|
|
|
|
|
|
if( im_copy( t, out ) )
|
|
|
|
return( -1 );
|
|
|
|
|
|
|
|
return( 0 );
|
|
|
|
}
|