comparison lib64gfx.c @ 511:4cdcaeb68b54

Collapse most of the probing functions into one generic probe, as they only check loading address and file size.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 19 Nov 2012 15:52:44 +0200
parents 43ea59887c69
children 486067f39bc1
comparison
equal deleted inserted replaced
510:43ea59887c69 511:4cdcaeb68b54
114 114
115 return 0; 115 return 0;
116 } 116 }
117 117
118 118
119 static int fmtProbeDrazPaint(const Uint8 *buf, const size_t len) 119 static BOOL dmCompareAddr16(const Uint8 *buf, const size_t offs, const Uint16 addr)
120 { 120 {
121 if (len == 10051 && buf[0] == 0x00 && buf[1] == 0x58) 121 return (buf[offs] == (addr & 0xff)) && (buf[offs + 1] == ((addr >> 8) & 0xff));
122 return DM_PROBE_SCORE_GOOD; 122 }
123 123
124 return DM_PROBE_SCORE_FALSE; 124
125 } 125 static int fmtProbeDrazPaint20Packed(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt)
126
127
128 static int fmtProbeDrazPaint20Packed(const Uint8 *buf, const size_t len)
129 { 126 {
130 const char *ident = (const char *) buf + 2; 127 const char *ident = (const char *) buf + 2;
131 if (len > 22 && buf[0] == 0x00 && buf[1] == 0x58 && 128
132 strncmp(ident, "DRAZPAINT ", 10) == 0 && 129 if (len > 22 &&
133 ident[11] == '.' && ( 130 dmCompareAddr16(buf, 0, fmt->addr) &&
134 (ident[10] == '1' && ident[12] == '4') || 131 strncmp(ident, "DRAZPAINT ", 10) == 0 &&
135 (ident[10] == '2' && ident[12] == '0') 132 ident[11] == '.' && (
136 )) 133 (ident[10] == '1' && ident[12] == '4') ||
134 (ident[10] == '2' && ident[12] == '0')
135 ))
137 return DM_PROBE_SCORE_MAX; 136 return DM_PROBE_SCORE_MAX;
138 137
139 return DM_PROBE_SCORE_FALSE; 138 return DM_PROBE_SCORE_FALSE;
140 } 139 }
141 140
176 175
177 return res; 176 return res;
178 } 177 }
179 178
180 179
181 static int fmtProbeDrazLace10(const Uint8 *buf, const size_t len) 180 static int fmtProbeDrazLace10Packed(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt)
182 {
183 if (len == 18242 && buf[0] == 0x00 && buf[1] == 0x58)
184 return DM_PROBE_SCORE_GOOD;
185 return DM_PROBE_SCORE_FALSE;
186 }
187
188
189 static int fmtProbeDrazLace10Packed(const Uint8 *buf, const size_t len)
190 { 181 {
191 const char *ident = (const char *) buf + 2; 182 const char *ident = (const char *) buf + 2;
192 if (len > 22 && buf[0] == 0x00 && buf[1] == 0x58 && 183 if (len > 22 &&
193 strncmp(ident, "DRAZLACE! 1.0", 13) == 0) 184 dmCompareAddr16(buf, 0, fmt->addr) &&
185 strncmp(ident, "DRAZLACE! 1.0", 13) == 0)
194 return DM_PROBE_SCORE_MAX; 186 return DM_PROBE_SCORE_MAX;
195 187
196 return DM_PROBE_SCORE_FALSE; 188 return DM_PROBE_SCORE_FALSE;
197 } 189 }
198 190
206 return TRUE; 198 return TRUE;
207 } 199 }
208 200
209 201
210 #define AMICA_DM_PROBE_SIZE 1024 202 #define AMICA_DM_PROBE_SIZE 1024
211 static int fmtProbeAmicaPaintPacked(const Uint8 *buf, const size_t len) 203 static int fmtProbeAmicaPaintPacked(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt)
212 { 204 {
213 int i, n; 205 int i, n;
214 if (len < AMICA_DM_PROBE_SIZE || buf[0] != 0x00 || buf[1] != 0x40) 206 if (len < AMICA_DM_PROBE_SIZE || !dmCompareAddr16(buf, 0, fmt->addr))
215 return DM_PROBE_SCORE_FALSE; 207 return DM_PROBE_SCORE_FALSE;
216 208
217 // Interpaint Hi-Res gives a false positive 209 // Interpaint Hi-Res gives a false positive
218 if (len == 9002) 210 if (len == 9002)
219 return DM_PROBE_SCORE_FALSE; 211 return DM_PROBE_SCORE_FALSE;
261 res = dmC64DecodeGenericBMP(img, mem, dst - mem + 1, fmt); 253 res = dmC64DecodeGenericBMP(img, mem, dst - mem + 1, fmt);
262 254
263 dmFree(mem); 255 dmFree(mem);
264 256
265 return res; 257 return res;
266 }
267
268
269 static int fmtProbeKoalaPaint(const Uint8 *buf, const size_t len)
270 {
271 if (len == 10003 && buf[0] == 0x00 && buf[1] == 0x60)
272 return DM_PROBE_SCORE_AVG;
273 return DM_PROBE_SCORE_FALSE;
274 }
275
276
277 static int fmtProbeTruePaint(const Uint8 *buf, const size_t len)
278 {
279 if (len == 19434 && buf[0] == 0x00 && buf[1] == 0x9c)
280 return DM_PROBE_SCORE_GOOD;
281 return DM_PROBE_SCORE_FALSE;
282 } 258 }
283 259
284 260
285 static BOOL fmtTruePaintSetLaceType(DMC64Image *img, const struct _DMC64EncDecOp *op, const Uint8 *buf, const size_t len) 261 static BOOL fmtTruePaintSetLaceType(DMC64Image *img, const struct _DMC64EncDecOp *op, const Uint8 *buf, const size_t len)
286 { 262 {
294 270
295 271
296 DMC64ImageFormat dmC64ImageFormats[] = 272 DMC64ImageFormat dmC64ImageFormats[] =
297 { 273 {
298 { 274 {
299 DM_C64IFMT_MC, ".drp", "DrazPaint 2.0 (packed)", 275 DM_C64IFMT_MC, ".drp", "DrazPaint 2.0 (packed)", 0x5800, -1,
300 fmtProbeDrazPaint20Packed, fmtDecodeDrazPaintPacked, 276 fmtProbeDrazPaint20Packed, fmtDecodeDrazPaintPacked,
301 NULL, NULL, NULL, 277 NULL, NULL, NULL,
302 4, 278 4,
303 { 279 {
304 { DT_COLOR_RAM, 0x0000, 0, 0, NULL, NULL }, 280 { DT_COLOR_RAM, 0x0000, 0, 0, NULL, NULL },
307 { DT_BGCOLOR, 0x2740, 0, 0, NULL, NULL }, 283 { DT_BGCOLOR, 0x2740, 0, 0, NULL, NULL },
308 } 284 }
309 }, 285 },
310 286
311 { 287 {
312 DM_C64IFMT_MC_ILACE, ".dlp", "DrazLace 1.0 (packed)", 288 DM_C64IFMT_MC_ILACE, ".dlp", "DrazLace 1.0 (packed)", 0x5800, -1,
313 fmtProbeDrazLace10Packed, fmtDecodeDrazPaintPacked, 289 fmtProbeDrazLace10Packed, fmtDecodeDrazPaintPacked,
314 NULL, NULL, NULL, 290 NULL, NULL, NULL,
315 6, 291 6,
316 { 292 {
317 { DT_COLOR_RAM, 0x0000, 0, 0, NULL, NULL }, 293 { DT_COLOR_RAM, 0x0000, 0, 0, NULL, NULL },
322 { DT_DEC_FUNCTION, 0x2742, 0, 1, fmtDrazLaceSetLaceType, NULL }, 298 { DT_DEC_FUNCTION, 0x2742, 0, 1, fmtDrazLaceSetLaceType, NULL },
323 } 299 }
324 }, 300 },
325 301
326 { 302 {
327 DM_C64IFMT_MC, ".drp", "DrazPaint (unpacked)", 303 DM_C64IFMT_MC, ".drp", "DrazPaint (unpacked)", 0x5800, 10051,
328 fmtProbeDrazPaint, NULL, 304 NULL, NULL,
329 NULL, NULL, NULL, 305 NULL, NULL, NULL,
330 4, 306 4,
331 { 307 {
332 { DT_COLOR_RAM, 0x0000, 0, 0, NULL, NULL }, 308 { DT_COLOR_RAM, 0x0000, 0, 0, NULL, NULL },
333 { DT_BITMAP, 0x0800, 0, 0, NULL, NULL }, 309 { DT_BITMAP, 0x0800, 0, 0, NULL, NULL },
335 { DT_BGCOLOR, 0x2740, 0, 0, NULL, NULL }, 311 { DT_BGCOLOR, 0x2740, 0, 0, NULL, NULL },
336 } 312 }
337 }, 313 },
338 314
339 { 315 {
340 DM_C64IFMT_MC_ILACE, ".drl", "DrazLace 1.0 (unpacked)", 316 DM_C64IFMT_MC_ILACE, ".drl", "DrazLace 1.0 (unpacked)", 0x5800, 18242,
341 fmtProbeDrazLace10, NULL, 317 NULL, NULL,
342 NULL, NULL, NULL, 318 NULL, NULL, NULL,
343 6, 319 6,
344 { 320 {
345 { DT_COLOR_RAM, 0x0000, 0, 0, NULL, NULL }, 321 { DT_COLOR_RAM, 0x0000, 0, 0, NULL, NULL },
346 { DT_BITMAP, 0x0800, 0, 0, NULL, NULL }, 322 { DT_BITMAP, 0x0800, 0, 0, NULL, NULL },
350 { DT_DEC_FUNCTION, 0x2742, 0, 1, fmtDrazLaceSetLaceType, NULL }, 326 { DT_DEC_FUNCTION, 0x2742, 0, 1, fmtDrazLaceSetLaceType, NULL },
351 } 327 }
352 }, 328 },
353 329
354 { 330 {
355 DM_C64IFMT_MC_ILACE, ".mci", "Truepaint (unpacked)", 331 DM_C64IFMT_MC_ILACE, ".mci", "Truepaint (unpacked)", 0x9c00, 19434,
356 fmtProbeTruePaint, NULL, 332 NULL, NULL,
357 NULL, NULL, NULL, 333 NULL, NULL, NULL,
358 6, 334 6,
359 { 335 {
360 { DT_SCREEN_RAM, 0x0000, 0, 0, NULL, NULL }, 336 { DT_SCREEN_RAM, 0x0000, 0, 0, NULL, NULL },
361 { DT_BGCOLOR, 0x03e8, 0, 0, NULL, NULL }, 337 { DT_BGCOLOR, 0x03e8, 0, 0, NULL, NULL },
366 { DT_DEC_FUNCTION, 0x0000, 0, 0, fmtTruePaintSetLaceType, NULL }, 342 { DT_DEC_FUNCTION, 0x0000, 0, 0, fmtTruePaintSetLaceType, NULL },
367 } 343 }
368 }, 344 },
369 345
370 { 346 {
371 DM_C64IFMT_MC, ".kla", "Koala Paint (unpacked)", 347 DM_C64IFMT_MC, ".kla", "Koala Paint (unpacked)", 0x6000, 10003,
372 fmtProbeKoalaPaint, NULL, 348 NULL, NULL,
373 NULL, NULL, NULL, 349 NULL, NULL, NULL,
374 4, 350 4,
375 { 351 {
376 { DT_COLOR_RAM, 0x2328, 0, 0, NULL, NULL }, 352 { DT_COLOR_RAM, 0x2328, 0, 0, NULL, NULL },
377 { DT_BITMAP, 0x0000, 0, 0, NULL, NULL }, 353 { DT_BITMAP, 0x0000, 0, 0, NULL, NULL },
379 { DT_BGCOLOR, 0x2710, 0, 0, NULL, NULL }, 355 { DT_BGCOLOR, 0x2710, 0, 0, NULL, NULL },
380 } 356 }
381 }, 357 },
382 358
383 { 359 {
384 DM_C64IFMT_MC, ".ami", "Amica Paint (packed)", 360 DM_C64IFMT_MC, ".ami", "Amica Paint (packed)", 0x4000, -1,
385 fmtProbeAmicaPaintPacked, fmtDecodeAmicaPaintPacked, 361 fmtProbeAmicaPaintPacked, fmtDecodeAmicaPaintPacked,
386 NULL, NULL, NULL, 362 NULL, NULL, NULL,
387 4, 363 4,
388 { 364 {
389 { DT_COLOR_RAM, 0x2328, 0, 0, NULL, NULL }, 365 { DT_COLOR_RAM, 0x2328, 0, 0, NULL, NULL },
403 int i, scoreMax = DM_PROBE_SCORE_FALSE, scoreIndex = -1; 379 int i, scoreMax = DM_PROBE_SCORE_FALSE, scoreIndex = -1;
404 380
405 for (i = 0; i < ndmC64ImageFormats; i++) 381 for (i = 0; i < ndmC64ImageFormats; i++)
406 { 382 {
407 DMC64ImageFormat *fmt = &dmC64ImageFormats[i]; 383 DMC64ImageFormat *fmt = &dmC64ImageFormats[i];
408 int score = fmt->probe(buf, len); 384 int score = DM_PROBE_SCORE_FALSE;
385 if (fmt->probe == NULL && fmt->size > 0 && fmt->addr > 0)
386 {
387 // Generic probe just checks matching size and load address
388 if (len == fmt->size && dmCompareAddr16(buf, 0, fmt->addr))
389 score = DM_PROBE_SCORE_GOOD;
390 }
391 else
392 score = fmt->probe(buf, len, fmt);
393
409 if (score > scoreMax) 394 if (score > scoreMax)
410 { 395 {
411 scoreMax = score; 396 scoreMax = score;
412 scoreIndex = i; 397 scoreIndex = i;
413 } 398 }