diff options
author | kdx <kikoodx@paranoici.org> | 2023-07-27 06:51:03 +0200 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2023-07-27 06:51:03 +0200 |
commit | b9bb06da3c4f60aedaa7bf2ce93de0db5b6fbd79 (patch) | |
tree | ac9b7b69337e80d36b7888a06814a563a2bafbb9 | |
parent | d7b8205596486b60869858c9c46dd63bd1549724 (diff) | |
download | kld-b9bb06da3c4f60aedaa7bf2ce93de0db5b6fbd79.tar.gz |
add
-rw-r--r-- | main.c | 4 | ||||
-rw-r--r-- | src/image.c | 31 | ||||
-rw-r--r-- | src/image.h | 3 |
3 files changed, 35 insertions, 3 deletions
@@ -13,12 +13,10 @@ main(void) kldImage_resize(cloud, sky->width, sky->height, 0); kldImage_vflip(cloud); - kldImage_chaos3(cloud); kldImage_invert(sky); - kldImage_chaos3(sky); - kldImage_blend(cloud, sky, 0.5f); + kldImage_add(cloud, sky); kldImage_writePAM(cloud, stdout); kldImage_free(sky); diff --git a/src/image.c b/src/image.c index 46daa23..2e57a5f 100644 --- a/src/image.c +++ b/src/image.c @@ -471,3 +471,34 @@ kldImage_blend(KldImage *img, KldImage *other, float ratio) return 0; } + +int +kldImage_add(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 i = 0; i < img->size; i++) { + const KldColor c0 = img->data[i]; + const KldColor c1 = other->data[i]; + const unsigned int r = KLD_COLOR_R(c0) + KLD_COLOR_R(c1); + const unsigned int g = KLD_COLOR_G(c0) + KLD_COLOR_G(c1); + const unsigned int b = KLD_COLOR_B(c0) + KLD_COLOR_B(c1); + const unsigned int a = KLD_COLOR_A(c0) + KLD_COLOR_A(c1); + img->data[i] = KLD_COLOR( + (r > 0xff) ? 0xff : r, + (g > 0xff) ? 0xff : g, + (b > 0xff) ? 0xff : b, + (a > 0xff) ? 0xff : a + ); + } + + return 0; +} diff --git a/src/image.h b/src/image.h index afaaa44..fbc8442 100644 --- a/src/image.h +++ b/src/image.h @@ -55,3 +55,6 @@ void kldImage_mask(KldImage *img, KldColor mask); /* return -1 if sizes are not equal */ int kldImage_blend(KldImage *img, KldImage *other, float ratio); + +/* return -1 if sizes are not equal */ +int kldImage_add(KldImage *img, KldImage *other); |