int im__arith_binary_const( const char *domain, IMAGE *in, IMAGE *out, int n, double *c, VipsBandFmt vfmt, int format_table[10], im_wrapone_fn fn1, im_wrapone_fn fnn ) { PEL *vector; if( im_piocheck( in, out ) || im_check_vector( domain, n, in ) || im_check_uncoded( domain, in ) ) return( -1 ); if( im_cp_desc( out, in ) ) return( -1 ); out->BandFmt = format_table[in->BandFmt]; /* 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, vfmt, n, c )) ) return( -1 ); /* Band-up the input image if we have a >1 vector and * a 1-band image. */ if( n > 1 && out->Bands == 1 ) { IMAGE *t; if( !(t = im_open_local( out, domain, "p" )) || im__bandup( domain, in, t, n ) ) return( -1 ); in = t; } if( n == 1 ) { if( im_wrapone( in, out, fn1, vector, in ) ) return( -1 ); } else { if( im_wrapone( in, out, fnn, vector, in ) ) return( -1 ); } return( 0 ); }
/** * im_LabS2LabQ: * @in: input image * @out: output image * * Convert a LabS three-band signed short image to LabQ * * See also: im_LabQ2LabS(). * * Returns: 0 on success, -1 on error. */ int im_LabS2LabQ( IMAGE *in, IMAGE *out ) { IMAGE *t[1]; if( im_check_uncoded( "im_LabS2LabQ", in ) || im_check_bands( "im_LabS2LabQ", in, 3 ) || im_open_local_array( out, t, 1, "im_LabS2LabQ", "p" ) || im_clip2fmt( in, t[0], IM_BANDFMT_SHORT ) ) return( -1 ); /* Set up output image */ if( im_cp_desc( out, in ) ) return( -1 ); out->Bands = 4; out->Type = IM_TYPE_LABQ; out->BandFmt = IM_BANDFMT_UCHAR; out->Coding = IM_CODING_LABQ; if( im_wrapone( in, out, (im_wrapone_fn) imb_LabS2LabQ, NULL, NULL ) ) return( -1 ); return( 0 ); }
int im_disp2XYZ( IMAGE *in, IMAGE *out, struct im_col_display *d ) { /* Check input image. */ if( in->Bands != 3 || in->BandFmt != IM_BANDFMT_UCHAR || in->Coding != IM_CODING_NONE ) { im_error( "im_disp2XYZ", "%s", _( "input not 3-band uncoded char" ) ); return( -1 ); } /* Prepare the output image */ if( im_cp_desc( out, in ) ) return( -1 ); out->BandFmt = IM_BANDFMT_FLOAT; out->Type = IM_TYPE_XYZ; /* Do the processing. */ if( im_wrapone( in, out, (im_wrapone_fn) imb_disp2XYZ, d, NULL ) ) return( -1 ); return( 0 ); }
int im_LabQ2LabS( IMAGE *labim, IMAGE *outim ) { /* check for coded Lab type */ if( labim->Coding != IM_CODING_LABQ ) { im_errormsg( "im_LabQ2LabS: not a packed Lab image" ); return( -1 ); } /* set up output image */ if( im_cp_desc( outim, labim ) ) return( -1 ); outim->Bands = 3; outim->Type = IM_TYPE_LABS; outim->BandFmt = IM_BANDFMT_SHORT; outim->Bbits = IM_BBITS_SHORT; outim->Coding = IM_CODING_NONE; /* Produce output. */ if( im_wrapone( labim, outim, (im_wrapone_fn) imb_LabQ2LabS, NULL, NULL ) ) return( -1 ); return( 0 ); }
int im_Lab2LCh( IMAGE *in, IMAGE *out ) { /* Check input image. */ if( in->Bands != 3 || in->BandFmt != IM_BANDFMT_FLOAT || in->Coding != IM_CODING_NONE ) { im_errormsg( "im_Lab2LCh: 3-band uncoded float input only" ); return( -1 ); } /* Prepare the output image */ if( im_cp_desc( out, in ) ) return( -1 ); out->Type = IM_TYPE_LCH; /* Process! */ if( im_wrapone( in, out, (im_wrapone_fn) imb_Lab2LCh, NULL, NULL ) ) return( -1 ); return( 0 ); }
int im_Lab2LabS( IMAGE *labim, IMAGE *outim ) { /* Check for uncoded Lab type */ if( labim->Coding != IM_CODING_NONE ) { im_errormsg( "im_Lab2LabS: uncoded input only" ); return( -1 ); } if( labim->BandFmt != IM_BANDFMT_FLOAT || labim->Bands != 3 ) { im_errormsg( "im_Lab2LabS: three-band float input only" ); return( -1 ); } /* Set up output image. */ if( im_cp_desc( outim, labim ) ) return( -1 ); outim->Type = IM_TYPE_LABS; outim->BandFmt = IM_BANDFMT_SHORT; outim->Bbits = IM_BBITS_SHORT; /* Process. */ if( im_wrapone( labim, outim, (im_wrapone_fn) imb_Lab2LabS, NULL, NULL ) ) return( -1 ); return( 0 ); }
int im_c2real( IMAGE *in, IMAGE *out ) { if( in->Coding != IM_CODING_NONE || !im_iscomplex( in ) ) { im_errormsg( "im_c2real: input should be uncoded complex" ); return( -1 ); } if( im_cp_desc( out, in ) ) return( -1 ); /* Output will be float or double. */ if( in->BandFmt == IM_BANDFMT_DPCOMPLEX ) { out->BandFmt = IM_BANDFMT_DOUBLE; out->Bbits = IM_BBITS_DOUBLE; } else { out->BandFmt = IM_BANDFMT_FLOAT; out->Bbits = IM_BBITS_FLOAT; } /* Do the processing. */ if( im_wrapone( in, out, (im_wrapone_fn) buffer_c2real, in, NULL ) ) return( -1 ); return( 0 ); }
int im_LabS2Lab( IMAGE *in, IMAGE *out ) { /* Check type. */ if( in->Coding != IM_CODING_NONE ) { im_errormsg( "im_LabS2Lab: not an uncoded image" ); return( -1 ); } if( in->BandFmt != IM_BANDFMT_SHORT || in->Bands != 3 ) { im_errormsg( "im_LabS2Lab: not a 3-band signed short image" ); return( -1 ); } /* Set up output image */ if( im_cp_desc( out, in ) ) return( -1 ); out->Type = IM_TYPE_LAB; out->BandFmt = IM_BANDFMT_FLOAT; out->Bbits = IM_BBITS_FLOAT; if( im_wrapone( in, out, (im_wrapone_fn) imb_LabS2Lab, NULL, NULL ) ) return( -1 ); return( 0 ); }
int im_XYZ2disp( IMAGE *in, IMAGE *out, struct im_col_display *d ) { /* Check input image. */ if( in->Bands != 3 || in->BandFmt != IM_BANDFMT_FLOAT || in->Coding != IM_CODING_NONE ) { im_error( "im_XYZ2disp", "%s", _( "3-band uncoded float only" ) ); return( -1 ); } if( im_cp_desc( out, in ) ) return( -1 ); out->BandFmt = IM_BANDFMT_UCHAR; out->Type = IM_TYPE_RGB; /* Do the processing. */ if( im_wrapone( in, out, (im_wrapone_fn) imb_XYZ2disp, d, NULL ) ) return( -1 ); return( 0 ); }
int im_XYZ2Lab_temp( IMAGE *in, IMAGE *out, double X0, double Y0, double Z0 ) { im_colour_temperature *temp; /* Check input image. */ if( !(temp = IM_NEW( out, im_colour_temperature )) ) return( -1 ); if( in->Bands != 3 || in->BandFmt != IM_BANDFMT_FLOAT || in->Coding != IM_CODING_NONE ) { im_error( "im_XYZ2Lab", _( "not 3-band uncoded float" ) ); return( -1 ); } /* Prepare the output image */ if( im_cp_desc( out, in) ) return( -1 ); out->Type = IM_TYPE_LAB; /* Do the processing. */ imb_XYZ2Lab_tables(); temp->X0 = X0; temp->Y0 = Y0; temp->Z0 = Z0; if( im_wrapone( in, out, (im_wrapone_fn) imb_XYZ2Lab, temp, NULL ) ) return( -1 ); return( 0 ); }
/** * im_copy_swap: * @in: input image * @out: output image * * Copy an image, swapping byte order between little and big endian. This * really does change image pixels and does not just alter the header. * * See also: im_copy(), im_amiMSBfirst(), im_isMSBfirst(). * * Returns: 0 on success, -1 on error. */ int im_copy_swap( IMAGE *in, IMAGE *out ) { if( im_piocheck( in, out ) || im_check_uncoded( "im_copy_swap", in ) || im_cp_desc( out, in ) ) return( -1 ); switch( in->BandFmt ) { case IM_BANDFMT_CHAR: case IM_BANDFMT_UCHAR: if( im_copy( in, out ) ) return( -1 ); break; case IM_BANDFMT_SHORT: case IM_BANDFMT_USHORT: if( im_wrapone( in, out, (im_wrapone_fn) im_copy_swap2_gen, in, NULL ) ) return( -1 ); break; case IM_BANDFMT_INT: case IM_BANDFMT_UINT: case IM_BANDFMT_FLOAT: case IM_BANDFMT_COMPLEX: if( im_wrapone( in, out, (im_wrapone_fn) im_copy_swap4_gen, in, NULL ) ) return( -1 ); break; case IM_BANDFMT_DOUBLE: case IM_BANDFMT_DPCOMPLEX: if( im_wrapone( in, out, (im_wrapone_fn) im_copy_swap8_gen, in, NULL ) ) return( -1 ); break; default: im_error( "im_copy_swap", "%s", _( "unsupported image type" ) ); return( -1 ); } return( 0 ); }
/* Morph an image. */ int im_lab_morph( IMAGE *in, IMAGE *out, DOUBLEMASK *mask, double L_offset, double L_scale, double a_scale, double b_scale ) { Params *parm; /* Recurse for coded images. */ if( in->Coding == IM_CODING_LABQ ) { IMAGE *t1 = im_open_local( out, "im_lab_morph:1", "p" ); IMAGE *t2 = im_open_local( out, "im_lab_morph:2", "p" ); if( !t1 || !t2 || im_LabQ2Lab( in, t1 ) || im_lab_morph( t1, t2, mask, L_offset, L_scale, a_scale, b_scale ) || im_Lab2LabQ( t2, out ) ) return( -1 ); return( 0 ); } if( in->Coding != IM_CODING_NONE ) { im_errormsg( "im_lab_morph: must be uncoded or IM_CODING_LABQ" ); return( -1 ); } if( in->BandFmt != IM_BANDFMT_FLOAT && in->BandFmt != IM_BANDFMT_DOUBLE ) { im_errormsg( "im_lab_morph: must be uncoded float or double" ); return( -1 ); } if( in->Bands != 3 ) { im_errormsg( "im_lab_morph: must be 3 bands" ); return( -1 ); } if( !(parm = IM_NEW( out, Params )) || morph_init( parm, in, out, L_scale, L_offset, mask, a_scale, b_scale ) ) return( -1 ); if( im_cp_desc( out, in ) ) return( -1 ); out->Type = IM_TYPE_LAB; if( im_wrapone( in, out, (im_wrapone_fn) morph_buffer, parm, NULL ) ) return( -1 ); return( 0 ); }
/** * im_c2amph: * @in: input image * @out: output image * * Convert a complex image from rectangular to polar coordinates. Angles are * expressed in degrees. * * See also: im_c2rect(), im_abs(). * * Returns: 0 on success, -1 on error */ int im_c2amph( IMAGE *in, IMAGE *out ) { if( im_check_uncoded( "im_c2amph", in ) || im_check_complex( "im_c2amph", in ) || im_cp_desc( out, in ) ) return( -1 ); if( im_wrapone( in, out, (im_wrapone_fn) buffer_c2amph, in, NULL ) ) return( -1 ); return( 0 ); }
/** * im_abs: * @in: input #IMAGE * @out: output #IMAGE * * This operation finds the absolute value of an image. It does a copy for * unsigned integer types, negate for negative values in * signed integer types, <function>fabs(3)</function> for * float types, and calculate modulus for complex * types. * * See also: im_exp10tra(), im_sign(). * * Returns: 0 on success, -1 on error */ int im_abs( IMAGE *in, IMAGE *out ) { if( im_piocheck( in, out ) || im_check_uncoded( "im_abs", in ) ) return( -1 ); /* Is this one of the unsigned types? Degenerate to im_copy() if it * is. */ if( vips_bandfmt_isuint( in->BandFmt ) ) return( im_copy( in, out ) ); /* Prepare output header. Output type == input type, except for * complex. */ if( im_cp_desc( out, in ) ) return( -1 ); switch( in->BandFmt ) { case IM_BANDFMT_CHAR: case IM_BANDFMT_SHORT: case IM_BANDFMT_INT: case IM_BANDFMT_FLOAT: case IM_BANDFMT_DOUBLE: /* No action. */ break; case IM_BANDFMT_COMPLEX: out->BandFmt = IM_BANDFMT_FLOAT; break; case IM_BANDFMT_DPCOMPLEX: out->BandFmt = IM_BANDFMT_DOUBLE; break; default: im_error( "im_abs", "%s", _( "unknown input type" ) ); return( -1 ); } /* Generate! */ if( im_wrapone( in, out, (im_wrapone_fn) abs_gen, in, NULL ) ) return( -1 ); return( 0 ); }
/** * im_msb: * @in: input image * @out: output image * * Turn any integer image to 8-bit unsigned char by discarding all but the most * significant byte. * Signed values are converted to unsigned by adding 128. * * This operator also works for LABQ coding. * * See also: im_msb_band(). * * Returns: 0 on success, -1 on error */ int im_msb( IMAGE *in, IMAGE *out ) { Msb *msb; im_wrapone_fn func; if( in->Coding == IM_CODING_NONE && in->BandFmt == IM_BANDFMT_UCHAR ) return( im_copy( in, out ) ); if( im_piocheck( in, out ) || !(msb = IM_NEW( out, Msb )) ) return( -1 ); if( in->Coding == IM_CODING_NONE ) { if( im_check_int( "im_msb", in ) ) return( -1 ); msb->width = IM_IMAGE_SIZEOF_ELEMENT( in ); msb->index = im_amiMSBfirst() ? 0 : msb->width - 1; msb->repeat = in->Bands; if( vips_bandfmt_isuint( in->BandFmt ) ) func = (im_wrapone_fn) byte_select; else func = (im_wrapone_fn) byte_select_flip; } else if( IM_CODING_LABQ == in->Coding ) func = (im_wrapone_fn) msb_labq; else { im_error( "im_msb", "%s", _( "unknown coding" ) ); return( -1 ); } if( im_cp_desc( out, in ) ) return( -1 ); out->BandFmt = IM_BANDFMT_UCHAR; out->Coding = IM_CODING_NONE; return( im_wrapone( in, out, func, msb, NULL ) ); }
/** * im_c2real: * @in: input image * @out: output image * * Extract the real part of a complex image. * * See also: im_c2imag(). * * Returns: 0 on success, -1 on error */ int im_c2real( IMAGE *in, IMAGE *out ) { if( im_check_uncoded( "im_c2real", in ) || im_check_complex( "im_c2real", in ) || im_cp_desc( out, in ) ) return( -1 ); /* Output will be float or double. */ if( in->BandFmt == IM_BANDFMT_DPCOMPLEX ) out->BandFmt = IM_BANDFMT_DOUBLE; else out->BandFmt = IM_BANDFMT_FLOAT; if( im_wrapone( in, out, (im_wrapone_fn) buffer_c2real, in, NULL ) ) return( -1 ); return( 0 ); }
int im__colour_unary( const char *domain, IMAGE *in, IMAGE *out, VipsType type, im_wrapone_fn buffer_fn, void *a, void *b ) { IMAGE *t[1]; if( im_check_uncoded( domain, in ) || im_check_bands( domain, in, 3 ) || im_open_local_array( out, t, 1, domain, "p" ) || im_clip2fmt( in, t[0], IM_BANDFMT_FLOAT ) ) return( -1 ); if( im_cp_desc( out, t[0] ) ) return( -1 ); out->Type = type; if( im_wrapone( t[0], out, (im_wrapone_fn) buffer_fn, a, b ) ) return( -1 ); return( 0 ); }
int im_msb_band (IMAGE * in, IMAGE * out, int band) { #define FUNCTION_NAME "im_msb_band" size_t *params; im_wrapone_fn func; #define index (params[0]) #define width (params[1]) #define repeat (params[2]) if (band < 0) { im_error (FUNCTION_NAME, _("bad arguments")); return -1; } if (im_piocheck (in, out)) return -1; params = IM_ARRAY (out, 3, size_t); if (!params) return -1; if (IM_UNCODED (in)) { if (!IM_ANY_INT (in)) { im_error (FUNCTION_NAME, _("char, short or int only")); return -1; } if (band >= in->Bands) { im_error (FUNCTION_NAME, _("image does not have that many bands")); return -1; } width = SIZEOF_BAND (in->BandFmt); #if G_BYTE_ORDER == G_BIG_ENDIAN index = width * band; #else index = (width * (band + 1)) - 1; #endif width *= in->Bands; repeat = 1; if (IM_UNSIGNED (in)) func = (im_wrapone_fn) byte_select; else func = (im_wrapone_fn) byte_select_flip; } else if (IM_CODING_LABQ == in->Coding) { if (band > 2) { im_error (FUNCTION_NAME, _("image does not have that many bands")); return -1; } width = 4; repeat = 1; index = band; if (band) func = (im_wrapone_fn) byte_select_flip; else func = (im_wrapone_fn) byte_select; } else { im_error (FUNCTION_NAME, _("unknown coding")); return -1; } if (im_cp_desc (out, in)) return -1; out->Bands = 1; out->Bbits = sizeof (unsigned char) << 3; out->BandFmt = IM_BANDFMT_UCHAR; out->Coding = IM_CODING_NONE; return im_wrapone (in, out, func, (void *) params, NULL); #undef index #undef width #undef repeat #undef FUNCTION_NAME }
/** * im_msb_band: * @in: input image * @out: output image * @band: select this band * * Turn any integer image to a single-band 8-bit unsigned char by discarding * all but the most significant byte from the selected band. * Signed values are converted to unsigned by adding 128. * * This operator also works for LABQ coding. * * See also: im_msb_band(). * * Returns: 0 on success, -1 on error */ int im_msb_band( IMAGE *in, IMAGE *out, int band ) { Msb *msb; im_wrapone_fn func; if( band < 0 ) { im_error( "im_msb_band", "%s", _( "bad arguments" ) ); return( -1 ); } if( im_piocheck( in, out ) || !(msb = IM_NEW( out, Msb )) ) return( -1 ); if( in->Coding == IM_CODING_NONE ) { if( im_check_int( "im_msb_band", in ) ) return( -1 ); if( band >= in->Bands ) { im_error( "im_msb_band", "%s", _( "image does not have that many bands" ) ); return( -1 ); } msb->width = IM_IMAGE_SIZEOF_ELEMENT( in ); msb->index = im_amiMSBfirst() ? msb->width * band : msb->width * (band + 1) - 1; msb->repeat = 1; if( vips_bandfmt_isuint( in->BandFmt ) ) func = (im_wrapone_fn) byte_select; else func = (im_wrapone_fn) byte_select_flip; } else if( IM_CODING_LABQ == in->Coding ) { if( band > 2 ) { im_error( "im_msb_band", "%s", _( "image does not have that many bands" ) ); return( -1 ); } msb->width = 4; msb->repeat = 1; msb->index = band; if( band ) func = (im_wrapone_fn) byte_select_flip; else func = (im_wrapone_fn) byte_select; } else { im_error( "im_msb", "%s", _( "unknown coding" ) ); return( -1 ); } if( im_cp_desc( out, in ) ) return( -1 ); out->BandFmt = IM_BANDFMT_UCHAR; out->Coding = IM_CODING_NONE; out->Bands = 1; return( im_wrapone( in, out, func, msb, NULL ) ); }
int im_msb (IMAGE * in, IMAGE * out) { #define FUNCTION_NAME "im_msb" size_t *params; im_wrapone_fn func; #define index (params[0]) #define width (params[1]) #define repeat (params[2]) if (im_piocheck (in, out)) return -1; /* Stops a used-before-set warning. */ params = NULL; if (IM_UNCODED (in)) { if (!IM_ANY_INT (in)) { im_error (FUNCTION_NAME, _("char, short or int only")); return -1; } params = IM_ARRAY (out, 3, size_t); if (!params) return -1; width = SIZEOF_BAND (in->BandFmt); #if G_BYTE_ORDER == G_BIG_ENDIAN index = 0; #else index = width - 1; #endif repeat = in->Bands; if (IM_UNSIGNED (in)) func = (im_wrapone_fn) byte_select; else func = (im_wrapone_fn) byte_select_flip; if (1 == width && (im_wrapone_fn) byte_select == func) { return im_copy (in, out); } } else if (IM_CODING_LABQ == in->Coding) func = (im_wrapone_fn) msb_labq; else { im_error (FUNCTION_NAME, _("unknown coding")); return -1; } if (im_cp_desc (out, in)) return -1; out->Bbits = sizeof (unsigned char) << 3; out->BandFmt = IM_BANDFMT_UCHAR; out->Coding = IM_CODING_NONE; return im_wrapone (in, out, func, (void *) params, NULL); #undef index #undef width #undef repeat #undef FUNCTION_NAME }