This commit is contained in:
John Cupitt 2011-10-28 17:36:20 +01:00
parent d503e710e2
commit 441ae2305e
13 changed files with 157 additions and 213 deletions

24
TODO
View File

@ -1,14 +1,28 @@
- try:
$ vips insert Gugg_coloured.jpg x.jpg x.v 100 100 --expand --background "1 2 3"
- vips_image_new_array() needs to go ... replcae with vips_object_array()
often gets the BG colour wrong, eg. notworking:
see new sizealike/foprmatalike in bandjoin.c ... move these into binary.c
$ vips insert Gugg_coloured.jpg x.jpg x.v 100 100 --expand --background "1 2 3"
vips__vector_to_ink: starting
vips_cast_build: 0xbff920
vips_cast_build: 0xbff920 done
vips_cast_gen: 0xbff920
vips__vector_to_ink: ink = 0xc1c660 (1 2 3)
sort out naming
vs. working:
GObject **vips_array_object_get( const GValue *value, int *n );
VipsArea *vips_array_object_new( int n );
$ vips insert Gugg_coloured.jpg x.jpg x.v 100 100 --expand --background "1 2 3"
vips__vector_to_ink: starting
vips_cast_build: 0x1760920
vips_cast_build: 0x1760920 done
vips__vector_to_ink: ink = 0x177d660 (0 0 0)
vips_cast_gen() is never called???
vips__vector_to_ink() breakage something to do with the new bandjoin thing?

View File

@ -117,27 +117,12 @@ vips__formatalike_vec( VipsImage **in, VipsImage **out, int n )
format = vips_format_common( format, in[i]->BandFmt );
for( i = 0; i < n; i++ )
if( im_clip2fmt( in[i], out[i], format ) )
if( vips_cast( in[i], &out[i], format, NULL ) )
return( -1 );
return( 0 );
}
int
vips__formatalike( VipsImage *in1, VipsImage *in2,
VipsImage *out1, VipsImage *out2 )
{
IMAGE *in[2];
IMAGE *out[2];
in[0] = in1;
in[1] = in2;
out[0] = out1;
out[1] = out2;
return( vips__formatalike_vec( in, out, 2 ) );
}
int
vips__sizealike_vec( VipsImage **in, VipsImage **out, int n )
{
@ -155,37 +140,23 @@ vips__sizealike_vec( VipsImage **in, VipsImage **out, int n )
}
for( i = 0; i < n; i++ )
if( im_embed( in[i], out[i], 0, 0, 0, width_max, height_max ) )
if( vips_embed( in[i], &out[i],
0, 0, width_max, height_max, NULL ) )
return( -1 );
return( 0 );
}
int
vips__sizealike( VipsImage *in1, VipsImage *in2,
VipsImage *out1, VipsImage *out2 )
{
IMAGE *in[2];
IMAGE *out[2];
in[0] = in1;
in[1] = in2;
out[0] = out1;
out[1] = out2;
return( vips__sizealike_vec( in, out, 2 ) );
}
/* Make an n-band image. Input 1 or n bands.
*/
int
vips__bandup( const char *domain, VipsImage *in, VipsImage *out, int n )
vips__bandup( const char *domain, VipsImage *in, VipsImage **out, int n )
{
VipsImage *bands[256];
int i;
if( in->Bands == n )
return( im_copy( in, out ) );
return( vips_copy( in, out, NULL ) );
if( in->Bands != 1 ) {
vips_error( domain, _( "not one band or %d bands" ), n );
return( -1 );
@ -198,7 +169,7 @@ vips__bandup( const char *domain, VipsImage *in, VipsImage *out, int n )
for( i = 0; i < n; i++ )
bands[i] = in;
return( im_gbandjoin( bands, out, n ) );
return( vips_bandjoin( bands, out, n, NULL ) );
}
int
@ -214,26 +185,66 @@ vips__bandalike_vec( const char *domain,
for( i = 1; i < n; i++ )
max_bands = VIPS_MAX( max_bands, in[i]->Bands );
for( i = 0; i < n; i++ )
if( vips__bandup( domain, in[i], out[i], max_bands ) )
if( vips__bandup( domain, in[i], &out[i], max_bands ) )
return( -1 );
return( 0 );
}
int
vips__formatalike( VipsImage *in1, VipsImage *in2,
VipsImage **out1, VipsImage **out2 )
{
IMAGE *in[2];
IMAGE *out[2];
in[0] = in1;
in[1] = in2;
if( vips__formatalike_vec( in, out, 2 ) )
return( -1 );
*out1 = out[0];
*out2 = out[1];
return( 0 );
}
int
vips__sizealike( VipsImage *in1, VipsImage *in2,
VipsImage **out1, VipsImage **out2 )
{
IMAGE *in[2];
IMAGE *out[2];
in[0] = in1;
in[1] = in2;
if( vips__sizealike_vec( in, out, 2 ) )
return( -1 );
*out1 = out[0];
*out2 = out[1];
return( 0 );
}
int
vips__bandalike( const char *domain,
VipsImage *in1, VipsImage *in2, VipsImage *out1, VipsImage *out2 )
VipsImage *in1, VipsImage *in2, VipsImage **out1, VipsImage **out2 )
{
VipsImage *in[2];
VipsImage *out[2];
in[0] = in1;
in[1] = in2;
out[0] = out1;
out[1] = out2;
if( vips__bandalike_vec( domain, in, out, 2 ) )
return( -1 );
*out1 = out[0];
*out2 = out[1];
return( 0 );
}
@ -288,8 +299,8 @@ vips_binary_build( VipsObject *object )
VipsArithmetic *arithmetic = VIPS_ARITHMETIC( object );
VipsArithmeticClass *aclass = VIPS_ARITHMETIC_GET_CLASS( arithmetic );
VipsBinary *binary = VIPS_BINARY( object );
VipsImage **t = (VipsImage **) vips_object_local_array( object, 6 );
VipsImage *t[6];
VipsImage **arry;
if( VIPS_OBJECT_CLASS( vips_binary_parent_class )->build( object ) )
@ -303,14 +314,11 @@ vips_binary_build( VipsObject *object )
vips_check_uncoded( domain, binary->right ) )
return( -1 );
if( vips_image_new_array( object, t, 6 ) )
return( -1 );
/* Cast our input images up to a common format, bands and size.
*/
if( vips__formatalike( binary->left, binary->right, t[0], t[1] ) ||
vips__bandalike( domain, t[0], t[1], t[2], t[3] ) ||
vips__sizealike( t[2], t[3], t[4], t[5] ) )
if( vips__formatalike( binary->left, binary->right, &t[0], &t[1] ) ||
vips__bandalike( domain, t[0], t[1], &t[2], &t[3] ) ||
vips__sizealike( t[2], t[3], &t[4], &t[5] ) )
return( -1 );
binary->left_processed = t[4];
binary->right_processed = t[5];

View File

@ -107,101 +107,6 @@ typedef VipsConversionClass VipsBandjoinClass;
G_DEFINE_TYPE( VipsBandjoin, vips_bandjoin, VIPS_TYPE_CONVERSION );
/* Save a bit of typing.
*/
#define UC VIPS_FORMAT_UCHAR
#define C VIPS_FORMAT_CHAR
#define US VIPS_FORMAT_USHORT
#define S VIPS_FORMAT_SHORT
#define UI VIPS_FORMAT_UINT
#define I VIPS_FORMAT_INT
#define F VIPS_FORMAT_FLOAT
#define X VIPS_FORMAT_COMPLEX
#define D VIPS_FORMAT_DOUBLE
#define DX VIPS_FORMAT_DPCOMPLEX
/* For two integer types, the "largest", ie. one which can represent the
* full range of both.
*/
static VipsBandFormat format_largest[6][6] = {
/* UC C US S UI I */
/* UC */ { UC, S, US, S, UI, I },
/* C */ { S, C, I, S, I, I },
/* US */ { US, I, US, I, UI, I },
/* S */ { S, S, I, S, I, I },
/* UI */ { UI, I, UI, I, UI, I },
/* I */ { I, I, I, I, I, I }
};
/* For two formats, find one which can represent the full range of both.
*/
static VipsBandFormat
vips_format_common( VipsBandFormat a, VipsBandFormat b )
{
if( vips_band_format_iscomplex( a ) ||
vips_band_format_iscomplex( b ) ) {
if( a == VIPS_FORMAT_DPCOMPLEX ||
b == VIPS_FORMAT_DPCOMPLEX )
return( VIPS_FORMAT_DPCOMPLEX );
else
return( VIPS_FORMAT_COMPLEX );
}
else if( vips_band_format_isfloat( a ) ||
vips_band_format_isfloat( b ) ) {
if( a == VIPS_FORMAT_DOUBLE ||
b == VIPS_FORMAT_DOUBLE )
return( VIPS_FORMAT_DOUBLE );
else
return( VIPS_FORMAT_FLOAT );
}
else
return( format_largest[a][b] );
}
static int
vips_formatalike( VipsImage **in, VipsImage **out, int n )
{
int i;
VipsBandFormat format;
g_assert( n >= 1 );
format = in[0]->BandFmt;
for( i = 1; i < n; i++ )
format = vips_format_common( format, in[i]->BandFmt );
for( i = 0; i < n; i++ )
if( vips_cast( in[i], &out[i], format, NULL ) )
return( -1 );
return( 0 );
}
int
vips_sizealike( VipsImage **in, VipsImage **out, int n )
{
int i;
int width_max;
int height_max;
g_assert( n >= 1 );
width_max = in[0]->Xsize;
height_max = in[0]->Ysize;
for( i = 1; i < n; i++ ) {
width_max = VIPS_MAX( width_max, in[i]->Xsize );
height_max = VIPS_MAX( height_max, in[i]->Ysize );
}
for( i = 0; i < n; i++ )
if( vips_embed( in[i], &out[i],
0, 0, width_max, height_max, NULL ) )
return( -1 );
return( 0 );
}
static int
vips_bandjoin_gen( VipsRegion *or, void *seq, void *a, void *b, gboolean *stop )
{
@ -282,8 +187,8 @@ vips_bandjoin_build( VipsObject *object )
format = (VipsImage **) vips_object_local_array( object, n );
size = (VipsImage **) vips_object_local_array( object, n );
if( vips_formatalike( in, format, n ) ||
vips_sizealike( format, size, n ) )
if( vips__formatalike_vec( in, format, n ) ||
vips__sizealike_vec( format, size, n ) )
return( -1 );
in = size;

View File

@ -343,6 +343,8 @@ vips_cast_gen( VipsRegion *or, void *vseq, void *a, void *b,
int sz = VIPS_REGION_N_ELEMENTS( or );
int x, y;
printf( "vips_cast_gen: %p\n", cast );
if( vips_region_prepare( ir, r ) )
return( -1 );
@ -443,6 +445,8 @@ vips_cast_build( VipsObject *object )
if( cast->in->BandFmt == cast->format )
return( vips_image_write( cast->in, conversion->out ) );
printf( "vips_cast_build: %p\n", object );
if( vips_check_uncoded( "VipsCast", cast->in ) ||
vips_image_pio_input( cast->in ) ||
vips_image_pio_output( conversion->out ) )
@ -465,6 +469,8 @@ vips_cast_build( VipsObject *object )
cast->in, cast ) )
return( -1 );
printf( "vips_cast_build: %p done\n", object );
return( 0 );
}

View File

@ -251,6 +251,8 @@ vips__vector_to_ink( const char *domain, VipsImage *im, double *vec, int n )
double *zeros;
int i;
printf( "vips__vector_to_ink: starting\n" );
if( vips_check_vector( domain, n, im ) )
return( NULL );
if( im_open_local_array( im, t, 3, "vtoi", "t" ) ||
@ -264,6 +266,10 @@ vips__vector_to_ink( const char *domain, VipsImage *im, double *vec, int n )
im_clip2fmt( t[1], t[2], im->BandFmt ) )
return( NULL );
printf( "vips__vector_to_ink: ink = %p (%d %d %d)\n",
t[2]->data,
t[2]->data[0], t[2]->data[1], t[2]->data[2] );
return( (PEL *) t[2]->data );
}
@ -272,8 +278,8 @@ vips_insert_build( VipsObject *object )
{
VipsConversion *conversion = VIPS_CONVERSION( object );
VipsInsert *insert = (VipsInsert *) object;
VipsImage **t = (VipsImage **) vips_object_local_array( object, 6 );
VipsImage *t[4];
VipsImage **arry;
if( VIPS_OBJECT_CLASS( vips_insert_parent_class )->build( object ) )
@ -289,13 +295,10 @@ vips_insert_build( VipsObject *object )
insert->main, insert->sub ) )
return( -1 );
if( vips_image_new_array( object, t, 4 ) )
return( -1 );
/* Cast our input images up to a common format and bands.
*/
if( vips__formatalike( insert->main, insert->sub, t[0], t[1] ) ||
vips__bandalike( "VipsInsert", t[0], t[1], t[2], t[3] ) )
if( vips__formatalike( insert->main, insert->sub, &t[0], &t[1] ) ||
vips__bandalike( "VipsInsert", t[0], t[1], &t[2], &t[3] ) )
return( -1 );
insert->main_processed = t[2];
insert->sub_processed = t[3];

View File

@ -81,7 +81,7 @@ im_open_local( VipsImage *parent,
return( image );
}
/* Just for compatibility. New code should use vips_image_new_array().
/* Just for compatibility. New code should use vips_object_local_array().
*/
int
im_open_local_array( VipsImage *parent,

View File

@ -463,7 +463,6 @@ gboolean vips_image_get_kill( VipsImage *image );
void vips_image_set_kill( VipsImage *image, gboolean kill );
VipsImage *vips_image_new( void );
int vips_image_new_array( VipsObject *parent, VipsImage **images, int n );
VipsImage *vips_image_new_mode( const char *filename, const char *mode );
VipsImage *vips_image_new_from_file( const char *filename );
VipsImage *vips_image_new_from_file_raw( const char *filename,

View File

@ -117,16 +117,17 @@ extern GMutex *vips__global_lock;
int vips__formatalike_vec( VipsImage **in, VipsImage **out, int n );
int vips__formatalike( VipsImage *in1, VipsImage *in2,
VipsImage *out1, VipsImage *out2 );
int vips__sizealike_vec( VipsImage **in, VipsImage **out, int n );
int vips__sizealike( VipsImage *in1, VipsImage *in2,
VipsImage *out1, VipsImage *out2 );
int vips__bandup( const char *domain, VipsImage *in, VipsImage *out, int n );
int vips__bandup( const char *domain, VipsImage *in, VipsImage **out, int n );
int vips__bandalike_vec( const char *domain,
VipsImage **in, VipsImage **out, int n );
int vips__formatalike( VipsImage *in1, VipsImage *in2,
VipsImage **out1, VipsImage **out2 );
int vips__sizealike( VipsImage *in1, VipsImage *in2,
VipsImage **out1, VipsImage **out2 );
int vips__bandalike( const char *domain,
VipsImage *in1, VipsImage *in2, VipsImage *out1, VipsImage *out2 );
VipsImage *in1, VipsImage *in2, VipsImage **out1, VipsImage **out2 );

View File

@ -1394,47 +1394,6 @@ vips_image_new( void )
return( image );
}
/**
* vips_image_new_array:
* @parent: images unref when this object unrefs
* @OUT: array to fill with #VipsImage *
* @N: array size
*
* Just like vips_image_new(), but opens an array of "p" images.
* Handy for creating a
* set of temporary images for a function.
*
* Example:
*
* |[
* VipsImage *t[5];
*
* if( vips_image_new_array( out, t, 5 ) ||
* vips_add( a, b, t[0] ) ||
* vips_invert( t[0], t[1] ) ||
* vips_add( t[1], t[0], t[2] ) ||
* vips_costra( t[2], out ) )
* return( -1 );
* ]|
*
* See also: vips_image_new(), vips_object_local().
*
* Returns: 0 on sucess, or -1 on error
*/
int
vips_image_new_array( VipsObject *parent, VipsImage **images, int n )
{
int i;
for( i = 0; i < n; i++ ) {
if( !(images[i] = vips_image_new()) )
return( -1 );
vips_object_local( parent, images[i] );
}
return( 0 );
}
/**
* vips_image_new_mode:
* @filename: file to open

View File

@ -1788,7 +1788,34 @@ vips_object_local_array_cb( GObject *parent, VipsObjectLocal *local )
g_free( local );
}
/* Make an array of VipsObject refs which will be unreffed when parent closes.
/**
* vips_object_local_array:
* @parent: objects unref when this object unrefs
* @n: array size
*
* Make an array of NULL VipsObject pointers. When @parent closes, every
* non-NULL pointer in the array will be unreffed and the arraqy will be
* freed.
* Handy for creating a
* set of temporary images for a function.
*
* Example:
*
* |[
* VipsObject **t;
*
* t = vips_object_local_array( out, 5 );
* if(
* vips_add( a, b, &t[0], NULL ) ||
* vips_invert( t[0], &t[1], NULL ) ||
* vips_add( t[1], t[0], &t[2], NULL ) ||
* vips_costra( t[2], out, NULL ) )
* return( -1 );
* ]|
*
* See also: vips_object_local().
*
* Returns: an array of NULL pointers of length @n
*/
VipsObject **
vips_object_local_array( VipsObject *parent, int n )

View File

@ -91,10 +91,30 @@ sink_work( VipsThreadState *state, void *a )
{
Sink *sink = (Sink *) a;
VIPS_DEBUG_MSG( "sink_work: %p "
"left = %d, top = %d, width = %d, height = %d\n",
sink,
state->pos.left,
state->pos.top,
state->pos.width,
state->pos.height );
if( vips_region_prepare_to( state->reg, sink->all,
&state->pos, state->pos.left, state->pos.top ) )
return( -1 );
#ifdef VIPS_DEBUG
{
PEL *p = (PEL *) VIPS_REGION_ADDR( state->reg,
state->pos.left, state->pos.top );
int i;
VIPS_DEBUG_MSG( "sink_work: %p\n", sink );
for( i = 0; i < VIPS_IMAGE_SIZEOF_PEL( state->reg->im ); i++ )
printf( "\t%d) %02x\n", i, p[i] );
}
#endif /*VIPS_DEBUG*/
return( 0 );
}
@ -110,31 +130,33 @@ sink_work( VipsThreadState *state, void *a )
* Returns: 0 on success, or -1 on error.
*/
int
vips_sink_memory( VipsImage *im )
vips_sink_memory( VipsImage *image )
{
Sink sink;
int result;
g_assert( vips_object_sanity( VIPS_OBJECT( im ) ) );
VIPS_DEBUG_MSG( "vips_sink_memory: %p\n", image );
g_assert( vips_object_sanity( VIPS_OBJECT( image ) ) );
/* We don't use this, but make sure it's set in case any old binaries
* are expecting it.
*/
im->Bbits = vips_format_sizeof( im->BandFmt ) << 3;
image->Bbits = vips_format_sizeof( image->BandFmt ) << 3;
if( sink_init( &sink, im ) )
if( sink_init( &sink, image ) )
return( -1 );
vips_image_preeval( im );
vips_image_preeval( image );
result = vips_threadpool_run( im,
result = vips_threadpool_run( image,
vips_thread_state_new,
vips_sink_base_allocate,
sink_work,
vips_sink_base_progress,
&sink );
vips_image_posteval( im );
vips_image_posteval( image );
sink_free( &sink );

View File

@ -588,7 +588,7 @@ vips_thread_new( VipsThreadpool *pool )
thr->btime = VIPS_ARRAY( pool->im, TBUF_SIZE, double );
thr->etime = VIPS_ARRAY( pool->im, TBUF_SIZE, double );
if( !thr->btime || !thr->etime ) {
thread_free( thr );
vips_thread_free( thr );
return( NULL );
}
#endif /*TIME_THREAD*/

View File

@ -680,7 +680,7 @@ transform_array_double_g_string( const GValue *src_value, GValue *dest_value )
/* Use space as a separator since ',' may be a decimal point
* in this locale.
*/
vips_buf_appends( &buf, "%g ", array[i] );
vips_buf_appendf( &buf, "%g ", array[i] );
g_value_set_string( dest_value, vips_buf_all( &buf ) );
}