aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-07-28 05:36:33 +0200
committerkdx <kikoodx@paranoici.org>2023-07-28 05:37:10 +0200
commit53ea822e9cb3426c2a045ec09ad11ea183e56685 (patch)
tree1f678a52a767083553821d0b71f642929e7ffa5e
parent78a3549185557c4970e5397d6d4a4c79a429d350 (diff)
downloadkld-53ea822e9cb3426c2a045ec09ad11ea183e56685.tar.gz
move chans
-rw-r--r--main.c1
-rw-r--r--src/image.c29
-rw-r--r--src/image.h6
3 files changed, 36 insertions, 0 deletions
diff --git a/main.c b/main.c
index 2cf7fa0..e2977fa 100644
--- a/main.c
+++ b/main.c
@@ -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);