]> bicyclesonthemoon.info Git - ott/enhance/blobdiff - diff.c
newpixbot online
[ott/enhance] / diff.c
diff --git a/diff.c b/diff.c
index b68fffc64a85acf2cd0ba06d068ccb42682498de..83c14c9b8cdbe2dc9cbb682f10ee149316fa2a7d 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -1,7 +1,7 @@
 /*
 diff.c
 see the difference!
-29.11.2022
+30.11.2022
 
 Copyright (C) 2022  Balthasar SzczepaƄski
 
@@ -103,7 +103,7 @@ int subtool_diff (int argc, char **argv, int argi, char **err)
        if ((info[0].image_height != info[1].image_height) || (info[0].image_width != info[1].image_width) || (info[0].num_images != info[1].num_images))
        {
                *err = SIZE_MISMATCH;
-               return r;
+               return EINVAL;
        }
        
        if ((info[0].image_bpc != info[1].image_bpc) || (!(flags[0] & IS_OVER_8BIT)) || (!(flags[0] & IS_OVER_8BIT)))
@@ -142,12 +142,14 @@ int subtool_diff (int argc, char **argv, int argi, char **err)
        }
        
        r = convert_picture(0, &(info[0]), &(flags[0]));
+       if (r!=0)
        {
                *err = CONVERT_FAILED;
                return EIO;
        }
        
        r = convert_picture(1, &(info[1]), &(flags[1]));
+       if (r!=0)
        {
                *err = CONVERT_FAILED;
                return EIO;
@@ -183,6 +185,7 @@ int subtool_diff (int argc, char **argv, int argi, char **err)
                data.g_b = upscale_value(GB, info[0].image_bpc);
                data.b_b = upscale_value(BB, info[0].image_bpc);
        }
+       data.max = upscale_value(0xFF, info[0].image_bpc);
        
        r = build_picture_from_info(2, &(info[0]), &(info[2]), &(flags[2]));
        if (r!=0)
@@ -215,6 +218,23 @@ int subtool_diff (int argc, char **argv, int argi, char **err)
                        *err = CONVERT_FAILED;
                        return r;
                }
+               flags[0] &= ~OK_PALETTE_ONLY;
+               flags[1] &= ~OK_PALETTE_ONLY;
+               flags[2] &= ~OK_PALETTE_ONLY;
+               r = perform_action(
+                       3,
+                       id,
+                       xyf0, xyf0, xyf0,
+                       0, 0, 0,
+                       &palette_mix_index,
+                       flags,
+                       &data
+               );
+               if (r)
+               {
+                       *err = CONVERT_FAILED;
+                       return r;
+               }
        }
        else
        {
@@ -249,13 +269,13 @@ int difference (ILuint n, struct PixelInfo *p, void *data)
        struct diff_data *d;
        d = data;
        
-       if (n != 3)
+       if (n < 3)
                return EIO;
        
        p[2].red   = diff_1ch(p[0].red,   p[1].red,   d->r_a, d->r_b, d->max);
        p[2].green = diff_1ch(p[0].green, p[1].green, d->g_a, d->g_b, d->max);
        p[2].blue  = diff_1ch(p[0].blue,  p[1].blue,  d->b_a, d->b_b, d->max);
-       if (p[2].flags & HAS_ALPHA)
+       if (p[2].flags & EFF_ALPHA)
                p[2].alpha = (p[0].alpha + p[1].alpha) / 2; /* no better idea */
        
        return 0;
@@ -268,9 +288,9 @@ static inline ILuint diff_1ch (ILint64 x, ILint64 y, ILint64 A, ILint64 B, ILint
        if (x == y)
                return (ILuint) x;
        else if (x > y)
-               v = (A * (x - y)) / F;
+               v = y + ((A * (x - y)) / F);
        else
-               v = (B * (y - x)) / F;
+               v = x + ((B * (y - x)) / F);
        
        return (ILuint) v;
 }