Exemple #1
0
void _make_dragg(QSP_ARG_DECL  const char *name,Data_Obj *bm,Data_Obj *dp)
{
	Draggable *dgp;

	if( !dp_same_size(bm,dp,"make_dragg") ){
		warn("image/bitmap size mismatch");
		return;
	}
	if( OBJ_PREC(bm) != PREC_BIT ){
		sprintf(ERROR_STRING,"Object %s has precision %s, should be %s",
			OBJ_NAME(bm),PREC_NAME(OBJ_PREC_PTR(bm)),
			PREC_NAME(PREC_FOR_CODE(PREC_BIT)));
		warn(ERROR_STRING);
		return;
	}
	if( OBJ_PREC(dp) != PREC_BY && OBJ_PREC(dp) != PREC_UBY ){
		sprintf(ERROR_STRING,"Image %s (for draggable object) has %s precision, should be %s or %s",
			OBJ_NAME(dp),PREC_NAME(OBJ_PREC_PTR(dp)),
			PREC_NAME(PREC_FOR_CODE(PREC_BY)),
			PREC_NAME(PREC_FOR_CODE(PREC_UBY)) );
		warn(ERROR_STRING);
		return;
	}

	dgp = new_dragg(name);
	if( dgp == NULL ) return;

	dgp->dg_width = (int) OBJ_COLS(dp);
	dgp->dg_height = (int) OBJ_ROWS(dp);
	dgp->dg_bitmap = bm;
	dgp->dg_image = dp;
	dgp->dg_np = mk_node(dgp);
}
Exemple #2
0
void vinterp(QSP_ARG_DECL  Data_Obj *target,Data_Obj *source,Data_Obj *control)
{
	float *to, *fr, *c;
	dimension_t i;
	int32_t n_to_interpolate=0;
	float *interp_dest;
	int32_t start_index=(-1);

	assert( target != NULL );
	assert( source != NULL );
	assert( control != NULL );

	INSIST_RAM_OBJ(target,vinterp)
	INSIST_RAM_OBJ(source,vinterp)
	INSIST_RAM_OBJ(control,vinterp)

	if( not_prec(target,PREC_SP) )  return;
	if( not_prec(source,PREC_SP) )  return;
	if( not_prec(control,PREC_SP) ) return;


	if( !dp_same_size(target,source,"vinterp") ){
		warn("vinterp:  target/source length mismatch");
		return;
	}
	if( !dp_same_size(target,control,"vinterp") ){
		warn("vinterp:  target/control length mismatch");
		return;
	}
	if( OBJ_COMPS(source) != 1 || OBJ_COMPS(target) != 1 ){
		warn("vinterp:  component dimensions must be 1");
		return;
	}

	/* could check that they are all vectors... */

	to=(float *)OBJ_DATA_PTR(target);
	fr=(float *)OBJ_DATA_PTR(source);
	c=(float *)OBJ_DATA_PTR(control);

	interp_dest=to;

	for(i=0;i<OBJ_COLS(target);i++){
		if( *c == 1.0 ){			/* copy data */
			if( n_to_interpolate > 0 ){	/* end of gap? */
				int j; float start_val, end_val;

				end_val = get_end_val(source,control,i);

				/* if we haven't seen any good values yet,
				 * just fill in with the first good value.
				 */

				if( start_index < 0 ) start_val=end_val;

				/*
				 * Otherwise, use a starting value which
				 * is an average of the last N good values...
				 */

				else start_val = get_start_val(source,control,start_index);

#ifdef DEBUG
if( debug ){
sprintf(ERROR_STRING,
"vinterp:  %d values at index %d (start_i = %d), start = %f end = %f",
n_to_interpolate,i,start_index,start_val,end_val);
advise(ERROR_STRING);
}
#endif /* DEBUG */
				for(j=0;j<n_to_interpolate;j++){
					float factor;
					factor=((float)j+1)/((float)n_to_interpolate+1);
					*interp_dest = factor*end_val
						+ (1-factor)*start_val;
					interp_dest += OBJ_PXL_INC(target);
				}
			}
			*to = *fr;
			start_index = i;		/* always the last good one seen */
			n_to_interpolate=0;
		} else {				/* control is 0 */
			if( n_to_interpolate == 0 )	/* remember start */
				interp_dest = to;
			n_to_interpolate++;
		}
		to += OBJ_PXL_INC(target);
		c += OBJ_PXL_INC(control);
		fr += OBJ_PXL_INC(source);
	}
	if( n_to_interpolate > 0 ){		/* fill in at end? */
		float fill_val;
		int j;
		if( start_index < 0 ){
			warn("vinterp:  no valid data!?");
			fill_val=0.0;
		} else fill_val = get_start_val(source,control,start_index);
		for(j=0;j<n_to_interpolate;j++){
			*interp_dest = fill_val;
			interp_dest += OBJ_PXL_INC(target);
		}
	}
}
Exemple #3
0
static COMMAND_FUNC( do_cyplot )
{
    Data_Obj *dp;
    Data_Obj *cdp;
    u_long i, np;		/* number of points */
    long inc;
    long cinc;
    std_type x,y,dx,*yp;
    char *cp;

    dp=PICK_OBJ("data vector");
    cdp=PICK_OBJ("color vector");

    if( dp==NO_OBJ ) return;
    if( cdp==NO_OBJ ) return;

    INSIST_RAM_OBJ(dp,"cyplot")
    INSIST_RAM_OBJ(cdp,"cyplot")

    if( OBJ_PREC(dp) != PREC_SP ) {
        WARN("do_cyplot:  data vector should be float");
        return;
    }
    if( OBJ_PREC(cdp) != PREC_BY ) {
        WARN("color vector should be byte");
        return;
    }
    if( !dp_same_size(QSP_ARG  dp,cdp,"do_cyplot") ) {
        sprintf(ERROR_STRING,"data vector %s and color vector %s must have identical sizes",
                OBJ_NAME(dp),OBJ_NAME(cdp));
        WARN(ERROR_STRING);
        return;
    }

    if( OBJ_COLS(dp)==1 ) {	/* maybe this is a column vector? */
        np=OBJ_ROWS(dp);
        inc = OBJ_ROW_INC(dp);
        cinc = OBJ_ROW_INC(cdp);
    } else {
        np=OBJ_COLS(dp);
        inc = OBJ_PXL_INC(dp);
        cinc = OBJ_PXL_INC(cdp);
    }


    x=0;
    dx=1;
    i=np-1;
    yp = (std_type *) OBJ_DATA_PTR(dp);
    cp = (char *) OBJ_DATA_PTR(cdp);

    xp_fmove(x,*yp);
    xp_select(*cp);
    xp_fcont(x,*yp);
    while(i--) {
        yp += inc;
        cp += cinc;
        x += dx;
        y = *yp;
        xp_select(*cp);
        xp_fcont(x,y);
    }
}