diff --git a/ChangeLog b/ChangeLog index aae1834d..e503eb90 100644 --- a/ChangeLog +++ b/ChangeLog @@ -73,6 +73,7 @@ - added im_col_display_get_table(), so display tables are now shared by name - added im__colour_unary() - drop "set" postfix from names, so "insert" can now take a vector of positions +- deprecate all the "_raw" variants, not really necessary now 25/3/09 started 7.18.0 - revised version numbers diff --git a/TODO b/TODO index 6f243468..43761db0 100644 --- a/TODO +++ b/TODO @@ -1,21 +1,12 @@ -- vips.c should drop "set" suffix from operators - - poor SMP scaling in benchmark + kernel changes? benchmark an old version + avg is different? used to 120.134, now 120.151 -- _raw() variants should be deprecated? - -- look through more sections for stuff in the wrong place - - more stuff from util.c? too much to do it all now -- maybe im_insertplaceset() should be im_insertset()? it's not an inplace - operator now - -- like _vec(), remove set() from the ends of operator names in C++ - -- load 500 jpegs, shrink, save +- load 500 jpegs, group, shrink, save VM use is huge, ouch, could we use a bit less? @@ -26,15 +17,10 @@ -- VipsFormat next? where should we document the im_vip2jpeg() options? - - - - - constant images: we make them with im_black(), then m_lintra(), then im_clip(). How - about instead making a 1x1 pixel image and expanding it with im_emed() + about instead making a 1x1 pixel image and expanding with im_embed() would this be quicker? test wth nip2 diff --git a/libvips/convolution/convol_dispatch.c b/libvips/convolution/convol_dispatch.c index ff9cff2b..a2f9fb23 100644 --- a/libvips/convolution/convol_dispatch.c +++ b/libvips/convolution/convol_dispatch.c @@ -100,38 +100,6 @@ static im_function contrast_surface_desc = { contrast_surface_args /* Arg list */ }; -/* Args to im_contrast_surface_raw. - */ -static im_arg_desc contrast_surface_raw_args[] = { - IM_INPUT_IMAGE( "in" ), - IM_OUTPUT_IMAGE( "out" ), - IM_INPUT_INT( "half_win_size" ), - IM_INPUT_INT( "spacing" ) -}; - -/* Call im_contrast_surface_raw via arg vector. - */ -static int -contrast_surface_raw_vec( im_object *argv ) -{ - int half_win_size = *((int *) argv[2]); - int spacing = *((int *) argv[3]); - - return( im_contrast_surface_raw( argv[0], argv[1], - half_win_size, spacing ) ); -} - -/* Description of im_contrast_surface_raw. - */ -static im_function contrast_surface_raw_desc = { - "im_contrast_surface_raw", /* Name */ - "find high-contrast points in an image", - IM_FN_PIO, /* Flags */ - contrast_surface_raw_vec, /* Dispatch function */ - IM_NUMBER( contrast_surface_raw_args ),/* Size of arg list */ - contrast_surface_raw_args /* Arg list */ -}; - /* Args to im_sharpen. */ static im_arg_desc sharpen_args[] = { @@ -229,27 +197,6 @@ static im_function conv_desc = { conv_imask /* Arg list */ }; -/* Call im_conv_raw via arg vector. - */ -static int -conv_raw_vec( im_object *argv ) -{ - im_mask_object *mo = argv[2]; - - return( im_conv_raw( argv[0], argv[1], mo->mask ) ); -} - -/* Description of im_conv_raw. - */ -static im_function conv_raw_desc = { - "im_conv_raw", /* Name */ - "convolve, no border", - IM_FN_TRANSFORM | IM_FN_PIO, /* Flags */ - conv_raw_vec, /* Dispatch function */ - IM_NUMBER( conv_imask ), /* Size of arg list */ - conv_imask /* Arg list */ -}; - /* Call im_convf via arg vector. */ static int @@ -271,27 +218,6 @@ static im_function convf_desc = { conv_dmask /* Arg list */ }; -/* Call im_convf_raw via arg vector. - */ -static int -convf_raw_vec( im_object *argv ) -{ - im_mask_object *mo = argv[2]; - - return( im_convf_raw( argv[0], argv[1], mo->mask ) ); -} - -/* Description of im_convf_raw. - */ -static im_function convf_raw_desc = { - "im_convf_raw", /* Name */ - "convolve, with DOUBLEMASK, no border", - IM_FN_TRANSFORM | IM_FN_PIO, /* Flags */ - convf_raw_vec, /* Dispatch function */ - IM_NUMBER( conv_dmask ), /* Size of arg list */ - conv_dmask /* Arg list */ -}; - /* Call im_convsep via arg vector. */ static int @@ -313,27 +239,6 @@ static im_function convsep_desc = { conv_imask /* Arg list */ }; -/* Call im_convsep_raw via arg vector. - */ -static int -convsep_raw_vec( im_object *argv ) -{ - im_mask_object *mo = argv[2]; - - return( im_convsep_raw( argv[0], argv[1], mo->mask ) ); -} - -/* Description of im_convsep_raw. - */ -static im_function convsep_raw_desc = { - "im_convsep_raw", /* Name */ - "seperable convolution, no border", - IM_FN_TRANSFORM | IM_FN_PIO, /* Flags */ - convsep_raw_vec, /* Dispatch function */ - IM_NUMBER( conv_imask ), /* Size of arg list */ - conv_imask /* Arg list */ -}; - /* Call im_convsepf via arg vector. */ static int @@ -355,27 +260,6 @@ static im_function convsepf_desc = { conv_dmask /* Arg list */ }; -/* Call im_convsepf_raw via arg vector. - */ -static int -convsepf_raw_vec( im_object *argv ) -{ - im_mask_object *mo = argv[2]; - - return( im_convsepf_raw( argv[0], argv[1], mo->mask ) ); -} - -/* Description of im_convsepf_raw. - */ -static im_function convsepf_raw_desc = { - "im_convsepf_raw", /* Name */ - "seperable convolution, with DOUBLEMASK, no border", - IM_FN_PIO | IM_FN_TRANSFORM, /* Flags */ - convsepf_raw_vec, /* Dispatch function */ - IM_NUMBER( conv_dmask ), /* Size of arg list */ - conv_dmask /* Arg list */ -}; - /* Call im_fastcor via arg vector. */ static int @@ -395,25 +279,6 @@ static im_function fastcor_desc = { two_in_one_out /* Arg list */ }; -/* Call im_fastcor_raw via arg vector. - */ -static int -fastcor_raw_vec( im_object *argv ) -{ - return( im_fastcor_raw( argv[0], argv[1], argv[2] ) ); -} - -/* Description of im_fastcor_raw. - */ -static im_function fastcor_raw_desc = { - "im_fastcor_raw", /* Name */ - "fast correlate in2 within in1, no border", - IM_FN_TRANSFORM | IM_FN_PIO, /* Flags */ - fastcor_raw_vec, /* Dispatch function */ - IM_NUMBER( two_in_one_out ), /* Size of arg list */ - two_in_one_out /* Arg list */ -}; - /* Call im_grad_x via arg vector. */ static int @@ -471,25 +336,6 @@ static im_function gradcor_desc = { two_in_one_out /* Arg list */ }; -/* Call im_gradcor_raw via arg vector. - */ -static int -gradcor_raw_vec( im_object *argv ) -{ - return( im_gradcor_raw( argv[0], argv[1], argv[2] ) ); -} - -/* Description of im_gradcor_raw. - */ -static im_function gradcor_raw_desc = { - "im_gradcor_raw", /* Name */ - "non-normalised correlation of gradient of in2 within in1, no padding", - IM_FN_PIO | IM_FN_TRANSFORM, /* Flags */ - gradcor_raw_vec, /* Dispatch function */ - IM_NUMBER( two_in_one_out ), /* Size of arg list */ - two_in_one_out /* Arg list */ -}; - /* Call im_gradient via arg vector. */ static int @@ -551,50 +397,23 @@ static im_function spcor_desc = { two_in_one_out /* Arg list */ }; -/* Call im_spcor_raw via arg vector. - */ -static int -spcor_raw_vec( im_object *argv ) -{ - return( im_spcor_raw( argv[0], argv[1], argv[2] ) ); -} - -/* Description of im_spcor_raw. - */ -static im_function spcor_raw_desc = { - "im_spcor_raw", /* Name */ - "normalised correlation of in2 within in1, no black padding", - IM_FN_PIO | IM_FN_TRANSFORM, /* Flags */ - spcor_raw_vec, /* Dispatch function */ - IM_NUMBER( two_in_one_out ), /* Size of arg list */ - two_in_one_out /* Arg list */ -}; - /* Package up all these functions. */ static im_function *convol_list[] = { &compass_desc, &contrast_surface_desc, - &contrast_surface_raw_desc, &conv_desc, &convf_desc, - &convf_raw_desc, - &conv_raw_desc, &convsep_desc, &convsepf_desc, - &convsepf_raw_desc, - &convsep_raw_desc, &fastcor_desc, - &fastcor_raw_desc, &gradcor_desc, - &gradcor_raw_desc, &gradient_desc, &grad_x_desc, &grad_y_desc, &lindetect_desc, &sharpen_desc, &spcor_desc, - &spcor_raw_desc }; /* Package of functions. diff --git a/libvips/convolution/im_conv.c b/libvips/convolution/im_conv.c index 8768b564..5e8c2bb1 100644 --- a/libvips/convolution/im_conv.c +++ b/libvips/convolution/im_conv.c @@ -474,114 +474,3 @@ im_conv( IMAGE *in, IMAGE *out, INTMASK *mask ) return( 0 ); } - -/* im__create_int_luts is not used in this file. We have to keep it for the use - * of other conv functions in this directory which have not yet been - * rewritten. - - FIXME ... the only one left is im_convsub() which I'm sure no one - uses. Scrap this junk in the next version. Kill off the old gradient - and lindetect things too. - - */ - -/* Create multiplication luts for all non zero elements of the original mask; - * which is kept in buffer of length buffersize - * cnt is needed for freeing luts - */ -int -im__create_int_luts( int *buffer, int buffersize, - int **orig_luts, int **luts, int *cnt ) -{ - int *pbuffer; - int *buf1, *buf2, *pbuf1, *pbuf2; - int i, j; - int min, max; - int mark; /* used to mark the buffer mark = max+1 */ - int counter; /* counts the no of unique elms in mask; returned in cnt*/ - - buf1 = (int*)calloc( (unsigned)buffersize, sizeof(int) ); - buf2 = (int*)calloc( (unsigned)buffersize, sizeof(int) ); - if ( ( buf1 == NULL ) || ( buf2 == NULL ) ) - { - im_error( "im_create_int_luts", "%s", _( "calloc failed (1)") ); - return( -1 ); - } - - pbuffer = buffer; - pbuf1 = buf1; - /* find max and copy mask to buf1 */ - max = *pbuffer; - for ( i=0; i < buffersize; i++ ) - { - if ( *pbuffer > max ) - max = *pbuffer; - *pbuf1++ = *pbuffer++; - } - mark = max + 1; - pbuf1 = buf1; - pbuf2 = buf2; - counter = 0; -/* find a min at a time; put it into buf2 and mark all values of - * buf1 equal to found min, to INT_MAX - */ - for ( i=0; i < buffersize; i++ ) - { - min = mark + 1; /* force min to be greater than mark */ - pbuf1 = buf1; - /* find a min */ - for ( j=0; j < buffersize; j++ ) - { - if ( *pbuf1 < min ) - min = *pbuf1; - pbuf1++; - } - if ( min == mark ) /* all min are found */ - break; - *pbuf2++ = min; - counter++; - pbuf1 = buf1; - for ( j=0; j < buffersize; j++ ) /* mark values equal to min */ - { - if ( *pbuf1 == min ) - *pbuf1 = mark; - pbuf1++; - } - } -/* buf2 should keep now counter unique values of the mask, descending order - * Malloc counter luts and initialise them - */ - pbuf2 = buf2; - for ( i=0; iXsize / 2, ref->Ysize / 2, - in->Xsize + ref->Xsize - 1, - in->Ysize + ref->Ysize - 1 ) || - im_gradcor_raw( t1, ref, out ) ) - return( -1 ); - - out->Xoffset = 0; - out->Yoffset = 0; - - return( 0 ); -#undef FUNCTION_NAME -} - int im_gradcor_raw( IMAGE *large, IMAGE *small, IMAGE *out ){ #define FUNCTION_NAME "im_gradcor_raw" @@ -173,6 +152,27 @@ int im_gradcor_raw( IMAGE *large, IMAGE *small, IMAGE *out ){ #undef FUNCTION_NAME } +int +im_gradcor( IMAGE *in, IMAGE *ref, IMAGE *out ) +{ +#define FUNCTION_NAME "im_gradcor" + IMAGE *t1 = im_open_local( out, FUNCTION_NAME " intermediate", "p" ); + + if( !t1 || + im_embed( in, t1, 1, + ref->Xsize / 2, ref->Ysize / 2, + in->Xsize + ref->Xsize - 1, + in->Ysize + ref->Ysize - 1 ) || + im_gradcor_raw( t1, ref, out ) ) + return( -1 ); + + out->Xoffset = 0; + out->Yoffset = 0; + + return( 0 ); +#undef FUNCTION_NAME +} + int im_grad_x( IMAGE *in, IMAGE *out ){ #define FUNCTION_NAME "im_grad_x" diff --git a/libvips/deprecated/deprecated_dispatch.c b/libvips/deprecated/deprecated_dispatch.c index aada2c60..db5059bc 100644 --- a/libvips/deprecated/deprecated_dispatch.c +++ b/libvips/deprecated/deprecated_dispatch.c @@ -41,6 +41,62 @@ #include #endif /*WITH_DMALLOC*/ +/* Args for im_lhisteq. + */ +static im_arg_desc lhisteq_args[] = { + IM_INPUT_IMAGE( "in" ), + IM_OUTPUT_IMAGE( "out" ), + IM_INPUT_INT( "width" ), + IM_INPUT_INT( "height" ) +}; + +/* Args for im_stdif. + */ +static im_arg_desc stdif_args[] = { + IM_INPUT_IMAGE( "in" ), + IM_OUTPUT_IMAGE( "out" ), + IM_INPUT_DOUBLE( "a" ), + IM_INPUT_DOUBLE( "m0" ), + IM_INPUT_DOUBLE( "b" ), + IM_INPUT_DOUBLE( "s0" ), + IM_INPUT_INT( "xw" ), + IM_INPUT_INT( "yw" ) +}; + +/* Args to im_erode. + */ +static im_arg_desc erode_args[] = { + IM_INPUT_IMAGE( "in" ), + IM_OUTPUT_IMAGE( "out" ), + IM_INPUT_IMASK( "mask" ) +}; + +/* Args to im_rank. + */ +static im_arg_desc rank_args[] = { + IM_INPUT_IMAGE( "in" ), + IM_OUTPUT_IMAGE( "out" ), + IM_INPUT_INT( "xsize" ), + IM_INPUT_INT( "ysize" ), + IM_INPUT_INT( "n" ) +}; + +/* Args for convolver with imask. + */ +static im_arg_desc conv_imask[] = { + IM_INPUT_IMAGE( "in" ), + IM_OUTPUT_IMAGE( "out" ), + IM_INPUT_IMASK( "matrix" ) +}; + +/* Args for convolver with dmask. + */ +static im_arg_desc conv_dmask[] = { + IM_INPUT_IMAGE( "in" ), + IM_OUTPUT_IMAGE( "out" ), + IM_INPUT_DMASK( "matrix" ) +}; + /* One image in, one out. */ static im_arg_desc one_in_one_out[] = { @@ -826,6 +882,292 @@ static im_function insertplaceset_desc = { insertplaceset_args /* Arg list */ }; +/* Call im_spcor_raw via arg vector. + */ +static int +spcor_raw_vec( im_object *argv ) +{ + return( im_spcor_raw( argv[0], argv[1], argv[2] ) ); +} + +/* Description of im_spcor_raw. + */ +static im_function spcor_raw_desc = { + "im_spcor_raw", /* Name */ + "normalised correlation of in2 within in1, no black padding", + IM_FN_PIO | IM_FN_TRANSFORM, /* Flags */ + spcor_raw_vec, /* Dispatch function */ + IM_NUMBER( two_in_one_out ), /* Size of arg list */ + two_in_one_out /* Arg list */ +}; + +/* Call im_gradcor_raw via arg vector. + */ +static int +gradcor_raw_vec( im_object *argv ) +{ + return( im_gradcor_raw( argv[0], argv[1], argv[2] ) ); +} + +/* Description of im_gradcor_raw. + */ +static im_function gradcor_raw_desc = { + "im_gradcor_raw", /* Name */ + "non-normalised correlation of gradient of in2 within in1, no padding", + IM_FN_PIO | IM_FN_TRANSFORM, /* Flags */ + gradcor_raw_vec, /* Dispatch function */ + IM_NUMBER( two_in_one_out ), /* Size of arg list */ + two_in_one_out /* Arg list */ +}; + +/* Call im_fastcor_raw via arg vector. + */ +static int +fastcor_raw_vec( im_object *argv ) +{ + return( im_fastcor_raw( argv[0], argv[1], argv[2] ) ); +} + +/* Description of im_fastcor_raw. + */ +static im_function fastcor_raw_desc = { + "im_fastcor_raw", /* Name */ + "fast correlate in2 within in1, no border", + IM_FN_TRANSFORM | IM_FN_PIO, /* Flags */ + fastcor_raw_vec, /* Dispatch function */ + IM_NUMBER( two_in_one_out ), /* Size of arg list */ + two_in_one_out /* Arg list */ +}; + +/* Call im_convsepf_raw via arg vector. + */ +static int +convsepf_raw_vec( im_object *argv ) +{ + im_mask_object *mo = argv[2]; + + return( im_convsepf_raw( argv[0], argv[1], mo->mask ) ); +} + +/* Description of im_convsepf_raw. + */ +static im_function convsepf_raw_desc = { + "im_convsepf_raw", /* Name */ + "seperable convolution, with DOUBLEMASK, no border", + IM_FN_PIO | IM_FN_TRANSFORM, /* Flags */ + convsepf_raw_vec, /* Dispatch function */ + IM_NUMBER( conv_dmask ), /* Size of arg list */ + conv_dmask /* Arg list */ +}; + +/* Call im_convsep_raw via arg vector. + */ +static int +convsep_raw_vec( im_object *argv ) +{ + im_mask_object *mo = argv[2]; + + return( im_convsep_raw( argv[0], argv[1], mo->mask ) ); +} + +/* Description of im_convsep_raw. + */ +static im_function convsep_raw_desc = { + "im_convsep_raw", /* Name */ + "seperable convolution, no border", + IM_FN_TRANSFORM | IM_FN_PIO, /* Flags */ + convsep_raw_vec, /* Dispatch function */ + IM_NUMBER( conv_imask ), /* Size of arg list */ + conv_imask /* Arg list */ +}; + +/* Call im_convf_raw via arg vector. + */ +static int +convf_raw_vec( im_object *argv ) +{ + im_mask_object *mo = argv[2]; + + return( im_convf_raw( argv[0], argv[1], mo->mask ) ); +} + +/* Description of im_convf_raw. + */ +static im_function convf_raw_desc = { + "im_convf_raw", /* Name */ + "convolve, with DOUBLEMASK, no border", + IM_FN_TRANSFORM | IM_FN_PIO, /* Flags */ + convf_raw_vec, /* Dispatch function */ + IM_NUMBER( conv_dmask ), /* Size of arg list */ + conv_dmask /* Arg list */ +}; + +/* Call im_conv_raw via arg vector. + */ +static int +conv_raw_vec( im_object *argv ) +{ + im_mask_object *mo = argv[2]; + + return( im_conv_raw( argv[0], argv[1], mo->mask ) ); +} + +/* Description of im_conv_raw. + */ +static im_function conv_raw_desc = { + "im_conv_raw", /* Name */ + "convolve, no border", + IM_FN_TRANSFORM | IM_FN_PIO, /* Flags */ + conv_raw_vec, /* Dispatch function */ + IM_NUMBER( conv_imask ), /* Size of arg list */ + conv_imask /* Arg list */ +}; + +/* Args to im_contrast_surface_raw. + */ +static im_arg_desc contrast_surface_raw_args[] = { + IM_INPUT_IMAGE( "in" ), + IM_OUTPUT_IMAGE( "out" ), + IM_INPUT_INT( "half_win_size" ), + IM_INPUT_INT( "spacing" ) +}; + +/* Call im_contrast_surface_raw via arg vector. + */ +static int +contrast_surface_raw_vec( im_object *argv ) +{ + int half_win_size = *((int *) argv[2]); + int spacing = *((int *) argv[3]); + + return( im_contrast_surface_raw( argv[0], argv[1], + half_win_size, spacing ) ); +} + +/* Description of im_contrast_surface_raw. + */ +static im_function contrast_surface_raw_desc = { + "im_contrast_surface_raw", /* Name */ + "find high-contrast points in an image", + IM_FN_PIO, /* Flags */ + contrast_surface_raw_vec, /* Dispatch function */ + IM_NUMBER( contrast_surface_raw_args ),/* Size of arg list */ + contrast_surface_raw_args /* Arg list */ +}; + +/* Call im_stdif_raw via arg vector. + */ +static int +stdif_raw_vec( im_object *argv ) +{ + double a = *((double *) argv[2]); + double m0 = *((double *) argv[3]); + double b = *((double *) argv[4]); + double s0 = *((double *) argv[5]); + int xw = *((int *) argv[6]); + int yw = *((int *) argv[7]); + + return( im_stdif_raw( argv[0], argv[1], a, m0, b, s0, xw, yw ) ); +} + +/* Description of im_stdif. + */ +static im_function stdif_raw_desc = { + "im_stdif_raw", /* Name */ + "statistical differencing, no border", + IM_FN_PIO, /* Flags */ + stdif_raw_vec, /* Dispatch function */ + IM_NUMBER( stdif_args ), /* Size of arg list */ + stdif_args /* Arg list */ +}; + +/* Call im_lhisteq_raw via arg vector. + */ +static int +lhisteq_raw_vec( im_object *argv ) +{ + int xw = *((int *) argv[2]); + int yw = *((int *) argv[3]); + + return( im_lhisteq_raw( argv[0], argv[1], xw, yw ) ); +} + +/* Description of im_lhisteq_raw. + */ +static im_function lhisteq_raw_desc = { + "im_lhisteq_raw", /* Name */ + "local histogram equalisation, no border", + IM_FN_PIO, /* Flags */ + lhisteq_raw_vec, /* Dispatch function */ + IM_NUMBER( lhisteq_args ), /* Size of arg list */ + lhisteq_args /* Arg list */ +}; + +/* Call im_rank_raw via arg vector. + */ +static int +rank_raw_vec( im_object *argv ) +{ + int xsize = *((int *) argv[2]); + int ysize = *((int *) argv[3]); + int n = *((int *) argv[4]); + + return( im_rank_raw( argv[0], argv[1], xsize, ysize, n ) ); +} + +/* Description of im_rank_raw. + */ +static im_function rank_raw_desc = { + "im_rank_raw", /* Name */ + "rank filter nth element of xsize/ysize window, no border", + IM_FN_PIO, /* Flags */ + rank_raw_vec, /* Dispatch function */ + IM_NUMBER( rank_args ), /* Size of arg list */ + rank_args /* Arg list */ +}; + +/* Call im_erode_raw via arg vector. + */ +static int +erode_raw_vec( im_object *argv ) +{ + im_mask_object *mo = argv[2]; + + return( im_erode_raw( argv[0], argv[1], mo->mask ) ); +} + +/* Description of im_erode_raw. + */ +static im_function erode_raw_desc = { + "im_erode_raw", /* Name */ + "erode image with mask", + IM_FN_PIO | IM_FN_TRANSFORM, /* Flags */ + erode_raw_vec, /* Dispatch function */ + IM_NUMBER( erode_args ), /* Size of arg list */ + erode_args /* Arg list */ +}; + +/* Call im_dilate_raw via arg vector. + */ +static int +dilate_raw_vec( im_object *argv ) +{ + im_mask_object *mo = argv[2]; + + return( im_dilate_raw( argv[0], argv[1], mo->mask ) ); +} + +/* Description of im_dilate_raw. + */ +static im_function dilate_raw_desc = { + "im_dilate_raw", /* Name */ + "dilate image with mask", + IM_FN_PIO | IM_FN_TRANSFORM, /* Flags */ + dilate_raw_vec, /* Dispatch function */ + IM_NUMBER( erode_args ), /* Size of arg list */ + erode_args /* Arg list */ +}; + /* Package up all these functions. */ static im_function *deprecated_list[] = { @@ -854,6 +1196,19 @@ static im_function *deprecated_list[] = { &segment_desc, &line_desc, &thresh_desc, + &convf_raw_desc, + &conv_raw_desc, + &contrast_surface_raw_desc, + &convsepf_raw_desc, + &convsep_raw_desc, + &fastcor_raw_desc, + &gradcor_raw_desc, + &spcor_raw_desc, + &lhisteq_raw_desc, + &stdif_raw_desc, + &rank_raw_desc, + &dilate_raw_desc, + &erode_raw_desc, &similarity_area_desc, &similarity_desc }; diff --git a/libvips/deprecated/im_convsub.c b/libvips/deprecated/im_convsub.c index d829c9a8..af85530d 100644 --- a/libvips/deprecated/im_convsub.c +++ b/libvips/deprecated/im_convsub.c @@ -60,6 +60,107 @@ #include #endif /*WITH_DMALLOC*/ +/* Create multiplication luts for all non zero elements of the original mask; + * which is kept in buffer of length buffersize + * cnt is needed for freeing luts + */ +static int +im__create_int_luts( int *buffer, int buffersize, + int **orig_luts, int **luts, int *cnt ) +{ + int *pbuffer; + int *buf1, *buf2, *pbuf1, *pbuf2; + int i, j; + int min, max; + int mark; /* used to mark the buffer mark = max+1 */ + int counter; /* counts the no of unique elms in mask; returned in cnt*/ + + buf1 = (int*)calloc( (unsigned)buffersize, sizeof(int) ); + buf2 = (int*)calloc( (unsigned)buffersize, sizeof(int) ); + if ( ( buf1 == NULL ) || ( buf2 == NULL ) ) + { + im_error( "im_create_int_luts", "%s", _( "calloc failed (1)") ); + return( -1 ); + } + + pbuffer = buffer; + pbuf1 = buf1; + /* find max and copy mask to buf1 */ + max = *pbuffer; + for ( i=0; i < buffersize; i++ ) + { + if ( *pbuffer > max ) + max = *pbuffer; + *pbuf1++ = *pbuffer++; + } + mark = max + 1; + pbuf1 = buf1; + pbuf2 = buf2; + counter = 0; +/* find a min at a time; put it into buf2 and mark all values of + * buf1 equal to found min, to INT_MAX + */ + for ( i=0; i < buffersize; i++ ) + { + min = mark + 1; /* force min to be greater than mark */ + pbuf1 = buf1; + /* find a min */ + for ( j=0; j < buffersize; j++ ) + { + if ( *pbuf1 < min ) + min = *pbuf1; + pbuf1++; + } + if ( min == mark ) /* all min are found */ + break; + *pbuf2++ = min; + counter++; + pbuf1 = buf1; + for ( j=0; j < buffersize; j++ ) /* mark values equal to min */ + { + if ( *pbuf1 == min ) + *pbuf1 = mark; + pbuf1++; + } + } +/* buf2 should keep now counter unique values of the mask, descending order + * Malloc counter luts and initialise them + */ + pbuf2 = buf2; + for ( i=0; imask ) ); -} - -/* Description of im_dilate_raw. - */ -static im_function dilate_raw_desc = { - "im_dilate_raw", /* Name */ - "dilate image with mask", - IM_FN_PIO | IM_FN_TRANSFORM, /* Flags */ - dilate_raw_vec, /* Dispatch function */ - IM_NUMBER( erode_args ), /* Size of arg list */ - erode_args /* Arg list */ -}; - /* Call im_erode via arg vector. */ static int @@ -153,27 +132,6 @@ static im_function erode_desc = { erode_args /* Arg list */ }; -/* Call im_erode_raw via arg vector. - */ -static int -erode_raw_vec( im_object *argv ) -{ - im_mask_object *mo = argv[2]; - - return( im_erode_raw( argv[0], argv[1], mo->mask ) ); -} - -/* Description of im_erode_raw. - */ -static im_function erode_raw_desc = { - "im_erode_raw", /* Name */ - "erode image with mask", - IM_FN_PIO | IM_FN_TRANSFORM, /* Flags */ - erode_raw_vec, /* Dispatch function */ - IM_NUMBER( erode_args ), /* Size of arg list */ - erode_args /* Arg list */ -}; - /* Args to im_cntlines. */ static im_arg_desc cntlines_args[] = { @@ -312,29 +270,6 @@ static im_function rank_image_desc = { rank_image_args /* Arg list */ }; -/* Call im_rank_raw via arg vector. - */ -static int -rank_raw_vec( im_object *argv ) -{ - int xsize = *((int *) argv[2]); - int ysize = *((int *) argv[3]); - int n = *((int *) argv[4]); - - return( im_rank_raw( argv[0], argv[1], xsize, ysize, n ) ); -} - -/* Description of im_rank_raw. - */ -static im_function rank_raw_desc = { - "im_rank_raw", /* Name */ - "rank filter nth element of xsize/ysize window, no border", - IM_FN_PIO, /* Flags */ - rank_raw_vec, /* Dispatch function */ - IM_NUMBER( rank_args ), /* Size of arg list */ - rank_args /* Arg list */ -}; - /* Args for im_label_regions(). */ static im_arg_desc label_regions_args[] = { @@ -376,10 +311,7 @@ static im_function *morph_list[] = { &maxvalue_desc, &label_regions_desc, &zerox_desc, - &rank_raw_desc, - &dilate_raw_desc, &erode_desc, - &erode_raw_desc, &profile_desc };