2 // The enhancement software - reveal hidden details
5 // Copyright (C) 2014 - 2019 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)
26 #define INPIX_MUSTARD 1
27 #define OUTPIX_MUSTARD 2
29 #define ARGUMENT_MUSTARD 4
31 #define ANIMATED_MUSTARD 6
40 void mustard(int mustard);
41 ILubyte swap1(ILubyte x);
42 ILubyte swap2(ILubyte x);
43 ILubyte swap4(ILubyte x);
44 int main (int argc, const char *argv[]);
48 ILboolean pixOpen=false;
51 ILubyte swap1(ILubyte x)
81 ILubyte swap2(ILubyte x)
99 ILubyte swap4(ILubyte x)
111 int main (int argc, const char *argv[])
113 ILuint inX, inY, inZ, inC;
114 ILubyte *newdata, *pal;
115 unsigned char indexed;
118 mustard(ARGUMENT_MUSTARD);
121 if (argv[3][0]=='q' || argv[3][0]=='Q')
125 if(q) printf("%s -> %s ",argv[1],argv[2]);
129 if(!ilEnable(IL_ORIGIN_SET))mustard(FAIL);
130 if(!ilEnable(IL_FILE_OVERWRITE))mustard(FAIL);
131 ilClearColour(255,255,0,0);
132 ilGenImages(1, &pix);
135 if(!ilLoadImage(argv[1]))mustard(INPIX_MUSTARD);
136 indexed=(ilGetInteger(IL_IMAGE_FORMAT)==IL_COLOUR_INDEX)?1:0;
140 ilConvertPal(IL_PAL_RGB24);
141 inC=ilGetInteger(IL_PALETTE_NUM_COLS);
144 for(unsigned long k=0;k<inC;++k)
146 pal[k*3 ]=swap4(pal[k*3 ]);
147 pal[k*3+1]=swap2(pal[k*3+1]);
148 pal[k*3+2]=swap1(pal[k*3+2]);
155 if(!ilConvertImage(IL_RGB,IL_UNSIGNED_BYTE))mustard(INPIX_MUSTARD);
157 inX=ilGetInteger(IL_IMAGE_WIDTH);
158 inY=ilGetInteger(IL_IMAGE_HEIGHT);
159 inZ=ilGetInteger(IL_NUM_IMAGES);
163 // printf("%d %d %d\n", inX, inY, inZ);
166 for(unsigned long k=0;k<inZ;++k)
168 for(unsigned long i=0;i<inX;++i)
170 for(unsigned long j=0;j<inY;++j)
172 newdata[(k*inX*inY+j*inX+i)*3 ]=swap4(newdata[(k*inX*inY+j*inX+i)*3 ]);
173 newdata[(k*inX*inY+j*inX+i)*3+1]=swap2(newdata[(k*inX*inY+j*inX+i)*3+1]);
174 newdata[(k*inX*inY+j*inX+i)*3+2]=swap1(newdata[(k*inX*inY+j*inX+i)*3+2]);
179 if(!ilSave((inZ>1)?IL_GIF:IL_PNG,argv[2]))mustard(OUTPIX_MUSTARD);
184 void mustard(int mustard)
187 while((error=ilGetError())!=IL_NO_ERROR)
188 printf("%d: %s\n",error,iluErrorString(error));
192 if(q) printf("ENHANCED!\n");
194 case ARGUMENT_MUSTARD:
196 printf("enhance inPix outPix [q]\n");
200 printf("inPIX mustard.\n");
204 printf("outPIX mustard.\n");
206 case ANIMATED_MUSTARD:
208 printf("Animation is mustard.\n");
212 printf("Ch*rpin* mustard mustaard!\n");
215 ilDeleteImages(1, &pix);