6 Copyright (C) 2022 Balthasar SzczepaĆski
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU Affero General Public License as
10 published by the Free Software Foundation, either version 3 of the
11 License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Affero General Public License for more details.
18 You should have received a copy of the GNU Affero General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 Requires Dev Image Library (libdevil) (http://openil.sourceforge.net/)
23 on Pentium III libdevil must be recompiled with
24 --disable-ssl2 --disable-ssl3
25 (https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=572954)
36 char INFO_MISSING_ARGS[] = "Missing parameters.\ninfo inPix\n";
37 char INFO_LOAD_FAILED[] = "Failed to load picture.\n";
39 void print_info_uint (char *name, long unsigned value)
41 fprintf(stdout, "%s: %lu\n", name, value);
43 void print_info_bool (char *name, long unsigned value)
45 fprintf(stdout, "%s: %s\n", name, value?"TRUE":"FALSE");
47 void print_info_datatype (char *name, long unsigned value)
49 fprintf(stdout,"%s: ",name);
53 fputs("BYTE", stdout);
56 fputs("DOUBLE", stdout);
59 fputs("FLOAT", stdout);
65 fputs("SHORT", stdout);
68 fputs("UNSIGNED INT", stdout);
70 case IL_UNSIGNED_BYTE:
71 fputs("UNSIGNED BYTE", stdout);
73 case IL_UNSIGNED_SHORT:
74 fputs("UNSIGNED SHORT", stdout);
77 fprintf(stdout, "? %ld", value);
83 void print_info_dataformat (char *name, long unsigned value)
85 fprintf(stdout,"%s: ",name);
92 fputs("BGRA", stdout);
95 fputs("COLOUR INDEX", stdout);
98 fputs("LUMINANCE", stdout);
100 case IL_LUMINANCE_ALPHA:
101 fputs("LUMINANCE ALPHA", stdout);
104 fputs("RGB", stdout);
107 fputs("RGBA", stdout);
110 fprintf(stdout, "? %ld", value);
116 void print_info_originmode (char *name, long unsigned value)
118 fprintf(stdout,"%s: ",name);
121 case IL_ORIGIN_LOWER_LEFT:
122 fputs("LOWER LEFT", stdout);
124 case IL_ORIGIN_UPPER_LEFT:
125 fputs("UPPER LEFT", stdout);
128 fprintf(stdout, "? %ld", value);
134 void print_info_palettetype (char *name, long unsigned value)
136 fprintf(stdout,"%s: ",name);
140 fputs("BGR24", stdout);
143 fputs("BGR32", stdout);
146 fputs("BGRA32", stdout);
149 fputs("RGB24", stdout);
152 fputs("RGB32", stdout);
155 fputs("RGBA32", stdout);
158 fprintf(stdout, "? %ld", value);
164 int info (int argc, char **argv, char **err)
168 struct IL_full_info info;
172 *err = INFO_MISSING_ARGS;
176 r = create_pictures(1);
179 *err = INFO_LOAD_FAILED;
183 for (i=0; i<argc; ++i)
185 fprintf(stdout,"\n>>> %s <<<\n",argv[i]);
186 r = load_picture(0, argv[i],
187 OK_PALETTE_ONLY | CAN_BE_MULTIPLE | CAN_BE_OVER_8BIT);
190 fputs("FAIL\n",stdout);
195 print_info_uint ("active_image", info.active_image);
196 print_info_uint ("active_layer", info.active_layer);
197 print_info_uint ("active_mipmap", info.active_mipmap);
198 print_info_bool ("conv_pal", info.conv_pal);
199 print_info_uint ("cur_image", info.cur_image);
200 print_info_bool ("file_mode", info.file_mode);
201 print_info_dataformat ("format_mode", info.format_mode);
202 print_info_bool ("format_set", info.format_set);
203 print_info_uint ("image_bits_per_pixel", info.image_bits_per_pixel);
204 print_info_uint ("image_bytes_per_pixel", info.image_bytes_per_pixel);
205 print_info_dataformat ("image_format", info.image_format);
206 print_info_uint ("image_height", info.image_height);
207 print_info_datatype ("image_type", info.image_type);
208 print_info_uint ("image_width", info.image_width);
209 print_info_uint ("num_images", info.num_images);
210 print_info_uint ("num_mipmaps", info.num_mipmaps);
211 print_info_originmode ("origin_mode", info.origin_mode);
212 print_info_bool ("origin_set", info.origin_set);
213 print_info_uint ("palette_bpp", info.palette_bpp);
214 print_info_uint ("palette_num_cols", info.palette_num_cols);
215 print_info_palettetype("palette_type", info.palette_type);
216 print_info_datatype ("type_mode", info.type_mode);
217 print_info_bool ("type_set", info.type_set);
218 print_info_bool ("use_key_colour", info.use_key_colour);
219 print_info_uint ("version_num", info.palette_num_cols);
226 #define INPIX_MUSTARD 1
227 #define OUTPIX_MUSTARD 2
229 #define ARGUMENT_MUSTARD 4
231 #define ANIMATED_MUSTARD 6
235 #define CR newdata[4*(i+inX*j)+0]
236 #define CG newdata[4*(i+inX*j)+1]
237 #define CB newdata[4*(i+inX*j)+2]
239 #define RA ((long)(*ra))
240 #define RB ((long)(*rb))
241 #define GA ((long)(*ga))
242 #define GB ((long)(*gb))
243 #define BA ((long)(*ba))
244 #define BB ((long)(*bb))
250 void mustard(int mustard);
252 ILubyte enhance(ILubyte x, long r, long s, long t);
253 int main (int argc, const char *argv[]);
257 ILboolean pixOpen=false;
258 ILboolean allchannels=false;
260 ILubyte enhance(ILubyte x, long A, long B)
264 long y=(((long)x)-A)*255/(B-A);
265 return (ILubyte)((y>255)?255:((y<0)?0:y));
268 int main (int argc, const char *argv[])
270 ILubyte rav, rbv, gav, gbv, bav, bbv;
271 ILubyte *ra, *rb, *ga, *gb, *ba, *bb;
272 ILuint inX, inY, frame;
276 mustard(ARGUMENT_MUSTARD);
279 sscanf(argv[3],"%u",&frame);
285 if (argv[4][0]=='q' || argv[4][0]=='Q')
290 if (argv[5][0]=='a' || argv[5][0]=='A')
312 if(!ilEnable(IL_ORIGIN_SET))mustard(FAIL);
313 if(!ilEnable(IL_FILE_OVERWRITE))mustard(FAIL);
314 ilClearColour(255,255,0,0);
315 ilGenImages(1, &pix);
318 if(!ilLoadImage(argv[1]))mustard(INPIX_MUSTARD);
319 if(!ilConvertImage(IL_RGBA,IL_UNSIGNED_BYTE))mustard(INPIX_MUSTARD);
321 inX=ilGetInteger(IL_IMAGE_WIDTH);
322 inY=ilGetInteger(IL_IMAGE_HEIGHT);
323 if(ilGetInteger(IL_NUM_IMAGES)>1)
324 mustard(ANIMATED_MUSTARD);
335 for(unsigned long i=frame;i<inX-frame;++i)
337 for(unsigned long j=frame;j<inY-frame;++j)
354 for(unsigned long i=frame;i<inX-frame;++i)
356 for(unsigned long j=frame;j<inY-frame;++j)
359 CR=enhance(CR,RA,RB);
360 CG=enhance(CG,GA,GB);
361 CB=enhance(CB,BA,BB);
364 if(!ilSave(IL_PNG,argv[2]))mustard(OUTPIX_MUSTARD);
369 void mustard(int mustard)
374 if(q) printf("ENHANCED!\n");break;
375 case ARGUMENT_MUSTARD:
376 if(q) printf("nofadig inPix outPix [framesize] [q] [a]\n");break;
378 if(q) printf("inPIX mustard.\n");break;
380 if(q) printf("outPIX mustard.\n");break;
381 case ANIMATED_MUSTARD:
382 if(q) printf("Animation is mustard.\n");break;
384 if (q) printf("Ch*rpin* mustard mustaard!\n");
387 ilDeleteImages(1, &pix);