]> bicyclesonthemoon.info Git - ott/enhance/commitdiff
Fixed the diff tool
authorb <rowerynaksiezycu@gmail.com>
Tue, 29 Nov 2022 14:26:18 +0000 (15:26 +0100)
committerb <rowerynaksiezycu@gmail.com>
Tue, 29 Nov 2022 14:26:18 +0000 (15:26 +0100)
diff.c
testimg/bsta-000000.png [new file with mode: 0644]
testimg/bsta-000012.png [new file with mode: 0644]
testimg/gradient_h.png [new file with mode: 0644]
testimg/gradient_v.png [new file with mode: 0644]
testimg/phys-0001.png [new file with mode: 0644]
testimg/phys-0002.png [new file with mode: 0644]

diff --git a/diff.c b/diff.c
index b68fffc64a85acf2cd0ba06d068ccb42682498de..23b7054f8f1fb716ea173c4e286ebe8a687a6379 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -52,6 +52,7 @@ struct diff_data
 };
 
 int difference (ILuint n, struct PixelInfo *p, void *data);
+int palette_mix (ILuint n, struct PixelInfo *p, void *data);
 static inline ILuint diff_1ch (ILint64 x, ILint64 y, ILint64 A, ILint64 B, ILint64 F);
 
 char DIFF_MISSING_ARGS[] = "Missing parameters.\ndiff inPixA inPixB outPix [RA GA BA [RB GB BB]]\n";
@@ -103,7 +104,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 +143,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 +186,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 +219,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,
+                       flags,
+                       &data
+               );
+               if (r)
+               {
+                       *err = CONVERT_FAILED;
+                       return r;
+               }
        }
        else
        {
@@ -249,7 +270,7 @@ 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);
@@ -261,6 +282,16 @@ int difference (ILuint n, struct PixelInfo *p, void *data)
        return 0;
 }
 
+int palette_mix (ILuint n, struct PixelInfo *p, void *data)
+{
+       if (n < 3)
+               return EIO;
+       
+       p[2].index = p[0].index * p[0].info.palette_num_cols + p[1].index;
+       
+       return 0;
+}
+
 static inline ILuint diff_1ch (ILint64 x, ILint64 y, ILint64 A, ILint64 B, ILint64 F)
 {
        ILint64 v;
@@ -268,9 +299,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;
 }
diff --git a/testimg/bsta-000000.png b/testimg/bsta-000000.png
new file mode 100644 (file)
index 0000000..20455e2
Binary files /dev/null and b/testimg/bsta-000000.png differ
diff --git a/testimg/bsta-000012.png b/testimg/bsta-000012.png
new file mode 100644 (file)
index 0000000..dd0b003
Binary files /dev/null and b/testimg/bsta-000012.png differ
diff --git a/testimg/gradient_h.png b/testimg/gradient_h.png
new file mode 100644 (file)
index 0000000..b65217e
Binary files /dev/null and b/testimg/gradient_h.png differ
diff --git a/testimg/gradient_v.png b/testimg/gradient_v.png
new file mode 100644 (file)
index 0000000..4f1f87c
Binary files /dev/null and b/testimg/gradient_v.png differ
diff --git a/testimg/phys-0001.png b/testimg/phys-0001.png
new file mode 100644 (file)
index 0000000..deeb8c3
Binary files /dev/null and b/testimg/phys-0001.png differ
diff --git a/testimg/phys-0002.png b/testimg/phys-0002.png
new file mode 100644 (file)
index 0000000..0fd1b8a
Binary files /dev/null and b/testimg/phys-0002.png differ