Esempio n. 1
0
int gif2bmp(tGIF2BMP *gif2bmp, FILE *inputFile, FILE *outputFile)
{
	u_int16_t biBitCount;
	tGIF *img;

	// load image into memory
	if ((img = gif_load(inputFile)) == NULL)
		return -1;

	// decompress the image's data
	if (gif_lzw_decompression(img) != 0)
		return -1;

	struct logical_screen_descriptor *lsd = &(img->screen_desc);
	struct image_descriptor *id = &(img->image_desc);
	int color_tab_size = (lsd->glob_colors) ? lsd->glob_colors_len : id->local_colors_len;
	u_int32_t bfOffBits = FILEHEADER_SIZE+INFOHEADER_SIZE+4*(POW2(color_tab_size+1));

	bmp_add_fileHeader(outputFile, bfOffBits);
	biBitCount = bmp_add_infoHeader(outputFile, img, color_tab_size);
	bmp_add_rgbQuad(outputFile, img->colors_tab, POW2(color_tab_size+1));
	bmp_add_bits(outputFile, img, biBitCount);

	gif2bmp->bmpSize = bmp_add_bfSize(outputFile);
	gif2bmp->gifSize = img->size;

	gif_unload(img);

	return 0;
}
void RangeLevelEditor::mousePressEvent(QMouseEvent *e) {

	if (!scale_1 || !scale_2 || !range_1 || !range_2)
		return;

	if (e->button()!=Qt::LeftButton)
		return;

	float press_x=(float)e->x()/(float)width();
	float press_y=(float)(height()-e->y())/(float)height();
	
	float dist_1=sqrt(POW2(press_x-range_1->get())+POW2(press_y-scale_1->get()));
	float dist_2=sqrt(POW2(press_x-range_2->get())+POW2(press_y-scale_2->get()));
	
	int closer=(dist_1<dist_2)?1:2; //which is closer?
	float closer_dist=(closer==1)?dist_1:dist_2; //distance of closer
	
	
	click.drag_point=closer;
	click.scale=(closer==1)?scale_1->get():scale_2->get();
	click.range=(closer==1)?range_1->get():range_2->get();
	click.point=e->pos();
	
	

}
Esempio n. 3
0
double
cylinder_centers_distance (CYLINDER *c1, CYLINDER *c2)
{
	return sqrt (POW2 (c1->x - c2->x) +
		     POW2 (c1->y - c2->y) +
		     POW2 (c1->z - c2->z));
}
Esempio n. 4
0
static inline gfloat colordiff (gfloat *pixA,
                                gfloat *pixB)
{
    return POW2(pixA[0]-pixB[0])+
           POW2(pixA[1]-pixB[1])+
           POW2(pixA[2]-pixB[2]);
}
Esempio n. 5
0
extern double
cosmoPk_forceSigma8(cosmoPk_t pk,
                    double    sigma8,
                    double    kmin,
                    double    kmax,
                    double    *error)
{
	double sigma8Actual;
	double sigma8First;
	int    numIter    = 0;
	int    numIterMax = LOCAL_MAX_FORCESIGMA8_ITERATIONS;

	assert(pk != NULL);
	assert(isgreater(sigma8, 0.0));
	assert(isgreater(kmin, 0.0));
	assert(isgreater(kmax, kmin));
	assert(error != NULL);

	sigma8Actual = cosmoPk_calcSigma8(pk, kmin, kmax, error);
	sigma8First  = sigma8Actual;
	do {
		cosmoPk_scale(pk, POW2(sigma8 / sigma8Actual));
		sigma8Actual = cosmoPk_calcSigma8(pk, kmin, kmax, error);
		*error       = fabs(1. - sigma8 / sigma8Actual);
		numIter++;
	} while (numIter < numIterMax && isgreater(*error, 1e-10));
	if (numIter >= numIterMax)
		fprintf(stderr, "Exhausted iterations in %s: error %15.13e\n",
		        __func__, *error);

	return POW2(sigma8 / sigma8First);
}
Esempio n. 6
0
/*If square == 1, the square of the L2 is returned*/
real L2Distance(SparseDim* x, SparseDim* z,uchar square) {
    real res = 0.0;
    SparseElem* x_elem = x->first;
    SparseElem* z_elem = z->first;

    while(x_elem || z_elem) {
        if(x_elem && z_elem) {
            if(x_elem->c < z_elem->c) {
                res += POW2(x_elem->val);
                x_elem = x_elem->nextC;
            }
            else if (x_elem->c > z_elem->c) {
                res += POW2(z_elem->val);
                z_elem = z_elem->nextC;
            }
            else {
                res += POW2((x_elem->val) - (z_elem->val));
                x_elem = x_elem->nextC;
                z_elem = z_elem->nextC;
            }
        }
        else {
            if(x_elem) {
                res += POW2(x_elem->val);
                x_elem = x_elem->nextC;
            }
            else {
                res += POW2(z_elem->val);
                z_elem = z_elem->nextC;
            }
        }
    }

    /*if(res == 0.0){
    	fprintf(stderr,"Null distance\n");
    	if(x_elem == z_elem)
    		fprintf(stderr,"Pointers are the same\n");
    	fprintf(stderr,"Vector x : \n");
    	x_elem = x->first;
    	while(x_elem){
    		fprintf(stderr," %i:%e",(x_elem->c)+1,x_elem->val);
    		x_elem = x_elem->nextC;
    	}
    	fprintf(stderr,"\n");
    	fprintf(stderr,"Vector z : \n");
    	z_elem = z->first;
    	while(z_elem){
    		fprintf(stderr," %i:%e",(z_elem->c)+1,z_elem->val);
    		z_elem = z_elem->nextC;
    	}
    	fprintf(stderr,"\n");
    	fflush(stderr);
    	exit(EXIT_FAILURE);
    }*/

    if (square)
        return res;
    else
        return (real)sqrt(res);
}
control_t *route_control_create(route_t* route) {
		if (route == NULL)
				return NULL;

		control_t *control = (control_t*)vp_os_malloc(sizeof(control_t));
		control_t *control_head = control;
		NODE_T *target = route->head;

		if (target == NULL)
				return NULL;

		//INIT_CONTROL(control, 0, 0, 0);

		angle_t hori_angle;
		angle_t vert_angle;
		distance_t distance;

		vp_os_mutex_lock(&NOW_mutex);
		distance_t last_x = NOW.x;
		distance_t last_y = NOW.y;
		distance_t last_z = NOW.z;
		vp_os_mutex_unlock(&NOW_mutex);

		while (target != NULL) {
				//get paras
				distance_t vect_x = target->x - last_x;
				distance_t vect_y = target->y - last_y;
				distance_t vect_z = target->z - last_z;

				printf("last %lf %lf %lf\n", last_x, last_y, last_z);
				printf("vect %lf %lf %lf\n", vect_x, vect_y, vect_z);

				last_x = target->x;
				last_y = target->y;
				last_z = target->z;

				//calcu
				MAKE_HORI_ANGLE(hori_angle, vect_x, vect_y);
				MAKE_VERT_ANGLE(vert_angle, vect_x, vect_y, vect_z);
				distance = sqrt(POW2(vect_x) + POW2(vect_y) + POW2(vect_z)) * route->unit_distance;
				
				//init control node
				INIT_CONTROL(control, hori_angle, vert_angle, distance);

				printf("control dis%lf angle%lf\n", control->distance, control->hori_angle);
				
				if (target->next != NULL) {
						control->next = (control_t*)vp_os_malloc(sizeof(control_t));
						control = control->next;
				}


				target = target->next;
		}

		return control_head;
}
Esempio n. 8
0
/**
* Given a location, an azimuth and a distance, computes the
* location of the projected point. Based on Vincenty's formula
* for the geodetic direct problem as described in "Geocentric
* Datum of Australia Technical Manual", Chapter 4. Tested against:
* http://mascot.gdbc.gov.bc.ca/mascot/util1b.html
* and
* http://www.ga.gov.au/nmd/geodesy/datums/vincenty_direct.jsp
*
* @param r - location of first point.
* @param distance - distance in meters.
* @param azimuth - azimuth in radians.
* @return s - location of projected point.
*/
int spheroid_project(const GEOGRAPHIC_POINT *r, const SPHEROID *spheroid, double distance, double azimuth, GEOGRAPHIC_POINT *g)
{
	double omf = 1 - spheroid->f;
	double tan_u1 = omf * tan(r->lat);
	double u1 = atan(tan_u1);
	double sigma, last_sigma, delta_sigma, two_sigma_m;
	double sigma1, sin_alpha, alpha, cos_alphasq;
	double u2, A, B;
	double lat2, lambda, lambda2, C, omega;
	int i = 0;

	if (azimuth < 0.0)
	{
		azimuth = azimuth + M_PI * 2.0;
	}
	if (azimuth > (PI * 2.0))
	{
		azimuth = azimuth - M_PI * 2.0;
	}

	sigma1 = atan2(tan_u1, cos(azimuth));
	sin_alpha = cos(u1) * sin(azimuth);
	alpha = asin(sin_alpha);
	cos_alphasq = 1.0 - POW2(sin_alpha);

	u2 = spheroid_mu2(alpha, spheroid);
	A = spheroid_big_a(u2);
	B = spheroid_big_b(u2);

	sigma = (distance / (spheroid->b * A));
	do
	{
		two_sigma_m = 2.0 * sigma1 + sigma;
		delta_sigma = B * sin(sigma) * (cos(two_sigma_m) + (B / 4.0) * (cos(sigma) * (-1.0 + 2.0 * POW2(cos(two_sigma_m)) - (B / 6.0) * cos(two_sigma_m) * (-3.0 + 4.0 * POW2(sin(sigma))) * (-3.0 + 4.0 * POW2(cos(two_sigma_m))))));
		last_sigma = sigma;
		sigma = (distance / (spheroid->b * A)) + delta_sigma;
		i++;
	}
	while (i < 999 && fabs((last_sigma - sigma) / sigma) > 1.0e-9);

	lat2 = atan2((sin(u1) * cos(sigma) + cos(u1) * sin(sigma) *
	              cos(azimuth)), (omf * sqrt(POW2(sin_alpha) +
	                                         POW2(sin(u1) * sin(sigma) - cos(u1) * cos(sigma) *
	                                              cos(azimuth)))));
	lambda = atan2((sin(sigma) * sin(azimuth)), (cos(u1) * cos(sigma) -
	               sin(u1) * sin(sigma) * cos(azimuth)));
	C = (spheroid->f / 16.0) * cos_alphasq * (4.0 + spheroid->f * (4.0 - 3.0 * cos_alphasq));
	omega = lambda - (1.0 - C) * spheroid->f * sin_alpha * (sigma + C * sin(sigma) *
	        (cos(two_sigma_m) + C * cos(sigma) * (-1.0 + 2.0 * POW2(cos(two_sigma_m)))));
	lambda2 = r->lon + omega;
	g->lat = lat2;
	g->lon = lambda2;
	return G_SUCCESS;
}
Esempio n. 9
0
//static void fftInit(sp_fft *fft, int M)
void sp_fft_init(sp_fft *fft, int M)
{
    /* malloc and init cosine and bit reversed tables for a given size  */
    /* fft, ifft, rfft, rifft                                           */
    /* INPUTS                                                           */
    /*   M = log2 of fft size (ex M=10 for 1024 point fft)              */
    /* OUTPUTS                                                          */
    /*   private cosine and bit reversed tables                         */

    //SPFLOAT **UtblArray;
    //int16_t **BRLowArray;
    SPFLOAT *utbl;
    int16_t *BRLow;
    int i;

    //fft->FFT_table_1 = malloc(sizeof(SPFLOAT*) * 32);
    //fft->FFT_table_2 = malloc(sizeof(int16_t*) * 32);

    //for (i = 0; i < 32; i++) {
    //    ((SPFLOAT**) fft->FFT_table_1)[i] = (SPFLOAT*) NULL;
    //    ((int16_t**) fft->FFT_table_2)[i] = (int16_t*) NULL;
    //}

    //UtblArray = (SPFLOAT**) fft->FFT_table_1;
    //BRLowArray = (int16_t**) fft->FFT_table_2;

    /*** I did NOT test cases with M>27 ***/
    /* init cos table */
    utbl = (SPFLOAT*) malloc((POW2(M) / 4 + 1) * sizeof(SPFLOAT));
    fftCosInit(M, utbl);

    /*TODO: implement this later when we need complex FFT*/ 
    /* init bit reversed table for cmplx FFT */
    /*
    if (M > 1) {
      if (BRLowArray[M / 2] == NULL) {
        BRLowArray[M / 2] =
          (int16_t*) malloc(POW2(M / 2 - 1) * sizeof(int16_t));
        fftBRInit(M, BRLowArray[M / 2]);
      }
    }
    */

  /* init bit reversed table for real FFT */
     BRLow =
      (int16_t*) malloc(POW2((M - 1) / 2 - 1) * sizeof(int16_t));

    fftBRInit(M - 1, BRLow);
    fft->BRLow = BRLow;
    fft->utbl = utbl;

    //fft->FFT_max_size |= (1 << M);
}
Esempio n. 10
0
/* make a new extra list with specific capacity */
void mk_el(uint64 cap){
	printf("dc_mm : %s%8ld%s\n","start to generate extra chunks list of chunks with specific capacity ", 
	        POW2(cap), " Bytes.");
	struct slist * list_ptr;
	if(elm_table[cap])
		return;
	elm_table[cap] = (struct extra_list_manager *)malloc(sizeof(struct extra_list_manager));
	list_ptr = mm_pre_alloc(cap , DEFAULT_EXTRA);
	elm_table[cap]->idle_num = DEFAULT_EXTRA;
	elm_table[cap]->total_num = DEFAULT_EXTRA;
	elm_table[cap]->chunks_list = list_ptr;
	printf("dc_mm : %s%8ld%s\n","finish to generate extra chunks list of chunks with specific capacity ",
	        POW2(cap), " Bytes.");
}
Esempio n. 11
0
void EQ::recalculate_band_coefficients() {

#define BAND_LOG(m_f) (log((m_f)) / log(2.))

	for (int i = 0; i < band.size(); i++) {

		double octave_size;

		double frq = band[i].freq;

		if (i == 0) {

			octave_size = BAND_LOG(band[1].freq) - BAND_LOG(frq);
		} else if (i == (band.size() - 1)) {

			octave_size = BAND_LOG(frq) - BAND_LOG(band[i - 1].freq);
		} else {

			double next = BAND_LOG(band[i + 1].freq) - BAND_LOG(frq);
			double prev = BAND_LOG(frq) - BAND_LOG(band[i - 1].freq);
			octave_size = (next + prev) / 2.0;
		}

		double frq_l = round(frq / pow(2.0, octave_size / 2.0));

		double side_gain2 = POW2(Math_SQRT12);
		double th = 2.0 * Math_PI * frq / mix_rate;
		double th_l = 2.0 * Math_PI * frq_l / mix_rate;

		double c2a = side_gain2 * POW2(cos(th)) - 2.0 * side_gain2 * cos(th_l) * cos(th) + side_gain2 - POW2(sin(th_l));

		double c2b = 2.0 * side_gain2 * POW2(cos(th_l)) + side_gain2 * POW2(cos(th)) - 2.0 * side_gain2 * cos(th_l) * cos(th) - side_gain2 + POW2(sin(th_l));

		double c2c = 0.25 * side_gain2 * POW2(cos(th)) - 0.5 * side_gain2 * cos(th_l) * cos(th) + 0.25 * side_gain2 - 0.25 * POW2(sin(th_l));

		//printf("band %i, precoefs = %f,%f,%f\n",i,c2a,c2b,c2c);

		double r1, r2; //roots
		int roots = solve_quadratic(c2a, c2b, c2c, &r1, &r2);

		ERR_CONTINUE(roots == 0);

		band[i].c1 = 2.0 * ((0.5 - r1) / 2.0);
		band[i].c2 = 2.0 * r1;
		band[i].c3 = 2.0 * (0.5 + r1) * cos(th);
		//printf("band %i, coefs = %f,%f,%f\n",i,(float)bands[i].c1,(float)bands[i].c2,(float)bands[i].c3);
	}
}
Esempio n. 12
0
void naHash_set(naRef hash, naRef key, naRef val)
{
    HashRec* hr = REC(hash);
    if(!hr || hr->next >= POW2(hr->lgsz))
        hr = resize(PTR(hash).hash);
    hashset(hr, key, val);
}
Esempio n. 13
0
static void scale3d_clocks(unsigned long percent)
{
    unsigned long hz, curr;

    if (!tegra_is_clk_enabled(scale3d.clk_3d))
        return;

    if (tegra_get_chipid() == TEGRA_CHIPID_TEGRA3)
        if (!tegra_is_clk_enabled(scale3d.clk_3d2))
            return;

    curr = clk_get_rate(scale3d.clk_3d);
    hz = percent * (curr / 100);

    if (!(hz >= scale3d.max_rate_3d && curr == scale3d.max_rate_3d)) {
        if (tegra_get_chipid() == TEGRA_CHIPID_TEGRA3)
            clk_set_rate(scale3d.clk_3d2, 0);
        clk_set_rate(scale3d.clk_3d, hz);

        if (scale3d.p_scale_emc) {
            long after = (long) clk_get_rate(scale3d.clk_3d);
            hz = after * scale3d.emc_slope + scale3d.emc_offset;
            if (scale3d.p_emc_dip)
                hz -=
                    (scale3d.emc_dip_slope *
                     POW2(after / 1000 - scale3d.emc_xmid) +
                     scale3d.emc_dip_offset);
            clk_set_rate(scale3d.clk_3d_emc, hz);
        }
    }
}
Esempio n. 14
0
inline float CubicFilter(int x, int y, const int Radius)
{
	const int DatSize = POW2((Radius << 1) + 1);
	float *Dat = new float[DatSize];
	Cint2 Offset = {x-Radius, y-Radius};
	float Accum = 0.0f;
	int Denom = 0;

	int w = Bmp.TellWidth();
	int h = Bmp.TellHeight();

	for(int Cpt = 0; Cpt < DatSize; Cpt++){
		
		if(Offset.x >= 0 && Offset.x < w && 
		   Offset.y >= 0 && Offset.y < h){

			Accum += RGBMIXER(Offset.x, Offset.y);
			Denom++;
		}

		Offset.x++;
		if(Offset.x - x > Radius){
			Offset.x = x-Radius;
			Offset.y++;
		}

	}

	SAFE_DELETE_ARRAY(Dat);

	return Accum / (float)Denom;
}
Esempio n. 15
0
/* select a node frome the extra idle list */
void * select_extra(uint64 cap)
{
	void * ptr , * chunk_ptr;
	if(0 == elm_table[cap]->idle_num)
		return dc_alloc(POW2(cap));
	pthread_mutex_lock(extra_mutex[cap]);
	ptr = pop(elm_table[cap]->chunks_list);
	append(ptr,elm_table[cap]->chunks_list);
	--(elm_table[cap]->idle_num);
	extra_apply[cap]++;
	pthread_mutex_unlock(extra_mutex[cap]);
	chunk_ptr = (void *)((uint64 *)ptr + 1);
	printf("dc_mm : %s%8ld%s\n","select a specific capacity ", POW2(cap), 
	       " Bytes form extra chunks list.");
	return chunk_ptr;
}
Esempio n. 16
0
void mm_init()
{
	int i = CHUNK_TYPE_NUM;
	while(i--){
		/* init all the pre-allocated chunks */
		chunks_manager_table[i] = (struct chunks_manager *)malloc(sizeof(struct chunks_manager));
		if(!chunks_manager_table[i]){
			printf("dc_mm : initilization failed!!!");	
			exit(1);
		}
		chunks_manager_table[i]->chunks_cap = SMALL+i;
		chunks_manager_table[i]->idle_num = chunks_num[i];
		chunks_manager_table[i]->idle_chunks = mm_pre_alloc((SMALL+i), chunks_num[i]);	
		chunks_manager_table[i]->alloced_chunks = mk_slist(malloc, chunks_num[i]);	
		printf("dc_mm : %s%8ld%s\n","chunks list and extra chunks list with specific capacity ",
		        POW2(SMALL + i), " Bytes has been initilized.");
		pre_alloc_mutex[i] = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
		pthread_mutex_init(pre_alloc_mutex[i] , NULL);
		pre_alloc_apply[i] = pre_alloc_free[i] = 0;
	}
	int j = BIGGEST_CAP + 1;
	while(--j){
		extra_mutex[j] = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
		pthread_mutex_init(extra_mutex[j] , NULL);
		extra_apply[j] = extra_free[j] = 0;
	}
	printf("dc_mm : %s\n","dns cache memory management modules has been initilized.");
	return;	
}
Esempio n. 17
0
static dali_t* dali_from_input( int ulen, int vlen, int wlen,
      const double *data, const double *mask )
{
   int id;
   int u, v, k;
   int done;
   int ue, ve;
   dali_t *desc;
   
   desc        = calloc( 1, sizeof(dali_t) );
   desc->n     = 1;
   desc->ulen  = ulen;
   desc->vlen  = vlen;
   desc->wlen  = wlen;
   desc->len   = ulen*vlen;
   desc->sz    = (desc->ulen-1)/2;
   desc->desc  = malloc( desc->ulen*desc->vlen*desc->wlen * sizeof(double) );
   desc->mask  = malloc( desc->ulen*desc->vlen * sizeof(char) );
   desc->shape = malloc( desc->ulen*desc->vlen * sizeof(int) );
   desc->gauss = malloc( desc->ulen*desc->vlen * sizeof(double) );
   desc->sgauss = malloc( desc->ulen*desc->vlen * sizeof(double) );
   desc->sigma = malloc( sizeof(double) );

   /* Defaults. */
   *desc->sigma = INFINITY;

   /* Store output. */
   id = 0;
   for (u=0; u < desc->ulen; u++) {
      for (v=0; v < desc->vlen; v++) {
         /* Data. */
         for (k=0; k < desc->wlen; k++)
            desc->desc[ id*desc->wlen + k ] = 
                  data[ k*desc->ulen*desc->vlen + u*desc->vlen + v ];
         /* Mask. */
         desc->mask[ id ]  = (fabs(mask[ u*desc->vlen + v ]) > 1e-10);
         /* Shape. */
         desc->shape[ id ] = id;
         /* Gaussian. */
         desc->gauss[ id ] = -(double)(POW2(u-desc->sz)+POW2(v-desc->sz));
         /* Inc. */
         id++;
      }
   }

   return desc;
}
Esempio n. 18
0
/* select a node from the pre-allocated idle list */
void * select_pre_alloced(uint64 cap)
{
	int pos = cap - SMALL;  /* position of the pointer in the array. */
	void * ptr , * chunk_ptr;
	if(0 == chunks_manager_table[pos]->idle_num)
		return dc_alloc(POW2(cap));
	pthread_mutex_lock(pre_alloc_mutex[pos]);
	ptr = pop(chunks_manager_table[pos]->idle_chunks);
	push(ptr,chunks_manager_table[pos]->alloced_chunks);
	--(chunks_manager_table[pos]->idle_num);
	pre_alloc_apply[pos]++;
	pthread_mutex_unlock(pre_alloc_mutex[pos]);
	chunk_ptr = (void *)((uint64 *)ptr + 1);
	printf("dc_mm : %s%8ld%s\n","select a specific capacity ", POW2(cap),
	       " Bytes form pre-allocated chunks list.");
	return chunk_ptr; 
} 
Esempio n. 19
0
/* Returns the index of a cell that either contains a matching key, or
 * is the empty slot to receive a new insertion. */
static int findcell(struct HashRec *hr, naRef key, unsigned int hash)
{
    int i, mask = POW2(hr->lgsz+1)-1, step = (2*hash+1) & mask;
    for(i=HBITS(hr,hash); TAB(hr)[i] != ENT_EMPTY; i=(i+step)&mask)
        if(TAB(hr)[i] != ENT_DELETED && equal(key, ENTS(hr)[TAB(hr)[i]].key))
            break;
    return i;
}
Esempio n. 20
0
// Stores all prime numbers < 2^16 in the array primeNumbers
inline void init()
{
	int i, j;
	for ( i = 2; i <= POW2(16) ; i ++ ) {
		if(notPrime[i]) continue;		
		for ( j = 2 * i ; j <= POW2(16) ; j += i) {
			notPrime[j] = 1;
		}
	}
	for ( i = 2 , j = 0; i < POW2(16) ; i ++ ) {
		if(!notPrime[i]) {
			primeNumbers[j++] = i;
			//printf("%d\n", i);
		}
	}
	MAX = j;
}
Esempio n. 21
0
static void scale3d_clocks(unsigned long percent)
{
	unsigned long hz, curr;
	int i = 0;
	ktime_t t;

	if (!tegra_is_clk_enabled(scale3d.clk_3d))
		return;

	if (tegra_get_chipid() == TEGRA_CHIPID_TEGRA3)
		if (!tegra_is_clk_enabled(scale3d.clk_3d2))
			return;

	curr = clk_get_rate(scale3d.clk_3d);
	hz = percent * (curr / 100);

	if (!(hz >= scale3d.max_rate_3d && curr == scale3d.max_rate_3d)) {
		if (tegra_get_chipid() == TEGRA_CHIPID_TEGRA3)
			clk_set_rate(scale3d.clk_3d2, 0);

		if (is_tegra_camera_on())
			clk_set_rate(scale3d.clk_3d, CAMERA_3D_CLK);
		else
			clk_set_rate(scale3d.clk_3d, hz);

		if (scale3d.p_scale_emc) {
			long after = (long) clk_get_rate(scale3d.clk_3d);
			hz = after * scale3d.emc_slope + scale3d.emc_offset;
			if (scale3d.p_emc_dip)
				hz -=
					(scale3d.emc_dip_slope *
					POW2(after / 1000 - scale3d.emc_xmid) +
					scale3d.emc_dip_offset);
			if (is_tegra_camera_on())
				clk_set_rate(scale3d.clk_3d_emc, CAMERA_3D_EMC_CLK);
			else
				clk_set_rate(scale3d.clk_3d_emc, hz);
		}
	}
	t = ktime_get();

	hz = clk_get_rate(scale3d.clk_3d);

	if (hz != curr)
	{
		gpu_loading[curr_idx].total_time +=
			ktime_us_delta(t, gpu_loading[curr_idx].last_start);

		for (i=0 ; i<FREQ_LEVEL ; i++) {
			if (gpu_loading[i].freq == hz) {
				curr_idx = i;
				break;
			}
		}

		gpu_loading[curr_idx].last_start = t;
	}
}
Esempio n. 22
0
double QVVector::variance() const
	{
	const double avg = mean();
	double accum = 0;
	foreach(double value, *this)
		accum += POW2(value - avg);
		
        return accum / (double) (size());
	}
Esempio n. 23
0
/* As above, a special naHash_set for setting local variables.
 * Assumes that the key is interned, and also that it isn't already
 * present in the hash. */
void naiHash_newsym(struct naHash* hash, naRef* sym, naRef* val)
{
    HashRec* hr = hash->rec;
    int mask, step, cell, ent;
    struct naStr *s = PTR(*sym).str;
    if(!hr || hr->next >= POW2(hr->lgsz))
        hr = resize(hash);
    mask = POW2(hr->lgsz+1) - 1;
    step = (2*s->hashcode+1) & mask;
    cell = HBITS(hr, s->hashcode);
    while(TAB(hr)[cell] != ENT_EMPTY)
        cell = (cell + step) & mask;
    ent = hr->next++;
    if(ent >= NCELLS(hr)) return; /* race protection, don't overrun */
    TAB(hr)[cell] = ent;
    hr->size++;
    ENTS(hr)[TAB(hr)[cell]].key = *sym;
    ENTS(hr)[TAB(hr)[cell]].val = *val;
}
Esempio n. 24
0
/* expand a extra list with specific capacity */
void expand_el(uint64 cap)
{
	printf("dc_mm : %s%8ld%s\n","start to expand extra chunks list of chunks with specific capacity ", 
	        POW2(cap), " Bytes.");
	struct slist * list_ptr;
	void * ptr , * chunk_ptr;
	list_ptr = elm_table[cap]->chunks_list;
	list_ptr = sl_expand(list_ptr,malloc,DEFAULT_EXTRA);
	int i = DEFAULT_EXTRA;	
	while(i--){
		ptr = malloc(sizeof(uint64) + POW2(cap));//added by wakemecn
		*(uint64 *)ptr = cap;
		void * chunk_ptr = (void *)((uint64 *)ptr + 1);
		push(ptr , list_ptr);
	}
	elm_table[cap]->idle_num += DEFAULT_EXTRA;
	elm_table[cap]->total_num += DEFAULT_EXTRA;
	printf("dc_mm : %s%8ld%s\n","finish to expand extra chunks list of chunks with specific capacity ", 
	        POW2(cap), " Bytes.");
}
Esempio n. 25
0
void naHash_delete(naRef hash, naRef key)
{
    HashRec* hr = REC(hash);
    if(hr) {
        int cell = findcell(hr, key, refhash(key));
        if(TAB(hr)[cell] >= 0) {
            TAB(hr)[cell] = ENT_DELETED;
            if(--hr->size < POW2(hr->lgsz-1))
                resize(PTR(hash).hash);
        }
    }
}
Esempio n. 26
0
/*
 * call mm_pre_alloc() to pre-allocate number of counts' chunks with 
 * 2^capacity KB memory.
 * RETURN the pointer to a chunks list.
 */
struct slist * mm_pre_alloc(uint64 capacity, uint16 counts)
{
	struct slist * init_idle_list;
	void * ptr;
	init_idle_list = mk_slist(malloc,counts);  /* make a blank single list. */
	while(counts--){
		ptr = malloc(POW2(capacity)+sizeof(uint64)); /* malloc for each element of the list. */
		*(uint64 *)ptr = capacity;				/* filled the capacity before the chunk. */
		push(ptr,init_idle_list);  /* push the chunk into list. */
	}
	return init_idle_list;	
}
Esempio n. 27
0
/**
* Computes the area on the spheroid of a box bounded by meridians and
* parallels. The box is defined by two points, the South West corner
* and the North East corner. Formula based on Bagratuni 1967.
*
* @param southWestCorner - lower left corner of bounding box.
* @param northEastCorner - upper right corner of bounding box.
* @return area in square meters.
*/
static double spheroid_boundingbox_area(const GEOGRAPHIC_POINT *southWestCorner, const GEOGRAPHIC_POINT *northEastCorner, const SPHEROID *spheroid)
{
	double z0 = (northEastCorner->lon - southWestCorner->lon) * POW2(spheroid->b) / 2.0;
	double e = sqrt(spheroid->e_sq);
	double sinPhi1 = sin(southWestCorner->lat);
	double sinPhi2 = sin(northEastCorner->lat);
	double t1p1 = sinPhi1 / (1.0 - spheroid->e_sq * sinPhi1 * sinPhi1);
	double t1p2 = sinPhi2 / (1.0 - spheroid->e_sq * sinPhi2 * sinPhi2);
	double oneOver2e = 1.0 / (2.0 * e);
	double t2p1 = oneOver2e * log((1.0 + e * sinPhi1) / (1.0 - e * sinPhi1));
	double t2p2 = oneOver2e * log((1.0 + e * sinPhi2) / (1.0 - e * sinPhi2));
	return z0 * (t1p2 + t2p2) - z0 * (t1p1 + t2p1);
}
Esempio n. 28
0
/* get_quick_fit_list_index
 *
 * get_quick_fit_list_index returns the quick fit list index for the given
 * number of bytes of data to allocate.
 * The size of the header is added in the calculations, so nbytes should be the
 * number of bytes of data to allocate.
 *
 */
int get_quick_fit_list_index(
        unsigned int nbytes) /* number of data bytes to allocate */
{
    unsigned int upper_bound;
    int i;
    for (i = 0; i < NRQUICKLISTS; ++i) {
        upper_bound = POW2(i + smallest_block_size_exp);
        if (nbytes + sizeof(Header) <= upper_bound) {
            return i;
        }
    }
    return NRQUICKLISTS;
}
Esempio n. 29
0
static void dali_updateGauss( dali_t *desc, double sigma )
{
   int i;
   double s;

   if (fabs(sigma - *desc->sigma) < 1e-10)
      return;

   s = 2.*POW2( (double)desc->sz * sigma );
   for (i=0; i<desc->len; i++)
      desc->sgauss[ i ] = exp( desc->gauss[ i ] / s );
   *desc->sigma = sigma;
}
Esempio n. 30
0
/* print the statics about the apply and free of chunks.*/
void print_statics(){
	int i = 0;
	uint64 apply_count, free_count;
	while((++i) <= BIGGEST_CAP)	{
		apply_count = extra_apply[i];
		free_count = extra_free[i];
		if(i >= SMALL && i <= BIG ){
			apply_count += pre_alloc_apply[i - SMALL];
			free_count += pre_alloc_free[i - SMALL];	
		}
		printf("dc_mm : statics, %s%10d%s%10ld%s%10ld%s\n","chunks with specific capacity ",
			   POW2(i)," were applied ", apply_count ," times and freed ",free_count," times.");	
	}
}