static int lookup_esr(int capacity, int temp) { struct sysedp_batmon_rbat_lut *lut = pdata->rbat_lut; int ret = pdata->r_const; ret += bilinear_interpolate(lut->data, lut->temp_axis, lut->capacity_axis, lut->temp_size, lut->capacity_size, temp, capacity); return ret; }
void arotate(int16_t **the_image, int16_t **out_image, rotate_options image, int32_t rows, int32_t cols) { double32_t cosa, sina, radian_angle, tmpx, tmpy; int16_t i, j, new_i, new_j; radian_angle = image.angle / MAGIC_NUMBER; cosa = cos(radian_angle); sina = sin(radian_angle); /************************** * * Loop over image array * **************************/ printf("\n"); for (i = 0; i < rows; i++) { if ((i % 10) == 0) { printf("%d ", i); } for (j = 0; j < cols; j++) { /****************************************** * * new x = x.cos(a) - y.sin(a) * -m.cos(a) + m + n.sin(a) * * new y = y.cos(a) + x.sin(a) * -m.sin(a) - n.cos(a) + n * *******************************************/ tmpx = j * cosa - i * sina - image.m * cosa + image.m + image.n * sina; tmpy = i * cosa + j * sina - image.m * sina - image.n * cosa + image.n; new_j = (int16_t) tmpx; new_i = (int16_t) tmpy; if (image.bilinear == 0) { if ((new_j < 0) || (new_j >= cols) || (new_i < 0) || (new_i >= rows)) { out_image[i][j] = FILL; } else { out_image[i][j] = the_image[new_i][new_j]; } } /* ends if bilinear */ else { out_image[i][j] = bilinear_interpolate(the_image, tmpx, tmpy, rows, cols); } /* ends bilinear if */ } /* ends loop over j */ } /* ends loop over i */ } /* ends arotate */
/* Image texture function */ int tex_fun(float u, float v, GzColor color) { unsigned char pixel[3]; unsigned char dummy; char foo[8]; int i, j; FILE *fd; if (reset) { /* open and load texture file */ fd = fopen ("texture", "rb"); if (fd == NULL) { fprintf (stderr, "texture file not found\n"); exit(-1); } fscanf (fd, "%s %d %d %c", foo, &xs, &ys, &dummy); image = (GzColor*)malloc(sizeof(GzColor)*(xs+1)*(ys+1)); if (image == NULL) { fprintf (stderr, "malloc for texture image failed\n"); exit(-1); } for (i = 0; i < xs*ys; i++) { /* create array of GzColor values */ fread(pixel, sizeof(pixel), 1, fd); image[i][RED] = (float)((int)pixel[RED]) * (1.0 / 255.0); image[i][GREEN] = (float)((int)pixel[GREEN]) * (1.0 / 255.0); image[i][BLUE] = (float)((int)pixel[BLUE]) * (1.0 / 255.0); } reset = 0; /* init is done */ fclose(fd); } /* bounds-test u,v to make sure nothing will overflow image array bounds */ if(u>1) u=1; if(u<0) u=0; if(v>1) v=1; if(v<0) v=0; /* determine texture cell corner values and perform bilinear interpolation */ float scaledu, scaledv; GzColor result; scaledu = u*( xs -1 ); scaledv = v*( ys -1 ); bilinear_interpolate(image, scaledu, scaledv, result, xs); /* set color to interpolated GzColor value and return */ color[RED] = result[RED]; color[GREEN] = result[GREEN]; color[BLUE] = result[BLUE]; return GZ_SUCCESS; }
image rotate_image(image im, float rad) { int x, y, c; float cx = im.w/2.; float cy = im.h/2.; image rot = make_image(im.w, im.h, im.c); for(c = 0; c < im.c; ++c){ for(y = 0; y < im.h; ++y){ for(x = 0; x < im.w; ++x){ float rx = cos(rad)*(x-cx) - sin(rad)*(y-cy) + cx; float ry = sin(rad)*(x-cx) + cos(rad)*(y-cy) + cy; float val = bilinear_interpolate(im, rx, ry, c); set_pixel(rot, x, y, c, val); } } } return rot; }
void geometry(int16_t **the_image, int16_t **out_image, geometry_options image, int32_t rows, int32_t cols) { double32_t cosa, sina, radian_angle, tmpx, tmpy; float32_t x_div, y_div, x_num, y_num; int16_t i, j, new_i, new_j; /****************************** * * Load the terms array with * the correct parameters. * *******************************/ radian_angle = (double32_t) image.x_angle / MAGIC_NUMBER; cosa = cos(radian_angle); sina = sin(radian_angle); /************************************ * * NOTE: You divide by the * stretching factors. Therefore, if * they are zero, you divide by 1. * You do this with the x_div y_div * variables. You also need a * numerator term to create a zero * product. You do this with the * x_num and y_num variables. * *************************************/ if (image.x_stretch < 0.00001) { x_div = 1.0; x_num = 0.0; } else { x_div = image.x_stretch; x_num = 1.0; } if (image.y_stretch < 0.00001) { y_div = 1.0; y_num = 0.0; } else { y_div = image.y_stretch; y_num = 1.0; } /************************** * * Loop over image array * **************************/ for (i = 0; i < rows; i++) { if ((i % 10) == 0) { printf("%d ", i); } for (j = 0; j < cols; j++) { tmpx = j * cosa + i * sina + image.x_displace + (double32_t) x_num * j / x_div + (double32_t) image.x_cross * i * j; tmpy = i * cosa - j * sina + image.y_displace + (double32_t) y_num * i / y_div + (double32_t) image.y_cross * i * j; if (image.x_stretch != 0.0) { tmpx = tmpx - j * cosa + i * sina; } if (image.y_stretch != 0.0) { tmpy = tmpy - i * cosa - j * sina; } new_j = (int16_t) tmpx; new_i = (int16_t) tmpy; if (image.bilinear == 0) { if ((new_j < 0) || (new_j >= cols) || (new_i < 0) || (new_i >= rows)) { out_image[i][j] = FILL; } else { out_image[i][j] = the_image[new_i][new_j]; } } /* ends if bilinear */ else { out_image[i][j] = bilinear_interpolate(the_image, tmpx, tmpy, rows, cols); } /* ends bilinear if */ } /* ends loop over j */ } /* ends loop over i */ } /* ends geometry */