fix more, moreeq

there was a problem with operation caching in complex programs because of
the way we were swapping pointers
This commit is contained in:
John Cupitt 2014-09-17 11:21:34 +01:00
parent 8b9dc20684
commit bb50478d77
2 changed files with 27 additions and 38 deletions

13
TODO
View File

@ -1,16 +1,6 @@
- python:
- try:
$ python test_arithmetic.py -v TestArithmetic.test_moreeq
test_moreeq (__main__.TestArithmetic) ... **
VIPS:ERROR:cache.c:606:vips_cache_insert: assertion failed:
(!g_hash_table_lookup( vips_cache_table, operation ))
Aborted (core dumped)
same for more; less, lesseq, equal and noteq are fine
- could import like this:
from gi.repository import Vips
@ -19,6 +9,9 @@
ie. make it a module, not a package, and make it clear that it
modifies Vips rather than adding anything itself
- should be a separate package?
easier to get into CPAN or whatever the python thing is called
- can we pick the vipsthumbnail int shrink factor more intelligently?

View File

@ -30,6 +30,8 @@
* - complex ==, != were broken
* 16/7/12
* - im1 > im2, im1 >= im2 were broken
* 17/9/14
* - im1 > im2, im1 >= im2 were still broken, but in a more subtle way
*/
/*
@ -87,31 +89,9 @@ typedef VipsBinaryClass VipsRelationalClass;
G_DEFINE_TYPE( VipsRelational, vips_relational, VIPS_TYPE_BINARY );
static int
vips_relational_build( VipsObject *object )
{
VipsRelational *relational = (VipsRelational *) object;
VipsBinary *binary = (VipsBinary *) object;
if( relational->relational == VIPS_OPERATION_RELATIONAL_MORE ) {
relational->relational = VIPS_OPERATION_RELATIONAL_LESS;
VIPS_SWAP( VipsImage *, binary->left, binary->right );
}
if( relational->relational == VIPS_OPERATION_RELATIONAL_MOREEQ ) {
relational->relational = VIPS_OPERATION_RELATIONAL_LESSEQ;
VIPS_SWAP( VipsImage *, binary->left, binary->right );
}
if( VIPS_OBJECT_CLASS( vips_relational_parent_class )->build( object ) )
return( -1 );
return( 0 );
}
#define RLOOP( TYPE, ROP ) { \
TYPE * restrict left = (TYPE *) in[0]; \
TYPE * restrict right = (TYPE *) in[1]; \
TYPE * restrict left = (TYPE *) in0; \
TYPE * restrict right = (TYPE *) in1; \
VipsPel * restrict q = (VipsPel *) out; \
\
for( x = 0; x < sz; x++ ) \
@ -119,8 +99,8 @@ vips_relational_build( VipsObject *object )
}
#define CLOOP( TYPE, COP ) { \
TYPE * restrict left = (TYPE *) in[0]; \
TYPE * restrict right = (TYPE *) in[1]; \
TYPE * restrict left = (TYPE *) in0; \
TYPE * restrict right = (TYPE *) in1; \
VipsPel * restrict q = (VipsPel *) out; \
\
for( x = 0; x < sz; x++ ) { \
@ -163,9 +143,26 @@ vips_relational_buffer( VipsArithmetic *arithmetic,
VipsImage *im = arithmetic->ready[0];
const int sz = width * vips_image_get_bands( im );
VipsOperationRelational op;
VipsPel *in0;
VipsPel *in1;
int x;
switch( relational->relational ) {
in0 = in[0];
in1 = in[1];
op = relational->relational;
if( op == VIPS_OPERATION_RELATIONAL_MORE ) {
op = VIPS_OPERATION_RELATIONAL_LESS;
VIPS_SWAP( VipsPel *, in0, in1 );
}
if( op == VIPS_OPERATION_RELATIONAL_MOREEQ ) {
op = VIPS_OPERATION_RELATIONAL_LESSEQ;
VIPS_SWAP( VipsPel *, in0, in1 );
}
switch( op ) {
case VIPS_OPERATION_RELATIONAL_EQUAL:
SWITCH( RLOOP, CLOOP, ==, CEQUAL );
break;
@ -217,7 +214,6 @@ vips_relational_class_init( VipsRelationalClass *class )
object_class->nickname = "relational";
object_class->description = _( "relational operation on two images" );
object_class->build = vips_relational_build;
aclass->process_line = vips_relational_buffer;