comparison tools/view64.c @ 1391:f3c5f80511ae

Add "probe only" mode to view64.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 24 Sep 2017 22:26:22 +0300
parents 5c3ee6f028dc
children 009534f27de5
comparison
equal deleted inserted replaced
1390:e3794fb2df83 1391:f3c5f80511ae
14 14
15 char * optFilename = NULL; 15 char * optFilename = NULL;
16 int optVFlags = SDL_SWSURFACE | SDL_HWPALETTE; 16 int optVFlags = SDL_SWSURFACE | SDL_HWPALETTE;
17 int optScrWidth, optScrHeight; 17 int optScrWidth, optScrHeight;
18 int optForcedFormat = -1; 18 int optForcedFormat = -1;
19 BOOL optProbeOnly = FALSE;
19 20
20 21
21 static const DMOptArg optList[] = 22 static const DMOptArg optList[] =
22 { 23 {
23 { 0, '?', "help", "Show this help", OPT_NONE }, 24 { 0, '?', "help", "Show this help", OPT_NONE },
24 { 1, 'v', "verbose", "Be more verbose", OPT_NONE }, 25 { 1, 'v', "verbose", "Be more verbose", OPT_NONE },
25 { 2, 0, "fs", "Fullscreen", OPT_NONE }, 26 { 2, 0, "fs", "Fullscreen", OPT_NONE },
26 { 3, 'S', "scale", "Scale image by factor (1-10)", OPT_ARGREQ }, 27 { 3, 'S', "scale", "Scale image by factor (1-10)", OPT_ARGREQ },
27 { 4, 'f', "format", "Force input format (see list below)", OPT_ARGREQ }, 28 { 4, 'f', "format", "Force input format (see list below)", OPT_ARGREQ },
29 { 5, 'p', "probe", "Probe only (no display)", OPT_NONE },
28 }; 30 };
29 31
30 const int optListN = sizeof(optList) / sizeof(optList[0]); 32 const int optListN = sizeof(optList) / sizeof(optList[0]);
31 33
32 34
111 return FALSE; 113 return FALSE;
112 } 114 }
113 } 115 }
114 break; 116 break;
115 117
118 case 5:
119 optProbeOnly = TRUE;
120 break;
121
116 default: 122 default:
117 dmErrorMsg("Unknown option '%s'.\n", currArg); 123 dmErrorMsg("Unknown option '%s'.\n", currArg);
118 return FALSE; 124 return FALSE;
119 } 125 }
120 126
147 } 153 }
148 return TRUE; 154 return TRUE;
149 } 155 }
150 156
151 157
152 void dmDumpC64Image(const DMC64Image *img) 158 void dmDumpC64Image(const size_t size, const DMC64Image *img, const DMC64ImageFormat *fmt)
153 { 159 {
154 char typeStr[64]; 160 char typeStr[64];
155 161
156 snprintf(typeStr, sizeof(typeStr), 162 snprintf(typeStr, sizeof(typeStr),
157 "%s%s%s%s", 163 "%s%s%s%s",
159 ((img->type & D64_FMT_ILACE) ? " Interlaced" : ""), 165 ((img->type & D64_FMT_ILACE) ? " Interlaced" : ""),
160 ((img->type & D64_FMT_FLI) ? " FLI" : ""), 166 ((img->type & D64_FMT_FLI) ? " FLI" : ""),
161 ((img->type & D64_FMT_CHAR) ? " CHAR" : "") 167 ((img->type & D64_FMT_CHAR) ? " CHAR" : "")
162 ); 168 );
163 169
164 dmPrint(0, 170 dmPrint(1,
171 "Format : %s [%s]\n"
172 "Data size : %" DM_PRIu_SIZE_T "\n"
165 "Type : %s\n" 173 "Type : %s\n"
166 "Banks : %d\n", 174 "Banks : %d\n",
167 typeStr, img->nbanks); 175 fmt->name, fmt->fext,
176 size,
177 typeStr,
178 img->nbanks);
168 179
169 if (img->type & D64_FMT_ILACE) 180 if (img->type & D64_FMT_ILACE)
170 { 181 {
171 char *tmps; 182 char *tmps;
172 switch(img->laceType) 183 switch(img->laceType)
173 { 184 {
174 case D64_ILACE_COLOR: tmps = "color"; break; 185 case D64_ILACE_COLOR: tmps = "color"; break;
175 case D64_ILACE_RES: tmps = "resolution"; break; 186 case D64_ILACE_RES: tmps = "resolution"; break;
176 default: tmps = "ERROR"; break; 187 default: tmps = "ERROR"; break;
177 } 188 }
178 dmPrint(0, 189 dmPrint(1,
179 "Interlace type : %s\n", 190 "Interlace type : %s\n",
180 tmps); 191 tmps);
181 } 192 }
182 193
183 dmPrint(0, 194 dmPrint(1,
184 "Width x Height : %d x %d\n" 195 "Width x Height : %d x %d\n"
185 "CHwidth x CHheight : %d x %d\n", 196 "CHwidth x CHheight : %d x %d\n",
186 img->width, img->height, 197 img->width, img->height,
187 img->ch_width, img->ch_height); 198 img->ch_width, img->ch_height);
188 } 199 }
214 { 225 {
215 dmErrorMsg("No input file specified, perhaps you need some --help\n"); 226 dmErrorMsg("No input file specified, perhaps you need some --help\n");
216 goto error; 227 goto error;
217 } 228 }
218 229
230 dmPrint(1, "\n%s\n", optFilename);
219 if ((ret = dmReadDataFile(NULL, optFilename, &dataBuf, &dataSize)) != DMERR_OK) 231 if ((ret = dmReadDataFile(NULL, optFilename, &dataBuf, &dataSize)) != DMERR_OK)
220 goto error; 232 goto error;
221 233
222 dmMsg(1, "Read %d bytes of input.\n", dataSize);
223 234
224 // Probe for format 235 // Probe for format
225 if (optForcedFormat >= 0) 236 if (optForcedFormat >= 0)
226 { 237 {
227 forced = &dmC64ImageFormats[optForcedFormat]; 238 forced = &dmC64ImageFormats[optForcedFormat];
228 dmMsg(0,"Forced %s format image, type %d, %s\n", 239 dmMsg(0, "Forced %s format image, type %d, %s\n",
229 forced->name, forced->type, forced->fext); 240 forced->name, forced->type, forced->fext);
230 } 241 }
231 else 242 else
232 forced = NULL; 243 forced = NULL;
233 244
237 { 248 {
238 dmErrorMsg("Failed to decode bitmap data %d: %s\n", ret, dmErrorStr(ret)); 249 dmErrorMsg("Failed to decode bitmap data %d: %s\n", ret, dmErrorStr(ret));
239 goto error; 250 goto error;
240 } 251 }
241 252
242 if (forced == NULL && fmt != NULL)
243 {
244 dmPrint(0, "Probed %s format image, type %d, %s\n",
245 fmt->name, fmt->type, fmt->fext);
246 }
247
248 if (fmt == NULL) 253 if (fmt == NULL)
249 { 254 {
250 dmErrorMsg("Probing could not find any matching image format. Perhaps try forcing a format via -f.\n"); 255 dmErrorMsg("Probing could not find any matching image format. Perhaps try forcing a format via -f.\n");
251 goto error; 256 goto error;
252 } 257 }
253 258
254 dmDumpC64Image(cimage); 259 dmDumpC64Image(dataSize, cimage, fmt);
260
261 if (optProbeOnly)
262 goto error;
255 263
256 // Initialize libSDL 264 // Initialize libSDL
257 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) 265 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0)
258 { 266 {
259 dmErrorMsg("Could not initialize SDL: %s\n", SDL_GetError()); 267 dmErrorMsg("Could not initialize SDL: %s\n", SDL_GetError());