From bc4a304fa1934e5c2e644373322a8ff944c68b04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedek=20Szab=C3=B3?= Date: Sun, 12 May 2024 20:34:53 +0200 Subject: [PATCH 1/5] removed comment --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index 9811dd6..7fe25eb 100644 --- a/main.c +++ b/main.c @@ -102,7 +102,7 @@ int main(int argc, char* argv[]) } else if (strcmp(argv[n], "-f") == 0 || strcmp(argv[n], "--format") == 0) { // If n-th arg -f fCount++; if ((argv[n + 1]) != NULL) { - if (strcmp(argv[n + 1], "png") == 0) { // Segfaults here + if (strcmp(argv[n + 1], "png") == 0) { strcpy(format, "png"); n++; } else if (strcmp(argv[n + 1], "jpeg") == 0 || strcmp(argv[n + 1], "jpg") == 0) { From 65641474ef51d545c540cb58610a1386d0dbe526 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedek=20Szab=C3=B3?= Date: Mon, 10 Jun 2024 16:38:28 +0200 Subject: [PATCH 2/5] Small bug and grammar fixes, adding additional checks section in code. --- main.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/main.c b/main.c index 7fe25eb..21dfe88 100644 --- a/main.c +++ b/main.c @@ -13,7 +13,7 @@ const int MS = 1000; -char format[] = "png"; +char format[4] = "png"; int main(int argc, char* argv[]) @@ -29,7 +29,7 @@ int main(int argc, char* argv[]) - printf("Welcome to RIG\n"); + printf("Welcome to RIG %s!\n", VERSION); // Declaring vars unsigned int width = 0; @@ -109,20 +109,35 @@ int main(int argc, char* argv[]) strcpy(format, "jpg"); n++; } else { - printf("RIG currently only supports png (default) and jpg as a format option"); + 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.\nWrite image format after -f or --format\n"); + printf("--format/-f is not set correctly or left empty.\nWrite image format after -f or --format.\n"); return 3; } - } else { - printf("format is not set, defaulting to png\n"); + } else { // If there is no known argument at a given argc location. + printf("Unknown option \"%s\" at the %d. argument.\n", argv[n], n); + } + } + + // Additional checks + if (!fCount) { + printf("format is not set, defaulting to png.\n"); strcpy(format, "png"); + } else if (aCount && (strcmp(format, "jpg") == 0) ) { + printf("--alpha (transparency) option will be ignored when using jpeg.\n"); } - } + + + + + + + + // Depends on allowDebugInfo == true From 8988eb0fd94f5d68bc34e5fc27314ff1f8bebb3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedek=20Szab=C3=B3?= Date: Mon, 10 Jun 2024 16:48:27 +0200 Subject: [PATCH 3/5] renamed jpeg function --- JPEG_generator.c | 8 ++++---- main.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/JPEG_generator.c b/JPEG_generator.c index 1761256..9c15891 100644 --- a/JPEG_generator.c +++ b/JPEG_generator.c @@ -6,7 +6,7 @@ /* Function to write a JPEG file */ -void write_JPEG_file(char *filename, long width, long height, int quality) { +void generateJPEG(char *filename, long width, long height, int quality) { struct jpeg_compress_struct cinfo; struct jpeg_error_mgr jerr; FILE *outfile; @@ -24,9 +24,9 @@ void write_JPEG_file(char *filename, long width, long height, int quality) { for (i = 0; i < height; i++) { for (j = 0; j < width; j++) { int index = (i * width + j) * 3; // Calculate index for RGB values - image_buffer[index] = rand() % 256; // Red - image_buffer[index + 1] = rand() % 256; // Green - image_buffer[index + 2] = rand() % 256; // Blue + image_buffer[index] = rand() % (255 + 1); // Red + image_buffer[index + 1] = rand() % (255 + 1); // Green + image_buffer[index + 2] = rand() % (255 + 1); // Blue } } diff --git a/main.c b/main.c index 21dfe88..200d142 100644 --- a/main.c +++ b/main.c @@ -13,7 +13,7 @@ const int MS = 1000; -char format[4] = "png"; +char format[4]; int main(int argc, char* argv[]) @@ -246,7 +246,7 @@ int main(int argc, char* argv[]) errorCount = errorCount + generatePNG(imagename, width, height, alpha, allowDebugInfo); } else { // Write JPEG file - write_JPEG_file(imagename, width, height, quality); + generateJPEG(imagename, width, height, quality); } From 3f01429bb1c8921a6d008e6fd05b3fef306b5f8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedek=20Szab=C3=B3?= Date: Mon, 10 Jun 2024 17:32:56 +0200 Subject: [PATCH 4/5] Added quality toggle and fixed a few errors. Bumped ver to 2.1 --- main.c | 48 +++++++++++++++++++++++++++++++++++------------- version.c | 2 +- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/main.c b/main.c index 200d142..fb90a04 100644 --- a/main.c +++ b/main.c @@ -42,6 +42,7 @@ int main(int argc, char* argv[]) char outDir[] = "out"; char outDirTermux[] = "/storage/emulated/0/"; int termuxPermissionNeeded = 0; + int quality = 100; // Terminal sizes: @@ -60,6 +61,8 @@ int main(int argc, char* argv[]) 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 + // Print the arguments // for (int i = 0; i <= argc+1; i++) { @@ -75,8 +78,8 @@ int main(int argc, char* argv[]) height = atoi(argv[n + 2]); n += 2; } else { - printf("size is not set\n"); - return 2; + printf("Size is not specified!\n"); + return 3; } } else if (strcmp(argv[n], "-a") == 0 || strcmp(argv[n], "--alpha") == 0) { // If n-th arg -a, alpha = true; @@ -87,7 +90,7 @@ int main(int argc, char* argv[]) cCount++; n++; } else { - printf("count is not set\n"); + printf("Count is not specified!\n"); return 3; } } else if (strcmp(argv[n], "-h") == 0 || strcmp(argv[n], "--help") == 0) { // If n-th arg -h, @@ -109,14 +112,30 @@ int main(int argc, char* argv[]) strcpy(format, "jpg"); n++; } else { - printf("RIG currently only supports png (default) and jpeg as a format option."); + 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.\nWrite image format after -f or --format.\n"); + printf("--format/-f is not set correctly or left empty, write image format after -f or --format!\n"); return 3; } + } else if (strcmp(argv[n], "-q") == 0 || strcmp(argv[n], "--quality") == 0) { // If n-th arg -q + qCount++; + if ((argv[n + 1]) != NULL) { + quality = atoi(argv[n + 1]); + if (quality > 0 && quality <= 100) { + n++; + } else { + printf("Quality isn't set correctly!\n"); + return 3; + } + + } else { + printf("Missing quality value after -q or --quality.\n"); + return 3; + } + } else { // If there is no known argument at a given argc location. printf("Unknown option \"%s\" at the %d. argument.\n", argv[n], n); } @@ -124,11 +143,15 @@ int main(int argc, char* argv[]) // Additional checks if (!fCount) { - printf("format is not set, defaulting to png.\n"); - strcpy(format, "png"); - } else if (aCount && (strcmp(format, "jpg") == 0) ) { - printf("--alpha (transparency) option will be ignored when using jpeg.\n"); - } + printf("Format is not set, defaulting to png.\n"); + strcpy(format, "png"); + + } else if (aCount && (strcmp(format, "jpg") == 0) ) { + printf("--alpha (transparency) option will be ignored when using jpeg.\n"); + + } else if (!qCount) { + printf("Quality is not set, defaulting to 100.\n"); + } @@ -161,8 +184,7 @@ int main(int argc, char* argv[]) // Too few arguments warning if ((width == 0 || height == 0 || count == 0) && !help) { printf("Too few arguments. Width, height or count is 0. Unexpected " - "behaviour may occur! (Argc = %d)\n", - argc); + "behaviour may occur! (Argc = %d)\n", argc); return 1; } @@ -208,7 +230,7 @@ int main(int argc, char* argv[]) double genTime1 = 0; double genTime2 = (double)ts.tv_sec + (double)ts.tv_nsec / 1.0e9; - int quality = 100; + char fileExtension[5]; diff --git a/version.c b/version.c index 072a006..d27d321 100644 --- a/version.c +++ b/version.c @@ -1 +1 @@ -const char VERSION[] = "2.0"; +const char VERSION[] = "2.1"; From 79a6d02c89be6a01beaa7cdd09df73d9acfc7b92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedek=20Szab=C3=B3?= Date: Thu, 13 Jun 2024 13:21:24 +0200 Subject: [PATCH 5/5] fixed quality check --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index fb90a04..798afff 100644 --- a/main.c +++ b/main.c @@ -149,7 +149,7 @@ int main(int argc, char* argv[]) } else if (aCount && (strcmp(format, "jpg") == 0) ) { printf("--alpha (transparency) option will be ignored when using jpeg.\n"); - } else if (!qCount) { + } else if ((!qCount) && (strcmp(format, "jpg") == 0)) { printf("Quality is not set, defaulting to 100.\n"); }