Example #1
0
int contourextract_malloc(void **d, int width, int height)
{
    contourextract_data *my;
    *d = (void*) vj_calloc(sizeof(contourextract_data));
    my = (contourextract_data*) *d;

    dw_ = nearest_div( width / 8  );
    dh_ = nearest_div( height / 8 );

    my->current = (uint8_t*) vj_calloc( ru8( sizeof(uint8_t) * dw_ * dh_ * 3 ) );
    my->bitmap = (uint8_t*) vj_calloc( ru8(sizeof(uint8_t) * width * height ));

    if(static_bg == NULL)
        static_bg = (uint8_t*) vj_calloc( ru8( width + width * height * sizeof(uint8_t)) );
    if(dt_map == NULL )
        dt_map = (uint32_t*) vj_calloc( ru8(width * height * sizeof(uint32_t) + width ) );

    veejay_memset( &template_, 0, sizeof(sws_template) );
    veejay_memset( proj_, 0, sizeof(proj_) );

    template_.flags = 1;

    vj_get_yuvgrey_template( &to_shrink_, width, height );
    vj_get_yuvgrey_template( &shrinked_ , dw_, dh_ );

    shrink_ = yuv_init_swscaler(
                  &(to_shrink_),
                  &(shrinked_),
                  &template_ ,
                  yuv_sws_get_cpu_flags() );

    points = (point_t**) vj_calloc( sizeof(point_t*) * 12000 );
    int i;
    for( i = 0; i < 12000; i ++ )
    {
        points[i] = (point_t*) vj_calloc( sizeof(point_t) );
    }

    veejay_memset( x_, 0, sizeof(x_) );
    veejay_memset( y_, 0, sizeof(y_) );

    return 1;
}
/**
 * Handle a packet to create a new registration with a name, password
 * and server admin flag.
 *
 * @param data the packet
 * @param len the length of the packet
 * @param pl the player who issued the request
 */
void *c_req_create_registration(char *data, unsigned int len, struct player *pl)
{
	char *name, *pass;
	char server_admin;
	struct registration *reg;
	struct server *s;
	unsigned char digest[SHA256_DIGEST_LENGTH];
	char *digest_readable, *ptr;

	s = pl->in_chan->in_server;

	send_acknowledge(pl);
	if (player_has_privilege(pl, SP_PL_REGISTER_PLAYER, NULL)) {
		ptr = data + 24;
		name = rstaticstring(29, &ptr);
		pass = rstaticstring(29, &ptr);
		server_admin = ru8(&ptr);
		if (name == NULL || pass == NULL) {
			logger(LOG_ERR, "c_req_create_registration, strndup failed : %s.", strerror(errno));
			if (name != NULL)
				free(name);
			if (pass != NULL)
				free(pass);
			return NULL;
		}
		reg = new_registration();
		strcpy(reg->name, name);
		/* hash the password */
		SHA256((unsigned char *)pass, strlen(pass), digest);
		digest_readable = ustrtohex(digest, SHA256_DIGEST_LENGTH);
		strcpy(reg->password, digest_readable);
		free(digest_readable);

		reg->global_flags = server_admin;
		add_registration(s, reg);
		/* database callback to insert a new registration */
		db_add_registration(s->conf, s, reg);

		free(name);
		free(pass);
	}

	return NULL;
}
Example #3
0
void srun() {                              /*  simulation RUN routine */

    int  lj, dcounter ; double  tmm ;   /* dcounter for MM displays <***/

    runf=1 ;              /* to keep display label in command mode */

    if (relval[mmm+15]<1) relval[mmm+15]=1 ;  /* MM must be >=1    */
       
    if (relval[mmm+1]<=1) relval[mmm+1]=251 ; /* AN=NN output pts. */
    if (relval[mmm+4]<=0) {                                /* TMAX */
	if (size) derror(87) ;
	else relval[mmm+4]=relval[mmm+1]-1 ;             /* irule 0 */
    }
    zCOMINT=relval[mmm+4]/(relval[mmm+1]-1) ; /* COMINT =TMAX/(NN-1)   <*****/

    if (INITE1>0) ICOM=1 ;   /* initially, ICOM>0 only if INITE1>0 */
    else ICOM= -1 ;             /* for "continued-run" store, etc. */

    if (size) {                              /* "true" integration */
	if (relval[mmm+5]==1.1E-275) relval[mmm+5]=0 ; /**!!**//* t */
	if (relval[mmm+3]<=0) relval[mmm+3]=zCOMINT/2 ;    /*default DT <****/
	if (relval[mmm+3]>zCOMINT) derror(110) ;    
/*   <**** DT is too large *******/
	/***         since          
		     DT <=TMAX/(NN-1)=COMINT ,   
		     NN <= (TMAX/DT) + 1            ***/         
	relval[mmm-3]=relval[mmm+3] ;          /* save DT for reset */
	for (lj=1 ; lj<= nn1 ; lj++)
	    storesv[lj]=dpsv[lj]=relval[lj] ;       
/* save state vars. for reset, make duplicates for integration */
	hdt=relval[mmm+3]/2 ;                         /* DT/2 */

	if ((size>3)&&(size!=5)) { /* prepare for variable-step integration */
	    if (relval[mmm+9]<=0) relval[mmm+9]=0.001 ;     /* ERMAX */
	    if (size<9) {
                if (relval[mmm+7]<=0 || relval[mmm+7]>zCOMINT)  
		    relval[mmm+7]=zCOMINT ;        /* DTMAX      <****/
                          
                if (relval[mmm+8]<=0 || relval[mmm+8]>relval[mmm+7])
		    relval[mmm+8]=relval[mmm+3]/16 ;   /* DTMIN */
                if (relval[mmm+10]<=0 || relval[mmm+10]>relval[mmm+9])
		    relval[mmm+10]=0.01*relval[mmm+9] ;   /* ERMIN */
                if (relval[mmm+2]>nn1) derror(93) ; /*CHECKN too large*/
	    }                          /* 3 < irule < 9 and not 5 */
	    else if (jcstart==0 && (size==10 || size==14))
		derror(229) ;     /* missing JACOBIAN */
	}                                 /* irule > 3 and not 5 */
    }                                             /* irule != 0 */
          
    else if (relval[mmm+5]==1.1E-275) relval[mmm+5]=1 ; 
    /***!!!***/ /* irule 0 */
                                               
    t0=relval[mmm-2]=relval[mmm+5] ;        /* save t0=t for reset */
    tmm=t0+relval[mmm+4] ;                        /* tmm = t0+TMAX */
    ztnext=t0+zCOMINT ;                /* tnext = t0 + COMINT <*****/

    dflag=dispp && dbegin ; sflag=disk && sbegin ;

/* ------------------------------------------------------------------ */

    if (dflag) {                          /* start display, if any */

	lj=dbegin ;               /* start of display label, if any */

	if (dmode<0) {                   /* "type"; do header label */
	    if (!typeflg) {                  /* ## suppresses header */
                WRITELN ; 
                fprintf(outptr,"\n\nt,   ") ;
                if (ferror(outptr)) derror(106) ;
                while (warea[lj]!=lf && warea[lj]!='|') 
		    putc(warea[lj++],outptr) ;      
	    }
	    fprintf(outptr,"\n\n") ;     /* could be printer or file */
	}                                           /* if "type" */

	else if (dispp>0) drstart() ;  /* dmode>=0, start CRT graph */
    }                               /* unless we have display 2 */             
/* ------------------------------------------------------------------ */

    if (rbegin) {
	if (fd[maxchan-1]==NULL) { chanlno=maxchan-1 ; derror(64) ; }
    }                                               /* not open */
    if (sflag) {                           /* connect .TIM file(s) */
	strcpy(fname,pname) ;
	lj=0 ;
	if (fname[lj]=='.') lj++ ; if (fname[lj]=='.') lj++ ;
	do lj++ ; while (fname[lj]!='.') ;         /* get extension */
	fname[lj+1]='T' ; fname[lj+2]='I' ; fname[lj+3]='M' ;
	fname[lj+4]=0 ;

	if (fd[maxchan]!=NULL)
	{ chanlno=maxchan ; derror(63) ; }               /* busy */

	if ((fd[maxchan]=fopen(fname,"w"))==NULL) derror(11) ; 
    }
/* ------------------------------------------------------------------ */
    /* communication loop */

    /*  NOTE: on "continued" runs, displays and stash files
	DUPLICATE the last point of a run as the first point
	of the "continued" run. "Continued" runs reproduced
	from .RCV files necessarily have THE SAME t0, TMAX,
	and NN as the original runs, so that the duplicated
	points are reproduced correctly.

	Time histories reproduced from STORE or DELAY arrays,
	however, do NOT contain duplicated points and can be
	used anywhere in a subsequent run.                  */

/*  ------------------------------------------------------------------ */
    IDERIV=1 ;           /* IDERIV>0, state variables valid */
    dcounter=0 ;                                /* initialize dcounter  <*****/

    /* initially, ICOM>0 only if INITE1>0;  otherwise, for continued-run
       STORE etc., ICOM<0, so the duplicate endpoints are not stored.
       Now make the initial derivative call; this scheme ensures that
       defined variables can be computed for output */

/*  ------------------------------------ */

    if (size>8) {        /* use GEAR module, initialize if INITE1>0 */

	if (nn1>EQUMAX) derror(100) ;    /* too many state variables */
	TOUT=ztnext ;                  /* tnext for GEARER.C */
	if (INITE1>0) aINDEX=1 ;   /* ** was in gearstart ** */

	do {   /* because of duplicate derve1, ICOM, INITE1 are OFF! */

	    if (rbegin) { recovr() ; if (errnum) goto L5 ; }
	    drun00(2) ; if (errnum) goto L5 ;
             
	    if (dcounter == 0) {  
/*  display only once in MM communication points <***/
		if (dflag) { if (dmode>=0) disply() ; else typex() ; }
		if (sflag) dstor() ;
	    }                                     
	    if (++dcounter==relval[mmm+15]) dcounter=0 ;    /*   <*****/
	    
	    ICOM=INITE1= -1 ;     /* ICOM<0, INITE1<0 for store, etc. */

	    DRIVE(); if (errnum) goto L5 ;    
/* driver routine in GEAR also increments TOUT by COMINT */
	    ICOM=1 ;                /* ICOM>0, mark next output point */
	    if (spare1) {                       /* look at ctl-c flag */
                spare1=0 ;
                if (lj=getchar()!=lf) {errnum=306 ; goto L55 ; }
	    }

	} while (relval[mmm+5]-tmm<0) ;    /* t - (t0 + TMAX) < 0 */
    }                                           /* if Gear module */

    else do {             /* NOT Gear module; ICOM, INITE1 are OFF! */
	if (rbegin) { recovr() ; if (errnum) goto L5 ; }
	drun00(2) ; if (errnum) goto L5 ; 
/* initial values of defined variables */
	if (dcounter == 0) {  
/*  display only once in MM communication points <***/
	    if (dflag) { if (dmode>=0) disply() ; else typex() ; }
	    if (sflag) dstor() ;
	}                                     
	if (++dcounter==relval[mmm+15]) dcounter=0 ;          /*   <*****/   
         
	ICOM=INITE1= -1 ;    /* ICOM<0, INITE1<0
				for store, etc. */
	switch(size) {
	    case 0 : relval[mmm+5]=ztnext ; break ;  
/* dummy integrator: t=tnext */
	    case 1 : ru1() ; break ;       /* integration loops */
	    case 2 : ru2() ; break ;
	    case 3 : ru3() ; break ;
	    case 4 : ru4() ; break ;
	    case 5 : ru5() ; break ;
	    case 6 : ru6() ; break ;
	    case 7 : ru7() ; break ;
	    case 8 : ru8() ; break ;

	} if (errnum) goto L5 ;

	ztnext+=zCOMINT ;          /* tnext=tnext+COMINT <*****/
	ICOM=1 ;                   /* ICOM>0, mark next output point */
  
	if (spare1) {                          /* look at ctl-c flag */
	    spare1=0 ;
	    if (lj=getchar()!=lf) {errnum=306 ; goto L55 ; }
	}

    } while (relval[mmm+5]-tmm<0) ;       /* t - (t0 + TMAX) < 0 */

/* ------------------------------------------------------------------- */
    /* last point */
    if (rbegin) { recovr() ; if (errnum) goto L5 ; }
    drun00(2) ; if (!errnum) goto L6 ;

    /* clean up; some of those errors are not errors! */

    L5 :   if (errnum==303) { errnum=0 ; goto L6 ; } /* derve1 terminated */
    if (errnum==305) {
	printf("\n Warning: END OF FILE or error on recover -    ") ;
	errnum=0 ;                        /* EOF or error on recover */
    }
    if (errnum>=304) errnum=0 ;                              /* eof */
    goto L55 ;         /* close stash and/or recovr file(s), if any */

    L6 :   if (dflag) { if (dmode>=0) disply() ; else typex() ; } /* last */
    if (sflag) dstor() ;                                   /* point */

    L55 :  if (sflag) {                        /* close stash file, if any */
	if (fclose(fd[maxchan])==EOF)  derror(95) ;
	fd[maxchan]=NULL ;
    }
    if (rbegin) {                     /* close recover file, if any */
	if (fclose(fd[maxchan-1])==EOF) derror(95) ;
	fd[maxchan-1]=NULL ;
    }
    if (!dflag || dmode<0) WRITELN ; else dflush() ;
    if (errnum) derror(errnum) ;
}                                                       /* srun */