void carmen_map_util_change_resolution(carmen_map_p map, double new_resolution) { double *new_complete_map; double **new_map; carmen_map_config_t new_config; double **padded_map; double *padded_backing; int padded_x_size, padded_y_size; double scale_factor; int x, y; double f_x, f_y, a, b, tmp, r1, r2; int i_x, i_y, m, n; new_config.x_size = map->config.resolution/new_resolution * map->config.x_size; new_config.y_size = map->config.resolution/new_resolution * map->config.y_size; new_config.resolution = new_resolution; new_config.map_name = map->config.map_name; new_complete_map = (double *) calloc(new_config.x_size*new_config.y_size, sizeof(double)); carmen_test_alloc(new_complete_map); new_map = (double **)calloc(new_config.x_size, sizeof(double *)); carmen_test_alloc(new_map); for (x = 0; x < new_config.x_size; x++) new_map[x] = new_complete_map+x*new_config.y_size; padded_x_size = map->config.x_size+4; padded_y_size = map->config.y_size+4; padded_backing = (double *)calloc(padded_x_size*padded_y_size, sizeof(double)); carmen_test_alloc(padded_backing); padded_map = (double **)calloc(padded_x_size, sizeof(double *)); carmen_test_alloc(padded_map); for (x = 0; x < padded_x_size; x++) padded_map[x] = padded_backing+x*padded_y_size; for (x = 2; x < padded_x_size-2; x++) { memcpy(padded_map[x]+2, map->map[x-2], map->config.y_size*sizeof(double)); memcpy(padded_map[x], padded_map[x]+2, 2*sizeof(double)); memcpy(padded_map[x]+2+map->config.y_size, padded_map[x]+map->config.y_size, 2*sizeof(double)); } memcpy(padded_map[0], padded_map[2], padded_y_size*sizeof(double)); memcpy(padded_map[1], padded_map[2], padded_y_size*sizeof(double)); memcpy(padded_map[padded_x_size-2], padded_map[padded_x_size-3], padded_y_size*sizeof(double)); memcpy(padded_map[padded_x_size-1], padded_map[padded_x_size-3], padded_y_size*sizeof(double)); scale_factor = map->config.resolution / new_resolution; for (y = 0; y < new_config.y_size; y++) { f_y = y / scale_factor; i_y = carmen_trunc(f_y); a = f_y - carmen_trunc(f_y); for (x = 0; x < new_config.x_size; x++) { f_x = x / scale_factor; i_x = carmen_trunc(f_x); b = f_x - carmen_trunc(f_x); // Implement EQ 14.5-3 here tmp = 0.0; for(m = -1; m < 3; m++) { r1 = cubic_bspline((double) m - a); for(n = -1; n < 3; n++) { r2 = cubic_bspline(-1.0*((double)n - b)); tmp += padded_map[i_x+n+2][i_y+m+2] * r1 * r2; } } if (tmp < 0) tmp = -1; if (tmp > 1.0) tmp = 1.0; new_map[x][y] = tmp; } } free(padded_map); free(padded_backing); free(map->map); free(map->complete_map); map->map = new_map; map->complete_map = new_complete_map; map->config = new_config; }
static int scale_icon(ICON_DATA *icon) { BITMAP *shape; int size, x_ofs = 2, y_ofs = 2; int x, y, m, n; int i_x, i_y; float k, f_x, f_y, a, b, r1, r2; float red, green, blue, alpha; unsigned int color; if (icon->original->w > icon->original->h) { size = 4 + icon->original->w; y_ofs = 2 + ((icon->original->w - icon->original->h) / 2); } else { size = 4 + icon->original->h; x_ofs = 2 + ((icon->original->h - icon->original->w) / 2); } k = (float)(size - 4) / (float)icon->size; icon->workspace = create_bitmap_ex(32, size, size); if (!icon->workspace) return -1; icon->scaled = create_bitmap_ex(32, icon->size, icon->size); if (!icon->scaled) return -1; shape = create_bitmap_ex(32, icon->original->w, icon->original->h); if (!shape) return -1; blit(icon->original, shape, 0, 0, 0, 0, icon->original->w, icon->original->h); clear_to_color(icon->workspace, makeacol32(0, 0, 0, 255)); shape->vtable->mask_color = makeacol32(255, 0, 255, 0); masked_blit(shape, icon->workspace, 0, 0, x_ofs, y_ofs, shape->w, shape->h); destroy_bitmap(shape); for (y = 0; y < icon->size; y++) { f_y = (float)y * k; i_y = (int)floor(f_y); a = f_y - floor(f_y); for (x = 0; x < icon->size; x++) { f_x = (float)x * k; i_x = (int)floor(f_x); b = f_x - floor(f_x); red = green = blue = alpha = 0.0; for (m = -1; m < 3; m++) { r1 = cubic_bspline((float)m - a); for (n = -1; n < 3; n++) { r2 = cubic_bspline(b - (float)n); color = ((unsigned int *)(icon->workspace->line[i_y + m + 2]))[i_x + n + 2]; red += ((float)getr32(color) * r1 * r2); green += ((float)getg32(color) * r1 * r2); blue += ((float)getb32(color) * r1 * r2); alpha += ((float)geta32(color) * r1 * r2); } } color = makeacol32((int)floor(red), (int)floor(green), (int)floor(blue), 255 - (int)floor(alpha)); ((unsigned int *)(icon->scaled->line[y]))[x] = color; } } return 0; }