From c9c9c6198f49a3a9159ed2f90753be548f42ecac Mon Sep 17 00:00:00 2001 From: b Date: Sat, 3 Dec 2022 20:04:44 +0000 Subject: [PATCH] palette diff tool --- core.c | 63 ++++++++++++++++- core.h | 5 +- enhance.c | 5 +- makefile | 6 +- makefile.1.mak | 6 +- pal_mixdiff.c | 180 +++++++++++++++++++++++++++++++++++++++++++++++++ pal_unmix.c | 65 +----------------- seediff.c | 176 ----------------------------------------------- 8 files changed, 260 insertions(+), 246 deletions(-) create mode 100644 pal_mixdiff.c delete mode 100644 seediff.c diff --git a/core.c b/core.c index 6e2928a..0a3d1c4 100644 --- a/core.c +++ b/core.c @@ -1,7 +1,7 @@ /* core.c The tool with multiple enhancements and manipulations of pictures -26.11.2022 +03.12.2022 Copyright (C) 2014, 2015, 2022 Balthasar Szczepański @@ -1561,6 +1561,67 @@ int palette_mix_index (ILuint n, struct PixelInfo *p, void *data) return 0; } +ILuint tsqrt(ILuint s) +{ + switch(s) + { + case 256: + return 16; + case 225: + return 15; + case 196: + return 14; + case 169: + return 13; + case 144: + return 12; + case 121: + return 11; + case 100: + return 10; + case 81: + return 9; + case 64: + return 8; + case 49: + return 7; + case 36: + return 6; + case 25: + return 5; + case 16: + return 4; + case 9: + return 3; + case 4: + return 2; + case 1: + return 1; + default: // not a square - please fail + return 0; + } +} + +//unsigned short isqrt(unsigned s) +//{ +// unsigned short r; +// unsigned short b=0x0040; +// +// while(b>s) +// b>>=2; +// while(b) +// { +// if(s>=r+b) +// { +// s-=r+b; +// r=(r>>1)+b; +// } +// else +// r>>1; +// b>>2; +// } +// return r; +//} // int action( diff --git a/core.h b/core.h index f697bff..999bf5e 100644 --- a/core.h +++ b/core.h @@ -1,7 +1,7 @@ /* core.h The tool with multiple enhancements and manipulations of pictures -30.11.2022 +03.12.2022 Copyright (C) 2022 Balthasar Szczepański @@ -249,4 +249,5 @@ int perform_action_palette_mix ( int copy_pixels (ILuint n, struct PixelInfo *p, void *data); ILuint copy_1p_alpha (ILint64 src, ILint64 dst, ILint64 alpha, ILint64 max); int fill_color (ILuint n, struct PixelInfo *p, void *data); -int palette_mix_index (ILuint n, struct PixelInfo *p, void *data); \ No newline at end of file +int palette_mix_index (ILuint n, struct PixelInfo *p, void *data); +ILuint tsqrt(ILuint s); diff --git a/enhance.c b/enhance.c index 1036266..2e0056b 100644 --- a/enhance.c +++ b/enhance.c @@ -1,7 +1,7 @@ /* enhance.c The tool with multiple enhancements and manipulations of pictures -01.12.2022 +03.12.2022 Copyright (C) 2022 Balthasar Szczepański @@ -37,6 +37,7 @@ on Pentium III libdevil must be recompiled with #include "npb.h" #include "pal_mix.h" #include "pal_unmix.h" +#include "pal_mixdiff.h" #include "remap_t_1.h" int main (int argc, char **argv) @@ -69,6 +70,8 @@ int main (int argc, char **argv) f = &subtool_pal_mix; else if (strcmp(argv[1], "pal_unmix")==0) f = &subtool_pal_unmix; + else if (strcmp(argv[1], "pal_mixdiff")==0) + f = &subtool_pal_mixdiff; else if (strcmp(argv[1], "remap_t_1")==0) f = &subtool_remap_t_1; else diff --git a/makefile b/makefile index a257374..5813e48 100644 --- a/makefile +++ b/makefile @@ -1,5 +1,5 @@ # "makefile" is automatically generated from "makefile.1.mak" -# 01.12.2022 +# 03.12.2022 # # Copyright (C) 2022 Balthasar Szczepański # @@ -46,6 +46,7 @@ diff\ npb\ pal_mix\ pal_unmix\ +pal_mixdiff\ remap_t_1 C_STANDALONE=\ @@ -57,6 +58,7 @@ standalone-diff.c\ standalone-npb.c\ standalone-pal_mix.c\ standalone-pal_unmix.c\ +standalone-pal_mixdiff.c\ standalone-remap_t_1.c C_SUBTOOL=\ @@ -68,6 +70,7 @@ diff.c\ npb.c\ pal_mix.c\ pal_unmix.c\ +pal_mixdiff.c\ remap_t_1.c H_SUBTOOL=\ @@ -79,6 +82,7 @@ diff.h\ npb.h\ pal_mix.h\ pal_unmix.h\ +pal_mixdiff.h\ remap_t_1.h H_PNG=\ diff --git a/makefile.1.mak b/makefile.1.mak index 103fdd2..15d1f31 100644 --- a/makefile.1.mak +++ b/makefile.1.mak @@ -1,5 +1,5 @@ # "makefile" is automatically generated from "makefile.1.mak" -# 01.12.2022 +# 03.12.2022 # # Copyright (C) 2022 Balthasar Szczepański # @@ -46,6 +46,7 @@ diff\ npb\ pal_mix\ pal_unmix\ +pal_mixdiff\ remap_t_1 C_STANDALONE=\ @@ -57,6 +58,7 @@ standalone-diff.c\ standalone-npb.c\ standalone-pal_mix.c\ standalone-pal_unmix.c\ +standalone-pal_mixdiff.c\ standalone-remap_t_1.c C_SUBTOOL=\ @@ -68,6 +70,7 @@ diff.c\ npb.c\ pal_mix.c\ pal_unmix.c\ +pal_mixdiff.c\ remap_t_1.c H_SUBTOOL=\ @@ -79,6 +82,7 @@ diff.h\ npb.h\ pal_mix.h\ pal_unmix.h\ +pal_mixdiff.h\ remap_t_1.h H_PNG=\ diff --git a/pal_mixdiff.c b/pal_mixdiff.c new file mode 100644 index 0000000..4b3deb4 --- /dev/null +++ b/pal_mixdiff.c @@ -0,0 +1,180 @@ +/* +pal_mixdiff.c +The tool to see difference between two images hidden iside one indexed image +03.12.2022 + +Copyright (C) 2015, 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) + +*/ + +#include +#include +#include + +#include "core.h" +#include "pal_mixdiff.h" + +int palette_mixdiff_index (ILuint n, struct PixelInfo *p, void *data); + +char PAL_MIXDIFF_MISSING_ARGS[] = "Missing parameters.\npal_mixdiff inPix outPix [n1 n2]\n"; + +int subtool_pal_mixdiff (int argc, char **argv, int argi, char **err) +{ + struct IL_full_info info; + FLAG_TYPE flags = MUST_BE_INDEXED | CAN_BE_MULTIPLE; + ILubyte new_pal[0x100 * 4]; + ILubyte *pal; + ILubyte *rd, *wr; + ILuint n0, n1, n; + uint_fast8_t size_defined = 0; + ILuint i, j, k; + ILuint max_index = 0; + int r; + + if (argc < argi + 2) + { + *err = PAL_MIXDIFF_MISSING_ARGS; + return EINVAL; + } + + if (argc >= argi + 4) + { + sscanf(argv[argi+2],"%u",&n0); + sscanf(argv[argi+3],"%u",&n1); + n = n0 * n1; + size_defined = 1; + } + + r = reserve_pictures(1); + if (r) + { + *err = CREATE_FAILED; + return r; + } + + r = load_picture(0, argv[argi], &info, &flags); + if (r) + { + *err = LOAD_FAILED; + return r; + } + + if (size_defined) + { + if (info.palette_num_cols < n) + { + *err = BAD_PALETTE_SIZE; + return EINVAL; + } + } + else + { + n = info.palette_num_cols; + n0 = tsqrt(n); + if (n0 == 0) + { + *err = BAD_PALETTE_SIZE; + return EINVAL; + } + n1 = n0; + } + + /* inefficiently find max index */ + for (i=0; iindex = (p->index / *d) ^ (p->index % *d); + + return 0; +} diff --git a/pal_unmix.c b/pal_unmix.c index 63461e4..2340a8c 100644 --- a/pal_unmix.c +++ b/pal_unmix.c @@ -1,7 +1,7 @@ /* pal_unmix.c The tool to extract two images hidden iside one indexed image -01.12.2022 +03.12.2022 Copyright (C) 2015, 2022 Balthasar Szczepański @@ -34,7 +34,6 @@ on Pentium III libdevil must be recompiled with #include "pal_unmix.h" int palette_unmix_index (ILuint n, struct PixelInfo *p, void *data); -ILuint tsqrt(ILuint s); char PAL_UNMIX_MISSING_ARGS[] = "Missing parameters.\npal_unmix inPix outPix1 outPix2 [n1 n2]\n"; @@ -235,65 +234,3 @@ int palette_unmix_index (ILuint n, struct PixelInfo *p, void *data) return 0; } - -ILuint tsqrt(ILuint s) -{ - switch(s) - { - case 256: - return 16; - case 225: - return 15; - case 196: - return 14; - case 169: - return 13; - case 144: - return 12; - case 121: - return 11; - case 100: - return 10; - case 81: - return 9; - case 64: - return 8; - case 49: - return 7; - case 36: - return 6; - case 25: - return 5; - case 16: - return 4; - case 9: - return 3; - case 4: - return 2; - case 1: - return 1; - default: // not a square - please fail - return 0; - } -} - -//unsigned short isqrt(unsigned s) -//{ -// unsigned short r; -// unsigned short b=0x0040; -// -// while(b>s) -// b>>=2; -// while(b) -// { -// if(s>=r+b) -// { -// s-=r+b; -// r=(r>>1)+b; -// } -// else -// r>>1; -// b>>2; -// } -// return r; -//} diff --git a/seediff.c b/seediff.c deleted file mode 100644 index cb4d9d2..0000000 --- a/seediff.c +++ /dev/null @@ -1,176 +0,0 @@ -// seediff.c -// The tool to see difference between two images hidden iside one indexed image -// 25.06.2015 -// -// Copyright (C) 2015 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) - -//#include -#include -#include "IL/il.h" - -int mustard(const char *t,int m,int e); -int main(int argc, char *argv[]); -//unsigned short psqrt(unsigned short s); -unsigned short tsqrt(unsigned short s); - -ILuint inpix, outpix; -unsigned char q =0; - -int main(int argc, char *argv[]) -{ - - ILubyte *pal, *data1, *data; - ILubyte pal12[16*3]; - unsigned short i; - unsigned long k; - ILuint col12, col, x, y; - - if (argc<3) - return mustard("seediff inpix outpix [q]",0,1); - else if(argc > 3) - q=1; - ilInit(); - - ilEnable(IL_ORIGIN_SET); - ilEnable(IL_FILE_OVERWRITE); - - ilGenImages(1,&inpix); - ilGenImages(1,&outpix); - - ilBindImage(inpix); - if(!ilLoadImage(argv[1])) - return mustard("inpix load fail.",1,1); - if(ilGetInteger(IL_IMAGE_FORMAT)!=IL_COLOUR_INDEX) - return mustard("inpix not indexed.",1,1); - ilConvertPal(IL_PAL_RGB24); - col=ilGetInteger(IL_PALETTE_NUM_COLS); - col12=tsqrt(col); - if(!col12) - return mustard("Palette is not squarish.",1,1); - x=ilGetInteger(IL_IMAGE_WIDTH); - y=ilGetInteger(IL_IMAGE_HEIGHT); - pal=ilGetPalette(); - data=ilGetData(); - - for(i=0;is) -// b>>=2; -// while(b) -// { -// if(s>=r+b) -// { -// s-=r+b; -// r=(r>>1)+b; -// } -// else -// r>>1; -// b>>2; -// } -// return r; -//} -- 2.30.2