Mercurial > hg > dmlib
comparison tools/lib64fmts.c @ 2168:b4f4251eaaae
Improve probing resiliency of Cosmos Designs and ECI formats, and try to
improve avoiding misprobes of other formats as ECI packed.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 11 Jun 2019 05:46:11 +0300 |
parents | 9d362ea1a606 |
children | 271850d7dd9b |
comparison
equal
deleted
inserted
replaced
2167:9d362ea1a606 | 2168:b4f4251eaaae |
---|---|
979 dmCompareAddr16(buf, 4, 0x7ff2)) | 979 dmCompareAddr16(buf, 4, 0x7ff2)) |
980 return DM_PROBE_SCORE_MAX; | 980 return DM_PROBE_SCORE_MAX; |
981 | 981 |
982 // Unpacked variant | 982 // Unpacked variant |
983 if (fmt->size != 0 && fmt->size == buf->len) | 983 if (fmt->size != 0 && fmt->size == buf->len) |
984 return DM_PROBE_SCORE_GOOD; | 984 { |
985 // In the unpacked format the first 0x40 bytes should be 0xff | |
986 for (size_t offs = 2; offs < 0x42; offs++) | |
987 if (buf->data[offs] != 0xff) | |
988 return DM_PROBE_SCORE_GOOD; | |
989 | |
990 return DM_PROBE_SCORE_MAX; | |
991 } | |
985 } | 992 } |
986 | 993 |
987 return DM_PROBE_SCORE_FALSE; | 994 return DM_PROBE_SCORE_FALSE; |
988 } | 995 } |
989 | 996 |
1397 } | 1404 } |
1398 | 1405 |
1399 | 1406 |
1400 static int fmtProbeECIPacked(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) | 1407 static int fmtProbeECIPacked(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) |
1401 { | 1408 { |
1402 size_t i, n; | 1409 int score = DM_PROBE_SCORE_FALSE; |
1403 | 1410 |
1404 // XXX TODO: Perhaps count statistics about used byte values | 1411 if (buf->len > 128 && |
1405 // and compare to value in buf[2] which is the RLE marker | 1412 dmCompareAddr16(buf, 0, fmt->addr)) |
1406 if (buf->len < 128 || | 1413 { |
1407 !dmCompareAddr16(buf, 0, fmt->addr) || | 1414 size_t i, n; |
1408 // Try to avoid misprobe of Crest Hires FLI Designer and Cosmos Design format | 1415 |
1409 buf->len == 16386 || buf->len == 16385 || | 1416 // Count statistics about used byte values and compare to |
1417 // value in buf[2] which is the RLE marker | |
1418 for (n = 0, i = 3; i < buf->len; i++) | |
1419 if (buf->data[i] == buf->data[2]) n++; | |
1420 | |
1421 if (n > 50) | |
1422 score = DM_PROBE_SCORE_GOOD; | |
1423 else | |
1424 if (n > 25) | |
1425 score = DM_PROBE_SCORE_AVG; | |
1426 else | |
1427 if (n > 10) | |
1428 score = DM_PROBE_SCORE_MAYBE; | |
1429 } | |
1430 | |
1431 if (// Try to avoid misprobe of Crest Hires FLI Designer and Cosmos Design format | |
1432 buf->len == 16386 || | |
1410 // Face Painter | 1433 // Face Painter |
1411 buf->len == 10004) | 1434 buf->len == 10004) |
1412 return DM_PROBE_SCORE_FALSE; | 1435 score /= 3; |
1413 | 1436 |
1414 for (n = 0, i = 3; i < buf->len; i++) | 1437 return score; |
1415 if (buf->data[i] == buf->data[2]) n++; | |
1416 | |
1417 if (n > 50) | |
1418 return DM_PROBE_SCORE_GOOD; | |
1419 if (n > 25) | |
1420 return DM_PROBE_SCORE_AVG; | |
1421 if (n > 10) | |
1422 return DM_PROBE_SCORE_MAYBE; | |
1423 | |
1424 return DM_PROBE_SCORE_FALSE; | |
1425 } | 1438 } |
1426 | 1439 |
1427 | 1440 |
1428 static int fmtDecodeECIPacked(DMC64Image *img, const DMGrowBuf *buf, const DMC64ImageFormat *fmt) | 1441 static int fmtDecodeECIPacked(DMC64Image *img, const DMGrowBuf *buf, const DMC64ImageFormat *fmt) |
1429 { | 1442 { |