From 07bd5be8308891f1d0c4de6959f6a55a2eb837a0 Mon Sep 17 00:00:00 2001 From: antifallobst Date: Tue, 21 Mar 2023 13:12:41 +0100 Subject: [PATCH] structurized codebase --- CMakeLists.txt | 3 ++- bench.png => images/bench.png | Bin bench_mask.png => images/bench_mask.png | Bin landscape.jpg => images/landscape.jpg | Bin paris.png => images/paris.png | Bin paris_mask.png => images/paris_mask.png | Bin gfx.h => inc/gfx.h | 0 gfx.c => src/gfx.c | 0 main.c => src/main.c | 23 ++++++++++++++++++++--- 9 files changed, 22 insertions(+), 4 deletions(-) rename bench.png => images/bench.png (100%) rename bench_mask.png => images/bench_mask.png (100%) rename landscape.jpg => images/landscape.jpg (100%) rename paris.png => images/paris.png (100%) rename paris_mask.png => images/paris_mask.png (100%) rename gfx.h => inc/gfx.h (100%) rename gfx.c => src/gfx.c (100%) rename main.c => src/main.c (89%) diff --git a/CMakeLists.txt b/CMakeLists.txt index b531b90..b510fbe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,8 @@ project(Juniorcamp C) set(CMAKE_C_STANDARD 99) -add_executable(Juniorcamp main.c gfx.c) +add_executable(Juniorcamp src/main.c src/gfx.c) target_link_libraries(Juniorcamp imago m X11) +target_include_directories(Juniorcamp PRIVATE inc) target_link_directories(Juniorcamp PRIVATE /usr/local/lib/) \ No newline at end of file diff --git a/bench.png b/images/bench.png similarity index 100% rename from bench.png rename to images/bench.png diff --git a/bench_mask.png b/images/bench_mask.png similarity index 100% rename from bench_mask.png rename to images/bench_mask.png diff --git a/landscape.jpg b/images/landscape.jpg similarity index 100% rename from landscape.jpg rename to images/landscape.jpg diff --git a/paris.png b/images/paris.png similarity index 100% rename from paris.png rename to images/paris.png diff --git a/paris_mask.png b/images/paris_mask.png similarity index 100% rename from paris_mask.png rename to images/paris_mask.png diff --git a/gfx.h b/inc/gfx.h similarity index 100% rename from gfx.h rename to inc/gfx.h diff --git a/gfx.c b/src/gfx.c similarity index 100% rename from gfx.c rename to src/gfx.c diff --git a/main.c b/src/main.c similarity index 89% rename from main.c rename to src/main.c index 9a7bb1c..13b597a 100644 --- a/main.c +++ b/src/main.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "gfx.h" #define MASK_MULTIPLIER 50 @@ -104,9 +105,9 @@ void image_calculate_dist_buffer(image_T* image) { shortest_dist = (distance_T) {dist, -1}; } - dist = -10; + dist = 0; dist += dist_last_row[x].distance; - dist += pixel_distance(pixel_row[x - 1], pixel_row[x + 1], mask_row[x]); + dist += pixel_distance(pixel_row[x - 1], pixel_row[x + 1], mask_row[x]) * 2; if (x == 0 || shortest_dist.distance > dist) { shortest_dist = (distance_T) {dist, 0}; @@ -185,14 +186,19 @@ void image_dump(image_T* image) { } gfx_flush(); +} +void image_export(image_T* image, const char* filename) { + printf("exporting image to '%s'\n", filename); + struct img_pixmap img; + img_init(&img); } int main(int argc, char* argv[]) { printf("Line Cutter - Juniorcamp Informatik\n"); - image_T* image = image_load("../paris.png", "../paris_mask.png"); + image_T* image = image_load("../bench.png", "../bench_mask.png"); gfx_open(800, 600, "Juniorcamp Informatik - Line Cutter"); image_dump(image); @@ -209,6 +215,17 @@ int main(int argc, char* argv[]) { } break; } + case 'e': { + time_t time_raw = time(NULL); + struct tm* timestamp = localtime(&time_raw); + + char filename[64]; + snprintf(filename, 64, "../output/export_%04d-%02d-%02d_%02d-%02d-%02d.png", + 1900+timestamp->tm_year, 1+timestamp->tm_mon, timestamp->tm_mday, + timestamp->tm_hour, timestamp->tm_min, timestamp->tm_sec); + image_export(image, filename); + break; + } case 'q': { running = false; break;