]> bicyclesonthemoon.info Git - ott/enhance/commitdiff
palette diff tool
authorb <rowerynaksiezycu@gmail.com>
Sat, 3 Dec 2022 20:04:44 +0000 (20:04 +0000)
committerb <rowerynaksiezycu@gmail.com>
Sat, 3 Dec 2022 20:04:44 +0000 (20:04 +0000)
core.c
core.h
enhance.c
makefile
makefile.1.mak
pal_mixdiff.c [new file with mode: 0644]
pal_unmix.c
seediff.c [deleted file]

diff --git a/core.c b/core.c
index 6e2928aebebc9dec8afe88e2d4a7b8cf9b713bcc..0a3d1c41da19d3670bb4bd1a238113063a1f8384 100644 (file)
--- 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 f697bff4aa35d4ec4aa7b0a9fc815be541a50907..999bf5ec9b30c0ed63b53b26ed1f008b0cded00d 100644 (file)
--- 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);
index 10362666e8352e7cfdedcb8ec215b9ba17228053..2e0056b07fbfea964969bb1d9ac5ceb8f825f1c1 100644 (file)
--- 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
index a2573740a423b0e8e8c1b0fca6f4bb8c688f7f94..5813e480997582e35d565285d3680d0edb5531b2 100644 (file)
--- 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=\
index 103fdd24bf6a864b341270899d2d65bf1a1d7b0c..15d1f317af647cf3da124dd694fedccdbc74b515 100644 (file)
@@ -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 (file)
index 0000000..4b3deb4
--- /dev/null
@@ -0,0 +1,180 @@
+/*\r
+pal_mixdiff.c\r
+The tool to see difference between two images hidden iside one indexed image\r
+03.12.2022\r
+\r
+Copyright (C) 2015, 2022  Balthasar Szczepański\r
+\r
+This program is free software: you can redistribute it and/or modify\r
+it under the terms of the GNU Affero General Public License as\r
+published by the Free Software Foundation, either version 3 of the\r
+License, or (at your option) any later version.\r
+\r
+This program is distributed in the hope that it will be useful,\r
+but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+GNU Affero General Public License for more details.\r
+\r
+You should have received a copy of the GNU Affero General Public License\r
+along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
+\r
+\r
+Requires Dev Image Library (libdevil) (http://openil.sourceforge.net/)\r
+on Pentium III libdevil must be recompiled with\r
+--disable-ssl2 --disable-ssl3\r
+(https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=572954)\r
+\r
+*/\r
+\r
+#include <stdint.h>\r
+#include <getopt.h>\r
+#include <errno.h>\r
+\r
+#include "core.h"\r
+#include "pal_mixdiff.h"\r
+\r
+int palette_mixdiff_index (ILuint n, struct PixelInfo *p, void *data);\r
+\r
+char PAL_MIXDIFF_MISSING_ARGS[] = "Missing parameters.\npal_mixdiff inPix outPix [n1 n2]\n";\r
+\r
+int subtool_pal_mixdiff (int argc, char **argv, int argi, char **err)\r
+{\r
+       struct IL_full_info info;\r
+       FLAG_TYPE flags = MUST_BE_INDEXED | CAN_BE_MULTIPLE;\r
+       ILubyte new_pal[0x100 * 4];\r
+       ILubyte *pal;\r
+       ILubyte *rd, *wr;\r
+       ILuint n0, n1, n;\r
+       uint_fast8_t size_defined = 0;\r
+       ILuint i, j, k;\r
+       ILuint max_index = 0;\r
+       int r;\r
+       \r
+       if (argc < argi + 2)\r
+       {\r
+               *err = PAL_MIXDIFF_MISSING_ARGS;\r
+               return EINVAL;\r
+       }\r
+       \r
+       if (argc >= argi + 4)\r
+       {\r
+               sscanf(argv[argi+2],"%u",&n0);\r
+               sscanf(argv[argi+3],"%u",&n1);\r
+               n = n0 * n1;\r
+               size_defined = 1;\r
+       }\r
+       \r
+       r = reserve_pictures(1);\r
+       if (r)\r
+       {\r
+               *err = CREATE_FAILED;\r
+               return r;\r
+       }\r
+       \r
+       r = load_picture(0, argv[argi], &info, &flags);\r
+       if (r)\r
+       {\r
+               *err = LOAD_FAILED;\r
+               return r;\r
+       }\r
+       \r
+       if (size_defined)\r
+       {\r
+               if (info.palette_num_cols < n)\r
+               {\r
+                       *err = BAD_PALETTE_SIZE;\r
+                       return EINVAL;\r
+               }\r
+       }\r
+       else\r
+       {\r
+               n = info.palette_num_cols;\r
+               n0 = tsqrt(n);\r
+               if (n0 == 0)\r
+               {\r
+                       *err = BAD_PALETTE_SIZE;\r
+                       return EINVAL;\r
+               }\r
+               n1 = n0;\r
+       }\r
+       \r
+       /* inefficiently find max index */\r
+       for (i=0; i<n0; ++i)\r
+       {\r
+               for (j=0; j<n1; ++j)\r
+               {\r
+                       k = i ^ j;\r
+                       if (max_index < k)\r
+                               max_index = k;\r
+               }\r
+       }\r
+       \r
+       /* create palettes - I didn't define separate action of this type */\r
+       \r
+       for (i=0; i<=info.num_images; ++i)\r
+       {\r
+               r = get_palette(0, &pal, i);\r
+               if (r!=0)\r
+               {\r
+                       *err = CONVERT_FAILED;\r
+                       return EIO;\r
+               }\r
+               \r
+               wr = new_pal;\r
+               for (j=0; j<=max_index; ++j)\r
+               {\r
+                       rd = pal + ((2*(j*(n-1))+1)/(2*max_index)) * info.palette_bpp;\r
+                       for (k=0; k<info.palette_bpp; ++k)\r
+                       {\r
+                               *wr = *rd;\r
+                               ++wr;\r
+                               ++rd;\r
+                       }\r
+               }\r
+               \r
+               r = set_palette (\r
+                       0,\r
+                       new_pal,\r
+                       (max_index+1) * info.palette_bpp,\r
+                       info.palette_type,\r
+                       i\r
+               );\r
+               if (r!=0)\r
+               {\r
+                       *err = CONVERT_FAILED;\r
+                       return EIO;\r
+               }\r
+       }\r
+       \r
+       r = perform_action_1picture(\r
+               0,\r
+               0, 0, 0,\r
+               0, 0, 0,\r
+               &palette_mixdiff_index,\r
+               flags,\r
+               &n1\r
+       );\r
+       if (r)\r
+       {\r
+               *err = CONVERT_FAILED;\r
+               return r;\r
+       }\r
+       \r
+       r = save_picture(0, argv[argi+1], flags);\r
+       if (r!=0)\r
+       {\r
+               *err = SAVE_FAILED;\r
+               return r;\r
+       }\r
+       \r
+       return 0;\r
+}\r
+\r
+int palette_mixdiff_index (ILuint n, struct PixelInfo *p, void *data)\r
+{\r
+       ILuint *d = data;\r
+       \r
+       p->index = (p->index / *d) ^ (p->index % *d);\r
+       \r
+       return 0;\r
+}\r
index 63461e47d6ff80d5bc3124676ebfbd465a4a727e..2340a8cc93d9b3fedf98be1b98c7aed3a059d36c 100644 (file)
@@ -1,7 +1,7 @@
 /*\r
 pal_unmix.c\r
 The tool to extract two images hidden iside one indexed image\r
-01.12.2022\r
+03.12.2022\r
 \r
 Copyright (C) 2015, 2022  Balthasar Szczepański\r
 \r
@@ -34,7 +34,6 @@ on Pentium III libdevil must be recompiled with
 #include "pal_unmix.h"\r
 \r
 int palette_unmix_index (ILuint n, struct PixelInfo *p, void *data);\r
-ILuint tsqrt(ILuint s);\r
 \r
 char PAL_UNMIX_MISSING_ARGS[] = "Missing parameters.\npal_unmix inPix outPix1 outPix2 [n1 n2]\n";\r
 \r
@@ -235,65 +234,3 @@ int palette_unmix_index (ILuint n, struct PixelInfo *p, void *data)
        \r
        return 0;\r
 }\r
-\r
-ILuint tsqrt(ILuint s)\r
-{\r
-       switch(s)\r
-       {\r
-       case 256:\r
-               return 16;\r
-       case 225:\r
-               return 15;\r
-       case 196:\r
-               return 14;\r
-       case 169:\r
-               return 13;\r
-       case 144:\r
-               return 12;\r
-       case 121:\r
-               return 11;\r
-       case 100:\r
-               return 10;\r
-       case 81:\r
-               return 9;\r
-       case 64:\r
-               return 8;\r
-       case 49:\r
-               return 7;\r
-       case 36:\r
-               return 6;\r
-       case 25:\r
-               return 5;\r
-       case 16:\r
-               return 4;\r
-       case 9:\r
-               return 3;\r
-       case 4:\r
-               return 2;\r
-       case 1:\r
-               return 1;\r
-       default: // not a square - please fail\r
-               return 0;\r
-       }\r
-}\r
-\r
-//unsigned short isqrt(unsigned s)\r
-//{\r
-//      unsigned short r;\r
-//      unsigned short b=0x0040;\r
-//      \r
-//      while(b>s)\r
-//           b>>=2;\r
-//      while(b)\r
-//      {\r
-//           if(s>=r+b)\r
-//           {\r
-//                   s-=r+b;\r
-//                   r=(r>>1)+b;\r
-//           }\r
-//           else\r
-//                   r>>1;\r
-//           b>>2;\r
-//      }\r
-//      return r;\r
-//}\r
diff --git a/seediff.c b/seediff.c
deleted file mode 100644 (file)
index cb4d9d2..0000000
--- a/seediff.c
+++ /dev/null
@@ -1,176 +0,0 @@
-// seediff.c\r
-// The tool to see difference between two images hidden iside one indexed image\r
-// 25.06.2015\r
-// \r
-// Copyright (C) 2015  Balthasar Szczepański\r
-// \r
-// This program is free software: you can redistribute it and/or modify\r
-// it under the terms of the GNU Affero General Public License as\r
-// published by the Free Software Foundation, either version 3 of the\r
-// License, or (at your option) any later version.\r
-// \r
-// This program is distributed in the hope that it will be useful,\r
-// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
-// GNU Affero General Public License for more details.\r
-// \r
-// You should have received a copy of the GNU Affero General Public License\r
-// along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
-// \r
-\r
-// Requires Dev Image Library (libdevil) (http://openil.sourceforge.net/)\r
-// on Pentium III libdevil must be recompiled with\r
-// --disable-ssl2 --disable-ssl3\r
-// (https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=572954)\r
-\r
-//#include <stdlib.h>\r
-#include <stdio.h>\r
-#include "IL/il.h"\r
-\r
-int mustard(const char *t,int m,int e);\r
-int main(int argc, char *argv[]);\r
-//unsigned short psqrt(unsigned short s);\r
-unsigned short tsqrt(unsigned short s);\r
-\r
-ILuint inpix, outpix;\r
-unsigned char q =0;\r
-\r
-int main(int argc, char *argv[])\r
-{\r
-       \r
-       ILubyte *pal, *data1, *data;\r
-       ILubyte pal12[16*3];\r
-       unsigned short i;\r
-       unsigned long k;\r
-       ILuint col12, col,  x, y;\r
-       \r
-       if (argc<3)\r
-               return mustard("seediff inpix outpix [q]",0,1);\r
-  else if(argc > 3)\r
-               q=1;\r
-       ilInit();\r
-               \r
-       ilEnable(IL_ORIGIN_SET);\r
-       ilEnable(IL_FILE_OVERWRITE);\r
-       \r
-       ilGenImages(1,&inpix);\r
-       ilGenImages(1,&outpix);\r
-       \r
-       ilBindImage(inpix);\r
-       if(!ilLoadImage(argv[1]))\r
-               return mustard("inpix load fail.",1,1);\r
-       if(ilGetInteger(IL_IMAGE_FORMAT)!=IL_COLOUR_INDEX)\r
-               return mustard("inpix not indexed.",1,1);\r
-       ilConvertPal(IL_PAL_RGB24);\r
-       col=ilGetInteger(IL_PALETTE_NUM_COLS);\r
-       col12=tsqrt(col);\r
-       if(!col12)\r
-               return mustard("Palette is not squarish.",1,1);\r
-       x=ilGetInteger(IL_IMAGE_WIDTH);\r
-       y=ilGetInteger(IL_IMAGE_HEIGHT);\r
-       pal=ilGetPalette();\r
-       data=ilGetData();\r
-       \r
-       for(i=0;i<col12;++i)\r
-       {\r
-               pal12[3*i  ]=pal[3*i*(col12+1)  ];\r
-               pal12[3*i+1]=pal[3*i*(col12+1)+1];\r
-               pal12[3*i+2]=pal[3*i*(col12+1)+2];\r
-       }\r
-       \r
-       ilBindImage(outpix);\r
-       if(!ilTexImage(x,y,1,1,IL_COLOUR_INDEX,IL_UNSIGNED_BYTE,NULL))\r
-               return mustard ("outpix create fail.",1,1);\r
-       ilRegisterPal(pal12,col12*3,IL_PAL_RGB24);\r
-       data1=ilGetData();\r
-       \r
-       \r
-       \r
-       for(k=0;k<x*y;++k)\r
-       \r
-               data1[k]=(data[k]/col12)^(data[k]%col12);\r
-       \r
-       \r
-       if(!ilSave(IL_PNG,argv[2]))\r
-               return mustard("outpix save fail",1,1);\r
-                               \r
-       return mustard("Ok",1,0);\r
-       \r
-       \r
-}\r
-\r
-int mustard(const char *t, int m,int e)\r
-{\r
-       if(!q)\r
-               puts(t);\r
-       switch (m)\r
-  {\r
-  case 1:\r
-       ilDeleteImages(1,&inpix);\r
-               ilDeleteImages(1,&outpix);\r
-  case 0:\r
-  default:\r
-               return e;\r
-       }\r
-}\r
-\r
-unsigned short tsqrt(unsigned short s)\r
-{\r
-       switch(s)\r
-       {\r
-       case 256:\r
-               return 16;\r
-       case 225:\r
-               return 15;\r
-       case 196:\r
-               return 14;\r
-       case 169:\r
-               return 13;\r
-       case 144:\r
-               return 12;\r
-       case 121:\r
-               return 11;\r
-       case 100:\r
-               return 10;\r
-       case 81:\r
-               return 9;\r
-       case 64:\r
-               return 8;\r
-       case 49:\r
-               return 7;\r
-       case 36:\r
-               return 6;\r
-       case 25:\r
-               return 5;\r
-       case 16:\r
-               return 4;\r
-       case 9:\r
-               return 3;\r
-       case 4:\r
-               return 2;\r
-       case 1:\r
-               return 1;\r
-       default:\r
-               return 0;\r
-       }\r
-}       \r
-//unsigned short isqrt(unsigned s)\r
-//{\r
-//      unsigned short r;\r
-//      unsigned short b=0x0040;\r
-//      \r
-//      while(b>s)\r
-//           b>>=2;\r
-//      while(b)\r
-//      {\r
-//           if(s>=r+b)\r
-//           {\r
-//                   s-=r+b;\r
-//                   r=(r>>1)+b;\r
-//           }\r
-//           else\r
-//                   r>>1;\r
-//           b>>2;\r
-//      }\r
-//      return r;\r
-//}\r