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 ); }
/* Copy image. */ int im_fliphor( IMAGE *in, IMAGE *out ) { /* Check args. */ if( im_piocheck( in, out ) ) return( -1 ); if( in->Coding != IM_CODING_NONE && in->Coding != IM_CODING_LABQ ) { im_error( "im_fliphor", _( "in must be uncoded" ) ); return( -1 ); } /* Prepare output header. */ if( im_cp_desc( out, in ) ) return( -1 ); /* Set demand hints. */ if( im_demand_hint( out, IM_THINSTRIP, in, NULL ) ) return( -1 ); /* Generate! */ if( im_generate( out, im_start_one, flip_gen, im_stop_one, in, NULL ) ) return( -1 ); out->Xoffset = in->Xsize; out->Yoffset = 0; 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 ); }
/** * 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_rot270( IMAGE *in, IMAGE *out ) { /* Make output image. */ if( im_piocheck( in, out ) ) return( -1 ); if( in->Coding != IM_CODING_NONE && in->Coding != IM_CODING_LABQ ) { im_error( "im_rot270", _( "uncoded or IM_CODING_LABQ only" ) ); return( -1 ); } if( im_cp_desc( out, in ) ) return( -1 ); out->Xsize = in->Ysize; out->Ysize = in->Xsize; /* We want smalltile if possible. */ if( im_demand_hint( out, IM_SMALLTILE, in, NULL ) ) return( -1 ); /* Generate! */ if( im_generate( out, im_start_one, rot270_gen, im_stop_one, in, NULL ) ) return( -1 ); out->Xoffset = 0; out->Yoffset = in->Xsize; 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_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_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_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_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_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_stdif_raw( IMAGE *in, IMAGE *out, double a, double m0, double b, double s0, int xwin, int ywin ) { StdifInfo *inf; if( xwin > in->Xsize || ywin > in->Ysize ) { im_error( "im_stdif", "%s", _( "window too large" ) ); return( -1 ); } if( xwin <= 0 || ywin <= 0 ) { im_error( "im_lhisteq", "%s", _( "window too small" ) ); return( -1 ); } if( m0 < 0 || m0 > 255 || a < 0 || a > 1.0 || b < 0 || b > 2 || s0 < 0 || s0 > 255 ) { im_error( "im_stdif", "%s", _( "parameters out of range" ) ); return( -1 ); } if( im_check_format( "im_stdif", in, IM_BANDFMT_UCHAR ) || im_check_uncoded( "im_stdif", in ) || im_check_mono( "im_stdif", in ) || im_piocheck( in, out ) ) return( -1 ); if( im_cp_desc( out, in ) ) return( -1 ); out->Xsize -= xwin; out->Ysize -= ywin; /* Save parameters. */ if( !(inf = IM_NEW( out, StdifInfo )) ) return( -1 ); inf->xwin = xwin; inf->ywin = ywin; inf->a = a; inf->m0 = m0; inf->b = b; inf->s0 = s0; /* Set demand hints. FATSTRIP is good for us, as THINSTRIP will cause * too many recalculations on overlaps. */ if( im_demand_hint( out, IM_FATSTRIP, in, NULL ) ) return( -1 ); /* Write the hist. */ if( im_generate( out, im_start_one, stdif_gen, im_stop_one, in, inf ) ) return( -1 ); return( 0 ); }
/** * im_grad_y: * @in: input image * @out: output image * * Find vertical differences between adjacent pixels. * * Generates an image where the value of each pixel is the difference between * it and the pixel below it. The output has the same width as the input * and one pixel less height. One-band integer formats only. The result is * always %IM_BANDFMT_INT. * * This operation is much faster than (though equivalent to) im_conv() with the * mask [[-1], [1]]. * * See also: im_grad_x(), im_conv(). * * Returns: 0 on success, -1 on error */ int im_grad_y( IMAGE *in, IMAGE *out ){ #define FUNCTION_NAME "im_grad_y" if( im_piocheck( in, out ) ) return -1; if( im_check_uncoded( "im_grad_y", in ) || im_check_mono( "im_grad_y", in ) || im_check_int( "im_grad_y", in ) ) return( -1 ); if( im_cp_desc( out, in ) ) return -1; -- out-> Ysize; out-> BandFmt= IM_BANDFMT_INT; /* do not change without updating im_gradcor() */ if( im_demand_hint( out, IM_FATSTRIP, in, NULL ) ) return -1; #define RETURN_GENERATE( TYPE ) return im_generate( out, im_start_one, ygrad_gen_ ## TYPE, im_stop_one, (void*) in, NULL ) switch( in-> BandFmt ){ case IM_BANDFMT_UCHAR: RETURN_GENERATE( guint8 ); case IM_BANDFMT_CHAR: RETURN_GENERATE( gint8 ); case IM_BANDFMT_USHORT: RETURN_GENERATE( guint16 ); case IM_BANDFMT_SHORT: RETURN_GENERATE( gint16 ); case IM_BANDFMT_UINT: RETURN_GENERATE( guint32 ); case IM_BANDFMT_INT: RETURN_GENERATE( gint32 ); #if 0 case IM_BANDFMT_FLOAT: RETURN_GENERATE( float ); case IM_BANDFMT_DOUBLE: RETURN_GENERATE( double ); #endif #undef RETURN_GENERATE default: g_assert( 0 ); } /* Keep gcc happy. */ return 0; #undef FUNCTION_NAME }
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 ); }
int im_contrast_surface_raw (IMAGE * in, IMAGE * out, int half_win_size, int spacing) { #define FUNCTION_NAME "im_contrast_surface_raw" cont_surf_params_t *params; if (im_piocheck (in, out) || im_check_uncoded (FUNCTION_NAME, in) || im_check_mono (FUNCTION_NAME, in) || im_check_format (FUNCTION_NAME, in, IM_BANDFMT_UCHAR)) return -1; if (half_win_size < 1 || spacing < 1) { im_error (FUNCTION_NAME, "%s", _("bad parameters")); return -1; } if (DOUBLE (half_win_size) >= LESSER (in->Xsize, in->Ysize)) { im_error (FUNCTION_NAME, "%s", _("parameters would result in zero size output image")); return -1; } params = IM_NEW (out, cont_surf_params_t); if (!params) return -1; params->half_win_size = half_win_size; params->spacing = spacing; if (im_cp_desc (out, in)) return -1; out->BandFmt = IM_BANDFMT_UINT; out->Xsize = 1 + ((in->Xsize - DOUBLE_ADD_ONE (half_win_size)) / spacing); out->Ysize = 1 + ((in->Ysize - DOUBLE_ADD_ONE (half_win_size)) / spacing); out->Xoffset = -half_win_size; out->Yoffset = -half_win_size; if (im_demand_hint (out, IM_FATSTRIP, in, NULL)) return -1; return im_generate (out, im_start_one, cont_surf_gen, im_stop_one, in, params); #undef FUNCTION_NAME }
/* 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 ); }
/* Copy image, changing header fields. */ static int im_copy_set_all( IMAGE *in, IMAGE *out, VipsType type, float xres, float yres, int xoffset, int yoffset, int bands, VipsBandFmt bandfmt, VipsCoding coding ) { /* Check args. */ if( im_check_coding_known( "im_copy", in ) || im_piocheck( in, out ) ) return( -1 ); if( coding != IM_CODING_NONE && coding != IM_CODING_LABQ && coding != IM_CODING_RAD ) { im_error( "im_copy", "%s", _( "coding must be NONE, LABQ or RAD" ) ); return( -1 ); } if( bandfmt < 0 || bandfmt > IM_BANDFMT_DPCOMPLEX ) { im_error( "im_copy", _( "bandfmt must be in range [0,%d]" ), IM_BANDFMT_DPCOMPLEX ); return( -1 ); } if( im_cp_desc( out, in ) ) return( -1 ); out->Type = type; out->Xres = xres; out->Yres = yres; out->Xoffset = xoffset; out->Yoffset = yoffset; out->Bands = bands; out->BandFmt = bandfmt; out->Coding = coding; /* Sanity check: we (may) have changed bytes-per-pixel since we've * changed Bands and BandFmt ... bad! */ if( IM_IMAGE_SIZEOF_PEL( in ) != IM_IMAGE_SIZEOF_PEL( out ) ) { im_error( "im_copy", "%s", _( "sizeof( pixel ) has changed" ) ); return( -1 ); } /* Generate! */ if( im_demand_hint( out, IM_THINSTRIP, in, NULL ) || im_generate( out, im_start_one, copy_gen, im_stop_one, in, 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 ); }
/* Morph an image. */ static int morphology( IMAGE *in, IMAGE *out, INTMASK *mask, MorphOp op ) { Morph *morph; im_generate_fn generate; /* Check parameters. */ if( !(morph = morph_new( in, out, mask, op )) ) return( -1 ); /* Prepare output. Consider a 7x7 mask and a 7x7 image --- the output * would be 1x1. */ if( im_cp_desc( morph->out, morph->in ) ) return( -1 ); morph->out->Xsize -= morph->mask->xsize - 1; morph->out->Ysize -= morph->mask->ysize - 1; if( morph->out->Xsize <= 0 || morph->out->Ysize <= 0 ) { im_error( "morph", "%s", _( "image too small for mask" ) ); return( -1 ); } if( morph->n_pass ) { generate = morph_vector_gen; #ifdef DEBUG printf( "morph_vector_gen: %d passes\n", morph->n_pass ); #endif /*DEBUG*/ } else if( morph->op == DILATE ) generate = dilate_gen; else generate = erode_gen; /* Set demand hints. FATSTRIP is good for us, as THINSTRIP will cause * too many recalculations on overlaps. */ if( im_demand_hint( morph->out, IM_FATSTRIP, morph->in, NULL ) || im_generate( morph->out, morph_start, generate, morph_stop, morph->in, morph ) ) return( -1 ); morph->out->Xoffset = -morph->mask->xsize / 2; morph->out->Yoffset = -morph->mask->ysize / 2; 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 ); }
int im_lhisteq_raw( IMAGE *in, IMAGE *out, int xwin, int ywin ) { LhistInfo *inf; if( im_check_mono( "im_lhisteq", in ) || im_check_uncoded( "im_lhisteq", in ) || im_check_format( "im_lhisteq", in, IM_BANDFMT_UCHAR ) || im_piocheck( in, out ) ) return( -1 ); if( xwin > in->Xsize || ywin > in->Ysize ) { im_error( "im_lhisteq", "%s", _( "window too large" ) ); return( -1 ); } if( xwin <= 0 || ywin <= 0 ) { im_error( "im_lhisteq", "%s", _( "window too small" ) ); return( -1 ); } if( im_cp_desc( out, in ) ) return( -1 ); out->Xsize -= xwin - 1; out->Ysize -= ywin - 1; /* Save parameters. */ if( !(inf = IM_NEW( out, LhistInfo )) ) return( -1 ); inf->xwin = xwin; inf->ywin = ywin; inf->npels = xwin * ywin; /* Set demand hints. FATSTRIP is good for us, as THINSTRIP will cause * too many recalculations on overlaps. */ if( im_demand_hint( out, IM_FATSTRIP, in, NULL ) ) return( -1 ); if( im_generate( out, im_start_one, lhist_gen, im_stop_one, in, inf ) ) return( -1 ); out->Xoffset = -xwin / 2; out->Yoffset = -xwin / 2; return( 0 ); }
/** * im_zerox: * @in: input image * @out: output image * @sign: detect positive or negative zero crossings * * im_zerox() detects the positive or negative zero crossings @in, * depending on @sign. If @sign is -1, negative zero crossings are returned, * if @sign is 1, positive zero crossings are returned. * * The output image is byte with zero crossing set to 255 and all other values * set to zero. Input can have any number of channels, and be any non-complex * type. * * See also: im_conv(), im_rot90. * * Returns: 0 on success, -1 on error */ int im_zerox( IMAGE *in, IMAGE *out, int sign ) { IMAGE *t1; if( sign != -1 && sign != 1 ) { im_error( "im_zerox", "%s", _( "flag not -1 or 1" ) ); return( -1 ); } if( in->Xsize < 2 ) { im_error( "im_zerox", "%s", _( "image too narrow" ) ); return( -1 ); } if( !(t1 = im_open_local( out, "im_zerox" , "p" )) || im_piocheck( in, t1 ) || im_check_uncoded( "im_zerox", in ) || im_check_noncomplex( "im_zerox", in ) ) return( -1 ); if( vips_bandfmt_isuint( in->BandFmt ) ) /* Unsigned type, therefore there will be no zero-crossings. */ return( im_black( out, in->Xsize, in->Ysize, in->Bands ) ); /* Force output to be BYTE. Output is narrower than input by 1 pixel. */ if( im_cp_desc( t1, in ) ) return( -1 ); t1->BandFmt = IM_BANDFMT_UCHAR; t1->Xsize -= 1; /* Set hints - THINSTRIP is ok with us. */ if( im_demand_hint( t1, IM_THINSTRIP, NULL ) ) return( -1 ); /* Generate image. */ if( im_generate( t1, im_start_one, zerox_gen, im_stop_one, in, GINT_TO_POINTER( sign ) ) ) return( -1 ); /* Now embed it in a larger image. */ if( im_embed( t1, out, 0, 0, 0, in->Xsize, in->Ysize ) ) 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 ); }
static int shrink( IMAGE *in, IMAGE *out, double xshrink, double yshrink ) { ShrinkInfo *st; /* Prepare output. Note: we round the output width down! */ if( im_cp_desc( out, in ) ) return( -1 ); out->Xsize = in->Xsize / xshrink; out->Ysize = in->Ysize / yshrink; out->Xres = in->Xres / xshrink; out->Yres = in->Yres / yshrink; if( out->Xsize <= 0 || out->Ysize <= 0 ) { im_error( "im_shrink", "%s", _( "image has shrunk to nothing" ) ); return( -1 ); } /* Build and attach state struct. */ if( !(st = IM_NEW( out, ShrinkInfo )) ) return( -1 ); st->xshrink = xshrink; st->yshrink = yshrink; st->mw = ceil( xshrink ); st->mh = ceil( yshrink ); st->np = st->mw * st->mh; /* Set demand hints. We want THINSTRIP, as we will be demanding a * large area of input for each output line. */ if( im_demand_hint( out, IM_THINSTRIP, in, NULL ) ) return( -1 ); /* Generate! */ if( im_generate( out, shrink_start, shrink_gen, shrink_stop, in, st ) ) return( -1 ); return( 0 ); }
/** * im_fav4: * @in: array of 4 input #IMAGE s * @out: output #IMAGE * * Average four identical images. * * Deprecated. */ int im_fav4( IMAGE **in, IMAGE *out) { PEL *result, *buffer, *p1, *p2, *p3, *p4; int x,y; int linebytes, PICY; /* check IMAGEs parameters */ if(im_iocheck(in[1], out)) return(-1); /* BYTE images only! */ if( (in[0]->BandFmt != IM_BANDFMT_CHAR) && (in[0]->BandFmt != IM_BANDFMT_UCHAR)) return(-1); if ( im_cp_desc(out, in[1]) == -1) /* copy image descriptors */ return(-1); if ( im_setupout(out) == -1) return(-1); linebytes = in[0]->Xsize * in[0]->Bands; PICY = in[0]->Ysize; buffer = (PEL*)im_malloc(NULL,linebytes); memset(buffer, 0, linebytes); p1 = (PEL*)in[0]->data; p2 = (PEL*)in[1]->data; p3 = (PEL*)in[2]->data; p4 = (PEL*)in[3]->data; for (y = 0; y < PICY; y++) { result = buffer; /* average 4 pels with rounding, for whole line*/ for (x = 0; x < linebytes; x++) { *result++ = (PEL)((int)((int)*p1++ + (int)*p2++ + (int)*p3++ + (int)*p4++ +2) >> 2); } im_writeline(y,out, buffer); } im_free(buffer); return(0); }
/** * im_rot180: * @in: input image * @out: output image * * Rotate an image 180 degrees. * * See also: im_rot90(), im_rot270(), im_affinei_all(). * * Returns: 0 on success, -1 on error */ int im_rot180( IMAGE *in, IMAGE *out ) { if( im_piocheck( in, out ) || im_check_coding_known( "im_rot180", in ) ) return( -1 ); if( im_cp_desc( out, in ) || im_demand_hint( out, IM_THINSTRIP, in, NULL ) ) return( -1 ); if( im_generate( out, im_start_one, rot180_gen, im_stop_one, in, NULL ) ) return( -1 ); out->Xoffset = in->Xsize; out->Yoffset = in->Ysize; 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_gradcor_raw( IMAGE *large, IMAGE *small, IMAGE *out ){ #define FUNCTION_NAME "im_gradcor_raw" if( im_piocheck( large, out ) || im_pincheck( small ) ) return -1; if( im_check_uncoded( "im_gradcor", large ) || im_check_mono( "im_gradcor", large ) || im_check_uncoded( "im_gradcor", small ) || im_check_mono( "im_gradcor", small ) || im_check_format_same( "im_gradcor", large, small ) || im_check_int( "im_gradcor", large ) ) return( -1 ); if( large-> Xsize < small-> Xsize || large-> Ysize < small-> Ysize ){ im_error( FUNCTION_NAME, "second image must be smaller than first" ); return -1; } if( im_cp_desc( out, large ) ) return -1; out-> Xsize= 1 + large-> Xsize - small-> Xsize; out-> Ysize= 1 + large-> Ysize - small-> Ysize; out-> BandFmt= IM_BANDFMT_FLOAT; if( im_demand_hint( out, IM_FATSTRIP, large, NULL ) ) return -1; { IMAGE *xgrad= im_open_local( out, FUNCTION_NAME ": xgrad", "t" ); IMAGE *ygrad= im_open_local( out, FUNCTION_NAME ": ygrad", "t" ); IMAGE **grads= im_allocate_input_array( out, xgrad, ygrad, NULL ); return ! xgrad || ! ygrad || ! grads || im_grad_x( small, xgrad ) || im_grad_y( small, ygrad ) || im_generate( out, gradcor_start, gradcor_gen, gradcor_stop, (void*) large, (void*) grads ); } #undef FUNCTION_NAME }
/** * im_tile_cache: * @in: input image * @out: output image * @tile_width: tile width * @tile_height: tile height * @max_tiles: maximum number of tiles to cache * * This operation behaves rather like im_copy() between images * @in and @out, except that it keeps a cache of computed pixels. * This cache is made of up to @max_tiles tiles (a value of -1 for * means any number of tiles), and each tile is of size @tile_width * by @tile_height pixels. Each cache tile is made with a single call to * im_prepare(). * * This is a lower-level operation than im_cache() since it does no * subdivision. It is suitable for caching the output of operations like * im_exr2vips() on tiled images. * * See also: im_cache(). * * Returns: 0 on success, -1 on error. */ int im_tile_cache( IMAGE *in, IMAGE *out, int tile_width, int tile_height, int max_tiles ) { Read *read; if( tile_width <= 0 || tile_height <= 0 || max_tiles < -1 ) { im_error( "im_tile_cache", "%s", _( "bad parameters" ) ); return( -1 ); } if( im_piocheck( in, out ) || im_cp_desc( out, in ) || im_demand_hint( out, IM_SMALLTILE, in, NULL ) || !(read = read_new( in, out, tile_width, tile_height, max_tiles )) || im_generate( out, im_start_one, tile_cache_fill, im_stop_one, in, read ) ) return( -1 ); return( 0 ); }