Esempio n. 1
0
pixel_t get_color(array_t *image, size_t bitdepth)
{
	uint32_t pixel_num = 0;
	lab_pixel_t *avg = NULL;
	for (size_t i = 0; i < image->size; i++)
	{
		array_t *row = ((array_t *) image->ptr);
		for (size_t j = 0; j < row->size; j++)
		{
			pixel_num++;
			pixel_t rgb = ((pixel_t *) row->ptr)[j];
			xyz_pixel_t xyz = rgb_to_xyz(rgb);
			lab_pixel_t lab = xyz_to_lab(xyz);
			if (avg == NULL)
			{
				avg = malloc(sizeof(lab_pixel_t));
				*avg = lab;
			}
			else
			{
				avg->L = running_avg(avg->L, lab->L, pixel_num);
				avg->a = running_avg(avg->a, lab->a, pixel_num);
				avg->b = running_avg(avg->b, lab->b, pixel_num);
			}
		}
	}
	xyz_pixel_t xyz_avg = lab_to_xyz(*avg);
	return xyz_to_rgb(xyz_avg);
}
Esempio n. 2
0
void
nv_bgseg_update(nv_bgseg_t *bg, nv_matrix_t *mask, const nv_matrix_t *frame)
{
	nv_matrix_t *tmp, *tmp2, *mask_vec, *lower, *upper;
	
	NV_ASSERT(bg->init_2nd_finished == 1);

	tmp = conv_image2vec(bg, frame);
	lower = nv_matrix_clone(tmp);
	upper = nv_matrix_clone(tmp);
	mask_vec = nv_matrix_clone(tmp);
	tmp2 = nv_matrix_dup(tmp);
	
	// range
	nv_vector_sub(lower, 0, bg->av, 0, bg->sgm, 0);
	nv_vector_subs(lower, 0, lower, 0, bg->zeta);
	nv_vector_add(upper, 0, bg->av, 0, bg->sgm, 0);
	nv_vector_adds(upper, 0, upper, 0, bg->zeta);
	nv_vector_in_range10(mask_vec, 0, lower, 0, upper, 0, tmp, 0);
	
	// update amplitude
	nv_vector_sub(tmp, 0, tmp, 0, bg->av, 0);
	nv_vector_mul(tmp,  0, tmp, 0, tmp, 0);
	nv_vector_muls(tmp, 0, tmp, 0, 2.0f);
	nv_vector_sqrt(tmp, 0, tmp, 0);
	
	// update background
	running_avg(bg->av, tmp2, bg->bg_v, mask_vec, 1.0f);
	running_avg(bg->sgm, tmp, bg->bg_v, mask_vec, 1.0f);
	
	// update foreground
	running_avg(bg->sgm, tmp, bg->fg_v, mask_vec, 0.0f);
	
	conv_mask(bg, mask, mask_vec);
	
	nv_matrix_free(&tmp);
	nv_matrix_free(&mask_vec);
	nv_matrix_free(&tmp2);
	nv_matrix_free(&upper);
	nv_matrix_free(&lower);
}
Esempio n. 3
0
void rcp_rate_calc(int signum)
{
	double tempRate = 0.0;
	char clip;
	double ratio = 0.0;
	double input_traffic_divider = 0.0;
	double virtual_link_capacity = 0.0; // Bytes/msec.
	unsigned long long rttSumTq = 0.0;
	double TqAvgRTT = 0.0;
	double rtt_moving_gain = 0.0;
	unsigned int numPktsValidRTT = 0;
	unsigned int interface_index = 0;
	int val1, val2;
	unsigned long long val_h;
	unsigned int rcp_reg_offset = 0;
	static int counter= 0; 
	
	printf ("timerHandler: counter= %d\n", counter++); 

  rcp_reg_offset = mac_index * RCP_REG_PER_MAC_OFFSET;
  
	/* ------------ Read stats from the kernel ------------------- */
	// Read sum of round-trip times
    readReg(&nf2, RCP_MAC_0_RTT_L_REG + rcp_reg_offset, &val1);
	  readReg(&nf2, RCP_MAC_0_RTT_H_REG + rcp_reg_offset, &val2);
	  val_h = val2;
	  rttSumTq = (val_h<<32)+val1;
        
	  // Number of RCP packets that arry a valid RTT 
	  readReg(&nf2, RCP_MAC_0_NUM_RCP_REG + rcp_reg_offset, &val1);
	  numPktsValidRTT = val1;

	  // Total number of arriving RCP bytes
	  readReg(&nf2, RCP_MAC_0_NUM_BYTE_L_REG + rcp_reg_offset, &val1);
	  readReg(&nf2, RCP_MAC_0_NUM_BYTE_H_REG + rcp_reg_offset, &val2);
	  val_h = val2;
	  input_traffic_=(val_h<<32)+val1;
	
	  // Queue occupancy
	  readReg(&nf2, OQ_NUM_PKTS_STORED_REG_0 + 
                     RCP_REG_OQ_PER_MAC_OFFSET * mac_index, &val1);
	  Q_ = val1;
	  //fscanf(fStats, "%u\t%lu\t%lu\t%lu\n", &interface_index, &rttSumTq, &numPktsValidRTT, &input_traffic_, &Q_);
	  
	  /* -------------- Compute avg_rtt ----------------------------- */

	  if (numPktsValidRTT > 0)
		    TqAvgRTT = rttSumTq/numPktsValidRTT; 

	  if (TqAvgRTT >= avg_rtt_)
		    rtt_moving_gain = (Tq_/avg_rtt_);
	  else 
        rtt_moving_gain = ((float)flow_rate_/link_capacity_)*(TqAvgRTT/avg_rtt_)*(Tq_/avg_rtt_);

	  avg_rtt_ = running_avg(TqAvgRTT, avg_rtt_, rtt_moving_gain);
  
	  /* -------------- Compute Rate --------------------------------- */
  
	  virtual_link_capacity = GAMMA * link_capacity_;
	  input_traffic_divider = input_traffic_/Tq_; // Bytes/msec
	  ratio		= (1 + ((Tq_/avg_rtt_)*(ALPHA*(virtual_link_capacity - input_traffic_divider) - BETA*(Q_/avg_rtt_)))/virtual_link_capacity);
    tempRate	= flow_rate_ * ratio;

	  if (tempRate < min_pprtt_ * (PKTSIZE/avg_rtt_) ) {  
		    flow_rate_ = min_pprtt_ * (PKTSIZE/avg_rtt_) ; // min-pkts/RTT 
		    clip  = 'L';
    } else if (tempRate > virtual_link_capacity) {
		    flow_rate_ = virtual_link_capacity;
		    clip = 'U';
    } else {
		    flow_rate_ = tempRate;
		    clip = 'M';
    }
	
	  if (flow_rate_ < 1)
		    flow_rate_ = 1; // 1 Byte/ms
		
	  Tq_ = min(avg_rtt_, TIMESLOT); // msec
		
	  /* -------------- Reset Kernel Stats ---------------------------- */
	  // Reset RTT
	  writeReg(&nf2, RCP_MAC_0_RTT_L_REG + rcp_reg_offset, 0);
	  writeReg(&nf2, RCP_MAC_0_RTT_H_REG + rcp_reg_offset, 0);

	  // Reset Number of RCP packets carrying a valid RTT
	  writeReg(&nf2, RCP_MAC_0_NUM_RCP_REG + rcp_reg_offset, 0);

	  // Reset number of incoming RCP bytes
	  writeReg(&nf2, RCP_MAC_0_NUM_BYTE_L_REG + rcp_reg_offset, 0);
	  writeReg(&nf2, RCP_MAC_0_NUM_BYTE_H_REG + rcp_reg_offset, 0);

	  //fprintf(fStats, "%u", interface_index);
	
	  /* -------------- Write RCP Rate ------------------------------- */
	  writeReg(&nf2, 
                   RCP_RATE_0_REG + 
                       mac_index * RCP_REG_RATE_PER_MAC_OFFSET, 
                   flow_rate_);
	  //fprintf(fRate, "%u %lu", interface_index, flow_rate_);
	  printf("flow rate=%lu\n", flow_rate_);
	  /* -------------- Reschedule Timer ------------------------------ */

	  timer_.it_value.tv_sec= 0;   // First timeout 
	  timer_.it_value.tv_usec= Tq_ * 1000; //usec 
	  timer_.it_interval.tv_sec= 0;   // Interval 
	  timer_.it_interval.tv_usec= Tq_ * 1000; //usec 
	  setitimer (ITIMER_REAL, &timer_, NULL);

	  fflush (stdout); 

}