From 6464e75b0da23e5a3a4116b9fb3ebdd28ea4a59e Mon Sep 17 00:00:00 2001 From: b Date: Tue, 29 Nov 2022 13:12:13 +0000 Subject: [PATCH] Diff tool added but doesn't work :( (yet!) --- core.c | 35 ++++++++------- core.h | 6 +-- diff.c | 115 +++++++++++++++++++++++++++++++++++++------------ diff.h | 28 ++++++++++++ enhance.c | 5 ++- makefile | 14 +++--- makefile.1.mak | 14 +++--- 7 files changed, 160 insertions(+), 57 deletions(-) create mode 100644 diff.h diff --git a/core.c b/core.c index a6408cf..f79c6ad 100644 --- 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> (8 * (bytes-1))); } - - - - // int action( // ILuint n, struct PixelInfo *info, void *data // ) diff --git a/core.h b/core.h index 09449ba..144979d 100644 --- 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 2ba097e..b68fffc 100644 --- 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 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 . + + +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); diff --git a/enhance.c b/enhance.c index a1f21a8..be6a6b5 100644 --- 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"); diff --git a/makefile b/makefile index d71ecb6..16f61c1 100644 --- 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 diff --git a/makefile.1.mak b/makefile.1.mak index 16ccecc..fd5f631 100644 --- a/makefile.1.mak +++ b/makefile.1.mak @@ -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 -- 2.30.2