cleaned up the UX (e.g. added chunked cutting)
This commit is contained in:
parent
aa66c04c17
commit
5a537d8c60
Binary file not shown.
After Width: | Height: | Size: 115 KiB |
39
src/main.c
39
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);
|
||||
|
|
Loading…
Reference in New Issue