diff --git a/images/landscape2.jpg b/images/landscape2.jpg new file mode 100644 index 0000000..b11e8b2 Binary files /dev/null and b/images/landscape2.jpg differ diff --git a/src/main.c b/src/main.c index 1703957..90a471f 100644 --- a/src/main.c +++ b/src/main.c @@ -8,6 +8,8 @@ #include "gfx.h" #include "distance.h" +#define CUT_CHUNK_SIZE 50 + typedef struct { uint32_t width; uint32_t height; @@ -115,7 +117,7 @@ uint32_t image_find_best_line(image_T* image) { return line_id; } -void image_cut_line(image_T* image, uint32_t line_id) { +void image_cut_line(image_T* image, uint32_t line_id, bool draw_cut) { uint32_t x = line_id; for (uint32_t y = image->new_height-1; y > 0; y--) { @@ -123,12 +125,17 @@ void image_cut_line(image_T* image, uint32_t line_id) { x += dist.direction; memcpy(&image->buffer[(image->width * y) + x], &image->buffer[(image->width * y) + x + 1], (image->new_width - x) * sizeof(uint32_t)); if (image->mask_buffer != NULL) memcpy(&image->mask_buffer[(image->width * y) + x], &image->mask_buffer[(image->width * y) + x + 1], (image->new_width - x) * sizeof(uint32_t)); - gfx_color(0, 0xFF, 0); - gfx_point((int)x, (int)y); + + if (draw_cut) { + gfx_color(0, 0xFF, 0); + gfx_point((int) x, (int) y); + } } image->new_width -= 1; - gfx_flush(); + if (draw_cut) { + gfx_flush(); + } } void image_dump(image_T* image) { @@ -167,10 +174,11 @@ void image_export(image_T* image, const char* filename) { } + int main() { printf("Line Cutter - Juniorcamp Informatik\n"); - image_T* image = image_load("../images/paris.png", "../images/paris_mask.png"); + image_T* image = image_load("../images/landscape2.jpg", NULL); gfx_open(800, 600, "Juniorcamp Informatik - Line Cutter"); image_dump(image); @@ -178,15 +186,32 @@ int main() { bool running = true; while(running) { char c = gfx_wait(); - image_dump(image); switch (c) { case 's': { if (image->new_width > 0) { + image_dump(image); image_calculate_dist_buffer(image); - image_cut_line(image, image_find_best_line(image)); + image_cut_line(image, image_find_best_line(image), true); } break; } + case 'c': { + int n = CUT_CHUNK_SIZE < image->new_width ? CUT_CHUNK_SIZE : image->new_width; + for (int i = 0; i < n; i++) { + image_calculate_dist_buffer(image); + image_cut_line(image, image_find_best_line(image), false); + printf("Progress: %d/%d\r", i+1, n); + fflush(stdout); + } + printf("\ndone\n"); + gfx_clear(); + image_dump(image); + break; + } + case 'd': { + image_dump(image); + break; + } case 'e': { time_t time_raw = time(NULL); struct tm* timestamp = localtime(&time_raw);