aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2024-02-04 22:15:39 +0100
committerkdx <kikoodx@paranoici.org>2024-02-04 22:15:39 +0100
commit0fe2cfad49079dcf2387c98792f300cc558f0fae (patch)
tree07f78b648e3148b9c676b8ab4af5ba683b9832d2
parent1331a05fcacd5d734d6bf00a51d452e63d2cfe80 (diff)
downloadkld-0fe2cfad49079dcf2387c98792f300cc558f0fae.tar.gz
cool featuresHEADmain
-rwxr-xr-xbuild.sh2
-rw-r--r--compile_flags.txt2
-rw-r--r--main.c15
-rw-r--r--src/image.c47
-rw-r--r--src/image.h12
-rwxr-xr-xtests.sh2
6 files changed, 69 insertions, 11 deletions
diff --git a/build.sh b/build.sh
new file mode 100755
index 0000000..38199fd
--- /dev/null
+++ b/build.sh
@@ -0,0 +1,2 @@
+#!/bin/sh
+gcc -O3 -s -o a.out -iquotesrc main.c src/*.c -lm
diff --git a/compile_flags.txt b/compile_flags.txt
index 3f68f0b..866f869 100644
--- a/compile_flags.txt
+++ b/compile_flags.txt
@@ -1,4 +1,4 @@
--std=c99
+-std=c2x
-Wall
-Wextra
-iquotesrc
diff --git a/main.c b/main.c
index 333bb30..2fca1a9 100644
--- a/main.c
+++ b/main.c
@@ -10,15 +10,18 @@ main(int argc, char **argv)
}
KldImage *img = kld_load(argv[1]);
- KldImage *img2 = kld_dup(img);
+ KldImage *img2 = kld_load(argv[2]);
- kld_grayscale(img2);
- kld_mod(img, KLD_COLOR(255, 255, 0, 255));
- kld_mod(img2, KLD_COLOR(0, 0, 255, 255));
- kld_add(img, img2);
+ kld_hinterlace(img, img2);
+ kld_bit3(img);
+ kld_free(img2);
+ img2 = kld_dup(img);
+ kld_vflip(img2);
+ kld_hflip(img2);
+ kld_vinterlace(img, img2);
kld_writePAM(img, stdout);
- kld_free(img2);
kld_free(img);
+ kld_free(img2);
return EXIT_SUCCESS;
}
diff --git a/src/image.c b/src/image.c
index 2909218..2709f3e 100644
--- a/src/image.c
+++ b/src/image.c
@@ -638,3 +638,50 @@ kld_subalpha(KldImage *img, KldImage *other)
return 0;
}
+
+int
+kld_vinterlace(KldImage *img, KldImage *other)
+{
+ NULL_SAFETY(-1);
+ NULL_SAFETY_EX(other, -1);
+
+ if (img->width != other->width || img->height != other->height) {
+ log_error("img (%lu x %lu) and other (%lu x %lu) "
+ "dims don't match",
+ img->width, img->height, other->width, other->height);
+ return -1;
+ }
+
+ for (size_t y = 1; y < img->height; y += 2) {
+ for (size_t x = 0; x < img->width; x++) {
+ const KldColor c = KLD_GET(other, x, y);
+ KLD_SET(img, x, y, c);
+ }
+ }
+
+ return 0;
+}
+
+int
+kld_hinterlace(KldImage *img, KldImage *other)
+{
+ NULL_SAFETY(-1);
+ NULL_SAFETY_EX(other, -1);
+
+ if (img->width != other->width || img->height != other->height) {
+ log_error("img (%lu x %lu) and other (%lu x %lu) "
+ "dims don't match",
+ img->width, img->height, other->width, other->height);
+ return -1;
+ }
+
+ for (size_t y = 0; y < img->height; y++) {
+ for (size_t x = 1; x < img->width; x += 2) {
+ const KldColor c = KLD_GET(other, x, y);
+ KLD_SET(img, x, y, c);
+ }
+ }
+
+ return 0;
+}
+
diff --git a/src/image.h b/src/image.h
index 59758a6..04d662d 100644
--- a/src/image.h
+++ b/src/image.h
@@ -6,7 +6,7 @@
#define KLD_GET(I, X, Y) ((I)->data[X + Y * (I)->width])
#define KLD_SET(I, X, Y, V) (I)->data[X + Y * (I)->width] = V
-/* return NULL on error */
+/* return nullptr on error */
KldImage *kld_alloc(size_t w, size_t h);
void kld_free(KldImage *img);
@@ -15,10 +15,10 @@ KldColor kld_get(KldImage *img, int x, int y);
void kld_set(KldImage *img, int x, int y, KldColor col);
-/* return NULL on error */
+/* return nullptr on error */
KldImage *kld_load(const char *path);
-/* return NULL on error */
+/* return nullptr on error */
KldImage *kld_dup(KldImage *img);
/* on error, return -1 and make no change */
@@ -79,3 +79,9 @@ int kld_sub(KldImage *img, KldImage *other);
/* return -1 if sizes are not equal */
int kld_subalpha(KldImage *img, KldImage *other);
+
+/* return -1 if sizes are not equal */
+int kld_vinterlace(KldImage *img, KldImage *other);
+
+/* return -1 if sizes are not equal */
+int kld_hinterlace(KldImage *img, KldImage *other);
diff --git a/tests.sh b/tests.sh
index ef6e149..6074dd2 100755
--- a/tests.sh
+++ b/tests.sh
@@ -1,3 +1,3 @@
#!/bin/sh
-gcc -O3 -std=c99 -Wall -Wextra -iquotesrc -o tests src/*.c tests.c -lm -ltap || exit 1
+gcc -O3 -std=c2x -Wall -Wextra -iquotesrc -o tests src/*.c tests.c -lm -ltap || exit 1
./tests