stuff
This commit is contained in:
parent
b3f2c93c5d
commit
150865045f
@ -45,6 +45,7 @@
|
|||||||
- renamed im_eorconst() as im_eorimage_const() for consistency, also and, or
|
- renamed im_eorconst() as im_eorimage_const() for consistency, also and, or
|
||||||
- relational revised: smaller, more general, faster
|
- relational revised: smaller, more general, faster
|
||||||
- im_blend() allows many-band conditional, 1-band then/else
|
- im_blend() allows many-band conditional, 1-band then/else
|
||||||
|
- im_blend() allows band and format to differ between then and else parts
|
||||||
|
|
||||||
25/3/09 started 7.18.0
|
25/3/09 started 7.18.0
|
||||||
- revised version numbers
|
- revised version numbers
|
||||||
|
13
TODO
13
TODO
@ -1,15 +1,4 @@
|
|||||||
- test im_blend, including new n-band cond + n-band a/b mode
|
- do im_ifthenelse
|
||||||
|
|
||||||
- do the same to im_ifthenelse
|
|
||||||
|
|
||||||
- should we bandup then/else too? could have
|
|
||||||
|
|
||||||
4 band cond
|
|
||||||
1 band then
|
|
||||||
4 band else
|
|
||||||
|
|
||||||
I guess
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- we have tools/ and contrib/ argh
|
- we have tools/ and contrib/ argh
|
||||||
|
@ -184,6 +184,19 @@ im__format_common( IMAGE *in1, IMAGE *in2 )
|
|||||||
return( bandfmt_largest[in1->BandFmt][in2->BandFmt] );
|
return( bandfmt_largest[in1->BandFmt][in2->BandFmt] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
im__formatalike( IMAGE *in1, IMAGE *in2, IMAGE *out1, IMAGE *out2 )
|
||||||
|
{
|
||||||
|
VipsBandFmt fmt;
|
||||||
|
|
||||||
|
fmt = im__format_common( in1, in2 );
|
||||||
|
if( im_clip2fmt( in1, out1, fmt ) ||
|
||||||
|
im_clip2fmt( in2, out2, fmt ) )
|
||||||
|
return( -1 );
|
||||||
|
|
||||||
|
return( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
/* Make an n-band image. Input 1 or n bands.
|
/* Make an n-band image. Input 1 or n bands.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
@ -209,15 +222,27 @@ im__bandup( IMAGE *in, IMAGE *out, int n )
|
|||||||
return( im_gbandjoin( bands, out, n ) );
|
return( im_gbandjoin( bands, out, n ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
im__bandalike( IMAGE *in1, IMAGE *in2, IMAGE *out1, IMAGE *out2 )
|
||||||
|
{
|
||||||
|
if( im_check_bands_1orn( "im__bandalike", in1, in2 ) )
|
||||||
|
return( -1 );
|
||||||
|
if( im__bandup( in1, out1, IM_MAX( in1->Bands, in2->Bands ) ) ||
|
||||||
|
im__bandup( in2, out2, IM_MAX( in1->Bands, in2->Bands ) ) )
|
||||||
|
return( -1 );
|
||||||
|
|
||||||
|
return( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
/* The common part of most binary arithmetic, relational and boolean
|
/* The common part of most binary arithmetic, relational and boolean
|
||||||
* operators. We:
|
* operators. We:
|
||||||
*
|
*
|
||||||
* - check in and out
|
* - check in and out
|
||||||
* - cast in1 and in2 up to a common format
|
* - cast in1 and in2 up to a common format
|
||||||
* - cast the common format to the output format with the supplied table
|
* - cast the common format to the output format with the supplied table
|
||||||
* - equalise bands
|
* - equalise bands and size
|
||||||
* - run the supplied buffer operation passing one of the up-banded and
|
* - run the supplied buffer operation passing one of the up-banded,
|
||||||
* up-casted inputs as the first param
|
* up-casted and up-sized inputs as the first param
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
im__arith_binary( const char *name,
|
im__arith_binary( const char *name,
|
||||||
@ -225,7 +250,6 @@ im__arith_binary( const char *name,
|
|||||||
int format_table[10],
|
int format_table[10],
|
||||||
im_wrapmany_fn fn, void *b )
|
im_wrapmany_fn fn, void *b )
|
||||||
{
|
{
|
||||||
VipsBandFmt fmt;
|
|
||||||
IMAGE *t[5];
|
IMAGE *t[5];
|
||||||
|
|
||||||
if( im_piocheck( in1, out ) ||
|
if( im_piocheck( in1, out ) ||
|
||||||
@ -235,39 +259,32 @@ im__arith_binary( const char *name,
|
|||||||
im_check_uncoded( name, in2 ) )
|
im_check_uncoded( name, in2 ) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
|
|
||||||
if( im_cp_descv( out, in1, in2, NULL ) )
|
/* Cast our input images up to a common format and bands.
|
||||||
|
*/
|
||||||
|
if( im_open_local_array( out, t, 4, "im__arith_binary", "p" ) ||
|
||||||
|
im__formatalike( in1, in2, t[0], t[1] ) ||
|
||||||
|
im__bandalike( t[0], t[1], t[2], t[3] ) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
|
|
||||||
/* What number of bands will we write?
|
/* Generate the output.
|
||||||
*/
|
*/
|
||||||
out->Bands = IM_MAX( in1->Bands, in2->Bands );
|
if( im_cp_descv( out, t[2], t[3], NULL ) )
|
||||||
|
return( -1 );
|
||||||
|
|
||||||
/* What output type will we write? int, float or complex.
|
/* What number of bands will we write? Same as up-banded input.
|
||||||
*/
|
*/
|
||||||
out->BandFmt = format_table[im__format_common( in1, in2 )];
|
out->Bands = t[2]->Bands;
|
||||||
|
|
||||||
|
/* What output type will we write?
|
||||||
|
*/
|
||||||
|
out->BandFmt = format_table[t[2]->BandFmt];
|
||||||
out->Bbits = im_bits_of_fmt( out->BandFmt );
|
out->Bbits = im_bits_of_fmt( out->BandFmt );
|
||||||
|
|
||||||
if( im_open_local_array( out, t, 4, "type cast:1", "p" ) )
|
|
||||||
return( -1 );
|
|
||||||
|
|
||||||
/* Cast our input images up to a common type.
|
|
||||||
*/
|
|
||||||
fmt = im__format_common( in1, in2 );
|
|
||||||
if( im_clip2fmt( in1, t[0], fmt ) ||
|
|
||||||
im_clip2fmt( in2, t[1], fmt ) )
|
|
||||||
return( -1 );
|
|
||||||
|
|
||||||
/* Force bands up to the same as out.
|
|
||||||
*/
|
|
||||||
if( im__bandup( t[0], t[2], out->Bands ) ||
|
|
||||||
im__bandup( t[1], t[3], out->Bands ) )
|
|
||||||
return( -1 );
|
|
||||||
|
|
||||||
/* And process! The buffer function gets one of the input images as a
|
/* And process! The buffer function gets one of the input images as a
|
||||||
* sample.
|
* sample.
|
||||||
*/
|
*/
|
||||||
t[4] = NULL;
|
t[4] = NULL;
|
||||||
if( im_wrapmany( t + 2, out, fn, t[0], b ) )
|
if( im_wrapmany( t + 2, out, fn, t[2], b ) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
|
|
||||||
return( 0 );
|
return( 0 );
|
||||||
|
@ -191,26 +191,26 @@ im_remainder( IMAGE *in1, IMAGE *in2, IMAGE *out )
|
|||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Cast a vector of double to the type of IMAGE.
|
/* Cast a vector of double to a passed format.
|
||||||
*/
|
*/
|
||||||
static PEL *
|
static PEL *
|
||||||
make_pixel( IMAGE *out, int n, double *p )
|
make_pixel( IMAGE *out, VipsBandFmt fmt, int n, double *p )
|
||||||
{
|
{
|
||||||
PEL *q;
|
PEL *q;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if( !(q = IM_ARRAY( out, n * IM_IMAGE_SIZEOF_ELEMENT( out ), PEL )) )
|
if( !(q = IM_ARRAY( out, n * (im_bits_of_fmt( fmt ) >> 3), PEL )) )
|
||||||
return( NULL );
|
return( NULL );
|
||||||
|
|
||||||
switch( out->BandFmt ) {
|
switch( fmt ) {
|
||||||
case IM_BANDFMT_CHAR: CAST( signed char ); break;
|
case IM_BANDFMT_CHAR: CAST( signed char ); break;
|
||||||
case IM_BANDFMT_UCHAR: CAST( unsigned char ); break;
|
case IM_BANDFMT_UCHAR: CAST( unsigned char ); break;
|
||||||
case IM_BANDFMT_SHORT: CAST( signed short ); break;
|
case IM_BANDFMT_SHORT: CAST( signed short ); break;
|
||||||
case IM_BANDFMT_USHORT: CAST( unsigned short ); break;
|
case IM_BANDFMT_USHORT: CAST( unsigned short ); break;
|
||||||
case IM_BANDFMT_INT: CAST( signed int ); break;
|
case IM_BANDFMT_INT: CAST( signed int ); break;
|
||||||
case IM_BANDFMT_UINT: CAST( unsigned int ); break;
|
case IM_BANDFMT_UINT: CAST( unsigned int ); break;
|
||||||
case IM_BANDFMT_FLOAT: CAST( float ); break;
|
case IM_BANDFMT_FLOAT: CAST( float ); break;
|
||||||
case IM_BANDFMT_DOUBLE: CAST( double ); break;
|
case IM_BANDFMT_DOUBLE: CAST( double ); break;
|
||||||
case IM_BANDFMT_COMPLEX: CASTC( float ); break;
|
case IM_BANDFMT_COMPLEX: CASTC( float ); break;
|
||||||
case IM_BANDFMT_DPCOMPLEX: CASTC( double ); break;
|
case IM_BANDFMT_DPCOMPLEX: CASTC( double ); break;
|
||||||
|
|
||||||
@ -223,7 +223,8 @@ make_pixel( IMAGE *out, int n, double *p )
|
|||||||
|
|
||||||
int
|
int
|
||||||
im__arith_binary_const( const char *name,
|
im__arith_binary_const( const char *name,
|
||||||
IMAGE *in, IMAGE *out, int n, double *c,
|
IMAGE *in, IMAGE *out,
|
||||||
|
int n, double *c, VipsBandFmt vfmt,
|
||||||
int format_table[10],
|
int format_table[10],
|
||||||
im_wrapone_fn fn1, im_wrapone_fn fnn )
|
im_wrapone_fn fn1, im_wrapone_fn fnn )
|
||||||
{
|
{
|
||||||
@ -238,9 +239,17 @@ im__arith_binary_const( const char *name,
|
|||||||
out->BandFmt = format_table[in->BandFmt];
|
out->BandFmt = format_table[in->BandFmt];
|
||||||
out->Bbits = im_bits_of_fmt( out->BandFmt );
|
out->Bbits = im_bits_of_fmt( out->BandFmt );
|
||||||
|
|
||||||
/* Cast vector to output type.
|
/* Some operations need the vector in the input type (eg.
|
||||||
|
* im_equal_vec() where the output type is always uchar and is useless
|
||||||
|
* for comparisons), some need it in the output type (eg.
|
||||||
|
* im_andimage_vec() where we want to get the double to an int so we
|
||||||
|
* can do bitwise-and without having to cast for each pixel), some
|
||||||
|
* need a fixed type (eg. im_powtra_vec(), where we want to keep it as
|
||||||
|
* double).
|
||||||
|
*
|
||||||
|
* Therefore pass in the desired vector type as a param.
|
||||||
*/
|
*/
|
||||||
if( !(vector = make_pixel( out, n, c )) )
|
if( !(vector = make_pixel( out, vfmt, n, c )) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
|
|
||||||
/* Band-up the input image if we have a >1 vector and
|
/* Band-up the input image if we have a >1 vector and
|
||||||
@ -350,7 +359,7 @@ remainderconst1_buffer( PEL *in, PEL *out, int width, PEL *vector, IMAGE *im )
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
remainderconst_buffer( PEL *in, PEL *out, int width, PEL *vector, IMAGE *im )
|
remainderconstn_buffer( PEL *in, PEL *out, int width, PEL *vector, IMAGE *im )
|
||||||
{
|
{
|
||||||
int b = im->Bands;
|
int b = im->Bands;
|
||||||
int i, x, k;
|
int i, x, k;
|
||||||
@ -399,10 +408,10 @@ im_remainder_vec( IMAGE *in, IMAGE *out, int n, double *c )
|
|||||||
return( -1 );
|
return( -1 );
|
||||||
|
|
||||||
return( im__arith_binary_const( "im_remainder",
|
return( im__arith_binary_const( "im_remainder",
|
||||||
in, out, n, c,
|
in, out, n, c, in->BandFmt,
|
||||||
bandfmt_remainder,
|
bandfmt_remainder,
|
||||||
(im_wrapone_fn) remainderconst1_buffer,
|
(im_wrapone_fn) remainderconst1_buffer,
|
||||||
(im_wrapone_fn) remainderconst_buffer ) );
|
(im_wrapone_fn) remainderconstn_buffer ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -67,22 +67,22 @@
|
|||||||
*/
|
*/
|
||||||
#define CONST1( IN, OUT, FUN ) { \
|
#define CONST1( IN, OUT, FUN ) { \
|
||||||
OUT *tq = (OUT *) q; \
|
OUT *tq = (OUT *) q; \
|
||||||
OUT tc = *((OUT *) vector); \
|
|
||||||
IN *tp = (IN *) p; \
|
IN *tp = (IN *) p; \
|
||||||
\
|
\
|
||||||
for( i = 0; i < ne; i++ ) \
|
for( i = 0; i < ne; i++ ) \
|
||||||
FUN( tq[i], tp[i], tc ); \
|
FUN( tq[i], tp[i], c ); \
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Operator with a single constant on a buffer.
|
/* Operator with a single constant on a buffer.
|
||||||
*/
|
*/
|
||||||
#define CONST1_BUFFER( FUN ) \
|
#define CONST1_BUFFER( FUN ) \
|
||||||
static void \
|
static void \
|
||||||
FUN ## 1_buffer( PEL *p, PEL *q, int n, PEL *vector, IMAGE *im ) \
|
FUN ## 1_buffer( PEL *p, PEL *q, int n, double *tc, IMAGE *im ) \
|
||||||
{ \
|
{ \
|
||||||
/* Complex just doubles the size. \
|
/* Complex just doubles the size. \
|
||||||
*/ \
|
*/ \
|
||||||
const int ne = n * im->Bands * (im_iscomplex( im ) ? 2 : 1); \
|
const int ne = n * im->Bands * (im_iscomplex( im ) ? 2 : 1); \
|
||||||
|
const double c = tc[0]; \
|
||||||
\
|
\
|
||||||
int i; \
|
int i; \
|
||||||
\
|
\
|
||||||
@ -118,7 +118,6 @@ FUN ## 1_buffer( PEL *p, PEL *q, int n, PEL *vector, IMAGE *im ) \
|
|||||||
#define CONSTN( IN, OUT, FUN ) { \
|
#define CONSTN( IN, OUT, FUN ) { \
|
||||||
OUT *tq = (OUT *) q; \
|
OUT *tq = (OUT *) q; \
|
||||||
IN *tp = (IN *) p; \
|
IN *tp = (IN *) p; \
|
||||||
OUT *tc = (OUT *) vector; \
|
|
||||||
\
|
\
|
||||||
for( i = 0, x = 0; x < n; x++ ) \
|
for( i = 0, x = 0; x < n; x++ ) \
|
||||||
for( b = 0; b < bands; b++, i++ ) \
|
for( b = 0; b < bands; b++, i++ ) \
|
||||||
@ -129,7 +128,7 @@ FUN ## 1_buffer( PEL *p, PEL *q, int n, PEL *vector, IMAGE *im ) \
|
|||||||
*/
|
*/
|
||||||
#define CONSTN_BUFFER( FUN ) \
|
#define CONSTN_BUFFER( FUN ) \
|
||||||
static void \
|
static void \
|
||||||
FUN ## n_buffer( PEL *p, PEL *q, int n, PEL *vector, IMAGE *im ) \
|
FUN ## n_buffer( PEL *p, PEL *q, int n, double *tc, IMAGE *im ) \
|
||||||
{ \
|
{ \
|
||||||
const int bands = im->Bands; \
|
const int bands = im->Bands; \
|
||||||
\
|
\
|
||||||
@ -220,7 +219,7 @@ im_powtra_vec( IMAGE *in, IMAGE *out, int n, double *c )
|
|||||||
return( -1 );
|
return( -1 );
|
||||||
|
|
||||||
return( im__arith_binary_const( "im_powtra_vec",
|
return( im__arith_binary_const( "im_powtra_vec",
|
||||||
in, out, n, c,
|
in, out, n, c, IM_BANDFMT_DOUBLE,
|
||||||
bandfmt_power,
|
bandfmt_power,
|
||||||
(im_wrapone_fn) POW1_buffer,
|
(im_wrapone_fn) POW1_buffer,
|
||||||
(im_wrapone_fn) POWn_buffer ) );
|
(im_wrapone_fn) POWn_buffer ) );
|
||||||
@ -283,7 +282,7 @@ im_expntra_vec( IMAGE *in, IMAGE *out, int n, double *c )
|
|||||||
return( -1 );
|
return( -1 );
|
||||||
|
|
||||||
return( im__arith_binary_const( "im_expntra_vec",
|
return( im__arith_binary_const( "im_expntra_vec",
|
||||||
in, out, n, c,
|
in, out, n, c, IM_BANDFMT_DOUBLE,
|
||||||
bandfmt_power,
|
bandfmt_power,
|
||||||
(im_wrapone_fn) POWC1_buffer,
|
(im_wrapone_fn) POWC1_buffer,
|
||||||
(im_wrapone_fn) POWCn_buffer ) );
|
(im_wrapone_fn) POWCn_buffer ) );
|
||||||
|
@ -319,7 +319,7 @@ int
|
|||||||
im_andimage_vec( IMAGE *in, IMAGE *out, int n, double *c )
|
im_andimage_vec( IMAGE *in, IMAGE *out, int n, double *c )
|
||||||
{
|
{
|
||||||
return( im__arith_binary_const( "im_andimage",
|
return( im__arith_binary_const( "im_andimage",
|
||||||
in, out, n, c,
|
in, out, n, c, in->BandFmt,
|
||||||
bandfmt_bool,
|
bandfmt_bool,
|
||||||
(im_wrapone_fn) AND1_buffer,
|
(im_wrapone_fn) AND1_buffer,
|
||||||
(im_wrapone_fn) ANDn_buffer ) );
|
(im_wrapone_fn) ANDn_buffer ) );
|
||||||
@ -367,7 +367,7 @@ int
|
|||||||
im_orimage_vec( IMAGE *in, IMAGE *out, int n, double *c )
|
im_orimage_vec( IMAGE *in, IMAGE *out, int n, double *c )
|
||||||
{
|
{
|
||||||
return( im__arith_binary_const( "im_orimage",
|
return( im__arith_binary_const( "im_orimage",
|
||||||
in, out, n, c,
|
in, out, n, c, in->BandFmt,
|
||||||
bandfmt_bool,
|
bandfmt_bool,
|
||||||
(im_wrapone_fn) OR1_buffer,
|
(im_wrapone_fn) OR1_buffer,
|
||||||
(im_wrapone_fn) ORn_buffer ) );
|
(im_wrapone_fn) ORn_buffer ) );
|
||||||
@ -416,7 +416,7 @@ int
|
|||||||
im_eorimage_vec( IMAGE *in, IMAGE *out, int n, double *c )
|
im_eorimage_vec( IMAGE *in, IMAGE *out, int n, double *c )
|
||||||
{
|
{
|
||||||
return( im__arith_binary_const( "im_eorimage",
|
return( im__arith_binary_const( "im_eorimage",
|
||||||
in, out, n, c,
|
in, out, n, c, in->BandFmt,
|
||||||
bandfmt_bool,
|
bandfmt_bool,
|
||||||
(im_wrapone_fn) EOR1_buffer,
|
(im_wrapone_fn) EOR1_buffer,
|
||||||
(im_wrapone_fn) EORn_buffer ) );
|
(im_wrapone_fn) EORn_buffer ) );
|
||||||
@ -466,7 +466,7 @@ int
|
|||||||
im_shiftleft_vec( IMAGE *in, IMAGE *out, int n, double *c )
|
im_shiftleft_vec( IMAGE *in, IMAGE *out, int n, double *c )
|
||||||
{
|
{
|
||||||
return( im__arith_binary_const( "im_shiftleft",
|
return( im__arith_binary_const( "im_shiftleft",
|
||||||
in, out, n, c,
|
in, out, n, c, in->BandFmt,
|
||||||
bandfmt_bool,
|
bandfmt_bool,
|
||||||
(im_wrapone_fn) SHIFTL1_buffer,
|
(im_wrapone_fn) SHIFTL1_buffer,
|
||||||
(im_wrapone_fn) SHIFTLn_buffer ) );
|
(im_wrapone_fn) SHIFTLn_buffer ) );
|
||||||
@ -516,7 +516,7 @@ int
|
|||||||
im_shiftright_vec( IMAGE *in, IMAGE *out, int n, double *c )
|
im_shiftright_vec( IMAGE *in, IMAGE *out, int n, double *c )
|
||||||
{
|
{
|
||||||
return( im__arith_binary_const( "im_shiftright",
|
return( im__arith_binary_const( "im_shiftright",
|
||||||
in, out, n, c,
|
in, out, n, c, in->BandFmt,
|
||||||
bandfmt_bool,
|
bandfmt_bool,
|
||||||
(im_wrapone_fn) SHIFTR1_buffer,
|
(im_wrapone_fn) SHIFTR1_buffer,
|
||||||
(im_wrapone_fn) SHIFTRn_buffer ) );
|
(im_wrapone_fn) SHIFTRn_buffer ) );
|
||||||
|
@ -132,12 +132,15 @@ char *im__gslist_gvalue_get( const GSList *list );
|
|||||||
void im__buffer_init( void );
|
void im__buffer_init( void );
|
||||||
|
|
||||||
int im__bandup( IMAGE *in, IMAGE *out, int n );
|
int im__bandup( IMAGE *in, IMAGE *out, int n );
|
||||||
|
int im__bandalike( IMAGE *in1, IMAGE *in2, IMAGE *out1, IMAGE *out2 );
|
||||||
|
int im__formatalike( IMAGE *in1, IMAGE *in2, IMAGE *out1, IMAGE *out2 );
|
||||||
int im__arith_binary( const char *name,
|
int im__arith_binary( const char *name,
|
||||||
IMAGE *in1, IMAGE *in2, IMAGE *out,
|
IMAGE *in1, IMAGE *in2, IMAGE *out,
|
||||||
int format_table[10],
|
int format_table[10],
|
||||||
im_wrapmany_fn fn, void *b );
|
im_wrapmany_fn fn, void *b );
|
||||||
int im__arith_binary_const( const char *name,
|
int im__arith_binary_const( const char *name,
|
||||||
IMAGE *in, IMAGE *out, int n, double *c,
|
IMAGE *in, IMAGE *out,
|
||||||
|
int n, double *c, VipsBandFmt vfmt,
|
||||||
int format_table[10],
|
int format_table[10],
|
||||||
im_wrapone_fn fn1, im_wrapone_fn fnn );
|
im_wrapone_fn fn1, im_wrapone_fn fnn );
|
||||||
int im__value( IMAGE *im, double *value );
|
int im__value( IMAGE *im, double *value );
|
||||||
|
@ -178,12 +178,12 @@ void im_vwarn( const char *domain, const char *fmt, va_list ap );
|
|||||||
void im_diag( const char *domain, const char *fmt, ... )
|
void im_diag( const char *domain, const char *fmt, ... )
|
||||||
__attribute__((format(printf, 2, 3)));
|
__attribute__((format(printf, 2, 3)));
|
||||||
|
|
||||||
int im_bits_of_fmt( int );
|
int im_bits_of_fmt( VipsBandFmt fmt );
|
||||||
const char *im_Type2char( int );
|
const char *im_Type2char( VipsType type );
|
||||||
const char *im_BandFmt2char( int );
|
const char *im_BandFmt2char( VipsBandFmt fmt );
|
||||||
const char *im_Coding2char( int );
|
const char *im_Coding2char( VipsCoding coding );
|
||||||
const char *im_Compression2char( int );
|
const char *im_Compression2char( int );
|
||||||
const char *im_dhint2char( im_demand_type );
|
const char *im_dhint2char( VipsDemandStyle style );
|
||||||
const char *im_dtype2char( im_desc_type );
|
const char *im_dtype2char( im_desc_type );
|
||||||
int im_char2Type( const char * );
|
int im_char2Type( const char * );
|
||||||
int im_char2BandFmt( const char * );
|
int im_char2BandFmt( const char * );
|
||||||
@ -621,29 +621,6 @@ int im_flood_blob_copy( IMAGE *in, IMAGE *out, int x, int y, PEL *ink );
|
|||||||
int im_lineset( IMAGE *in, IMAGE *out, IMAGE *mask, IMAGE *ink,
|
int im_lineset( IMAGE *in, IMAGE *out, IMAGE *mask, IMAGE *ink,
|
||||||
int n, int *x1v, int *y1v, int *x2v, int *y2v );
|
int n, int *x1v, int *y1v, int *x2v, int *y2v );
|
||||||
|
|
||||||
/* relational
|
|
||||||
*/
|
|
||||||
int im_equal( IMAGE *, IMAGE *, IMAGE * );
|
|
||||||
int im_equalconst( IMAGE *, IMAGE *, double );
|
|
||||||
int im_equal_vec( IMAGE *, IMAGE *, int, double * );
|
|
||||||
int im_notequal( IMAGE *, IMAGE *, IMAGE * );
|
|
||||||
int im_notequalconst( IMAGE *, IMAGE *, double );
|
|
||||||
int im_notequal_vec( IMAGE *, IMAGE *, int, double * );
|
|
||||||
int im_more( IMAGE *, IMAGE *, IMAGE * );
|
|
||||||
int im_moreconst( IMAGE *, IMAGE *, double );
|
|
||||||
int im_more_vec( IMAGE *, IMAGE *, int, double * );
|
|
||||||
int im_less( IMAGE *, IMAGE *, IMAGE * );
|
|
||||||
int im_lessconst( IMAGE *, IMAGE *, double );
|
|
||||||
int im_less_vec( IMAGE *, IMAGE *, int, double * );
|
|
||||||
int im_moreeq( IMAGE *, IMAGE *, IMAGE * );
|
|
||||||
int im_moreeqconst( IMAGE *, IMAGE *, double );
|
|
||||||
int im_moreeq_vec( IMAGE *, IMAGE *, int, double * );
|
|
||||||
int im_lesseq( IMAGE *, IMAGE *, IMAGE * );
|
|
||||||
int im_lesseqconst( IMAGE *, IMAGE *, double );
|
|
||||||
int im_lesseq_vec( IMAGE *, IMAGE *, int, double * );
|
|
||||||
int im_ifthenelse( IMAGE *, IMAGE *, IMAGE *, IMAGE * );
|
|
||||||
int im_blend( IMAGE *, IMAGE *, IMAGE *, IMAGE * );
|
|
||||||
|
|
||||||
/* matrix
|
/* matrix
|
||||||
*/
|
*/
|
||||||
DOUBLEMASK *im_mattrn( DOUBLEMASK *, const char * );
|
DOUBLEMASK *im_mattrn( DOUBLEMASK *, const char * );
|
||||||
|
@ -138,6 +138,7 @@ typedef struct im__DOUBLEMASK {
|
|||||||
#include <vips/proto.h>
|
#include <vips/proto.h>
|
||||||
#include <vips/arithmetic.h>
|
#include <vips/arithmetic.h>
|
||||||
#include <vips/boolean.h>
|
#include <vips/boolean.h>
|
||||||
|
#include <vips/relational.h>
|
||||||
|
|
||||||
#ifdef IM_ENABLE_DEPRECATED
|
#ifdef IM_ENABLE_DEPRECATED
|
||||||
#include <vips/deprecated.h>
|
#include <vips/deprecated.h>
|
||||||
|
@ -51,14 +51,14 @@ static const int bits[] = {
|
|||||||
IM_BBITS_DPCOMPLEX
|
IM_BBITS_DPCOMPLEX
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Return number of pels bits for band format or -1 on error.
|
/* Return number of pel bits for band format, or -1 on error.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
im_bits_of_fmt( int bandfmt )
|
im_bits_of_fmt( VipsBandFmt fmt )
|
||||||
{
|
{
|
||||||
return( bandfmt < 0 || bandfmt > IM_BANDFMT_DPCOMPLEX ?
|
return( fmt < 0 || fmt > IM_BANDFMT_DPCOMPLEX ?
|
||||||
im_error( "im_bits_of_fmt",
|
im_error( "im_bits_of_fmt",
|
||||||
_( "unsupported band format: %d" ), bandfmt ),
|
_( "unsupported band format: %d" ), fmt ),
|
||||||
-1 :
|
-1 :
|
||||||
bits[bandfmt] );
|
bits[fmt] );
|
||||||
}
|
}
|
||||||
|
@ -218,18 +218,18 @@ char2enum( EnumTable *etable, const char *name )
|
|||||||
|
|
||||||
/* Prettyprint various header fields.
|
/* Prettyprint various header fields.
|
||||||
*/
|
*/
|
||||||
const char *im_Type2char( int n )
|
const char *im_Type2char( VipsType type )
|
||||||
{ return( enum2char( &enumType, n ) ); }
|
{ return( enum2char( &enumType, type ) ); }
|
||||||
const char *im_BandFmt2char( int n )
|
const char *im_BandFmt2char( VipsBandFmt fmt )
|
||||||
{ return( enum2char( &enumBandFmt, n ) ); }
|
{ return( enum2char( &enumBandFmt, fmt ) ); }
|
||||||
const char *im_Coding2char( int n )
|
const char *im_Coding2char( VipsCoding coding )
|
||||||
{ return( enum2char( &enumCoding, n ) ); }
|
{ return( enum2char( &enumCoding, coding ) ); }
|
||||||
const char *im_Compression2char( int n )
|
const char *im_Compression2char( int n )
|
||||||
{ return( enum2char( &enumCompression, n ) ); }
|
{ return( enum2char( &enumCompression, n ) ); }
|
||||||
const char *im_dtype2char( im_desc_type n )
|
const char *im_dtype2char( im_desc_type n )
|
||||||
{ return( enum2char( &enumdtype, n ) ); }
|
{ return( enum2char( &enumdtype, n ) ); }
|
||||||
const char *im_dhint2char( im_demand_type n )
|
const char *im_dhint2char( VipsDemandStyle style )
|
||||||
{ return( enum2char( &enumdhint, n ) ); }
|
{ return( enum2char( &enumdhint, style ) ); }
|
||||||
|
|
||||||
int im_char2Type( const char *str )
|
int im_char2Type( const char *str )
|
||||||
{ return( char2enum( &enumType, str ) ); }
|
{ return( char2enum( &enumType, str ) ); }
|
||||||
|
@ -280,57 +280,11 @@ blend_gen( REGION *or, void *seq, void *client1, void *client2 )
|
|||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
static int
|
||||||
* im_blend:
|
blend( IMAGE *c, IMAGE *a, IMAGE *b, IMAGE *out )
|
||||||
* @c: condition #IMAGE
|
|
||||||
* @a: then #IMAGE
|
|
||||||
* @b: else #IMAGE
|
|
||||||
* @out: output #IMAGE
|
|
||||||
*
|
|
||||||
* This operation scans the condition image @c (which must be unsigned char)
|
|
||||||
* and uses it to blend pixels from either the then image @a or the else
|
|
||||||
* image @b. 255 means @a only, 0 means @b only, and intermediate values are a
|
|
||||||
* mixture.
|
|
||||||
*
|
|
||||||
* The conditional image @c can have either 1 band, in which case entire pels
|
|
||||||
* come either from @a or @b, or n bands, where n is the number of bands in
|
|
||||||
* both @a and @b, in which case individual band elements are chosen from
|
|
||||||
* @a and @b. Finally, @c may have n bands while @a and @b are single band. In
|
|
||||||
* this case, @a and @b are copied n times to make n band images and those are
|
|
||||||
* operated upon.
|
|
||||||
*
|
|
||||||
* Images @a and @b must match exactly in size, bands and format.
|
|
||||||
*
|
|
||||||
* See also: im_ifthenelse(), im_equal().
|
|
||||||
*
|
|
||||||
* Returns: 0 on success, -1 on error
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
im_blend( IMAGE *c, IMAGE *a, IMAGE *b, IMAGE *out )
|
|
||||||
{
|
{
|
||||||
/* If a and b are both LABPACK, repack agan after the blend.
|
|
||||||
*/
|
|
||||||
const int repack = a->Coding == IM_CODING_LABQ &&
|
|
||||||
b->Coding == IM_CODING_LABQ;
|
|
||||||
|
|
||||||
IMAGE *t[5];
|
|
||||||
IMAGE **in;
|
IMAGE **in;
|
||||||
|
|
||||||
/* Unpack LABPACK as a courtesy.
|
|
||||||
*/
|
|
||||||
if( im_open_local_array( out, t, 5, "im_blend", "p" ) )
|
|
||||||
return( -1 );
|
|
||||||
if( a->Coding == IM_CODING_LABQ ) {
|
|
||||||
if( im_LabQ2Lab( a, t[0] ) )
|
|
||||||
return( -1 );
|
|
||||||
a = t[0];
|
|
||||||
}
|
|
||||||
if( b->Coding == IM_CODING_LABQ ) {
|
|
||||||
if( im_LabQ2Lab( b, t[1] ) )
|
|
||||||
return( -1 );
|
|
||||||
b = t[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check args.
|
/* Check args.
|
||||||
*/
|
*/
|
||||||
if( im_check_uncoded( "im_blend", c ) ||
|
if( im_check_uncoded( "im_blend", c ) ||
|
||||||
@ -344,36 +298,88 @@ im_blend( IMAGE *c, IMAGE *a, IMAGE *b, IMAGE *out )
|
|||||||
im_pincheck( a ) ||
|
im_pincheck( a ) ||
|
||||||
im_pincheck( b ) )
|
im_pincheck( b ) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
if( im_demand_hint( out, IM_THINSTRIP, a, b, c, NULL ) )
|
|
||||||
return( -1 );
|
|
||||||
|
|
||||||
/* Make output image.
|
/* Make output image.
|
||||||
*/
|
*/
|
||||||
if( im_cp_descv( out, a, b, c, NULL ) )
|
if( im_cp_descv( out, a, b, c, NULL ) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
out->Bands = IM_MAX( c->Bands, a->Bands );
|
out->Bands = IM_MAX( c->Bands, a->Bands );
|
||||||
|
if( im_demand_hint( out, IM_THINSTRIP, a, b, c, NULL ) )
|
||||||
/* Force a/b bands up to the same as out.
|
|
||||||
*/
|
|
||||||
if( im_open_local_array( out, t, 2, "im_blend", "p" ) )
|
|
||||||
return( -1 );
|
return( -1 );
|
||||||
if( im__bandup( a, t[2], out->Bands ) ||
|
|
||||||
im__bandup( a, t[3], out->Bands ) )
|
|
||||||
return( -1 );
|
|
||||||
a = t[2];
|
|
||||||
b = t[3];
|
|
||||||
|
|
||||||
if( !(in = im_allocate_input_array( out, c, a, b, NULL )) ||
|
if( !(in = im_allocate_input_array( out, c, a, b, NULL )) ||
|
||||||
im_generate( t[4],
|
im_generate( out,
|
||||||
im_start_many, blend_gen, im_stop_many, in, NULL ) )
|
im_start_many, blend_gen, im_stop_many, in, NULL ) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
|
|
||||||
|
return( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* im_blend:
|
||||||
|
* @c: condition #IMAGE
|
||||||
|
* @a: then #IMAGE
|
||||||
|
* @b: else #IMAGE
|
||||||
|
* @out: output #IMAGE
|
||||||
|
*
|
||||||
|
* This operation scans the condition image @c (which must be unsigned char)
|
||||||
|
* and uses it to blend pixels from either the then image @a or the else
|
||||||
|
* image @b. 255 means @a only, 0 means @b only, and intermediate values are a
|
||||||
|
* mixture.
|
||||||
|
*
|
||||||
|
* Any image can have either 1 band or n bands, where n is the same for all
|
||||||
|
* the non-1-band images. Single band images are then effectively copied to
|
||||||
|
* make n-band images.
|
||||||
|
*
|
||||||
|
* Images @a and @b are cast up to the smallest common format.
|
||||||
|
*
|
||||||
|
* Images @a and @b must match exactly in size.
|
||||||
|
*
|
||||||
|
* See also: im_ifthenelse(), im_equal().
|
||||||
|
*
|
||||||
|
* Returns: 0 on success, -1 on error
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
im_blend( IMAGE *c, IMAGE *a, IMAGE *b, IMAGE *out )
|
||||||
|
{
|
||||||
|
/* If a and b are both LABPACK, repack agan after the blend.
|
||||||
|
*/
|
||||||
|
const int repack = a->Coding == IM_CODING_LABQ &&
|
||||||
|
b->Coding == IM_CODING_LABQ;
|
||||||
|
|
||||||
|
IMAGE *t[7];
|
||||||
|
|
||||||
|
if( im_open_local_array( out, t, 7, "im_blend", "p" ) )
|
||||||
|
return( -1 );
|
||||||
|
|
||||||
|
/* Unpack LABPACK as a courtesy.
|
||||||
|
*/
|
||||||
|
if( a->Coding == IM_CODING_LABQ ) {
|
||||||
|
if( im_LabQ2Lab( a, t[0] ) )
|
||||||
|
return( -1 );
|
||||||
|
a = t[0];
|
||||||
|
}
|
||||||
|
if( b->Coding == IM_CODING_LABQ ) {
|
||||||
|
if( im_LabQ2Lab( b, t[1] ) )
|
||||||
|
return( -1 );
|
||||||
|
b = t[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Make a and b match in bands and format.
|
||||||
|
*/
|
||||||
|
if( im__formatalike( a, b, t[2], t[3] ) ||
|
||||||
|
im__bandalike( t[2], t[3], t[4], t[5] ) )
|
||||||
|
return( -1 );
|
||||||
|
|
||||||
|
if( blend( c, t[4], t[5], t[6] ) )
|
||||||
|
return( -1 );
|
||||||
|
|
||||||
if( repack ) {
|
if( repack ) {
|
||||||
if( im_Lab2LabQ( t[4], out ) )
|
if( im_Lab2LabQ( t[6], out ) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if( im_copy( t[4], out ) )
|
if( im_copy( t[6], out ) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -430,7 +430,7 @@ int
|
|||||||
im_equal_vec( IMAGE *in, IMAGE *out, int n, double *c )
|
im_equal_vec( IMAGE *in, IMAGE *out, int n, double *c )
|
||||||
{
|
{
|
||||||
return( im__arith_binary_const( "im_equal",
|
return( im__arith_binary_const( "im_equal",
|
||||||
in, out, n, c,
|
in, out, n, c, in->BandFmt,
|
||||||
bandfmt_relational,
|
bandfmt_relational,
|
||||||
(im_wrapone_fn) EQUAL1_buffer,
|
(im_wrapone_fn) EQUAL1_buffer,
|
||||||
(im_wrapone_fn) EQUALn_buffer ) );
|
(im_wrapone_fn) EQUALn_buffer ) );
|
||||||
@ -458,7 +458,7 @@ int
|
|||||||
im_notequal_vec( IMAGE *in, IMAGE *out, int n, double *c )
|
im_notequal_vec( IMAGE *in, IMAGE *out, int n, double *c )
|
||||||
{
|
{
|
||||||
return( im__arith_binary_const( "im_notequal",
|
return( im__arith_binary_const( "im_notequal",
|
||||||
in, out, n, c,
|
in, out, n, c, in->BandFmt,
|
||||||
bandfmt_relational,
|
bandfmt_relational,
|
||||||
(im_wrapone_fn) NOTEQUAL1_buffer,
|
(im_wrapone_fn) NOTEQUAL1_buffer,
|
||||||
(im_wrapone_fn) NOTEQUALn_buffer ) );
|
(im_wrapone_fn) NOTEQUALn_buffer ) );
|
||||||
@ -486,7 +486,7 @@ int
|
|||||||
im_less_vec( IMAGE *in, IMAGE *out, int n, double *c )
|
im_less_vec( IMAGE *in, IMAGE *out, int n, double *c )
|
||||||
{
|
{
|
||||||
return( im__arith_binary_const( "im_less",
|
return( im__arith_binary_const( "im_less",
|
||||||
in, out, n, c,
|
in, out, n, c, in->BandFmt,
|
||||||
bandfmt_relational,
|
bandfmt_relational,
|
||||||
(im_wrapone_fn) LESS1_buffer,
|
(im_wrapone_fn) LESS1_buffer,
|
||||||
(im_wrapone_fn) LESSn_buffer ) );
|
(im_wrapone_fn) LESSn_buffer ) );
|
||||||
@ -514,7 +514,7 @@ int
|
|||||||
im_lesseq_vec( IMAGE *in, IMAGE *out, int n, double *c )
|
im_lesseq_vec( IMAGE *in, IMAGE *out, int n, double *c )
|
||||||
{
|
{
|
||||||
return( im__arith_binary_const( "im_lesseq",
|
return( im__arith_binary_const( "im_lesseq",
|
||||||
in, out, n, c,
|
in, out, n, c, in->BandFmt,
|
||||||
bandfmt_relational,
|
bandfmt_relational,
|
||||||
(im_wrapone_fn) LESSEQ1_buffer,
|
(im_wrapone_fn) LESSEQ1_buffer,
|
||||||
(im_wrapone_fn) LESSEQn_buffer ) );
|
(im_wrapone_fn) LESSEQn_buffer ) );
|
||||||
@ -559,7 +559,7 @@ int
|
|||||||
im_more_vec( IMAGE *in, IMAGE *out, int n, double *c )
|
im_more_vec( IMAGE *in, IMAGE *out, int n, double *c )
|
||||||
{
|
{
|
||||||
return( im__arith_binary_const( "im_more",
|
return( im__arith_binary_const( "im_more",
|
||||||
in, out, n, c,
|
in, out, n, c, in->BandFmt,
|
||||||
bandfmt_relational,
|
bandfmt_relational,
|
||||||
(im_wrapone_fn) MORE1_buffer,
|
(im_wrapone_fn) MORE1_buffer,
|
||||||
(im_wrapone_fn) MOREn_buffer ) );
|
(im_wrapone_fn) MOREn_buffer ) );
|
||||||
@ -605,7 +605,7 @@ int
|
|||||||
im_moreeq_vec( IMAGE *in, IMAGE *out, int n, double *c )
|
im_moreeq_vec( IMAGE *in, IMAGE *out, int n, double *c )
|
||||||
{
|
{
|
||||||
return( im__arith_binary_const( "im_moreeq",
|
return( im__arith_binary_const( "im_moreeq",
|
||||||
in, out, n, c,
|
in, out, n, c, in->BandFmt,
|
||||||
bandfmt_relational,
|
bandfmt_relational,
|
||||||
(im_wrapone_fn) MOREEQ1_buffer,
|
(im_wrapone_fn) MOREEQ1_buffer,
|
||||||
(im_wrapone_fn) MOREEQn_buffer ) );
|
(im_wrapone_fn) MOREEQn_buffer ) );
|
||||||
|
Loading…
Reference in New Issue
Block a user