From e1c117395995bab414914cb94865ee197b96ba04 Mon Sep 17 00:00:00 2001 From: Xerbo Date: Tue, 24 Jan 2023 22:24:47 +0000 Subject: [PATCH] Implement strip effect --- CMakeLists.txt | 2 +- aptdec-cli/main.c | 58 ++++++++++++++++++++++++++++++++++++++++++----- build_arm.sh | 2 +- 3 files changed, 54 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c99a00..6b59dae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,7 +76,7 @@ else() target_compile_options(aptdec PRIVATE -Wall -Wextra -pedantic -Wno-missing-field-initializers) endif() -install(TARGETS aptdec PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/aptdec LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) +install(TARGETS aptdec PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) # Packaging string(REPLACE v "" CPACK_PACKAGE_VERSION ${VERSION}) diff --git a/aptdec-cli/main.c b/aptdec-cli/main.c index 7fe5413..581933f 100644 --- a/aptdec-cli/main.c +++ b/aptdec-cli/main.c @@ -67,6 +67,8 @@ static int freq_from_filename(const char *filename); static int satid_from_freq(int freq); static size_t callback(float *samples, size_t count, void *context); static void write_line(writer_t *png, float *row); +apt_image_t strip(apt_image_t img); +int array_contains(char **array, char *value, size_t n); static volatile int sigint_stop = 0; void sigint_handler(int signum) { @@ -361,8 +363,16 @@ static int process_file(const char *path, options_t *opts) { channel_desc[img.ch[1]] ); - writer_t *writer = writer_init(filename, APT_REGION_FULL, img.rows, PNG_COLOR_TYPE_GRAY, description); - writer_write_image(writer, &img); + writer_t *writer; + if (array_contains(effects, "strip", effects_len)) { + writer = writer_init(filename, (apt_region_t){0, APT_CH_WIDTH*2}, img.rows, PNG_COLOR_TYPE_GRAY, description); + apt_image_t _img = strip(img); + writer_write_image(writer, &_img); + free(_img.data); + } else { + writer = writer_init(filename, APT_REGION_FULL, img.rows, PNG_COLOR_TYPE_GRAY, description); + writer_write_image(writer, &img); + } writer_free(writer); } else if (strcmp(images[i], "lut") == 0) { if (opts->lut != NULL && opts->lut[0] != '\0') { @@ -393,8 +403,16 @@ static int process_file(const char *path, options_t *opts) { char description[128]; sprintf(description, "Channel A: %s - %s", channel_name[img.ch[0]], channel_desc[img.ch[0]]); - writer_t *writer = writer_init(filename, APT_REGION_CHA_FULL, img.rows, PNG_COLOR_TYPE_GRAY, description); - writer_write_image(writer, &img); + writer_t *writer; + if (array_contains(effects, "strip", effects_len)) { + writer = writer_init(filename, (apt_region_t){0, APT_CH_WIDTH}, img.rows, PNG_COLOR_TYPE_GRAY, description); + apt_image_t _img = strip(img); + writer_write_image(writer, &_img); + free(_img.data); + } else { + writer = writer_init(filename, APT_REGION_CHA_FULL, img.rows, PNG_COLOR_TYPE_GRAY, description); + writer_write_image(writer, &img); + } writer_free(writer); } else if (strcmp(images[i], "b") == 0) { char filename[269]; @@ -402,8 +420,16 @@ static int process_file(const char *path, options_t *opts) { char description[128]; sprintf(description, "Channel B: %s - %s", channel_name[img.ch[1]], channel_desc[img.ch[1]]); - writer_t *writer = writer_init(filename, APT_REGION_CHB_FULL, img.rows, PNG_COLOR_TYPE_GRAY, description); - writer_write_image(writer, &img); + writer_t *writer; + if (array_contains(effects, "strip", effects_len)) { + writer = writer_init(filename, (apt_region_t){APT_CH_WIDTH, APT_CH_WIDTH}, img.rows, PNG_COLOR_TYPE_GRAY, description); + apt_image_t _img = strip(img); + writer_write_image(writer, &_img); + free(_img.data); + } else { + writer = writer_init(filename, APT_REGION_CHB_FULL, img.rows, PNG_COLOR_TYPE_GRAY, description); + writer_write_image(writer, &img); + } writer_free(writer); } } @@ -489,3 +515,23 @@ static void write_line(writer_t *png, float *row) { png_write_row(png->png, pixels); #pragma GCC diagnostic pop } + +apt_image_t strip(apt_image_t img) { + uint8_t *data = (uint8_t *)malloc(img.rows * APT_IMG_WIDTH); + for (size_t y = 0; y < img.rows; y++) { + memcpy(&data[y*APT_IMG_WIDTH], &img.data[y*APT_IMG_WIDTH + APT_CHA_OFFSET], APT_CH_WIDTH); + memcpy(&data[y*APT_IMG_WIDTH + APT_CH_WIDTH], &img.data[y*APT_IMG_WIDTH + APT_CHB_OFFSET], APT_CH_WIDTH); + } + + img.data = data; + return img; +} + +int array_contains(char **array, char *value, size_t n) { + for (size_t i = 0; i < n; i++) { + if (strcmp(array[i], value) == 0) { + return 1; + } + } + return 0; +} \ No newline at end of file diff --git a/build_arm.sh b/build_arm.sh index 7c44c9c..aa4034f 100755 --- a/build_arm.sh +++ b/build_arm.sh @@ -4,7 +4,7 @@ # docker run -v $(pwd):/aptdec:z -w /aptdec debian:11 ./build_arm.sh apt-get update -apt-get install -y debootstrap cmake gcc-arm-linux-gnueabihf +apt-get install -y debootstrap cmake gcc-arm-linux-gnueabihf git # Prepare armhf root environment if [ ! -d root ]; then