/*
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
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(
/*
core.h
The tool with multiple enhancements and manipulations of pictures
-30.11.2022
+03.12.2022
Copyright (C) 2022 Balthasar Szczepański
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);
/*
enhance.c
The tool with multiple enhancements and manipulations of pictures
-01.12.2022
+03.12.2022
Copyright (C) 2022 Balthasar Szczepański
#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)
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
# "makefile" is automatically generated from "makefile.1.mak"
-# 01.12.2022
+# 03.12.2022
#
# Copyright (C) 2022 Balthasar Szczepański
#
npb\
pal_mix\
pal_unmix\
+pal_mixdiff\
remap_t_1
C_STANDALONE=\
standalone-npb.c\
standalone-pal_mix.c\
standalone-pal_unmix.c\
+standalone-pal_mixdiff.c\
standalone-remap_t_1.c
C_SUBTOOL=\
npb.c\
pal_mix.c\
pal_unmix.c\
+pal_mixdiff.c\
remap_t_1.c
H_SUBTOOL=\
npb.h\
pal_mix.h\
pal_unmix.h\
+pal_mixdiff.h\
remap_t_1.h
H_PNG=\
# "makefile" is automatically generated from "makefile.1.mak"
-# 01.12.2022
+# 03.12.2022
#
# Copyright (C) 2022 Balthasar Szczepański
#
npb\
pal_mix\
pal_unmix\
+pal_mixdiff\
remap_t_1
C_STANDALONE=\
standalone-npb.c\
standalone-pal_mix.c\
standalone-pal_unmix.c\
+standalone-pal_mixdiff.c\
standalone-remap_t_1.c
C_SUBTOOL=\
npb.c\
pal_mix.c\
pal_unmix.c\
+pal_mixdiff.c\
remap_t_1.c
H_SUBTOOL=\
npb.h\
pal_mix.h\
pal_unmix.h\
+pal_mixdiff.h\
remap_t_1.h
H_PNG=\
--- /dev/null
+/*\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
/*\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
#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
\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
+++ /dev/null
-// 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