]> bicyclesonthemoon.info Git - ott/enhance/blob - info.c
reveal online
[ott/enhance] / info.c
1 /*
2 info.c
3 Get information
4 13.11.2022
5
6 Copyright (C) 2022  Balthasar SzczepaƄski
7
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.
12
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.
17
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/>.
20
21
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)
26
27 */
28
29 #include <stdint.h>
30 #include <inttypes.h>
31 #include <errno.h>
32
33 #include "core.h"
34 #include "info.h"
35
36 char INFO_MISSING_ARGS[] = "Missing parameters.\ninfo inPix\n";
37
38 void print_info_uint (char *name, long unsigned value)
39 {
40         fprintf(stdout, "%s: %lu\n", name, value);
41 }
42 void print_info_bool (char *name, long unsigned value)
43 {
44         fprintf(stdout, "%s: %s\n", name, value?"TRUE":"FALSE");
45 }
46 void print_info_datatype (char *name, long unsigned value)
47 {
48         fprintf(stdout,"%s: ",name);
49         switch (value)
50         {
51         case IL_BYTE:
52                 fputs("BYTE", stdout);
53                 break;
54         case IL_DOUBLE:
55                 fputs("DOUBLE", stdout);
56                 break;
57         case IL_FLOAT:
58                 fputs("FLOAT", stdout);
59                 break;
60         case IL_INT:
61                 fputs("INT", stdout);
62                 break;
63         case IL_SHORT:
64                 fputs("SHORT", stdout);
65                 break;
66         case IL_UNSIGNED_INT:
67                 fputs("UNSIGNED INT", stdout);
68                 break;
69         case IL_UNSIGNED_BYTE:
70                 fputs("UNSIGNED BYTE", stdout);
71                 break;
72         case IL_UNSIGNED_SHORT:
73                 fputs("UNSIGNED SHORT", stdout);
74                 break;
75         default:
76                 fprintf(stdout, "? %ld", value);
77                 break;
78         }
79         fputs("\n", stdout);
80 }
81
82 void print_info_dataformat (char *name, long unsigned value)
83 {
84         fprintf(stdout,"%s: ",name);
85         switch (value)
86         {
87         case IL_BGR:
88                 fputs("BGR", stdout);
89                 break;
90         case IL_BGRA:
91                 fputs("BGRA", stdout);
92                 break;
93         case IL_COLOUR_INDEX:
94                 fputs("COLOUR INDEX", stdout);
95                 break;
96         case IL_LUMINANCE:
97                 fputs("LUMINANCE", stdout);
98                 break;
99         case IL_LUMINANCE_ALPHA:
100                 fputs("LUMINANCE ALPHA", stdout);
101                 break;
102         case IL_RGB:
103                 fputs("RGB", stdout);
104                 break;
105         case IL_RGBA:
106                 fputs("RGBA", stdout);
107                 break;
108         default:
109                 fprintf(stdout, "? %ld", value);
110                 break;
111         }
112         fputs("\n", stdout);
113 }
114
115 void print_info_originmode (char *name, long unsigned value)
116 {
117         fprintf(stdout,"%s: ",name);
118         switch (value)
119         {
120         case IL_ORIGIN_LOWER_LEFT:
121                 fputs("LOWER LEFT", stdout);
122                 break;
123         case IL_ORIGIN_UPPER_LEFT:
124                 fputs("UPPER LEFT", stdout);
125                 break;
126         default:
127                 fprintf(stdout, "? %ld", value);
128                 break;
129         }
130         fputs("\n", stdout);
131 }
132
133 void print_info_palettetype (char *name, long unsigned value)
134 {
135         fprintf(stdout,"%s: ",name);
136         switch (value)
137         {
138         case IL_PAL_BGR24:
139                 fputs("BGR24", stdout);
140                 break;
141         case IL_PAL_BGR32:
142                 fputs("BGR32", stdout);
143                 break;
144         case IL_PAL_BGRA32:
145                 fputs("BGRA32", stdout);
146                 break;
147         case IL_PAL_RGB24:
148                 fputs("RGB24", stdout);
149                 break;
150         case IL_PAL_RGB32:
151                 fputs("RGB32", stdout);
152                 break;
153         case IL_PAL_RGBA32:
154                 fputs("RGBA32", stdout);
155                 break;
156         default:
157                 fprintf(stdout, "? %ld", value);
158                 break;
159         }
160         fputs("\n", stdout);
161 }
162
163 int subtool_info (int argc, char **argv, int argi, char **err)
164 {
165         int r;
166         int i;
167         ILint j;
168         ILint frames=1;
169         struct IL_full_info info;
170         FLAG_TYPE flags = OK_PALETTE_ONLY | CAN_BE_MULTIPLE | CAN_BE_OVER_8BIT;
171         
172         if (argc <= argi)
173         {
174                 *err = INFO_MISSING_ARGS;
175                 return EINVAL;
176         }
177         
178         r = reserve_pictures(1);
179         if (r)
180         {
181                 *err = CREATE_FAILED;
182                 return r;
183         }
184         
185         for (i=argi; i<argc; ++i)
186         {
187                 fprintf(stdout,"\n>>> %s <<<\n",argv[i]);
188                 r = load_picture(0, argv[i], &info, &flags);
189                 if (r)
190                 {
191                         fputs("FAIL\n",stdout);
192                         continue;
193                 }
194                 
195                 for (j=0; j<frames; ++j)
196                 {
197                         get_info(0, &info, j);
198                         if (j==0)
199                                 frames = info.num_images+1;
200                         else
201                                 fprintf(stdout, "--- %lu ---\n", (unsigned long)j);
202                         print_info_uint       ("active_image",          info.active_image);
203                         print_info_uint       ("active_layer",          info.active_layer);
204                         print_info_uint       ("active_mipmap",         info.active_mipmap);
205                         print_info_bool       ("blit_blend",            info.blit_blend);
206                         print_info_uint       ("compress_mode",         info.compress_mode);
207                         print_info_bool       ("conv_pal",              info.conv_pal);
208                         print_info_uint       ("cur_image",             info.cur_image);
209                         print_info_bool       ("default_on_fail",       info.default_on_fail);
210                         print_info_uint /*?*/ ("dxtc_data_format",      info.dxtc_data_format);
211                         print_info_bool       ("file_mode",             info.file_mode);
212                         print_info_dataformat ("format_mode",           info.format_mode);
213                         print_info_bool       ("format_set",            info.format_set);
214                         print_info_uint       ("image_bits_per_pixel",  info.image_bits_per_pixel);
215                         print_info_uint       ("image_bpc",             info.image_bpc);
216                         print_info_uint       ("image_bytes_per_pixel", info.image_bytes_per_pixel);
217                         print_info_uint       ("image_channels",        info.image_channels);
218                         print_info_uint       ("image_cubeflags",       info.image_cubeflags);
219                         print_info_uint       ("image_depth",           info.image_depth);
220                         print_info_uint       ("image_duration",        info.image_duration);
221                         print_info_dataformat ("image_format",          info.image_format);
222                         print_info_uint       ("image_height",          info.image_height);
223                         print_info_uint       ("image_offx",            info.image_offx);
224                         print_info_uint       ("image_offy",            info.image_offy);
225                         print_info_originmode ("image_origin",          info.image_origin);
226                         print_info_uint       ("image_planesize",       info.image_planesize);
227                         print_info_uint       ("image_size_of_data",    info.image_size_of_data);
228                         print_info_datatype   ("image_type",            info.image_type);
229                         print_info_uint       ("image_width",           info.image_width);
230                         print_info_uint /*?*/ ("keep_dxtc_data",        info.keep_dxtc_data);
231                         print_info_uint       ("num_faces",             info.num_faces);
232                         print_info_uint       ("num_images",            info.num_images);
233                         print_info_uint       ("num_layers",            info.num_layers);
234                         print_info_uint       ("num_mipmaps",           info.num_mipmaps);
235                         print_info_originmode ("origin_mode",           info.origin_mode);
236                         print_info_bool       ("origin_set",            info.origin_set);
237                         print_info_dataformat ("palette_base_type",     info.palette_base_type);
238                         print_info_uint       ("palette_bpp",           info.palette_bpp);
239                         print_info_uint       ("palette_num_cols",      info.palette_num_cols);
240                         print_info_palettetype("palette_type",          info.palette_type);
241                         print_info_datatype   ("type_mode",             info.type_mode);
242                         print_info_bool       ("type_set",              info.type_set);
243                         print_info_bool       ("use_key_colour",        info.use_key_colour);
244                         print_info_uint       ("version_num",           info.palette_num_cols);
245                 }
246         }
247         return 0;
248 }
249