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";
38 void print_info_uint (char *name, long unsigned value)
40 fprintf(stdout, "%s: %lu\n", name, value);
42 void print_info_bool (char *name, long unsigned value)
44 fprintf(stdout, "%s: %s\n", name, value?"TRUE":"FALSE");
46 void print_info_datatype (char *name, long unsigned value)
48 fprintf(stdout,"%s: ",name);
52 fputs("BYTE", stdout);
55 fputs("DOUBLE", stdout);
58 fputs("FLOAT", stdout);
64 fputs("SHORT", stdout);
67 fputs("UNSIGNED INT", stdout);
69 case IL_UNSIGNED_BYTE:
70 fputs("UNSIGNED BYTE", stdout);
72 case IL_UNSIGNED_SHORT:
73 fputs("UNSIGNED SHORT", stdout);
76 fprintf(stdout, "? %ld", value);
82 void print_info_dataformat (char *name, long unsigned value)
84 fprintf(stdout,"%s: ",name);
91 fputs("BGRA", stdout);
94 fputs("COLOUR INDEX", stdout);
97 fputs("LUMINANCE", stdout);
99 case IL_LUMINANCE_ALPHA:
100 fputs("LUMINANCE ALPHA", stdout);
103 fputs("RGB", stdout);
106 fputs("RGBA", stdout);
109 fprintf(stdout, "? %ld", value);
115 void print_info_originmode (char *name, long unsigned value)
117 fprintf(stdout,"%s: ",name);
120 case IL_ORIGIN_LOWER_LEFT:
121 fputs("LOWER LEFT", stdout);
123 case IL_ORIGIN_UPPER_LEFT:
124 fputs("UPPER LEFT", stdout);
127 fprintf(stdout, "? %ld", value);
133 void print_info_palettetype (char *name, long unsigned value)
135 fprintf(stdout,"%s: ",name);
139 fputs("BGR24", stdout);
142 fputs("BGR32", stdout);
145 fputs("BGRA32", stdout);
148 fputs("RGB24", stdout);
151 fputs("RGB32", stdout);
154 fputs("RGBA32", stdout);
157 fprintf(stdout, "? %ld", value);
163 int info (int argc, char **argv, char **err)
167 struct IL_full_info info;
171 *err = INFO_MISSING_ARGS;
175 r = create_pictures(1);
178 *err = CREATE_FAILED;
182 for (i=0; i<argc; ++i)
184 fprintf(stdout,"\n>>> %s <<<\n",argv[i]);
185 r = load_picture(0, argv[i],
186 OK_PALETTE_ONLY | CAN_BE_MULTIPLE | CAN_BE_OVER_8BIT);
189 fputs("FAIL\n",stdout);
194 print_info_uint ("active_image", info.active_image);
195 print_info_uint ("active_layer", info.active_layer);
196 print_info_uint ("active_mipmap", info.active_mipmap);
197 print_info_bool ("conv_pal", info.conv_pal);
198 print_info_uint ("cur_image", info.cur_image);
199 print_info_bool ("file_mode", info.file_mode);
200 print_info_dataformat ("format_mode", info.format_mode);
201 print_info_bool ("format_set", info.format_set);
202 print_info_uint ("image_bits_per_pixel", info.image_bits_per_pixel);
203 print_info_uint ("image_bytes_per_pixel", info.image_bytes_per_pixel);
204 print_info_dataformat ("image_format", info.image_format);
205 print_info_uint ("image_height", info.image_height);
206 print_info_datatype ("image_type", info.image_type);
207 print_info_uint ("image_width", info.image_width);
208 print_info_uint ("num_images", info.num_images);
209 print_info_uint ("num_mipmaps", info.num_mipmaps);
210 print_info_originmode ("origin_mode", info.origin_mode);
211 print_info_bool ("origin_set", info.origin_set);
212 print_info_uint ("palette_bpp", info.palette_bpp);
213 print_info_uint ("palette_num_cols", info.palette_num_cols);
214 print_info_palettetype("palette_type", info.palette_type);
215 print_info_datatype ("type_mode", info.type_mode);
216 print_info_bool ("type_set", info.type_set);
217 print_info_bool ("use_key_colour", info.use_key_colour);
218 print_info_uint ("version_num", info.palette_num_cols);
225 #define INPIX_MUSTARD 1
226 #define OUTPIX_MUSTARD 2
228 #define ARGUMENT_MUSTARD 4
230 #define ANIMATED_MUSTARD 6
234 #define CR newdata[4*(i+inX*j)+0]
235 #define CG newdata[4*(i+inX*j)+1]
236 #define CB newdata[4*(i+inX*j)+2]
238 #define RA ((long)(*ra))
239 #define RB ((long)(*rb))
240 #define GA ((long)(*ga))
241 #define GB ((long)(*gb))
242 #define BA ((long)(*ba))
243 #define BB ((long)(*bb))
249 void mustard(int mustard);
251 ILubyte enhance(ILubyte x, long r, long s, long t);
252 int main (int argc, const char *argv[]);
256 ILboolean pixOpen=false;
257 ILboolean allchannels=false;
259 ILubyte enhance(ILubyte x, long A, long B)
263 long y=(((long)x)-A)*255/(B-A);
264 return (ILubyte)((y>255)?255:((y<0)?0:y));
267 int main (int argc, const char *argv[])
269 ILubyte rav, rbv, gav, gbv, bav, bbv;
270 ILubyte *ra, *rb, *ga, *gb, *ba, *bb;
271 ILuint inX, inY, frame;
275 mustard(ARGUMENT_MUSTARD);
278 sscanf(argv[3],"%u",&frame);
284 if (argv[4][0]=='q' || argv[4][0]=='Q')
289 if (argv[5][0]=='a' || argv[5][0]=='A')
311 if(!ilEnable(IL_ORIGIN_SET))mustard(FAIL);
312 if(!ilEnable(IL_FILE_OVERWRITE))mustard(FAIL);
313 ilClearColour(255,255,0,0);
314 ilGenImages(1, &pix);
317 if(!ilLoadImage(argv[1]))mustard(INPIX_MUSTARD);
318 if(!ilConvertImage(IL_RGBA,IL_UNSIGNED_BYTE))mustard(INPIX_MUSTARD);
320 inX=ilGetInteger(IL_IMAGE_WIDTH);
321 inY=ilGetInteger(IL_IMAGE_HEIGHT);
322 if(ilGetInteger(IL_NUM_IMAGES)>1)
323 mustard(ANIMATED_MUSTARD);
334 for(unsigned long i=frame;i<inX-frame;++i)
336 for(unsigned long j=frame;j<inY-frame;++j)
353 for(unsigned long i=frame;i<inX-frame;++i)
355 for(unsigned long j=frame;j<inY-frame;++j)
358 CR=enhance(CR,RA,RB);
359 CG=enhance(CG,GA,GB);
360 CB=enhance(CB,BA,BB);
363 if(!ilSave(IL_PNG,argv[2]))mustard(OUTPIX_MUSTARD);
368 void mustard(int mustard)
373 if(q) printf("ENHANCED!\n");break;
374 case ARGUMENT_MUSTARD:
375 if(q) printf("nofadig inPix outPix [framesize] [q] [a]\n");break;
377 if(q) printf("inPIX mustard.\n");break;
379 if(q) printf("outPIX mustard.\n");break;
380 case ANIMATED_MUSTARD:
381 if(q) printf("Animation is mustard.\n");break;
383 if (q) printf("Ch*rpin* mustard mustaard!\n");
386 ilDeleteImages(1, &pix);