redo im_extract*() as a class

This commit is contained in:
John Cupitt 2011-10-26 15:09:01 +01:00
parent b969ce2aa5
commit 7e6f885ea1
12 changed files with 497 additions and 471 deletions

View File

@ -2,7 +2,7 @@
- version bump for new dev cycle
- im_subtract(), im_avg(), im_min(), im_minpos(), im_copy(), im_embed(),
im_flophor(), im_flipver(), im_insert(), im_insert_noexpand(), im_lrjoin(),
im_tbjoin()
im_tbjoin(), im_extract_area(), im_extract_bands(), im_extract_areabands()
redone as classes
- added VIPS_ARGUMENT_APPEND to help control arg ordering
- generate has a 'stop' param to signal successful early termination

3
TODO
View File

@ -1,5 +1,6 @@
- do extract_area, needed by join
- bandalike: consider RGB + RGBA ... we should bandup by adding a black band
(or white?? unclear)
- note member free stuff in vipsobject docs

View File

@ -8,6 +8,7 @@ libconversion_la_SOURCES = \
flip.c \
insert.c \
join.c \
extract.c \
conver_dispatch.c \
im_black.c \
im_c2amph.c \
@ -16,10 +17,8 @@ libconversion_la_SOURCES = \
im_c2real.c \
im_clip2fmt.c \
im_copy_file.c \
im_extract.c \
im_falsecolour.c \
im_gbandjoin.c \
im_insert.c \
im_mask2vips.c \
im_msb.c \
im_replicate.c \

View File

@ -107,11 +107,15 @@ vips_conversion_operation_init( void )
extern GType vips_flip_get_type( void );
extern GType vips_insert_get_type( void );
extern GType vips_join_get_type( void );
extern GType vips_extract_area_get_type( void );
extern GType vips_extract_band_get_type( void );
vips_copy_get_type();
vips_embed_get_type();
vips_flip_get_type();
vips_insert_get_type();
vips_join_get_type();
vips_extract_area_get_type();
vips_extract_band_get_type();
}

View File

@ -0,0 +1,412 @@
/* extract an area and/or a set of bands
*
* Copyright: 1990, J. Cupitt
*
* Author: J. Cupitt
* Written on: 12/02/1990
* Modified on: 4/6/92, J.Cupitt
* - speed up! why wasn't this done before? Why am I stupid?
* - layout, messages fixed
* now extracts IM_CODING_LABQ to IM_CODING_LABQ file: K.Martinez 1/7/93
* 2/7/93 JC
* - adapted for partial v2
* - ANSIfied
* 7/7/93 JC
* - behaviour for IM_CODING_LABQ fixed
* - better messages
* 7/10/94 JC
* - new IM_NEW()
* 22/2/95 JC
* - new use of im_region_region()
* 6/7/98 JC
* - im_extract_area() and im_extract_band() added
* 11/7/01 JC
* - im_extract_band() now numbers from zero
* 7/11/01 JC
* - oh what pain, im_extract now numbers bands from zero as well
* 6/9/02 JC
* - zero xoff/yoff for extracted area
* 14/4/04 JC
* - nope, -ve the origin
* 17/7/04
* - added im_extract_bands(), remove many bands from image
* 24/3/09
* - added IM_CODING_RAD support
* 29/1/10
* - cleanups
* - gtkdoc
* 26/10/11
* - redone as a class
*/
/*
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
*/
/*
#define VIPS_DEBUG
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /*HAVE_CONFIG_H*/
#include <vips/intl.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <vips/vips.h>
#include <vips/internal.h>
#include <vips/debug.h>
#include "conversion.h"
/**
* VipsExtractArea:
* @input: input image
* @output: output image
* @left: left edge of area to extract
* @top: top edge of area to extract
* @width: width of area to extract
* @height: height of area to extract
*
* Extract an area from an image.
* Extracting outside @input will trigger an error.
*
* See also: VipsExtractBand().
*/
typedef struct _VipsExtractArea {
VipsConversion parent_instance;
/* The input image.
*/
VipsImage *input;
int left;
int top;
int width;
int height;
} VipsExtractArea;
typedef VipsConversionClass VipsExtractAreaClass;
G_DEFINE_TYPE( VipsExtractArea, vips_extract_area, VIPS_TYPE_CONVERSION );
/* Extract an area. Can just use pointers.
*/
static int
vips_extract_area_gen( VipsRegion *or, void *seq, void *a, void *b,
gboolean *stop )
{
VipsRegion *ir = (VipsRegion *) seq;
VipsExtractArea *extract = (VipsExtractArea *) b;
VipsRect iarea;
/* Ask for input we need. Translate from demand in or's space to
* demand in ir's space.
*/
iarea = or->valid;
iarea.left += extract->left;
iarea.top += extract->top;
if( vips_region_prepare( ir, &iarea ) )
return( -1 );
/* Attach or to ir.
*/
if( vips_region_region( or, ir, &or->valid, iarea.left, iarea.top ) )
return( -1 );
return( 0 );
}
static int
vips_extract_area_build( VipsObject *object )
{
VipsConversion *conversion = VIPS_CONVERSION( object );
VipsExtractArea *extract = (VipsExtractArea *) object;
if( VIPS_OBJECT_CLASS( vips_extract_area_parent_class )->build( object ) )
return( -1 );
if( extract->left + extract->width > extract->input->Xsize ||
extract->top + extract->height > extract->input->Ysize ||
extract->left < 0 || extract->top < 0 ||
extract->width <= 0 || extract->height <= 0 ) {
im_error( "VipsExtractArea", "%s", _( "bad extract area" ) );
return( -1 );
}
if( vips_image_pio_input( extract->input ) ||
vips_image_pio_output( conversion->output ) ||
vips_check_coding_known( "VipsExtractArea", extract->input ) )
return( -1 );
if( vips_image_copy_fields( conversion->output, extract->input ) )
return( -1 );
vips_demand_hint( conversion->output,
VIPS_DEMAND_STYLE_THINSTRIP, extract->input, NULL );
conversion->output->Xsize = extract->width;
conversion->output->Ysize = extract->height;
conversion->output->Xoffset = -extract->left;
conversion->output->Yoffset = -extract->top;
if( vips_image_generate( conversion->output,
vips_start_one, vips_extract_area_gen, vips_stop_one,
extract->input, extract ) )
return( -1 );
return( 0 );
}
/* xy range we sanity check on ... just to stop crazy numbers from 1/0 etc.
* causing g_assert() failures later.
*/
#define RANGE (100000000)
static void
vips_extract_area_class_init( VipsExtractAreaClass *class )
{
GObjectClass *gobject_class = G_OBJECT_CLASS( class );
VipsObjectClass *vobject_class = VIPS_OBJECT_CLASS( class );
VIPS_DEBUG_MSG( "vips_extract_area_class_init\n" );
gobject_class->set_property = vips_object_set_property;
gobject_class->get_property = vips_object_get_property;
vobject_class->nickname = "extract_area";
vobject_class->description = _( "extract an area from an image" );
vobject_class->build = vips_extract_area_build;
VIPS_ARG_IMAGE( class, "input", 0,
_( "Input" ),
_( "Input image" ),
VIPS_ARGUMENT_REQUIRED_INPUT,
G_STRUCT_OFFSET( VipsExtractArea, input ) );
VIPS_ARG_INT( class, "left", 2,
_( "Left" ),
_( "Left edge of extract area" ),
VIPS_ARGUMENT_REQUIRED_INPUT,
G_STRUCT_OFFSET( VipsExtractArea, left ),
-RANGE, RANGE, 0 );
VIPS_ARG_INT( class, "top", 3,
_( "Top" ),
_( "Top edge of extract area" ),
VIPS_ARGUMENT_REQUIRED_INPUT,
G_STRUCT_OFFSET( VipsExtractArea, top ),
-RANGE, RANGE, 0 );
VIPS_ARG_INT( class, "width", 4,
_( "Width" ),
_( "Width of extract area" ),
VIPS_ARGUMENT_REQUIRED_INPUT,
G_STRUCT_OFFSET( VipsExtractArea, width ),
1, RANGE, 1 );
VIPS_ARG_INT( class, "height", 5,
_( "Height" ),
_( "Height of extract area" ),
VIPS_ARGUMENT_REQUIRED_INPUT,
G_STRUCT_OFFSET( VipsExtractArea, height ),
1, RANGE, 1 );
}
static void
vips_extract_area_init( VipsExtractArea *extract )
{
}
int
vips_extract_area( VipsImage *input, VipsImage **output,
int left, int top, int width, int height, ... )
{
va_list ap;
int result;
va_start( ap, height );
result = vips_call_split( "extract_area", ap, input, output,
left, top, width, height );
va_end( ap );
return( result );
}
/**
* VipsExtractBand:
* @input: input image
* @output: output image
* @band: band to extract
* @n: number of bands to extract
*
* Extract a band or bands from an image. Extracting out of range is an error.
*
* See also: VipsExtractArea().
*/
typedef struct _VipsExtractBand {
VipsConversion parent_instance;
/* The input image.
*/
VipsImage *input;
int band;
int n;
} VipsExtractBand;
typedef VipsConversionClass VipsExtractBandClass;
G_DEFINE_TYPE( VipsExtractBand, vips_extract_band, VIPS_TYPE_CONVERSION );
static int
vips_extract_band_gen( VipsRegion *or, void *seq, void *a, void *b,
gboolean *stop )
{
VipsRegion *ir = (VipsRegion *) seq;
VipsExtractBand *extract = (VipsExtractBand *) b;
VipsRect *r = &or->valid;
int es = VIPS_IMAGE_SIZEOF_ELEMENT( ir->im );
int ipel = VIPS_IMAGE_SIZEOF_PEL( ir->im );
int opel = VIPS_IMAGE_SIZEOF_PEL( or->im );
char *p, *q;
int x, y, z;
if( vips_region_prepare( ir, r ) )
return( -1 );
for( y = 0; y < r->height; y++ ) {
p = VIPS_REGION_ADDR( ir, r->left, r->top + y ) +
extract->band * es;
q = VIPS_REGION_ADDR( or, r->left, r->top + y );
for( x = 0; x < r->width; x++ ) {
for( z = 0; z < opel; z++ )
q[z] = p[z];
p += ipel;
q += opel;
}
}
return( 0 );
}
static int
vips_extract_band_build( VipsObject *object )
{
VipsConversion *conversion = VIPS_CONVERSION( object );
VipsExtractBand *extract = (VipsExtractBand *) object;
if( VIPS_OBJECT_CLASS( vips_extract_band_parent_class )->build( object ) )
return( -1 );
if( extract->band + extract->n > extract->input->Bands ) {
im_error( "VipsExtractBand", "%s", _( "bad extract band" ) );
return( -1 );
}
if( vips_image_pio_input( extract->input ) ||
vips_image_pio_output( conversion->output ) ||
vips_check_coding_known( "VipsExtractBand", extract->input ) )
return( -1 );
if( vips_image_copy_fields( conversion->output, extract->input ) )
return( -1 );
vips_demand_hint( conversion->output,
VIPS_DEMAND_STYLE_THINSTRIP, extract->input, NULL );
conversion->output->Bands = extract->n;
if( vips_image_generate( conversion->output,
vips_start_one, vips_extract_band_gen, vips_stop_one,
extract->input, extract ) )
return( -1 );
return( 0 );
}
static void
vips_extract_band_class_init( VipsExtractBandClass *class )
{
GObjectClass *gobject_class = G_OBJECT_CLASS( class );
VipsObjectClass *vobject_class = VIPS_OBJECT_CLASS( class );
VIPS_DEBUG_MSG( "vips_extract_band_class_init\n" );
gobject_class->set_property = vips_object_set_property;
gobject_class->get_property = vips_object_get_property;
vobject_class->nickname = "extract_band";
vobject_class->description = _( "extract band from an image" );
vobject_class->build = vips_extract_band_build;
VIPS_ARG_IMAGE( class, "input", 0,
_( "Input" ),
_( "Input image" ),
VIPS_ARGUMENT_REQUIRED_INPUT,
G_STRUCT_OFFSET( VipsExtractBand, input ) );
VIPS_ARG_INT( class, "band", 3,
_( "Band" ),
_( "Band to extract" ),
VIPS_ARGUMENT_REQUIRED_INPUT,
G_STRUCT_OFFSET( VipsExtractBand, band ),
0, RANGE, 0 );
VIPS_ARG_INT( class, "n", 4,
_( "n" ),
_( "Number of bands to extract" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsExtractBand, n ),
1, RANGE, 1 );
}
static void
vips_extract_band_init( VipsExtractBand *extract )
{
}
int
vips_extract_band( VipsImage *input, VipsImage **output, int band, ... )
{
va_list ap;
int result;
va_start( ap, band );
result = vips_call_split( "extract_band", ap, input, output, band );
va_end( ap );
return( result );
}

View File

@ -67,7 +67,7 @@
/**
* VipsFlip:
* @in: input image
* @out: output image
* @output: output image
* @direction: flip horizontally or vertically
*
* Flips an image left-right or up-down.

View File

@ -1,298 +0,0 @@
/* im_extract
*
* Copyright: 1990, J. Cupitt
*
* Author: J. Cupitt
* Written on: 12/02/1990
* Modified on: 4/6/92, J.Cupitt
* - speed up! why wasn't this done before? Why am I stupid?
* - layout, messages fixed
* now extracts IM_CODING_LABQ to IM_CODING_LABQ file: K.Martinez 1/7/93
* 2/7/93 JC
* - adapted for partial v2
* - ANSIfied
* 7/7/93 JC
* - behaviour for IM_CODING_LABQ fixed
* - better messages
* 7/10/94 JC
* - new IM_NEW()
* 22/2/95 JC
* - new use of im_region_region()
* 6/7/98 JC
* - im_extract_area() and im_extract_band() added
* 11/7/01 JC
* - im_extract_band() now numbers from zero
* 7/11/01 JC
* - oh what pain, im_extract now numbers bands from zero as well
* 6/9/02 JC
* - zero xoff/yoff for extracted area
* 14/4/04 JC
* - nope, -ve the origin
* 17/7/04
* - added im_extract_bands(), remove many bands from image
* 24/3/09
* - added IM_CODING_RAD support
* 29/1/10
* - cleanups
* - gtkdoc
*/
/*
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 <stdio.h>
#include <vips/vips.h>
typedef struct _Extract {
IMAGE *in;
IMAGE *out;
int left;
int top;
int width;
int height;
int band;
int nbands;
} Extract;
/* Extract one or more bands. This needs pixel copying.
*/
static int
extract_band( REGION *or, void *seq, void *a, void *b )
{
REGION *ir = (REGION *) seq;
Extract *extract = (Extract *) b;
Rect *r = &or->valid;
int es = IM_IMAGE_SIZEOF_ELEMENT( ir->im );
int ipel = IM_IMAGE_SIZEOF_PEL( ir->im );
int opel = IM_IMAGE_SIZEOF_PEL( or->im );
Rect iarea;
char *p, *q;
int x, y, z;
/* Ask for input we need.
*/
iarea = or->valid;
iarea.left += extract->left;
iarea.top += extract->top;
if( im_prepare( ir, &iarea ) )
return( -1 );
for( y = 0; y < r->height; y++ ) {
p = IM_REGION_ADDR( ir,
extract->left + r->left,
extract->top + r->top + y ) +
extract->band * es;
q = IM_REGION_ADDR( or, r->left, r->top + y );
for( x = 0; x < r->width; x++ ) {
for( z = 0; z < opel; z++ )
q[z] = p[z];
p += ipel;
q += opel;
}
}
return( 0 );
}
/* Extract an area. Can just use pointers.
*/
static int
extract_area( REGION *or, void *seq, void *a, void *b )
{
REGION *ir = (REGION *) seq;
Extract *extract = (Extract *) b;
Rect iarea;
/* Ask for input we need. Translate from demand in or's space to
* demand in ir's space.
*/
iarea = or->valid;
iarea.left += extract->left;
iarea.top += extract->top;
if( im_prepare( ir, &iarea ) )
return( -1 );
/* Attach or to ir.
*/
if( im_region_region( or, ir, &or->valid, iarea.left, iarea.top ) )
return( -1 );
return( 0 );
}
/**
* im_extract_areabands:
* @in: input image
* @out: output image
* @left: left edge of rectangle
* @top: top edge rectangle
* @width: width of rectangle
* @height: height of rectangle
* @band: first band to extract
* @nbands: number of bands to extract
*
* Extract an area and a number of bands from an image. Bands number from
* zero. Extracting outside @in will trigger an error.
*
* See also: im_embed(), im_insert(), im_extract_area(), im_extract_bands().
*
* Returns: 0 on success, -1 on error
*/
int
im_extract_areabands( IMAGE *in, IMAGE *out,
int left, int top, int width, int height, int band, int nbands )
{
Extract *extract;
if( im_piocheck( in, out ) ||
im_check_coding_known( "im_extract_areabands", in ) )
return( -1 );
if( band < 0 || nbands < 1 || band + nbands > in->Bands ) {
im_error( "im_extract_areabands",
"%s", _( "band selection out of range" ) );
return( -1 );
}
if( left + width > in->Xsize ||
top + height > in->Ysize ||
left < 0 || top < 0 ||
width <= 0 || height <= 0 ) {
im_error( "im_extract_areabands",
"%s", _( "bad extract area" ) );
return( -1 );
}
/* Set up the output header.
*/
if( im_cp_desc( out, in ) )
return( -1 );
out->Bands = nbands;
out->Xsize = width;
out->Ysize = height;
if( im_demand_hint( out, IM_THINSTRIP, in, NULL ) )
return( -1 );
if( !(extract = IM_NEW( out, Extract )) )
return( -1 );
extract->in = in;
extract->out = out;
extract->left = left;
extract->top = top;
extract->width = width;
extract->height = height;
extract->band = band;
extract->nbands = nbands;
/* Extracting all bands is a special case ... we can do it with
* pointers.
*/
if( band == 0 && nbands == in->Bands ) {
if( im_generate( out,
im_start_one, extract_area, im_stop_one, in, extract ) )
return( -1 );
}
else {
if( im_generate( out,
im_start_one, extract_band, im_stop_one, in, extract ) )
return( -1 );
}
out->Xoffset = -left;
out->Yoffset = -top;
return( 0 );
}
/**
* im_extract_area:
* @in: input image
* @out: output image
* @left: left edge of rectangle
* @top: top edge of rectangle
* @width: width of rectangle
* @height: height of rectangle
*
* Extract an area from an image.
* Extracting outside @in will trigger an error.
*
* See also: im_embed(), im_insert(), im_extract_bands().
*
* Returns: 0 on success, -1 on error
*/
int
im_extract_area( IMAGE *in, IMAGE *out,
int left, int top, int width, int height )
{
return( im_extract_areabands( in, out,
left, top, width, height, 0, in->Bands ) );
}
/**
* im_extract_bands:
* @in: input image
* @out: output image
* @band: first band to extract
* @nbands: number of bands to extract
*
* Extract a number of bands from an image.
* Extracting outside @in will trigger an error.
*
* See also: im_bandjoin().
*
* Returns: 0 on success, -1 on error
*/
int
im_extract_bands( IMAGE *in, IMAGE *out, int band, int nbands )
{
return( im_extract_areabands( in, out,
0, 0, in->Xsize, in->Ysize, band, nbands ) );
}
/**
* im_extract_band:
* @in: input image
* @out: output image
* @band: band to extract
*
* Extract a single band from an image.
* Extracting outside @in will trigger an error.
*
* See also: im_bandjoin().
*
* Returns: 0 on success, -1 on error
*/
int
im_extract_band( IMAGE *in, IMAGE *out, int band )
{
return( im_extract_bands( in, out, band, 1 ) );
}

View File

@ -1,161 +0,0 @@
/* im_insert
*
* Copyright: 1990, J. Cupitt
*
* Author: J. Cupitt
* Written on: 02/08/1990
* Modified on :
* 31/8/93 JC
* - ANSIfied
* - Nicos' reformatting undone. Grr!
* 22/12/94
* - modernised
* - now does IM_CODING_LABQ too
* 22/6/95 JC
* - partialized
* 10/2/02 JC
* - adapted for im_prepare_to() stuff
* 14/4/04
* - sets Xoffset / Yoffset
* 3/7/06
* - add sanity range checks
* 24/3/09
* - added IM_CODING_RAD support
* 30/1/10
* - cleanups
* - formatalike/bandalike
* - gtkdoc
*/
/*
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vips/vips.h>
#include <vips/internal.h>
/* 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]
*/
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 );
}

View File

@ -216,7 +216,7 @@ vips_join_build( VipsObject *object )
g_assert( 0 );
}
if( vips_call( "extract_area", t, &t2,
if( vips_extract_area( t, &t2,
left, top, width, height, NULL ) ) {
g_object_unref( t );
return( -1 );

View File

@ -1180,3 +1180,66 @@ im_tbjoin( IMAGE *left, IMAGE *right, IMAGE *out )
return( 0 );
}
int
im_extract_area( IMAGE *in, IMAGE *out,
int left, int top, int width, int height )
{
VipsImage *t;
if( vips_extract_area( in, &t, left, top, width, height,
NULL ) )
return( -1 );
if( vips_image_write( t, out ) ) {
g_object_unref( t );
return( -1 );
}
g_object_unref( t );
return( 0 );
}
int
im_extract_bands( IMAGE *in, IMAGE *out, int band, int nbands )
{
VipsImage *t;
if( vips_extract_band( in, &t, band,
"n", nbands,
NULL ) )
return( -1 );
if( vips_image_write( t, out ) ) {
g_object_unref( t );
return( -1 );
}
g_object_unref( t );
return( 0 );
}
int
im_extract_areabands( IMAGE *in, IMAGE *out,
int left, int top, int width, int height, int band, int nbands )
{
VipsImage *t1, *t2;
if( vips_extract_area( in, &t1, left, top, width, height,
NULL ) )
return( -1 );
if( vips_extract_band( t1, &t2, band,
"n", nbands,
NULL ) ) {
g_object_unref( t1 );
return( -1 );
}
g_object_unref( t1 );
if( vips_image_write( t2, out ) ) {
g_object_unref( t2 );
return( -1 );
}
g_object_unref( t2 );
return( 0 );
}

View File

@ -127,6 +127,11 @@ int vips_insert( VipsImage *main, VipsImage *sub, VipsImage **out,
int vips_join( VipsImage *main, VipsImage *sub, VipsImage **out,
VipsDirection direction, ... )
__attribute__((sentinel));
int vips_extract_area( VipsImage *input, VipsImage **output,
int left, int top, int width, int height, ... )
__attribute__((sentinel));
int vips_extract_band( VipsImage *input, VipsImage **output, int band, ... )
__attribute__((sentinel));
@ -155,12 +160,6 @@ int im_black( VipsImage *out, int x, int y, int bands );
int im_text( VipsImage *out, const char *text, const char *font,
int width, int alignment, int dpi );
int im_extract_band( VipsImage *in, VipsImage *out, int band );
int im_extract_bands( VipsImage *in, VipsImage *out, int band, int nbands );
int im_extract_area( VipsImage *in, VipsImage *out,
int left, int top, int width, int height );
int im_extract_areabands( VipsImage *in, VipsImage *out,
int left, int top, int width, int height, int band, int nbands );
int im_bandjoin( VipsImage *in1, VipsImage *in2, VipsImage *out );
int im_gbandjoin( VipsImage **in, VipsImage *out, int n );
int im_insertset( VipsImage *main, VipsImage *sub, VipsImage *out, int n, int *x, int *y );

View File

@ -549,6 +549,13 @@ int im_insert_noexpand( VipsImage *main, VipsImage *sub, VipsImage *out, int x,
int im_lrjoin( VipsImage *left, VipsImage *right, VipsImage *out );
int im_tbjoin( VipsImage *top, VipsImage *bottom, VipsImage *out );
int im_extract_area( VipsImage *in, VipsImage *out,
int left, int top, int width, int height );
int im_extract_band( VipsImage *in, VipsImage *out, int band );
int im_extract_bands( VipsImage *in, VipsImage *out, int band, int nbands );
int im_extract_areabands( VipsImage *in, VipsImage *out,
int left, int top, int width, int height, int band, int nbands );
/* ruby-vips uses this
*/
#define vips_class_map_concrete_all vips_class_map_all