2 // The tool to hide two indexed images iside one
5 // Copyright (C) 2015 Balthasar Szczepański
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 // Requires Dev Image Library (libdevil) (http://openil.sourceforge.net/)
22 // on Pentium III libdevil must be recompiled with
23 // --disable-ssl2 --disable-ssl3
24 // (https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=572954)
30 int mustard(const char *t,int m,int e);
31 int main(int argc, char *argv[]);
33 ILuint inpix1, inpix2, outpix;
37 int main(int argc, char *argv[])
40 ILubyte *pal1, *pal2, *data1, *data2, *data;
44 ILuint col1, col2, col, x1, x2, y1, y2;
46 unsigned short p1, p2, p3;
49 return mustard("insert inpix1 inpix2 outpix [p1 p2]",0,1);
64 ilEnable(IL_ORIGIN_SET);
65 ilEnable(IL_FILE_OVERWRITE);
67 ilGenImages(1,&inpix1);
68 ilGenImages(1,&inpix2);
69 ilGenImages(1,&outpix);
72 if(!ilLoadImage(argv[1]))
73 return mustard("inpix1 load fail.",1,1);
74 if(ilGetInteger(IL_IMAGE_FORMAT)!=IL_COLOUR_INDEX)
75 return mustard("inpix1 not indexed.",1,1);
76 ilConvertPal(IL_PAL_RGB24);
77 col1=ilGetInteger(IL_PALETTE_NUM_COLS);
79 return mustard("inpix1 too many colors.",1,1);
80 x1=ilGetInteger(IL_IMAGE_WIDTH);
81 y1=ilGetInteger(IL_IMAGE_HEIGHT);
86 if(!ilLoadImage(argv[2]))
87 return mustard("inpix2 load fail.",1,1);
88 if(ilGetInteger(IL_IMAGE_FORMAT)!=IL_COLOUR_INDEX)
89 return mustard("inpix2 not indexed.",1,1);
90 ilConvertPal(IL_PAL_RGB24);
91 col2=ilGetInteger(IL_PALETTE_NUM_COLS);
93 return mustard("inpix2 too many colors.",1,1);
95 return mustard("different palette size.",1,1);
96 x2=ilGetInteger(IL_IMAGE_WIDTH);
98 return mustard("different widths",1,1);
99 y2=ilGetInteger(IL_IMAGE_HEIGHT);
101 return mustard("different heights",1,1);
110 pal[3*(i*col1+j) ]=(pal1[3*i ]*p1+pal2[3*j ]*p2)/p3;
111 pal[3*(i*col1+j)+1]=(pal1[3*i+1]*p1+pal2[3*j+1]*p2)/p3;
112 pal[3*(i*col1+j)+2]=(pal1[3*i+2]*p1+pal2[3*j+2]*p2)/p3;
117 if(!ilTexImage(x1,y1,1,1,IL_COLOUR_INDEX,IL_UNSIGNED_BYTE,NULL))
118 return mustard ("outpix create fail.",1,1);
119 ilRegisterPal(pal,col*3,IL_PAL_RGB24);
123 data[k]=data1[k]*col2+data2[k];
125 if(!ilSave(IL_PNG,argv[3]))
126 return mustard("outpix save fail",1,1);
128 return mustard("Ok",1,0);
132 int mustard(const char *t, int m,int e)
138 ilDeleteImages(1,&inpix1);
139 ilDeleteImages(1,&inpix2);
140 ilDeleteImages(1,&outpix);