]> bicyclesonthemoon.info Git - ott/enhance/commitdiff
Diff tool added but doesn't work :( (yet!)
authorb <rowerynaksiezycu@gmail.com>
Tue, 29 Nov 2022 13:12:13 +0000 (13:12 +0000)
committerb <rowerynaksiezycu@gmail.com>
Tue, 29 Nov 2022 13:12:13 +0000 (13:12 +0000)
core.c
core.h
diff.c
diff.h [new file with mode: 0644]
enhance.c
makefile
makefile.1.mak

diff --git a/core.c b/core.c
index a6408cfa1a0850e408319fa8ea50b3a96dd3d99b..f79c6ad140e82f6c8a2892497c4daf1c28b73091 100644 (file)
--- a/core.c
+++ b/core.c
@@ -1,7 +1,7 @@
 /*
 core.c
 The tool with multiple enhancements and manipulations of pictures
-28.11.2022
+26.11.2022
 
 Copyright (C) 2014, 2015, 2022  Balthasar Szczepański
 
@@ -105,6 +105,22 @@ int get_palette (uint_fast16_t id, void **palette, ILuint frame)
        return 0;
 }
 
+int set_palette (uint_fast16_t id, void *palette, ILuint size, ILenum type, ILuint frame)
+{
+       if (id >= n_pictures)
+               return EINVAL;
+       if (!(picture[id].open))
+               return EIO;
+       ilBindImage(picture[id].handle);
+       if (frame > ilGetInteger(IL_NUM_IMAGES))
+               return EINVAL;
+       ilActiveImage(frame);
+       if (ilGetInteger(IL_IMAGE_FORMAT) != IL_COLOUR_INDEX)
+               return EINVAL;
+       ilRegisterPal(palette, size, type);
+       return 0;
+}
+
 void create_picture (uint_fast16_t id)
 {
        if (id<n_pictures)
@@ -1187,11 +1203,8 @@ int perform_action (
        return r;
 }
 
-
 int perform_action_palette_mix (
        uint_fast16_t *id,
-       ILint *f0,
-       ILint frames,
        ACTION_F *function,
        FLAG_TYPE *flags,
        void *data
@@ -1235,10 +1248,7 @@ int perform_action_palette_mix (
                else
                        actual_frames = 1;
                
-               if (*flags & IN_WINDOW) /* check first flags only! */
-                       p[i].f0 = f0[i];
-               else
-                       p[i].f0 = f0[i];
+               p[i].f0 = 0;
        }
        
        n_colors = p[0].info.palette_num_cols * p[1].info.palette_num_cols;
@@ -1248,10 +1258,7 @@ int perform_action_palette_mix (
                return EINVAL;
        }
        
-       if (!(*flags & IN_WINDOW)) /* check first flags only! */
-               frames = actual_frames;
-       
-       for (f = 0; (f < frames) && (r == 0); ++f)
+       for (f = 0; (f < actual_frames) && (r == 0); ++f)
        {
                skip_frame = 0;
                for (i=0; i<3; ++i)
@@ -1408,10 +1415,6 @@ ILubyte downscale_value (ILuint x, ILint bytes)
        return (ILubyte)(x >> (8 * (bytes-1)));
 }
 
-
-
-
-
 // int action(
        // ILuint n, struct PixelInfo *info, void *data
 // )
diff --git a/core.h b/core.h
index 09449ba83e2371d96a0b51bd334176e98fdf2caa..144979d89cf1569f668fa69cc91159120b322f8c 100644 (file)
--- a/core.h
+++ b/core.h
@@ -1,7 +1,7 @@
  /*
 core.h
 The tool with multiple enhancements and manipulations of pictures
-28.11.2022
+29.11.2022
 
 Copyright (C) 2022  Balthasar Szczepański
 
@@ -180,6 +180,8 @@ void finish (int const returnvalue, char const * const returntext);
 int init (void);
 ILuint get_handle (uint_fast16_t id);
 int get_data (uint_fast16_t id, void **data, ILuint frame);
+int get_palette (uint_fast16_t id, void **palette, ILuint frame);
+int set_palette (uint_fast16_t id, void *palette, ILuint size, ILenum type, ILuint frame);
 void create_picture (uint_fast16_t id);
 int create_pictures (uint_fast16_t n);
 void close_picture (uint_fast16_t id);
@@ -218,8 +220,6 @@ int perform_action (
 
 int perform_action_palette_mix (
        uint_fast16_t *id,
-       ILint *f0,
-       ILint frames,
        ACTION_F *function,
        FLAG_TYPE *flags,
        void *data
diff --git a/diff.c b/diff.c
index 2ba097e86a511f942de096c78ba061217a7818c8..b68fffc64a85acf2cd0ba06d068ccb42682498de 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -1,7 +1,7 @@
 /*
 diff.c
 see the difference!
-15.11.2022
+29.11.2022
 
 Copyright (C) 2022  Balthasar Szczepański
 
@@ -43,14 +43,17 @@ on Pentium III libdevil must be recompiled with
 struct diff_data
 {
        ILuint r_a;
-       ILuint r_a;
-       ILuint r_a;
-       ILuint g_b;
-       ILuint g_b;
+       ILuint g_a;
+       ILuint b_a;
+       ILuint r_b;
        ILuint g_b;
+       ILuint b_b;
        ILuint max;
 };
 
+int difference (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";
 
 int subtool_diff (int argc, char **argv, int argi, char **err)
@@ -66,13 +69,10 @@ int subtool_diff (int argc, char **argv, int argi, char **err)
                CAN_BE_MULTIPLE | CAN_BE_OVER_8BIT | CANNOT_BE_GRAY | NOT_READABLE
        };
        uint_fast8_t palette_only;
-       uint_fast8_t i;
+       ILuint i;
        ILubyte new_pal[0x100 * 4];
-       ILubyte *pal[3];
-       ILuint handle;
        int r;
        
-       
        if (argc < argi + 3)
        {
                *err = DIFF_MISSING_ARGS;
@@ -93,7 +93,7 @@ int subtool_diff (int argc, char **argv, int argi, char **err)
                return r;
        }
        
-       r = load_picture(1, argv[argi], &(info[1]), &(flags[1]));
+       r = load_picture(1, argv[argi+1], &(info[1]), &(flags[1]));
        if (r)
        {
                *err = LOAD_FAILED;
@@ -141,13 +141,13 @@ int subtool_diff (int argc, char **argv, int argi, char **err)
                flags[2] |= CANNOT_BE_INDEXED;
        }
        
-       r = convert_picture(0, &(info[0]), &(flags[0]);
+       r = convert_picture(0, &(info[0]), &(flags[0]));
        {
                *err = CONVERT_FAILED;
                return EIO;
        }
        
-       r = convert_picture(1, &(info[1]), &(flags[1]);
+       r = convert_picture(1, &(info[1]), &(flags[1]));
        {
                *err = CONVERT_FAILED;
                return EIO;
@@ -184,7 +184,7 @@ int subtool_diff (int argc, char **argv, int argi, char **err)
                data.b_b = upscale_value(BB, info[0].image_bpc);
        }
        
-       r = build_picture_from_info(2, &(info[0], &(info[2]), &(flags[2]));
+       r = build_picture_from_info(2, &(info[0]), &(info[2]), &(flags[2]));
        if (r!=0)
        {
                *err = CREATE_FAILED;
@@ -193,23 +193,84 @@ int subtool_diff (int argc, char **argv, int argi, char **err)
        
        if (palette_only)
        {
+               for (i=0; i<=info[2].num_images; ++i)
+               {
+                       set_palette (
+                       2,
+                       new_pal,
+                       info[0].palette_num_cols * info[1].palette_num_cols * info[0].palette_bpp,
+                       info[0].palette_type,
+                       i
+                       );
+               }
                
-               ilRegisterPal
-               
-               
+               r = perform_action_palette_mix(
+                       id,
+                       &difference,
+                       flags,
+                       &data
+               );
+               if (r)
+               {
+                       *err = CONVERT_FAILED;
+                       return r;
+               }
        }
        else
        {
-               for (i=0; i<3; ++i)
+               r = perform_action(
+                       3,
+                       id,
+                       xyf0, xyf0, xyf0,
+                       0, 0, 0,
+                       &difference,
+                       flags,
+                       &data
+               );
+               if (r)
                {
-                       handle = get_handle(i);
-                       ilBindImage(handle);
-                       if (i==2)
-                       {
-                               ilRegisterPal(
-                                       new_pal,
-                                       ((flags[0] & HAS_ALPHA)?4:3) * info[0].palette_num_cols * info[1].palette_num_cols,
-                                       
-               
-               
+                       *err = CONVERT_FAILED;
+                       return r;
+               }
        }
+       
+       r = save_picture(2, argv[argi+2], flags[2]);
+       if (r!=0)
+       {
+               *err = SAVE_FAILED;
+               return r;
+       }
+       
+       return 0;
+}
+
+int difference (ILuint n, struct PixelInfo *p, void *data)
+{
+       struct diff_data *d;
+       d = data;
+       
+       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)
+               p[2].alpha = (p[0].alpha + p[1].alpha) / 2; /* no better idea */
+       
+       return 0;
+}
+
+static inline ILuint diff_1ch (ILint64 x, ILint64 y, ILint64 A, ILint64 B, ILint64 F)
+{
+       ILint64 v;
+       
+       if (x == y)
+               return (ILuint) x;
+       else if (x > y)
+               v = (A * (x - y)) / F;
+       else
+               v = (B * (y - x)) / F;
+       
+       return (ILuint) v;
+}
diff --git a/diff.h b/diff.h
new file mode 100644 (file)
index 0000000..9248740
--- /dev/null
+++ b/diff.h
@@ -0,0 +1,28 @@
+/*
+diff.h
+see the difference!
+29.11.2022
+
+Copyright (C) 2022  Balthasar Szczepański
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU Affero General Public License as
+published by the Free Software Foundation, either version 3 of the
+License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU Affero General Public License for more details.
+
+You should have received a copy of the GNU Affero General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+
+Requires Dev Image Library (libdevil) (http://openil.sourceforge.net/)
+on Pentium III libdevil must be recompiled with
+--disable-ssl2 --disable-ssl3
+(https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=572954)
+*/
+
+int subtool_diff (int argc, char **argv, int argi, char **err);
index a1f21a89ebd0a6d276701e5776f3f2ed35b80094..be6a6b575ea70372b3e728ae1a1f8194c418fd54 100644 (file)
--- a/enhance.c
+++ b/enhance.c
@@ -1,7 +1,7 @@
 /*
 enhance.c
 The tool with multiple enhancements and manipulations of pictures
-13.11.2022
+29.11.2022
 
 Copyright (C) 2022  Balthasar Szczepański
 
@@ -33,6 +33,7 @@ on Pentium III libdevil must be recompiled with
 #include "nofading.h"
 #include "bluenh.h"
 #include "reveal.h"
+#include "diff.h"
 
 int main (int argc, char **argv)
 {
@@ -56,6 +57,8 @@ int main (int argc, char **argv)
                f = &subtool_bluenh;
        else if (strcmp(argv[1], "reveal")==0)
                f = &subtool_reveal;
+       else if (strcmp(argv[1], "diff")==0)
+               f = &subtool_diff;
        else
                finish(EINVAL, "Unknown mode.\n");
        
index d71ecb63476cbaa4206fd4dd625051d48d8bed2a..16f61c11eab7211382e21583e71495e2335b7c93 100644 (file)
--- a/makefile
+++ b/makefile
@@ -1,5 +1,5 @@
 # "makefile" is automatically generated from "makefile.1.mak"
-# 12.11.2022
+# 29.11.2022
 # 
 # Copyright (C) 2022  Balthasar Szczepański
 # 
@@ -41,25 +41,29 @@ STANDALONE=\
 nofading\
 info\
 bluenh\
-reveal
+reveal\
+diff
 
 C_STANDALONE=\
 standalone-nofading.c\
 standalone-info.c\
 standalone-bluenh.c\
-standalone-reveal.c
+standalone-reveal.c\
+standalone-diff.c
 
 C_SUBTOOL=\
 nofading.c\
 info.c\
 bluenh.c\
-reveal.c
+reveal.c\
+diff.c
 
 H_SUBTOOL=\
 nofading.h\
 info.h\
 bluenh.h\
-reveal.h
+reveal.h\
+diff.h
 
 
 #all: 403 npb npbd npb-ong1 npbd-ong1 bluenh bluenhd insert extract seediff insertframe mremapt-1 compare nofading nofadingd
index 16ccecc0848c91c15efeeac93be351b72ddc4f79..fd5f6316e1af5a357215aa8bc5608e26bb6e5e43 100644 (file)
@@ -1,5 +1,5 @@
 # "makefile" is automatically generated from "makefile.1.mak"
-# 12.11.2022
+# 29.11.2022
 # 
 # Copyright (C) 2022  Balthasar Szczepański
 # 
@@ -41,25 +41,29 @@ STANDALONE=\
 nofading\
 info\
 bluenh\
-reveal
+reveal\
+diff
 
 C_STANDALONE=\
 standalone-nofading.c\
 standalone-info.c\
 standalone-bluenh.c\
-standalone-reveal.c
+standalone-reveal.c\
+standalone-diff.c
 
 C_SUBTOOL=\
 nofading.c\
 info.c\
 bluenh.c\
-reveal.c
+reveal.c\
+diff.c
 
 H_SUBTOOL=\
 nofading.h\
 info.h\
 bluenh.h\
-reveal.h
+reveal.h\
+diff.h
 
 
 #all: 403 npb npbd npb-ong1 npbd-ong1 bluenh bluenhd insert extract seediff insertframe mremapt-1 compare nofading nofadingd