]> bicyclesonthemoon.info Git - ott/enhance/blob - seediff.c
The reveal tool is ready.
[ott/enhance] / seediff.c
1 // seediff.c\r
2 // The tool to see difference between two images hidden iside one indexed image\r
3 // 25.06.2015\r
4 // \r
5 // Copyright (C) 2015  Balthasar Szczepański\r
6 // \r
7 // This program is free software: you can redistribute it and/or modify\r
8 // it under the terms of the GNU Affero General Public License as\r
9 // published by the Free Software Foundation, either version 3 of the\r
10 // License, or (at your option) any later version.\r
11 // \r
12 // This program is distributed in the hope that it will be useful,\r
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
15 // GNU Affero General Public License for more details.\r
16 // \r
17 // You should have received a copy of the GNU Affero General Public License\r
18 // along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
19 // \r
20 \r
21 // Requires Dev Image Library (libdevil) (http://openil.sourceforge.net/)\r
22 // on Pentium III libdevil must be recompiled with\r
23 // --disable-ssl2 --disable-ssl3\r
24 // (https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=572954)\r
25 \r
26 //#include <stdlib.h>\r
27 #include <stdio.h>\r
28 #include "IL/il.h"\r
29 \r
30 int mustard(const char *t,int m,int e);\r
31 int main(int argc, char *argv[]);\r
32 //unsigned short psqrt(unsigned short s);\r
33 unsigned short tsqrt(unsigned short s);\r
34 \r
35 ILuint inpix, outpix;\r
36 unsigned char q =0;\r
37 \r
38 int main(int argc, char *argv[])\r
39 {\r
40         \r
41         ILubyte *pal, *data1, *data;\r
42         ILubyte pal12[16*3];\r
43         unsigned short i;\r
44         unsigned long k;\r
45         ILuint col12, col,  x, y;\r
46         \r
47         if (argc<3)\r
48                 return mustard("seediff inpix outpix [q]",0,1);\r
49   else if(argc > 3)\r
50                 q=1;\r
51         ilInit();\r
52                 \r
53         ilEnable(IL_ORIGIN_SET);\r
54         ilEnable(IL_FILE_OVERWRITE);\r
55         \r
56         ilGenImages(1,&inpix);\r
57         ilGenImages(1,&outpix);\r
58         \r
59         ilBindImage(inpix);\r
60         if(!ilLoadImage(argv[1]))\r
61                 return mustard("inpix load fail.",1,1);\r
62         if(ilGetInteger(IL_IMAGE_FORMAT)!=IL_COLOUR_INDEX)\r
63                 return mustard("inpix not indexed.",1,1);\r
64         ilConvertPal(IL_PAL_RGB24);\r
65         col=ilGetInteger(IL_PALETTE_NUM_COLS);\r
66         col12=tsqrt(col);\r
67         if(!col12)\r
68                 return mustard("Palette is not squarish.",1,1);\r
69         x=ilGetInteger(IL_IMAGE_WIDTH);\r
70         y=ilGetInteger(IL_IMAGE_HEIGHT);\r
71         pal=ilGetPalette();\r
72         data=ilGetData();\r
73         \r
74         for(i=0;i<col12;++i)\r
75         {\r
76                 pal12[3*i  ]=pal[3*i*(col12+1)  ];\r
77                 pal12[3*i+1]=pal[3*i*(col12+1)+1];\r
78                 pal12[3*i+2]=pal[3*i*(col12+1)+2];\r
79         }\r
80         \r
81         ilBindImage(outpix);\r
82         if(!ilTexImage(x,y,1,1,IL_COLOUR_INDEX,IL_UNSIGNED_BYTE,NULL))\r
83                 return mustard ("outpix create fail.",1,1);\r
84         ilRegisterPal(pal12,col12*3,IL_PAL_RGB24);\r
85         data1=ilGetData();\r
86         \r
87         \r
88         \r
89         for(k=0;k<x*y;++k)\r
90         \r
91                 data1[k]=(data[k]/col12)^(data[k]%col12);\r
92         \r
93         \r
94         if(!ilSave(IL_PNG,argv[2]))\r
95                 return mustard("outpix save fail",1,1);\r
96                                 \r
97         return mustard("Ok",1,0);\r
98         \r
99         \r
100 }\r
101 \r
102 int mustard(const char *t, int m,int e)\r
103 {\r
104         if(!q)\r
105                 puts(t);\r
106         switch (m)\r
107   {\r
108   case 1:\r
109         ilDeleteImages(1,&inpix);\r
110                 ilDeleteImages(1,&outpix);\r
111   case 0:\r
112   default:\r
113                 return e;\r
114         }\r
115 }\r
116 \r
117 unsigned short tsqrt(unsigned short s)\r
118 {\r
119         switch(s)\r
120         {\r
121         case 256:\r
122                 return 16;\r
123         case 225:\r
124                 return 15;\r
125         case 196:\r
126                 return 14;\r
127         case 169:\r
128                 return 13;\r
129         case 144:\r
130                 return 12;\r
131         case 121:\r
132                 return 11;\r
133         case 100:\r
134                 return 10;\r
135         case 81:\r
136                 return 9;\r
137         case 64:\r
138                 return 8;\r
139         case 49:\r
140                 return 7;\r
141         case 36:\r
142                 return 6;\r
143         case 25:\r
144                 return 5;\r
145         case 16:\r
146                 return 4;\r
147         case 9:\r
148                 return 3;\r
149         case 4:\r
150                 return 2;\r
151         case 1:\r
152                 return 1;\r
153         default:\r
154                 return 0;\r
155         }\r
156 }       \r
157 //unsigned short isqrt(unsigned s)\r
158 //{\r
159 //      unsigned short r;\r
160 //      unsigned short b=0x0040;\r
161 //      \r
162 //      while(b>s)\r
163 //            b>>=2;\r
164 //      while(b)\r
165 //      {\r
166 //            if(s>=r+b)\r
167 //            {\r
168 //                    s-=r+b;\r
169 //                    r=(r>>1)+b;\r
170 //            }\r
171 //            else\r
172 //                    r>>1;\r
173 //            b>>2;\r
174 //      }\r
175 //      return r;\r
176 //}\r