diff options
author | kdx <kikoodx@paranoici.org> | 2023-07-28 05:36:33 +0200 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2023-07-28 05:37:10 +0200 |
commit | 53ea822e9cb3426c2a045ec09ad11ea183e56685 (patch) | |
tree | 1f678a52a767083553821d0b71f642929e7ffa5e | |
parent | 78a3549185557c4970e5397d6d4a4c79a429d350 (diff) | |
download | kld-53ea822e9cb3426c2a045ec09ad11ea183e56685.tar.gz |
move chans
-rw-r--r-- | main.c | 1 | ||||
-rw-r--r-- | src/image.c | 29 | ||||
-rw-r--r-- | src/image.h | 6 |
3 files changed, 36 insertions, 0 deletions
@@ -20,6 +20,7 @@ main(int argc, char **argv) kldImage_mod(sky, KLD_COLOR(m, m, m, 255)); kldImage_sub(cloud, sky); + kldImage_movechans(cloud, KLD_COLOR(3, 3, 2, -1)); kldImage_writePAM(cloud, stdout); kldImage_free(sky); diff --git a/src/image.c b/src/image.c index aa5024a..35d6ee5 100644 --- a/src/image.c +++ b/src/image.c @@ -444,6 +444,35 @@ kldImage_mod(KldImage *img, KldColor mask) } } +void +kldImage_movechans(KldImage *img, KldColor cmd) +{ + NULL_SAFETY(); + + const uint8_t cmds[4] = { + (KLD_COLOR_R(cmd) <= 4) ? KLD_COLOR_R(cmd) : 1, + (KLD_COLOR_G(cmd) <= 4) ? KLD_COLOR_G(cmd) : 2, + (KLD_COLOR_B(cmd) <= 4) ? KLD_COLOR_B(cmd) : 3, + (KLD_COLOR_A(cmd) <= 4) ? KLD_COLOR_A(cmd) : 4, + }; + for (size_t i = 0; i < img->size; i++) { + const KldColor col = img->data[i]; + const uint8_t chans[5] = { + 0, + KLD_COLOR_R(col), + KLD_COLOR_G(col), + KLD_COLOR_B(col), + KLD_COLOR_A(col) + }; + img->data[i] = KLD_COLOR( + chans[cmds[0]], + chans[cmds[1]], + chans[cmds[2]], + chans[cmds[3]] + ); + } +} + int kldImage_blend(KldImage *img, KldImage *other, float ratio) { diff --git a/src/image.h b/src/image.h index 2c6b453..95fe32f 100644 --- a/src/image.h +++ b/src/image.h @@ -53,6 +53,12 @@ void kldImage_bit3(KldImage *img); void kldImage_mod(KldImage *img, KldColor mask); +/* cmd examples: + * KLD_COLOR(-1, -1, -1, -1) does nothing + * KLD_COLOR(2, 3, 1, -1) R->G G->B B->R A->A + * KLD_COLOR(4, -1, 0, 3) R->A B->0 A->B */ +void kldImage_movechans(KldImage *img, KldColor cmd); + /* return -1 if sizes are not equal */ int kldImage_blend(KldImage *img, KldImage *other, float ratio); |