2 // The tool to extract two images hidden iside one indexed image
\r
5 // Copyright (C) 2015 Balthasar SzczepaĆski
\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
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
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
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
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
35 ILuint inpix, outpix1, outpix2;
\r
40 int main(int argc, char *argv[])
\r
43 ILubyte *pal, *data1, *data2, *data;
\r
44 ILubyte pal12[16*3];
\r
47 ILuint col12, col, x, y;
\r
50 return mustard("extract inpix outpix1 outpix2 [q]",0,1);
\r
55 ilEnable(IL_ORIGIN_SET);
\r
56 ilEnable(IL_FILE_OVERWRITE);
\r
58 ilGenImages(1,&inpix);
\r
59 ilGenImages(1,&outpix1);
\r
60 ilGenImages(1,&outpix2);
\r
63 if(!ilLoadImage(argv[1]))
\r
64 return mustard("inpix load fail.",1,1);
\r
65 if(ilGetInteger(IL_IMAGE_FORMAT)!=IL_COLOUR_INDEX)
\r
66 return mustard("inpix not indexed.",1,1);
\r
67 ilConvertPal(IL_PAL_RGB24);
\r
68 col=ilGetInteger(IL_PALETTE_NUM_COLS);
\r
71 return mustard("Palette is not squarish.",1,1);
\r
72 x=ilGetInteger(IL_IMAGE_WIDTH);
\r
73 y=ilGetInteger(IL_IMAGE_HEIGHT);
\r
77 for(i=0;i<col12;++i)
\r
79 pal12[3*i ]=pal[3*i*(col12+1) ];
\r
80 pal12[3*i+1]=pal[3*i*(col12+1)+1];
\r
81 pal12[3*i+2]=pal[3*i*(col12+1)+2];
\r
84 ilBindImage(outpix1);
\r
85 if(!ilTexImage(x,y,1,1,IL_COLOUR_INDEX,IL_UNSIGNED_BYTE,NULL))
\r
86 return mustard ("outpix1 create fail.",1,1);
\r
87 ilRegisterPal(pal12,col12*3,IL_PAL_RGB24);
\r
90 ilBindImage(outpix2);
\r
91 if(!ilTexImage(x,y,1,1,IL_COLOUR_INDEX,IL_UNSIGNED_BYTE,NULL))
\r
92 return mustard ("outpix2 create fail.",1,1);
\r
93 ilRegisterPal(pal12,col12*3,IL_PAL_RGB24);
\r
98 data1[k]=data[k]/col12;
\r
99 data2[k]=data[k]%col12;
\r
102 if(!ilSave(IL_PNG,argv[3]))
\r
103 return mustard("outpix2 save fail",1,1);
\r
104 ilBindImage(outpix1);
\r
105 if(!ilSave(IL_PNG,argv[2]))
\r
106 return mustard("outpix1 save fail",1,1);
\r
108 return mustard("Ok",1,0);
\r
113 int mustard(const char *t, int m,int e)
\r
119 ilDeleteImages(1,&inpix);
\r
120 ilDeleteImages(1,&outpix1);
\r
121 ilDeleteImages(1,&outpix2);
\r
128 unsigned short tsqrt(unsigned short s)
\r
168 //unsigned short isqrt(unsigned s)
\r
170 // unsigned short r;
\r
171 // unsigned short b=0x0040;
\r