/** * Raster the color triangle to the screen. Points are in * NDC coordinates (converted to screen coordinates). * * colors correspond to the respective points. */ void raster_triangle(point *a, point *b, point *c, color ca, color cb, color cc, int xres, int yres, color** grid, float** depth_grid) { point screen_a = NDC_to_screen(a, xres, yres); point screen_b = NDC_to_screen(b, xres, yres); point screen_c = NDC_to_screen(c, xres, yres); float x_min = min_x(&screen_a, &screen_b, &screen_c); float x_max = max_x(&screen_a, &screen_b, &screen_c); float y_min = min_y(&screen_a, &screen_b, &screen_c); float y_max = max_y(&screen_a, &screen_b, &screen_c); x_max = x_max > xres ? xres : x_max; y_max = y_max > yres ? yres : y_max; for (int x = x_min; x < x_max; x++) { for (int y = y_min; y < y_max; y++) { point curr_point = create_point(x, y, 0); float alpha = compute_alpha(&screen_a, &screen_b, &screen_c, &curr_point); float beta = compute_beta(&screen_a, &screen_b, &screen_c, &curr_point); float gamma = compute_gamma(&screen_a, &screen_b, &screen_c, &curr_point); curr_point.z = alpha * screen_a.z + beta * screen_b.z + gamma * screen_c.z; if (valid_parameters(alpha, beta, gamma) && depth_grid[x][y] > curr_point.z) { color col = compute_color(ca, cb, cc, alpha, beta, gamma); grid[x][y].r = col.r; grid[x][y].g = col.g; grid[x][y].b = col.b; depth_grid[x][y] = curr_point.z; } } } }
/** * Also has depth buffering and ignores points where normals point away * * Points a, b, c are in NDC */ void raster_triangle_Phong(point *a, point *b, point *c, point *world_a, point *world_b, point *world_c, point *normal_a, point *normal_b, point *normal_c, object_copy *obj, vector<light> *lights, camera *CAM, int xres, int yres, color** grid, float** depth_grid, MatrixXd *perspective, MatrixXd *inv_cam) { point screen_a = NDC_to_screen(a, xres, yres); point screen_b = NDC_to_screen(b, xres, yres); point screen_c = NDC_to_screen(c, xres, yres); float x_min = min_x(&screen_a, &screen_b, &screen_c); float x_max = max_x(&screen_a, &screen_b, &screen_c); float y_min = min_y(&screen_a, &screen_b, &screen_c); float y_max = max_y(&screen_a, &screen_b, &screen_c); x_max = x_max > xres ? xres : x_max; y_max = y_max > yres ? yres : y_max; x_min = x_min < 0 ? 0 : x_min; y_min = y_min < 0 ? 0 : y_min; // TODO: compute colors by normals for (int x = x_min; x < x_max; x++) { for (int y = y_min; y < y_max; y++) { // get alpha/beta/gamma point curr_point = create_point(x, y, 0); float alpha = compute_alpha(&screen_a, &screen_b, &screen_c, &curr_point); float beta = compute_beta(&screen_a, &screen_b, &screen_c, &curr_point); float gamma = compute_gamma(&screen_a, &screen_b, &screen_c, &curr_point); curr_point.z = alpha * screen_a.z + beta * screen_b.z + gamma * screen_c.z; // compute interpolated point (in world view) and normal for the point point normal = (*normal_a) * alpha + (*normal_b) * beta + (*normal_c) * gamma; point coordinate = (*world_a) * alpha + (*world_b) * beta + (*world_c) * gamma; point ndc_coordinate = to_NDC(&coordinate, perspective, inv_cam); if (is_in_box(&ndc_coordinate) && valid_parameters(alpha, beta, gamma) && depth_grid[x][y] > curr_point.z) { color col = lighting(&coordinate, &normal, obj, lights, CAM); grid[x][y].r = col.r; grid[x][y].g = col.g; grid[x][y].b = col.b; depth_grid[x][y] = curr_point.z; } } } }
/* synth_buffer * ============ * synthesizes a buffer of sound using * amplitude linear interpolation and * phase cubic interpolation * a1: strating amplitude * a2: ending amplitude * f1: starting frequency in radians per sample * f2: ending frequency in radians per sample * p1: starting phase in radians * p2: ending phase in radians * buffer: pointer to synthsis buffer * which is filled out by the function * NOTE: caller should allocate memory for buffer * frame_samps: number of samples in frame (buffer) */ void synth_buffer(double a1,double a2, double f1, double f2, double p1, double p2, double *buffer, int frame_samps) { int k, M; double aux, alpha, beta, amp, amp_inc, int_pha; M = compute_m(p1, f1, p2, f2, frame_samps); aux = compute_aux(p1, p2, f1, frame_samps, M); alpha = compute_alpha(aux, f1, f2, frame_samps); beta = compute_beta(aux, f1, f2, frame_samps); amp = a1; amp_inc = (a2 - a1) / (double)frame_samps; for(k = 0; k < frame_samps; k++) { int_pha = interp_phase(p1, f1, alpha, beta, k); buffer[k] += amp * cos(int_pha); amp += amp_inc; } }
void householder(double **a_mat, int size){ int i, j, k; //p is the household matrix double **p = (double**)malloc(sizeof(double*)*size); double **I = (double**)malloc(sizeof(double*)*size); double **tmp = (double**)malloc(sizeof(double*)*size); double *v = (double*)malloc(sizeof(double)*size); for(i=0; i<size; i++){ p[i] = (double*)malloc(sizeof(double)*size); I[i] = (double*)malloc(sizeof(double)*size); tmp[i] = (double*)malloc(sizeof(double)*size); I[i][i] = 1; } for(i=0; i<size-1; i++){ int sign = a_mat[i+1][i]>0?-1:1; double alpha = sign*compute_alpha(a_mat, i, size); double r = sqrt((alpha*alpha - a_mat[i+1][i]*alpha)/2); //printf("sign: %d alpha %3.2f r %3.2f\n", sign, alpha, r); compute_v(a_mat, v, alpha, r, i, size); multiply_and_minus(v, p, I, size); mat_mul(tmp, p, a_mat, size); mat_mul(a_mat, tmp, p, size); if(check_is_triangularized(a_mat, size)==TRUE) break; } //free for(i=0; i<size; i++){ free(p[i]); free(I[i]); free(tmp[i]); } free(p); free(I); free(tmp); free(v); }
void ia_css_xnrvideo4_encode( struct sh_css_isp_xnrvideo4_params *to, const struct ia_css_xnrvideo4_config *from, unsigned size) { int kernel_size = XNR_FILTER_SIZE; int adjust_factor = 2 * (kernel_size - 1); int32_t alpha_y0 = compute_alpha(from->sigma.y0); int32_t alpha_y1 = compute_alpha(from->sigma.y1); int32_t alpha_u0 = compute_alpha(from->sigma.u0); int32_t alpha_u1 = compute_alpha(from->sigma.u1); int32_t alpha_v0 = compute_alpha(from->sigma.v0); int32_t alpha_v1 = compute_alpha(from->sigma.v1); int32_t coring_u0 = compute_coring(from->coring.u0); int32_t coring_u1 = compute_coring(from->coring.u1); int32_t coring_v0 = compute_coring(from->coring.v0); int32_t coring_v1 = compute_coring(from->coring.v1); (void)size; /* alpha's are represented in qN.5 format */ to->alpha.y0 = alpha_y0; to->alpha.u0 = alpha_u0; to->alpha.v0 = alpha_v0; to->alpha.ydiff = (alpha_y1 - alpha_y0) * adjust_factor / kernel_size; to->alpha.udiff = (alpha_u1 - alpha_u0) * adjust_factor / kernel_size; to->alpha.vdiff = (alpha_v1 - alpha_v0) * adjust_factor / kernel_size; /* coring parameters are expressed in q1.NN format */ to->coring.u0 = coring_u0; to->coring.v0 = coring_v0; to->coring.udiff = (coring_u1 - coring_u0) * adjust_factor / kernel_size; to->coring.vdiff = (coring_v1 - coring_v0) * adjust_factor / kernel_size; }
void test_sparse_apply_corrections() { Hyperloglog *hll = mock_sparse_hll(8); uint cardinality = hyperloglog_cardinality(hll, compute_alpha(hll->m)); sassert(3 == apply_corrections(hll, cardinality)); free(hll); }
void test_sparse_hyperloglog_cardinality() { Hyperloglog *hll = mock_sparse_hll(8); sassert(185 == hyperloglog_cardinality(hll, compute_alpha(hll->m))); free(hll); }