From d138bc52cd8d4495922f318a325bc9944f3124d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedek=20Szab=C3=B3?= Date: Fri, 30 Aug 2024 19:55:23 +0200 Subject: [PATCH 01/10] fix some weird things --- PNG_generator.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/PNG_generator.c b/PNG_generator.c index b040672..ad63524 100644 --- a/PNG_generator.c +++ b/PNG_generator.c @@ -50,10 +50,7 @@ int generatePNG(const char *filename, unsigned int width, unsigned int height, b if (alpha == true) { // If alpha true run png_bytep *row_pointers = (png_bytep *)malloc(sizeof(png_bytep) * height); for (int y = 0; y < height; y++) { - row_pointers[y] = - (png_byte *)malloc(4 * width); // 4 bytes per pixel (RGBA) - - // Fill row_pointers[y] with your image data for this row. + row_pointers[y] = (png_byte *)malloc(4 * width); // 4 bytes per pixel (RGBA) for (int x = 0; x < width; x++) { row_pointers[y][4 * x] = rand() % (255 + 1); // Red channel @@ -84,10 +81,7 @@ int generatePNG(const char *filename, unsigned int width, unsigned int height, b // Write the image data png_bytep *row_pointers = (png_bytep *)malloc(sizeof(png_bytep) * height); for (int y = 0; y < height; y++) { - row_pointers[y] = - (png_byte *)malloc(3 * width); // 4 bytes per pixel (RGBA) - - // Fill row_pointers[y] with your image data for this row. + row_pointers[y] = (png_byte *)malloc(3 * width); // 3 bytes per pixel (RGB) for (int x = 0; x < width; x++) { row_pointers[y][3 * x] = rand() % (255 + 1); // Red channel From 4316001502b2f1abfa85ecbcdbc30e16be077364 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedek=20Szab=C3=B3?= Date: Fri, 30 Aug 2024 20:05:54 +0200 Subject: [PATCH 02/10] tidying for upcoming stuffs --- JPEG_generator.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/JPEG_generator.c b/JPEG_generator.c index 58ee1c7..0d9d4b1 100644 --- a/JPEG_generator.c +++ b/JPEG_generator.c @@ -20,10 +20,9 @@ void generateJPEG(char *filename, long width, long height, int quality) { exit(1); } - int i, j; - for (i = 0; i < height; i++) { - for (j = 0; j < width; j++) { - int index = (i * width + j) * 3; // Calculate index for RGB values + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { + int index = (y * width + x) * 3; // Calculate index for RGB values image_buffer[index] = rand() % (255 + 1); // Red image_buffer[index + 1] = rand() % (255 + 1); // Green image_buffer[index + 2] = rand() % (255 + 1); // Blue From d7a866d06bc3e8661d15715060ecab05d8dac9d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedek=20Szab=C3=B3?= Date: Wed, 18 Sep 2024 10:42:05 +0200 Subject: [PATCH 03/10] Add RGB control for colored images, random TV/sensor noise, and new command-line options --rgb / --RGB and --sensor-noise --- JPEG_generator.c | 21 ++++++++++--- JPEG_generator.h | 4 +-- PNG_generator.c | 50 +++++++++++++++++++----------- PNG_generator.h | 3 +- main.c | 81 ++++++++++++++++++++++++++++++++++++------------ my_utils.c | 26 ++++++++++++++++ my_utils.h | 4 +++ 7 files changed, 145 insertions(+), 44 deletions(-) diff --git a/JPEG_generator.c b/JPEG_generator.c index 0d9d4b1..e821cb3 100644 --- a/JPEG_generator.c +++ b/JPEG_generator.c @@ -1,12 +1,17 @@ #include #include +#include +#include #include +#include #include "jpeglib.h" #include "JPEG_generator.h" +#include "my_utils.h" /* Function to write a JPEG file */ -void generateJPEG(char *filename, long width, long height, int quality) { +void generateJPEG(char *filename, long width, long height, int quality, uint8_t r, uint8_t g, uint8_t b, bool random_multiplier) { + float multiplier = 0.0f; struct jpeg_compress_struct cinfo; struct jpeg_error_mgr jerr; FILE *outfile; @@ -19,13 +24,21 @@ void generateJPEG(char *filename, long width, long height, int quality) { fprintf(stderr, "\nFailed to allocate memory for image buffer\n"); exit(1); } + // 1x1 + + for (int y = 0; y < height; y++) { + if (random_multiplier == true) { + multiplier = (rand() % 11)/10.0f; + } else { + multiplier = 1.0f; + } for (int x = 0; x < width; x++) { int index = (y * width + x) * 3; // Calculate index for RGB values - image_buffer[index] = rand() % (255 + 1); // Red - image_buffer[index + 1] = rand() % (255 + 1); // Green - image_buffer[index + 2] = rand() % (255 + 1); // Blue + image_buffer[index] = random_pixel(r, multiplier); // Red + image_buffer[index + 1] = random_pixel(g, multiplier); // Green + image_buffer[index + 2] = random_pixel(b, multiplier); // Blue } } diff --git a/JPEG_generator.h b/JPEG_generator.h index d37c104..6dbe2f3 100644 --- a/JPEG_generator.h +++ b/JPEG_generator.h @@ -1,6 +1,6 @@ #ifndef JPEG_GENERATOR #define JPEG_GENERATOR +#include -void generateJPEG(char *filename, long width, long height, int quality); - +void generateJPEG(char *filename, long width, long height, int quality, uint8_t r, uint8_t g, uint8_t b, bool random_multiplier); #endif // JPEG_GENERATOR diff --git a/PNG_generator.c b/PNG_generator.c index ad63524..9d00695 100644 --- a/PNG_generator.c +++ b/PNG_generator.c @@ -1,4 +1,3 @@ -// Include necessary header files #include #include #include @@ -7,8 +6,11 @@ #include "PNG_generator.h" -int generatePNG(const char *filename, unsigned int width, unsigned int height, bool alpha, bool allowDebugInfo) { - // Initialize PNG structures and open a file for writing +int generatePNG(const char *filename, unsigned int width, unsigned int height, bool alpha, bool allowDebugInfo, uint8_t r, uint8_t g, uint8_t b, bool random_multiplier) { + + float multiplier = 0.0f; + + // Initialize PNG structures and open a file for writing FILE *fp = fopen(filename, "wb"); // Handle file opening error @@ -50,14 +52,19 @@ int generatePNG(const char *filename, unsigned int width, unsigned int height, b if (alpha == true) { // If alpha true run png_bytep *row_pointers = (png_bytep *)malloc(sizeof(png_bytep) * height); for (int y = 0; y < height; y++) { - row_pointers[y] = (png_byte *)malloc(4 * width); // 4 bytes per pixel (RGBA) - - for (int x = 0; x < width; x++) { - row_pointers[y][4 * x] = rand() % (255 + 1); // Red channel - row_pointers[y][4 * x + 1] = rand() % (255 + 1); // Green channel - row_pointers[y][4 * x + 2] = rand() % (255 + 1); // Blue channel - row_pointers[y][4 * x + 3] = rand() % (255 + 1); // Alpha channel - } + if (random_multiplier == true) { + multiplier = (rand() % 11)/10.0f; + } else { + multiplier = 1.0f; + } + + row_pointers[y] = (png_byte *)malloc(4 * width); // 4 bytes per pixel (RGBA) + for (int x = 0; x < width; x++) { + row_pointers[y][4 * x] = random_pixel(r, multiplier); // Red channel + row_pointers[y][4 * x + 1] = random_pixel(g, multiplier); // Green channel + row_pointers[y][4 * x + 2] = random_pixel(b, multiplier); // Blue channel + row_pointers[y][4 * x + 3] = random_pixel(255, multiplier); // Alpha channel + } } int color_type = PNG_COLOR_TYPE_RGBA; @@ -80,14 +87,21 @@ int generatePNG(const char *filename, unsigned int width, unsigned int height, b } else { // If alpha false, run // Write the image data png_bytep *row_pointers = (png_bytep *)malloc(sizeof(png_bytep) * height); - for (int y = 0; y < height; y++) { - row_pointers[y] = (png_byte *)malloc(3 * width); // 3 bytes per pixel (RGB) - for (int x = 0; x < width; x++) { - row_pointers[y][3 * x] = rand() % (255 + 1); // Red channel - row_pointers[y][3 * x + 1] = rand() % (255 + 1); // Green channel - row_pointers[y][3 * x + 2] = rand() % (255 + 1); // Blue channel - } + for (int y = 0; y < height; y++) { + if (random_multiplier == true) { + multiplier = (rand() % 11)/10.0f; + } else { + multiplier = 1.0f; + } + + //printf("multiplier: %f\n", multiplier); + row_pointers[y] = (png_byte *)malloc(3 * width); // 3 bytes per pixel (RGB) + for (int x = 0; x < width; x++) { + row_pointers[y][3 * x] = random_pixel(r, multiplier); printDebugPlusInt("r:", r); // Red channel + row_pointers[y][3 * x + 1] = random_pixel(g, multiplier); printDebugPlusInt("g:", g); // Green channel + row_pointers[y][3 * x + 2] = random_pixel(b, multiplier); printDebugPlusInt("g:", b); // Blue channel + } } int color_type = PNG_COLOR_TYPE_RGB; diff --git a/PNG_generator.h b/PNG_generator.h index 2676037..c20ef68 100644 --- a/PNG_generator.h +++ b/PNG_generator.h @@ -2,7 +2,8 @@ #define PNG_GENERATOR #include +#include -int generatePNG(const char *filename, unsigned int width, unsigned int height, bool alpha, bool allowDebugInfo); +int generatePNG(const char *filename, unsigned int width, unsigned int height, bool alpha, bool allowDebugInfo, uint8_t r, uint8_t g, uint8_t b, bool random_multiplier); #endif diff --git a/main.c b/main.c index 466eb45..ff29f2a 100644 --- a/main.c +++ b/main.c @@ -13,6 +13,7 @@ #include #include #include +#include const int MS = 1000; @@ -42,10 +43,13 @@ int main(int argc, char* argv[]) int n; bool help = false; bool termuxExternal = false; + bool random_multiplier = false; char outDir[] = "out"; char androidInternalPath[] = "/storage/emulated/0/"; - int quality = 100; - + uint8_t quality = 100; + uint8_t r = 255; // Test values + uint8_t g = 255; + uint8_t b = 255; // Terminal sizes: @@ -56,20 +60,18 @@ int main(int argc, char* argv[]) }*/ // Number of the same arguments - short unsigned int sCount = 0; // -s, --size - short unsigned int cCount = 0; // -c --count - short unsigned int aCount = 0; // -a --alpha - short unsigned int hCount = 0; // -h --help - short unsigned int tCount = 0; // --termux_external - short unsigned int dCount = 0; // -d --debug - short unsigned int fCount = 0; // -f --format - short unsigned int qCount = 0; // -f --format + short unsigned int sCount = 0; // -s, --size + short unsigned int cCount = 0; // -c --count + short unsigned int aCount = 0; // -a --alpha + short unsigned int hCount = 0; // -h --help + short unsigned int tCount = 0; // --termux_external + short unsigned int dCount = 0; // -d --debug + short unsigned int fCount = 0; // -f --format + short unsigned int qCount = 0; // -q --quality + short unsigned int rgbCount = 0; // --rgb --RGB + short unsigned int snCount = 0; // --sensor-noise - // Print the arguments - // for (int i = 0; i <= argc+1; i++) { - // printf("Argv%d = %s\n", i, argv[i]); - //} // Handle the arguments. for (n = 1; n < argc; n++) { @@ -137,7 +139,47 @@ int main(int argc, char* argv[]) printf("Missing quality value after -q or --quality.\n"); return 3; } + } else if (strcmp(argv[n], "--rgb") == 0 || strcmp(argv[n], "--RGB") == 0) { + if ((argv[n + 1]) != NULL) { + r = atoi(argv[n + 1]); + if (r <= 255 && r >= 0) { + + } else { + printf("Red value isn't set correctly!\n"); + return 3; + } + } else { + printf("Red value missing!\n"); + return 3; + } + if ((argv[n + 2]) != NULL) { + g = atoi(argv[n + 2]); + if (g <= 255 && g >= 0) { + + } else { + printf("Green value isn't set correctly!\n"); + return 3; + } + } else { + printf("Green value missing!\n"); + return 3; + } + if ((argv[n + 3]) != NULL) { + b = atoi(argv[n + 3]); + if (b <= 255 && b >= 0) { + } else { + printf("Blue value isn't set correctly!\n"); + return 3; + } + } else { + printf("Blue value missing!\n"); + return 3; + } + n += 3; + } else if (strcmp(argv[n], "--sensor-noise") == 0) { + random_multiplier = true; + n++; } else { // If there is no known argument at a given argc location. printf("Unknown option \"%s\" at the %d. argument. Use -h for help.\n", argv[n], n); return 3; @@ -160,6 +202,9 @@ int main(int argc, char* argv[]) + printDebugPlusInt("r", r); + printDebugPlusInt("g", g); + printDebugPlusInt("b", b); // Depends on allowDebugInfo == true @@ -199,7 +244,6 @@ int main(int argc, char* argv[]) return 0; } - // New: dirCreatorLinux(outDir, termuxExternal); @@ -250,7 +294,6 @@ int main(int argc, char* argv[]) printDebugPlusFloat("time:", genTime * (args->total - args->progress)); - //progressbar(i, count, terminalWidth - 30, genTime); ----------------------------- // Create file for image sprintf(imagename, "%s/random_image%d.%s", outDir, i, format); @@ -258,10 +301,10 @@ int main(int argc, char* argv[]) if (strcmp(format, "png") == 0) { // Write PNG file - errorCount = errorCount + generatePNG(imagename, width, height, alpha, allowDebugInfo); + errorCount = errorCount + generatePNG(imagename, width, height, alpha, allowDebugInfo, r, g, b, random_multiplier); } else { // Write JPEG file - generateJPEG(imagename, width, height, quality); + generateJPEG(imagename, width, height, quality, r, g, b, random_multiplier); } @@ -313,7 +356,7 @@ int main(int argc, char* argv[]) printf(" Moving files\n"); // TODO: Make a progressbar - // To do that, I need to manually move the files. + // use ls and mv -v (verbose flag) to check the strings // The directory will be made with dirCreatorLinux, so the files should be only moved to it. shellCommand[0] = '\0'; // Initialize it as an empty string diff --git a/my_utils.c b/my_utils.c index 1e07164..b13c6b8 100644 --- a/my_utils.c +++ b/my_utils.c @@ -4,6 +4,8 @@ #include #include #include +#include +#include #include "my_utils.h" @@ -130,3 +132,27 @@ void printHelp() { "Example:\n" " -s 10 20 -a -c 10 -f png\n", RIG_VERSION); } + +uint8_t random_pixel(uint8_t max_value, float multiplier) { + //printf("\nmao\n"); + uint8_t pixel = 0; + if (max_value == 0) { + return pixel; + } + if (multiplier < 0.1) { + multiplier = 1.0; + } + if (multiplier < 0.2) { + multiplier = 0.3; + } + if (multiplier < 0.3) { + multiplier = 0.5; + } + multiplier = sqrt(multiplier); + pixel = rand() % (uint16_t)((max_value + 1) * multiplier); + + //printDebugPlusInt("Max value:", max_value); + //printDebugPlusFloat("Multiplier:", multiplier); //printf("Multiplier: %lf\n", multiplier); + //printDebugPlusInt("Pixel:", pixel); + return pixel; +} diff --git a/my_utils.h b/my_utils.h index 2741d29..b2fb656 100644 --- a/my_utils.h +++ b/my_utils.h @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include "version.h" @@ -34,5 +36,7 @@ void printDebugPlusInt(char text[], int numVar); void printDebugPlusFloat(char text[], double flVar); void printDebugPlusStr(char text[], char strVar[]); void printHelp(); +uint8_t random_pixel(uint8_t max_value, float multipier); + #endif From 619b964ee56b75fd200bd4e170de788cbe046ee0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedek=20Szab=C3=B3?= Date: Sat, 21 Sep 2024 19:36:30 +0200 Subject: [PATCH 04/10] Simplified help message printing. --- my_utils.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/my_utils.c b/my_utils.c index b13c6b8..7e25bd8 100644 --- a/my_utils.c +++ b/my_utils.c @@ -12,6 +12,8 @@ #define COLOR_BOLD "\e[1m" #define COLOR_OFF "\033[m" +#define BOLD(x) "\e[1m"x"\033[m" + // Global vars struct timespec ts; @@ -100,6 +102,8 @@ void printDebugPlusStr(char text[], char strVar[]){ } } + + void printHelp() { system("clear"); printf( "Random Image Generator %s.\n" @@ -109,24 +113,24 @@ void printHelp() { "\n" "RIG options:\n" "\n" - " "COLOR_BOLD "-s" COLOR_OFF " or "COLOR_BOLD "--size" COLOR_OFF " \n" // "COLOR_BOLD "" COLOR_OFF " + " " BOLD("-s") " or " BOLD("--size") " \n" " Changed the order in 2.0!\n" "\n" - " "COLOR_BOLD "-c" COLOR_OFF " or "COLOR_BOLD "--count" COLOR_OFF " \n" + " " BOLD("-c") " or " BOLD("--count") " \n" "\n" - " "COLOR_BOLD "-f" COLOR_OFF " or "COLOR_BOLD "--format" COLOR_OFF " \n" + " " BOLD("-f") " or " BOLD("--format") " \n" " It supports png or jpg (jpeg) formats. When not used, defaults to png.\n" "\n" - " "COLOR_BOLD "-a" COLOR_OFF " or "COLOR_BOLD "--alpha" COLOR_OFF "\n" + " " BOLD("-a") " or " BOLD("--alpha") "\n" " Use transparent pixels in png. With jpeg, this will be ignored.\n" "\n" - " "COLOR_BOLD "--termux-external" COLOR_OFF "\n" + " " BOLD("--termux-external") "\n" " When used in Termux, images will be moved to your internal storage.\n" "\n" - " "COLOR_BOLD "-d" COLOR_OFF " or "COLOR_BOLD "--debug" COLOR_OFF "\n" + " " BOLD("-d") " or " BOLD("--debug") "\n" " Print debug info.\n" "\n" - " "COLOR_BOLD "-h" COLOR_OFF " or "COLOR_BOLD "--help" COLOR_OFF "\n" + " " BOLD("-h") " or " BOLD("--help") "\n" " Prints this message to console.\n" "\n" "Example:\n" From 9ec27bc2526f81fa0f6c8ee98883588f2739cbb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedek=20Szab=C3=B3?= Date: Sat, 21 Sep 2024 20:34:22 +0200 Subject: [PATCH 05/10] Added description in help for the new options. --- my_utils.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/my_utils.c b/my_utils.c index 7e25bd8..479a443 100644 --- a/my_utils.c +++ b/my_utils.c @@ -117,6 +117,7 @@ void printHelp() { " Changed the order in 2.0!\n" "\n" " " BOLD("-c") " or " BOLD("--count") " \n" + " This many images will be generated.\n" "\n" " " BOLD("-f") " or " BOLD("--format") " \n" " It supports png or jpg (jpeg) formats. When not used, defaults to png.\n" @@ -130,6 +131,12 @@ void printHelp() { " " BOLD("-d") " or " BOLD("--debug") "\n" " Print debug info.\n" "\n" + " " BOLD("--rgb") " or " BOLD("--RGB") " \n" + " This sets the max values in each channel, so you can make colorful or darker images.\n" + "\n" + " " BOLD("--sensor-noise") "\n" + " Puts lines on the pictures, like image sensors with high iso.\n" + "\n" " " BOLD("-h") " or " BOLD("--help") "\n" " Prints this message to console.\n" "\n" From c9a5066ee78ba708e44cb68dc86de69d38fd3e61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedek=20Szab=C3=B3?= Date: Mon, 4 Nov 2024 12:21:35 +0100 Subject: [PATCH 06/10] Added --rgb / --RGB command-line option to set custom RGB values for image generation; Added --sensor-noise setting. Code changes: Separated random pixel generation to a function for maintainability, simplified help message screen, etc... --- PNG_generator.c | 2 +- main.c | 34 +++++++++++++++++++--------------- my_utils.c | 2 +- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/PNG_generator.c b/PNG_generator.c index 9d00695..2ca4f1e 100644 --- a/PNG_generator.c +++ b/PNG_generator.c @@ -34,7 +34,7 @@ int generatePNG(const char *filename, unsigned int width, unsigned int height, b if (!info_ptr) { png_destroy_write_struct(&png_ptr, NULL); fclose(fp); - printDebug("Error creating tunsigned inthe image file. png error 3"); + printDebug("Error creating unsigned int image file. png error 3"); return 3; } diff --git a/main.c b/main.c index ff29f2a..1ba65cb 100644 --- a/main.c +++ b/main.c @@ -50,6 +50,7 @@ int main(int argc, char* argv[]) uint8_t r = 255; // Test values uint8_t g = 255; uint8_t b = 255; + int temp = 0; // Terminal sizes: @@ -141,11 +142,11 @@ int main(int argc, char* argv[]) } } else if (strcmp(argv[n], "--rgb") == 0 || strcmp(argv[n], "--RGB") == 0) { if ((argv[n + 1]) != NULL) { - r = atoi(argv[n + 1]); - if (r <= 255 && r >= 0) { - + temp = atoi(argv[n + 1]); + if (temp <= 255 && r >= 0) { + r = temp; } else { - printf("Red value isn't set correctly!\n"); + printf("Red value is outside of the range (0-255)!\n"); return 3; } } else { @@ -153,11 +154,11 @@ int main(int argc, char* argv[]) return 3; } if ((argv[n + 2]) != NULL) { - g = atoi(argv[n + 2]); - if (g <= 255 && g >= 0) { - + temp = atoi(argv[n + 2]); + if (temp <= 255 && g >= 0) { + g = temp; } else { - printf("Green value isn't set correctly!\n"); + printf("Green value is outside of the range (0-255)!\n"); return 3; } } else { @@ -165,11 +166,12 @@ int main(int argc, char* argv[]) return 3; } if ((argv[n + 3]) != NULL) { - b = atoi(argv[n + 3]); - if (b <= 255 && b >= 0) { - + temp = atoi(argv[n + 3]); + printf("atoi %d\n", temp); + if (temp <= 255 && b >= 0) { + b = temp; } else { - printf("Blue value isn't set correctly!\n"); + printf("Blue value is outside of the range (0-255)!\n"); return 3; } } else { @@ -202,14 +204,16 @@ int main(int argc, char* argv[]) - printDebugPlusInt("r", r); - printDebugPlusInt("g", g); - printDebugPlusInt("b", b); + + printf("mao\n"); // Depends on allowDebugInfo == true errorFileOpener(); + printDebugPlusInt("r", r); + printDebugPlusInt("g", g); + printDebugPlusInt("b", b); // All printDebug depends on errorFileOpener printDebugPlusInt("sCount = ", sCount); diff --git a/my_utils.c b/my_utils.c index 479a443..6eeca2c 100644 --- a/my_utils.c +++ b/my_utils.c @@ -132,7 +132,7 @@ void printHelp() { " Print debug info.\n" "\n" " " BOLD("--rgb") " or " BOLD("--RGB") " \n" - " This sets the max values in each channel, so you can make colorful or darker images.\n" + " This sets the values in each channel, so you can make colorful or darker images.\n" "\n" " " BOLD("--sensor-noise") "\n" " Puts lines on the pictures, like image sensors with high iso.\n" From d562418a576f0d7fb3fecfa07f1e5384f0217791 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedek=20Szab=C3=B3?= Date: Mon, 4 Nov 2024 12:30:38 +0100 Subject: [PATCH 07/10] Removed some comments --- JPEG_generator.c | 10 +++++----- JPEG_generator.h | 2 +- dir_creator.c | 31 ++++++++++++++----------------- main.c | 5 ++--- 4 files changed, 22 insertions(+), 26 deletions(-) diff --git a/JPEG_generator.c b/JPEG_generator.c index e821cb3..6ecedb9 100644 --- a/JPEG_generator.c +++ b/JPEG_generator.c @@ -24,7 +24,7 @@ void generateJPEG(char *filename, long width, long height, int quality, uint8_t fprintf(stderr, "\nFailed to allocate memory for image buffer\n"); exit(1); } - // 1x1 + @@ -35,10 +35,10 @@ void generateJPEG(char *filename, long width, long height, int quality, uint8_t multiplier = 1.0f; } for (int x = 0; x < width; x++) { - int index = (y * width + x) * 3; // Calculate index for RGB values - image_buffer[index] = random_pixel(r, multiplier); // Red - image_buffer[index + 1] = random_pixel(g, multiplier); // Green - image_buffer[index + 2] = random_pixel(b, multiplier); // Blue + int index = (y * width + x) * 3; + image_buffer[index] = random_pixel(r, multiplier); // R + image_buffer[index + 1] = random_pixel(g, multiplier); // G + image_buffer[index + 2] = random_pixel(b, multiplier); // B } } diff --git a/JPEG_generator.h b/JPEG_generator.h index 6dbe2f3..28bdd0b 100644 --- a/JPEG_generator.h +++ b/JPEG_generator.h @@ -3,4 +3,4 @@ #include void generateJPEG(char *filename, long width, long height, int quality, uint8_t r, uint8_t g, uint8_t b, bool random_multiplier); -#endif // JPEG_GENERATOR +#endif diff --git a/dir_creator.c b/dir_creator.c index dd02d86..d9b6be6 100644 --- a/dir_creator.c +++ b/dir_creator.c @@ -21,7 +21,7 @@ bool check_access_termux () { } -int dirCreatorLinux(char dirName[], bool isTermux) { // Starting of the function +int dirCreatorLinux(char dirName[], bool isTermux) { mkdir(dirName, 0700); @@ -33,14 +33,14 @@ int dirCreatorLinux(char dirName[], bool isTermux) { // Starting of the function if (dir != NULL) { printDebug("Output directory created"); - closedir(dir); // Close dir! - return 0; // Return directory exists. - } else if (ENOENT == errno) { // If dir not exists + closedir(dir); + return 0; + } else if (ENOENT == errno) { printDebug("Output directory doesn't exist"); - return 1; // Return directory does not exist. - } else { // If other fail - printDebug("Output directory may or may not exist"); - return 2; // Return opendir() failed for some other reason. + return 1; + } else { + printDebug("Output directory is in a superposition"); + return 2; } } else { printDebugPlusInt("check_access_termux():", check_access_termux()); @@ -69,18 +69,15 @@ int dirCreatorLinux(char dirName[], bool isTermux) { // Starting of the function } DIR *dir = opendir(androidInternalPath); // androidInternalPath should now be the dir where pics will be placed. - if (dir) { // If dir exists + if (dir) { closedir(dir); - // Close dir! - return 0; // Return directory exists. - } else if (ENOENT == errno) { // If dir not exists - return 1; // Return directory does not exist. + return 0; + } else if (ENOENT == errno) { + return 1; - } else { // If other fail - return 2; // Return opendir() failed for some other reason. + } else { + return 2; } } } - -// Megcsinálni a termux-setup-storage-t diff --git a/main.c b/main.c index 1ba65cb..c49eb79 100644 --- a/main.c +++ b/main.c @@ -1,7 +1,7 @@ #include "PNG_generator.h" #include "dir_creator.h" #include "JPEG_generator.h" -#include "my_utils.h" // my_utils.c is replaced +#include "my_utils.h" #include "progressbar.h" #include "version.h" @@ -47,12 +47,11 @@ int main(int argc, char* argv[]) char outDir[] = "out"; char androidInternalPath[] = "/storage/emulated/0/"; uint8_t quality = 100; - uint8_t r = 255; // Test values + uint8_t r = 255; uint8_t g = 255; uint8_t b = 255; int temp = 0; - // Terminal sizes: getTerminalSize(&terminalHeight, &terminalWidth); From a6ab638e0e4e791dc3bcb0a65ccedd4dc98ca80e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedek=20Szab=C3=B3?= Date: Tue, 5 Nov 2024 14:16:53 +0100 Subject: [PATCH 08/10] Removed mao --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index c49eb79..0f7cc65 100644 --- a/main.c +++ b/main.c @@ -206,7 +206,7 @@ int main(int argc, char* argv[]) - printf("mao\n"); + // Depends on allowDebugInfo == true errorFileOpener(); From 4685bc18d12e78d526a957d7557b57c393b7d7a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedek=20Szab=C3=B3?= Date: Tue, 5 Nov 2024 14:49:29 +0100 Subject: [PATCH 09/10] Fixed argument handeling. --- main.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/main.c b/main.c index 0f7cc65..ce760c7 100644 --- a/main.c +++ b/main.c @@ -119,7 +119,6 @@ int main(int argc, char* argv[]) printf("RIG currently only supports png (default) and jpeg as a format option!"); return 3; } - } else { printf("--format/-f is not set correctly or left empty, write image format after -f or --format!\n"); return 3; @@ -134,7 +133,6 @@ int main(int argc, char* argv[]) printf("Quality isn't set correctly!\n"); return 3; } - } else { printf("Missing quality value after -q or --quality.\n"); return 3; @@ -180,7 +178,6 @@ int main(int argc, char* argv[]) n += 3; } else if (strcmp(argv[n], "--sensor-noise") == 0) { random_multiplier = true; - n++; } else { // If there is no known argument at a given argc location. printf("Unknown option \"%s\" at the %d. argument. Use -h for help.\n", argv[n], n); return 3; From bf3df9a4cb45d9e12799ead85b6571f1bd121e23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedek=20Szab=C3=B3?= Date: Tue, 5 Nov 2024 14:53:18 +0100 Subject: [PATCH 10/10] Incremented version number --- version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.h b/version.h index df8f433..5458e04 100644 --- a/version.h +++ b/version.h @@ -1,7 +1,7 @@ #ifndef VERSION_H #define VERSION_H -#define RIG_VERSION "2.3.1" +#define RIG_VERSION "2.4.0" #endif