int colour_map() { int max_count = 0; Uint8 max_colour = 0xFF; for(int c = 1; c < 31; c++) { for(int i = 0; i < 1000; i++) { int x = rand() % X_SQUARES; int y = rand() % Y_SQUARES; if(map[x][y].r == 0x00 && map[x][y].g == 0x00 && map[x][y].b == 0x00) { int temp_count = color_point(x,y,0x08*c,0x08*c,0x08*c); if(temp_count > max_count) { max_count = temp_count; max_colour = 0x08*c; } break; } } } for(int x = 0; x < X_SQUARES; x++) { for(int y = 0; y < Y_SQUARES; y++) { if(map[x][y].r == max_colour) { map[x][y].r = 0xFE; map[x][y].g = 0xFE; map[x][y].b = 0xFE; } else { map[x][y].r = 0x00; map[x][y].g = 0x00; map[x][y].b = 0x00; } } } return max_count; }
int color_point(int x, int y, Uint8 r, Uint8 g, Uint8 b) { int count = 1; map[x][y].r = r; map[x][y].g = g; map[x][y].b = b; if(x-1 >= 0 && map[x-1][y].r == 0x00 && map[x-1][y].g == 0x00 && map[x-1][y].b == 0x00) count += color_point(x-1, y, r, g, b); if(x+1 < X_SQUARES && map[x+1][y].r == 0x00 && map[x+1][y].g == 0x00 && map[x+1][y].b == 0x00) count += color_point(x+1, y, r, g, b); if(y-1 >= 0 && map[x][y-1].r == 0x00 && map[x][y-1].g == 0x00 && map[x][y-1].b == 0x00) count += color_point(x, y-1, r, g, b); if(y+1 < Y_SQUARES && map[x][y+1].r == 0x00 && map[x][y+1].g == 0x00 && map[x][y+1].b == 0x00) count += color_point(x, y+1, r, g, b); return count; }
void gradient_lut<T,S>::add_color(double offset, const color_type& color) { m_color_profile.add(color_point(offset, color)); }
int main(int argc, char **argv) { mpd_context_t ctx; mpd_t *x0, *y0; mpd_t *sqrt_2, *xstep, *ystep; uint32_t prec = 19; int iter = 1000; int points[40][80]; int i, j; clock_t start_clock, end_clock; if (argc != 3) { fprintf(stderr, "usage: ./bench prec iter\n"); exit(1); } prec = strtoul(argv[1], NULL, 10); iter = strtol(argv[2], NULL, 10); mpd_init(&ctx, prec); /* no more MPD_MINALLOC changes after here */ sqrt_2 = mpd_new(&ctx); xstep = mpd_new(&ctx); ystep = mpd_new(&ctx); x0 = mpd_new(&ctx); y0 = mpd_new(&ctx); mpd_set_u32(sqrt_2, 2, &ctx); mpd_sqrt(sqrt_2, sqrt_2, &ctx); mpd_div_u32(xstep, sqrt_2, 40, &ctx); mpd_div_u32(ystep, sqrt_2, 20, &ctx); start_clock = clock(); mpd_copy(y0, sqrt_2, &ctx); for (i = 0; i < 40; i++) { mpd_copy(x0, sqrt_2, &ctx); mpd_set_negative(x0); for (j = 0; j < 80; j++) { points[i][j] = color_point(x0, y0, iter, &ctx); mpd_add(x0, x0, xstep, &ctx); } mpd_sub(y0, y0, ystep, &ctx); } end_clock = clock(); #ifdef BENCH_VERBOSE for (i = 0; i < 40; i++) { for (j = 0; j < 80; j++) { if (points[i][j] == iter) { putchar('*'); } else if (points[i][j] >= 10) { putchar('+'); } else if (points[i][j] >= 5) { putchar('.'); } else { putchar(' '); } } putchar('\n'); } putchar('\n'); #endif printf("time: %f\n\n", (double)(end_clock-start_clock)/(double)CLOCKS_PER_SEC); mpd_del(x0); mpd_del(y0); mpd_del(sqrt_2); mpd_del(xstep); mpd_del(ystep); return 0; }