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 |
33
src/main.c
33
src/main.c
|
@ -8,6 +8,8 @@
|
||||||
#include "gfx.h"
|
#include "gfx.h"
|
||||||
#include "distance.h"
|
#include "distance.h"
|
||||||
|
|
||||||
|
#define CUT_CHUNK_SIZE 50
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t width;
|
uint32_t width;
|
||||||
uint32_t height;
|
uint32_t height;
|
||||||
|
@ -115,7 +117,7 @@ uint32_t image_find_best_line(image_T* image) {
|
||||||
return line_id;
|
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;
|
uint32_t x = line_id;
|
||||||
|
|
||||||
for (uint32_t y = image->new_height-1; y > 0; y--) {
|
for (uint32_t y = image->new_height-1; y > 0; y--) {
|
||||||
|
@ -123,13 +125,18 @@ void image_cut_line(image_T* image, uint32_t line_id) {
|
||||||
x += dist.direction;
|
x += dist.direction;
|
||||||
memcpy(&image->buffer[(image->width * y) + x], &image->buffer[(image->width * y) + x + 1], (image->new_width - x) * sizeof(uint32_t));
|
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));
|
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));
|
||||||
|
|
||||||
|
if (draw_cut) {
|
||||||
gfx_color(0, 0xFF, 0);
|
gfx_color(0, 0xFF, 0);
|
||||||
gfx_point((int) x, (int) y);
|
gfx_point((int) x, (int) y);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
image->new_width -= 1;
|
image->new_width -= 1;
|
||||||
|
|
||||||
|
if (draw_cut) {
|
||||||
gfx_flush();
|
gfx_flush();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void image_dump(image_T* image) {
|
void image_dump(image_T* image) {
|
||||||
for (int y = 0; y < image->new_height; y++) {
|
for (int y = 0; y < image->new_height; y++) {
|
||||||
|
@ -167,10 +174,11 @@ void image_export(image_T* image, const char* filename) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
printf("Line Cutter - Juniorcamp Informatik\n");
|
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");
|
gfx_open(800, 600, "Juniorcamp Informatik - Line Cutter");
|
||||||
image_dump(image);
|
image_dump(image);
|
||||||
|
@ -178,15 +186,32 @@ int main() {
|
||||||
bool running = true;
|
bool running = true;
|
||||||
while(running) {
|
while(running) {
|
||||||
char c = gfx_wait();
|
char c = gfx_wait();
|
||||||
image_dump(image);
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 's': {
|
case 's': {
|
||||||
if (image->new_width > 0) {
|
if (image->new_width > 0) {
|
||||||
|
image_dump(image);
|
||||||
image_calculate_dist_buffer(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;
|
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': {
|
case 'e': {
|
||||||
time_t time_raw = time(NULL);
|
time_t time_raw = time(NULL);
|
||||||
struct tm* timestamp = localtime(&time_raw);
|
struct tm* timestamp = localtime(&time_raw);
|
||||||
|
|
Loading…
Reference in New Issue