示例#1
0
int 
im_subtract( IMAGE *in1, IMAGE *in2, IMAGE *out )
{	
	/* Basic checks.
	 */
	if( im_piocheck( in1, out ) || im_pincheck( in2 ) )
		return( -1 );
	if( in1->Bands != in2->Bands &&
		(in1->Bands != 1 && in2->Bands != 1) ) {
		im_error( "im_subtract", _( "not same number of bands" ) );
		return( -1 );
	}
	if( in1->Coding != IM_CODING_NONE || in2->Coding != IM_CODING_NONE ) {
		im_error( "im_subtract", _( "not uncoded" ) );
		return( -1 );
	}
	if( im_cp_descv( out, in1, in2, NULL ) )
		return( -1 );

	/* What number of bands will we write?
	 */
	out->Bands = IM_MAX( in1->Bands, in2->Bands );

	/* What output type will we write? int, float or complex.
	 */
	if( im_iscomplex( in1 ) || im_iscomplex( in2 ) ) {
		/* What kind of complex?
		 */
		if( in1->BandFmt == IM_BANDFMT_DPCOMPLEX || 
			in2->BandFmt == IM_BANDFMT_DPCOMPLEX )
			/* Output will be DPCOMPLEX. 
			 */
			out->BandFmt = IM_BANDFMT_DPCOMPLEX;
		else
			out->BandFmt = IM_BANDFMT_COMPLEX;
	}
	else if( im_isfloat( in1 ) || im_isfloat( in2 ) ) {
		/* What kind of float?
		 */
		if( in1->BandFmt == IM_BANDFMT_DOUBLE || 
			in2->BandFmt == IM_BANDFMT_DOUBLE )
			out->BandFmt = IM_BANDFMT_DOUBLE;
		else
			out->BandFmt = IM_BANDFMT_FLOAT;
	}
	else 
		/* Must be int+int -> int.
		 */
		out->BandFmt = iformat[in1->BandFmt][in2->BandFmt];

	/* And process!
	 */
	if( im__cast_and_call( in1, in2, out, 
		(im_wrapmany_fn) subtract_buffer, NULL ) )
		return( -1 );

	/* Success!
	 */
	return( 0 );
}
示例#2
0
void
im_verror_system( int err, const char *domain, const char *fmt, va_list ap )
{
	im_verror( domain, fmt, ap );

#ifdef OS_WIN32
{
	char *buf;

	if( FormatMessageA(
		FORMAT_MESSAGE_ALLOCATE_BUFFER |
		FORMAT_MESSAGE_IGNORE_INSERTS |
		FORMAT_MESSAGE_FROM_SYSTEM,
		NULL,
		err,
		MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ), 
		(LPSTR) &buf, 0, NULL ) ) {
		im_error( _( "windows error" ), "%s", buf );
		LocalFree( buf );
	}
}
#else /*OS_WIN32*/
{
	char *buf;

	buf = g_locale_to_utf8( strerror( err ), -1, NULL, NULL, NULL );
	im_error( _( "unix error" ), "%s", buf );
	g_free( buf );
}
#endif /*OS_WIN32*/
}
示例#3
0
/* Break a string into a list of strings. Write '\0's into the string. out
 * needs to be MAX_FILES long. -1 for error, otherwise number of args found.

	"<fred> <jim poop> <sn aff le>"

	out[0] = "fred"
	out[1] = "jim poop"
	out[2] = "sn aff le"

 */
static int
break_items( char *line, char **out )
{
	int i;
	char *p;

	for( i = 0; i < MAX_ITEMS; i++ ) {
		/* Skip to first '<'.
		 */
		if( !(p = strchr( line, '<' )) )
			break;

		out[i] = line = p + 1;

		if( !(p = strchr( line, '>' )) ) {
			im_error( "break_files", _( "no matching '>'" ) );
			return( -1 );
		}

		*p = '\0';
		line = p + 1;
	}

	if( i == MAX_ITEMS ) {
		im_error( "break_files", _( "too many items" ) );
		return( -1 );
	}

	return( i );
}
示例#4
0
/* Scan the symbol table, looking for a node which no node references.
 */
static JoinNode *
find_root( SymbolTable *st )
{
	JoinNode *root;
	JoinNode *notroot;

	/* Clean the table, then scan it, setting all pointed-to nodes dirty.
	 */
	clean_table( st );
	im__map_table( st, set_referenced, NULL, NULL );

	/* Look for the first clean symbol.
	 */
	root = (JoinNode *) im__map_table( st, is_root, NULL, NULL );

	/* No root? Hot dang!
	 */
	if( !root ) {
		im_error( "im_global_balance", 
			_( "mosaic root not found in desc file\n"
			"is this really a mosaiced image?" ) );
		return( NULL );
	}

	/* Now dirty that - then if there are any more clean symbols, we have
	 * more than one root.
	 */
	root->dirty = 1;
	if( (notroot = im__map_table( st, is_root, NULL, NULL )) ) {
		im_error( "im_global_balance", _( "more than one root" ) );
		return( NULL );
	}

	return( root );
}
示例#5
0
static int
magick2vips_header( const char *filename, IMAGE *im )
{
	Read *read;

	if( !(read = read_new( filename, im )) )
		return( -1 );

	read->image = PingImage( read->image_info, &read->exception );
	if( !read->image ) {
		im_error( "im_magick2vips", _( "unable to ping file "
			"\"%s\"\nlibMagick error: %s %s" ),
			filename, 
			read->exception.reason, read->exception.description );
		return( -1 );
	}

	if( parse_header( read ) ) 
		return( -1 );

	if( im->Xsize <= 0 || im->Ysize <= 0 ) {
		im_error( "im_magick2vips", "%s", _( "bad image size" ) );
		return( -1 );
	}

	return( 0 );
}
示例#6
0
/* MATRIX concatenate (join columns ie add mask to bottom of another)
 */
DOUBLEMASK *
im_matcat( DOUBLEMASK *in1, DOUBLEMASK *in2, const char *name )
{
	int newxsize, newysize;
	DOUBLEMASK *mat;
	double *out;
	
	/* matrices must be same width
	 */
	if( in1->xsize != in2->xsize ) {
		im_error( "im_matcat", "%s", _( "matrices must be same width" ) );
		return( NULL );
	}

	newxsize = in1->xsize;
	newysize = in1->ysize + in2->ysize;

	/* Allocate output matrix.
	 */
	if( !(mat = im_create_dmask( name, newxsize, newysize )) ) {
		im_error( "im_matcat", "%s", _( "unable to allocate output matrix" ) );
		return( NULL );
	}

	/* copy first matrix then add second on the end
	 */
	memcpy( mat->coeff, in1->coeff, 
		in1->xsize * in1->ysize * sizeof( double ) );
	out = mat->coeff + in1->xsize * in1->ysize;
	memcpy( out, in2->coeff, 
		in2->xsize * in2->ysize * sizeof( double ) );

	return( mat );
}
示例#7
0
文件: fmask4th.c 项目: alon/libvips
static float *
gaussian_lpf( IMAGE *out, int xs, int ys, double fc, double ac )
{
	int x, y;
	float *coeff, *cpcoeff;
	double *xd, *yd, fc2, distance2, cnst;

	if( xs != ys || fc < 0.0 || ac >= 1.0 || ac <= 0.0 ) {
		im_error( "gaussian_lpf", "%s", _( "bad args" ) );
		return( NULL );
	}

	if( fc > 1.0 && fc <= xs/2 )
		fc2 = fc * fc * 4.0 / (double)(xs * ys);
	else if( fc <= 1.0 && fc > 0.0 )
		fc2 = fc * fc;
	else {
		im_error( "gaussian_lpf", "%s", _( "bad args" ) );
		return( NULL );
	}

        if( alloc( out, xs, ys, &xd, &yd, &coeff ) )
                return( NULL );

	cpcoeff = coeff;
	cnst = -log( ac );
	for( y = 0; y < ys/2 + 1; y++ )
		for( x = 0; x < xs/2 + 1; x++ ) {
			distance2 = (xd[x] + yd[y])/fc2;
			*cpcoeff++ =  exp( - cnst * distance2 );
		}	

	return( coeff );
}
示例#8
0
/**
 * im_region_region:
 * @reg: region to operate upon
 * @dest: region to connect to
 * @r: #Rect of pixels you need to be able to address
 * @x: postion of @r in @dest
 * @y: postion of @r in @dest
 *
 * Make IM_REGION_ADDR() on @reg go to @dest instead.
 *
 * @r is the part of @reg which you want to be able to address (this
 * effectively becomes the valid field), (@x, @y) is the top LH corner of the
 * corresponding area in @dest.
 *
 * Performs all clipping necessary to ensure that @reg->valid is indeed
 * valid.
 *
 * If the region we attach to is modified, we can be left with dangling
 * pointers! If the region we attach to is on another image, the two images
 * must have
 * the same sizeof( pel ).
 *
 * Returns: 0 on success, or -1 for error.
 */
int
im_region_region( REGION *reg, REGION *dest, Rect *r, int x, int y )
{
    Rect image;
    Rect wanted;
    Rect clipped;
    Rect clipped2;
    Rect final;

    /* Sanity check.
     */
    if( !dest->data ||
            IM_IMAGE_SIZEOF_PEL( dest->im ) !=
            IM_IMAGE_SIZEOF_PEL( reg->im ) ) {
        im_error( "im_region_region",
                  "%s", _( "inappropriate region type" ) );
        return( -1 );
    }
    im__region_check_ownership( reg );

    /* We can't test

    	g_assert( dest->thread == g_thread_self() );

     * since we can have several threads writing to the same region in
     * threadgroup.
     */

    /* Clip r against size of the image.
     */
    image.top = 0;
    image.left = 0;
    image.width = reg->im->Xsize;
    image.height = reg->im->Ysize;
    im_rect_intersectrect( r, &image, &clipped );

    /* Translate to dest's coordinate space and clip against the available
     * pixels.
     */
    wanted.left = x + (clipped.left - r->left);
    wanted.top = y + (clipped.top - r->top);
    wanted.width = clipped.width;
    wanted.height = clipped.height;

    /* Test that dest->valid is large enough.
     */
    if( !im_rect_includesrect( &dest->valid, &wanted ) ) {
        im_error( "im_region_region",
                  "%s", _( "dest too small" ) );
        return( -1 );
    }

    /* Clip against the available pixels.
     */
    im_rect_intersectrect( &wanted, &dest->valid, &clipped2 );

    /* Translate back to reg's coordinate space and set as valid.
     */
    final.left = r->left + (clipped2.left - wanted.left);
示例#9
0
/* Like im_insert, but perform an in-place insertion.
 */
int
im_insertplace( IMAGE *big, IMAGE *small, int x, int y )
{	
	Rect br, sr;
	PEL *p, *q;
	int z;

	/* Check IO.
	 */
	if( im_rwcheck( big ) || im_incheck( small ) )
		return( -1 );

	/* Check compatibility.
	 */
        if( big->BandFmt != small->BandFmt || big->Bands != small->Bands ||
                big->Coding != small->Coding ) {
                im_error( "im_insertplace", _( "inputs differ in format" ) );
                return( -1 );
        }
        if( big->Coding != IM_CODING_NONE && big->Coding != IM_CODING_LABQ ) {
                im_error( "im_insertplace", _( "input should be uncoded "
                        "or IM_CODING_LABQ" ) );
                return( -1 );
        }

	/* Make rects for big and small.
	 */
	br.left = 0;
	br.top = 0;
	br.width = big->Xsize;
	br.height = big->Ysize;
	sr.left = x;
	sr.top = y;
	sr.width = small->Xsize;
	sr.height = small->Ysize;

	/* Small fits inside big?
	 */
	if( !im_rect_includesrect( &br, &sr ) ) {
		im_error( "im_insertplace", _( "small not inside big" ) );
		return( -1 );
	}

	/* Loop, memcpying small to big.
	 */
	p = (PEL *) IM_IMAGE_ADDR( small, 0, 0 );
	q = (PEL *) IM_IMAGE_ADDR( big, x, y );
	for( z = 0; z < small->Ysize; z++ ) {
		memcpy( (char *) q, (char *) p, IM_IMAGE_SIZEOF_LINE( small ) );
		p += IM_IMAGE_SIZEOF_LINE( small );
		q += IM_IMAGE_SIZEOF_LINE( big );
	}

	im_invalidate( big );

	return( 0 );
}
示例#10
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 );
}
示例#11
0
int 
im__tbcalcon( IMAGE *ref, TIE_POINTS *points )
{
	/* Geometry: border we must leave around each area.
	 */
	const int border = points->halfareasize;

	/* Width of an area.
	 */
	const int awidth = ref->Xsize / AREAS;

	/* Number of points we find in each area.
	 */
	const int len = points->nopoints / AREAS;

	int i;
	Rect area;

	/* Make sure we can read image.
	 */
	if( im_incheck( ref ) )
		return( -1 );
	if( ref->Bands != 1 || ref->BandFmt != IM_BANDFMT_UCHAR ) { 
		im_error( "im__tbcalcon", "%s", _( "help!" ) );
		return( -1 );
	}

	/* Define bits to search for high-contrast areas.
	 */
	area.width = awidth;
	area.height = ref->Ysize;
	area.left = 0;
	area.top = 0;
	im_rect_marginadjust( &area, -border );
	area.width--;
	area.height--;
	if( area.width < 0 || area.height < 0 ) {
		im_error( "im__tbcalcon", "%s", _( "overlap too small" ) );
		return( -1 );
	}

	/* Loop over areas, finding points.
	 */
	for( i = 0; area.left < ref->Xsize; area.left += awidth, i++ ) 
		if( im__find_best_contrast( ref, 
			area.left, area.top, area.width, area.height,
			points->x_reference + i*len,
			points->y_reference + i*len,
			points->contrast + i*len, 
			len,
			points->halfcorsize ) )
				return( -1 );

	return( 0 );
}
示例#12
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
}
示例#13
0
/* width, height, optional scale, optional offset.
 */
static int
read_header( FILE *fp, int *xs, int *ys, double *scale, double *offset )
{
	char buf[MAX_LINE];
	char *p, *q;
	double v[4];
	int i;

	/* Read the first line: should contain size and optional 
	 * scale + offset. 
	 */
	if( get_line( fp, buf ) ) 
		return( -1 );

	/* Read as space separated doubles. \n is in the break list because
	 * our line will (usually) have a trailing \n which we want to count
	 * as whitespace.
	 */
	p = buf; 
	for( i = 0, p = buf; 
		i < 4 && (q = im_break_token( p, " \";,\t\n" )); 
		i++, p = q ) 
		v[i] = g_ascii_strtod( p, NULL );

	if( (i != 2 && i != 4) ||
		ceil( v[0] ) != v[0] ||
		ceil( v[1] ) != v[1] ||
		v[0] <= 0 ||
		v[1] <= 0 ) {
		im_error( "read_header", 
			"%s", _( "error reading matrix header" ) );
		return( -1 );
	}
	if( i == 4 && v[2] == 0 ) {
		im_error( "read_header", 
			"%s", _( "scale should be non-zero" ) );
		return( -1 );
	}

	*xs = v[0];
	*ys = v[1];
	if( i == 2 ) {
		*scale = 1.0;
		*offset = 0.0;
	}
	else {
		*scale = v[2];
		*offset = v[3];
	}

	return( 0 );
}
示例#14
0
/* Like im_prepare(): fill reg with data, ready to be read from by our caller.
 * Unlike im_prepare(), rather than allocating memory local to reg for the
 * result, we guarantee that we will fill the pixels in dest at offset x, y.
 * In other words, we generate an extra copy operation if necessary. 
 */
int
im_prepare_to( REGION *reg, REGION *dest, Rect *r, int x, int y )
{
	IMAGE *im = reg->im;
	Rect image;
	Rect wanted;
	Rect clipped;
	Rect clipped2;
	Rect final;

	if( im__test_kill( im ) )
		return( -1 );

	/* Sanity check.
	 */
	if( !dest->data || dest->im->BandFmt != reg->im->BandFmt ||
		dest->im->Bands != reg->im->Bands ) {
		im_error( "im_prepare_to", _( "inappropriate region type" ) );
		return( -1 );
	}

	/* clip r first against the size of reg->im, then again against the 
	 * memory we have available to write to on dest. Just like 
	 * im_region_region()
	 */
	image.top = 0;
	image.left = 0;
	image.width = reg->im->Xsize;
	image.height = reg->im->Ysize;
	im_rect_intersectrect( r, &image, &clipped );

	assert( clipped.left == r->left );
	assert( clipped.top == r->top );

	wanted.left = x + (clipped.left - r->left);
	wanted.top = y + (clipped.top - r->top);
	wanted.width = clipped.width;
	wanted.height = clipped.height;

	/* Test that dest->valid is large enough.
	 */
	if( !im_rect_includesrect( &dest->valid, &wanted ) ) {
		im_error( "im_prepare_to", _( "dest too small" ) );
		return( -1 );
	}

	im_rect_intersectrect( &wanted, &dest->valid, &clipped2 );

	/* Translate back to reg's coordinate space and set as valid.
	 */
	final.left = r->left + (clipped2.left - wanted.left);
示例#15
0
文件: magick.c 项目: waebbl/ledcat
/**
 * read frame using ImageMagick
 */
NftResult im_read_frame(struct Ledcat *c, size_t width, size_t height, char *buf)
{
#if HAVE_IMAGEMAGICK == 1

    /* is there an image from a previous read? */
    if(MagickHasNextImage(c->mw))
    {
        MagickNextImage(c->mw);
    }
    else
    {
        /* end-of-stream? */
        if(feof(c->file))
            return FALSE;

        /* read file */
        if(!MagickReadImageFile(c->mw, c->file))
        {
            im_error(c->mw);
            return FALSE;
        }

        /* reset iterator in case we read more than one file */
        //MagickResetIterator(c->mw);
    }


    /* turn possible alpha-channel black */
    /*PixelWand *pw;
    if(!(pw = NewPixelWand()))
            return FALSE;

    PixelSetColor(pw, "black");
    MagickSetImageBackgroundColor(c->mw, pw);
    DestroyPixelWand(pw);*/

    /* get raw-buffer from imagemagick */
    if(!(MagickExportImagePixels(c->mw, 0, 0, width, height, c->map, c->storage, buf)))
    {
        im_error(c->mw);
        return FALSE;
    }

    /* free resources */
    if(!MagickHasNextImage(c->mw))
        ClearMagickWand(c->mw);

#endif

    return TRUE;
}
示例#16
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 );
}
示例#17
0
int 
im__chkpair( IMAGE *ref, IMAGE *sec, TIE_POINTS *points )
{
	int i;
	int x, y;
	double correlation;

	const int hcor = points->halfcorsize;
	const int harea = points->halfareasize;

	/* Check images.
	 */
	if( im_incheck( ref ) || im_incheck( sec ) ) 
		return( -1 );
	if( ref->Bands != sec->Bands || ref->BandFmt != sec->BandFmt || 
		ref->Coding != sec->Coding ) {
		im_error( "im_chkpair", "%s", _( "inputs incompatible" ) ); 
		return( -1 ); 
	}
	if( ref->Bands != 1 || ref->BandFmt != IM_BANDFMT_UCHAR ) { 
		im_error( "im_chkpair", "%s", _( "help!" ) );
		return( -1 );
	}

	for( i = 0; i < points->nopoints; i++ ) {
		/* Find correlation point.
		 */
		if( im_correl( ref, sec, 
			points->x_reference[i], points->y_reference[i],
			points->x_reference[i], points->y_reference[i],
			hcor, harea, 
			&correlation, &x, &y ) ) 
			return( -1 );

		/* And note in x_secondary.
		 */
		points->x_secondary[i] = x;
		points->y_secondary[i] = y;
		points->correlation[i] = correlation;

		/* Note each dx, dy too.
		 */
		points->dx[i] = 
			points->x_secondary[i] - points->x_reference[i];
		points->dy[i] = 
			points->y_secondary[i] - points->y_reference[i];
	}

	return( 0 );
}
示例#18
0
文件: im_lhisteq.c 项目: alon/libvips
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 );
}
示例#19
0
/* Build per-call state.
 */
static Overlapping *
build_tbstate( IMAGE *ref, IMAGE *sec, IMAGE *out, int dx, int dy, int mwidth )
{
   	Overlapping *ovlap;

	if( !(ovlap = im__build_mergestate( "im_tbmerge", 
		ref, sec, out, dx, dy, mwidth )) )
		return( NULL );

	/* Select blender.
	 */
	switch( ovlap->ref->Coding ) {
	case IM_CODING_LABQ:
		ovlap->blend = tb_blend_labpack;
		break;

	case IM_CODING_NONE:
		ovlap->blend = tb_blend;
		break;

	default:
		im_error( "im_tbmerge", "%s", _( "unknown coding type" ) );
		return( NULL );
	}

	/* Find the parts of output which come just from ref and just from sec.
	 */
	ovlap->rpart = ovlap->rarea;
	ovlap->spart = ovlap->sarea;
	ovlap->rpart.height -= ovlap->overlap.height;
	ovlap->spart.top += ovlap->overlap.height;
	ovlap->spart.height -= ovlap->overlap.height;

	/* Is there too much overlap? ie. bottom edge of ref image is greater
	 * than bottom edge of sec image, or top edge of ref > top edge of
	 * sec.
	 */
	if( IM_RECT_BOTTOM( &ovlap->rarea ) > IM_RECT_BOTTOM( &ovlap->sarea ) ||
		ovlap->rarea.top > ovlap->sarea.top ) {
		im_error( "im_tbmerge", "%s", _( "too much overlap" ) );
		return( NULL );
	}

	/* Max number of pixels we may have to blend together.
	 */
	ovlap->blsize = ovlap->overlap.width;

	return( ovlap );
}
示例#20
0
static int
mat2vips_get_header( matvar_t *var, IMAGE *im )
{
	int width, height, bands, format, type;
	int i;

	width = 1;
	height = 1;
	bands = 1;
	switch( var->rank ) {
	case 3:
		bands = var->dims[2];

	case 2:
		height = var->dims[1];

	case 1:
		width = var->dims[0];
		break;

	default:
		im_error( "im_mat2vips", 
			_( "unsupported rank %d\n" ), var->rank );
		return( -1 );
	}

	if( bands > 1 )
		type = IM_TYPE_MULTIBAND;
	else
		type = IM_TYPE_B_W;

	for( i = 0; i < IM_NUMBER( mat2vips_formats ); i++ )
		if( mat2vips_formats[i][0] == var->class_type )
			break;
	if( i == IM_NUMBER( mat2vips_formats ) ) {
		im_error( "im_mat2vips", _( "unsupported class type %d\n" ),
			var->class_type );
		return( -1 );
	}
	format = mat2vips_formats[i][1];

	im_initdesc( im,
		 width, height, bands,
		 im_bits_of_fmt( format ), format,
		 IM_CODING_NONE, type, 1.0, 1.0, 0, 0 );

	return( 0 );
}
示例#21
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 );
}
示例#22
0
/**
 * im_matcat:
 * @top: input matrix
 * @bottom: input matrix
 * @filename: filename for output
 *
 * Matrix catenations. Returns a new matrix which is the two source matrices
 * joined together top-bottom. They must be the same width.
 *
 * See also: im_mattrn(), im_matmul(), im_matinv().
 *
 * Returns: the joined mask on success, or NULL on error.
 */
DOUBLEMASK *
im_matcat( DOUBLEMASK *top, DOUBLEMASK *bottom, const char *filename )
{
	int newxsize, newysize;
	DOUBLEMASK *mat;
	double *out;

	/* matrices must be same width
	 */
	if( top->xsize != bottom->xsize ) {
		im_error( "im_matcat", "%s", 
			_( "matrices must be same width" ) );
		return( NULL );
	}

	newxsize = top->xsize;
	newysize = top->ysize + bottom->ysize;

	/* Allocate output matrix.
	 */
	if( !(mat = im_create_dmask( filename, newxsize, newysize )) ) 
		return( NULL );

	/* copy first matrix then add second on the end
	 */
	memcpy( mat->coeff, top->coeff, 
		top->xsize * top->ysize * sizeof( double ) );
	out = mat->coeff + top->xsize * top->ysize;
	memcpy( out, bottom->coeff, 
		bottom->xsize * bottom->ysize * sizeof( double ) );

	return( mat );
}
示例#23
0
static int
lgrab_ioctl( LGrab *lg, int request, void *argp )
{
	if( !lg->fd ) {
		im_error( "lgrab_ioctl", "%s", _( "no file descriptor" ) );
		return( -1 );
	}

	if( ioctl( lg->fd, request, argp ) < 0 ) {
		im_error( "lgrab_ioctl", _( "ioctl(0x%x) failed: %s" ), 
			(unsigned int) request, strerror( errno ) );
		return( -1 );
	}

	return( 0 );
}
示例#24
0
/* Propogate a transform down a tree. If dirty is set, we've been here before,
 * so there is a doubling up of this node. If this is a leaf, then we have the
 * same leaf twice (which, in fact, we can cope with); if this is a node, we 
 * have circularity.
 */
static int
propogate_transform( JoinNode *node, Transformation *trn )
{
	if( !node )
		return( 0 );

	if( node->dirty && node->arg1 && node->arg2 ) {
		im_error( "im_global_balance", _( "circularity detected" ) );
		return( -1 );
	}
	node->dirty = 1;

	/* Transform our children.
	 */
	if( propogate_transform( node->arg1, trn ) ||
		propogate_transform( node->arg2, trn ) )
		return( -1 );

	/* Transform us, and recalculate our position and size.
	 */
	im__transform_add( &node->cumtrn, trn, &node->cumtrn );
	calc_geometry( node );

	return( 0 );
}
示例#25
0
文件: fmask4th.c 项目: alon/libvips
static float *
fractal_flt( IMAGE *out, int xs, int ys, double frdim )
{
	int x, y;
	float *coeff, *cpcoeff;
	double *xd, *yd, distance2, cnst;

	if( xs != ys || frdim <= 2.0 || frdim >= 3.0 ) {
		im_error( "fractal_flt", "%s", _( "bad args" ) );
		return( NULL );
	}

        if( alloc( out, xs, ys, &xd, &yd, &coeff ) )
                return( NULL );

	cpcoeff = coeff;
	cnst = (frdim - 4.0)/2.0;
	for( y = 0; y < ys/2 + 1; y++ )
                for( x = 0; x < xs/2 + 1; x++ ) {
			distance2 = xd[x] + yd[y];
			if( distance2 == 0.0 )
				*cpcoeff++ = 1.0;
			else
				*cpcoeff++ = pow( distance2, cnst );
		}

	return( coeff );
}
示例#26
0
/* We need to make pixels using reg's generate function, and write the result
 * to dest.
 */
static int
im_prepare_to_generate( REGION *reg, REGION *dest, Rect *r, int x, int y )
{
	IMAGE *im = reg->im;
	char *p;

	if( !im->generate ) {
		im_error( "im_prepare_to", _( "incomplete header" ) );
		return( -1 );
	}

	if( im_region_region( reg, dest, r, x, y ) )
		return( -1 );

	/* Remember where reg is pointing now.
	 */
	p = IM_REGION_ADDR( reg, reg->valid.left, reg->valid.top );

	/* Run sequence into reg.
	 */
	if( fill_region( reg ) )
		return( -1 );

	/* The generate function may not have actually made any pixels ... it
	 * might just have redirected reg to point somewhere else. If it has,
	 * we need an extra copy operation.
	 */
	if( IM_REGION_ADDR( reg, reg->valid.left, reg->valid.top ) != p )
		im__copy_region( reg, dest, r, x, y );

	return( 0 );
}
示例#27
0
文件: fits.c 项目: nrobidoux/libvips
static VipsFits *
vips_fits_new_read( const char *filename, VipsImage *out, int band_select )
{
	VipsFits *fits;
	int status;

	if( !(fits = VIPS_NEW( out, VipsFits )) )
		return( NULL );

	fits->filename = im_strdup( NULL, filename );
	fits->image = out;
	fits->fptr = NULL;
	fits->lock = NULL;
	fits->band_select = band_select;
	fits->buffer = NULL;
	g_signal_connect( out, "close", 
		G_CALLBACK( vips_fits_close_cb ), fits );

	status = 0;
	if( fits_open_file( &fits->fptr, filename, READONLY, &status ) ) {
		im_error( "fits", _( "unable to open \"%s\"" ), filename );
		vips_fits_error( status );
		return( NULL );
	}

	fits->lock = g_mutex_new();

	return( fits );
}
示例#28
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 );
}
示例#29
0
int
im_png2vips( const char *name, IMAGE *out )
{
	im_error( "im_png2vips", "%s",
		_( "PNG support disabled" ) );
	return( -1 );
}
示例#30
0
static int
lgrab_set_capture_size( LGrab *lg, int width, int height )
{
	lg->c_width = width;
	lg->c_height = height;

	lg->window.clipcount = 0;
	lg->window.flags = 0;
	lg->window.x = 0;
	lg->window.y = 0;
	lg->window.width = width;
	lg->window.height = height;
	if( lgrab_ioctl( lg, VIDIOCSWIN, &lg->window ) )
		return( -1 );

	/* Make sure the correct amount of memory is mapped.
	 */
	if( lgrab_ioctl( lg, VIDIOCGMBUF, &lg->mbuf ) )
		return( -1 );

	if( lg->capture_buffer ) {
		munmap( lg->capture_buffer, lg->capture_size );
		lg->capture_buffer = NULL;
	}

	lg->capture_size = lg->mbuf.size;
	if( !(lg->capture_buffer = mmap( 0, lg->capture_size, 
		PROT_READ | PROT_WRITE, MAP_SHARED, lg->fd, 0 )) ) {
		im_error( "lgrab_set_capture_size", 
			"%s", _( "unable to map memory" ) );
		return( -1 );
	}

	return( 0 );
}