diff options
-rwxr-xr-x | build.sh | 2 | ||||
-rw-r--r-- | compile_flags.txt | 2 | ||||
-rw-r--r-- | main.c | 15 | ||||
-rw-r--r-- | src/image.c | 47 | ||||
-rw-r--r-- | src/image.h | 12 | ||||
-rwxr-xr-x | tests.sh | 2 |
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 @@ -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); @@ -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 |