# HG changeset patch # User Matti Hamalainen # Date 1560221171 -10800 # Node ID b4f4251eaaaeb724715dd65a4e4852df6234ad10 # Parent 9d362ea1a6062acb9675be746a3ef464d67e56df Improve probing resiliency of Cosmos Designs and ECI formats, and try to improve avoiding misprobes of other formats as ECI packed. diff -r 9d362ea1a606 -r b4f4251eaaae tools/lib64fmts.c --- a/tools/lib64fmts.c Tue Jun 11 05:45:13 2019 +0300 +++ b/tools/lib64fmts.c Tue Jun 11 05:46:11 2019 +0300 @@ -981,7 +981,14 @@ // Unpacked variant if (fmt->size != 0 && fmt->size == buf->len) - return DM_PROBE_SCORE_GOOD; + { + // In the unpacked format the first 0x40 bytes should be 0xff + for (size_t offs = 2; offs < 0x42; offs++) + if (buf->data[offs] != 0xff) + return DM_PROBE_SCORE_GOOD; + + return DM_PROBE_SCORE_MAX; + } } return DM_PROBE_SCORE_FALSE; @@ -1399,29 +1406,35 @@ static int fmtProbeECIPacked(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) { - size_t i, n; - - // XXX TODO: Perhaps count statistics about used byte values - // and compare to value in buf[2] which is the RLE marker - if (buf->len < 128 || - !dmCompareAddr16(buf, 0, fmt->addr) || - // Try to avoid misprobe of Crest Hires FLI Designer and Cosmos Design format - buf->len == 16386 || buf->len == 16385 || + int score = DM_PROBE_SCORE_FALSE; + + if (buf->len > 128 && + dmCompareAddr16(buf, 0, fmt->addr)) + { + size_t i, n; + + // Count statistics about used byte values and compare to + // value in buf[2] which is the RLE marker + for (n = 0, i = 3; i < buf->len; i++) + if (buf->data[i] == buf->data[2]) n++; + + if (n > 50) + score = DM_PROBE_SCORE_GOOD; + else + if (n > 25) + score = DM_PROBE_SCORE_AVG; + else + if (n > 10) + score = DM_PROBE_SCORE_MAYBE; + } + + if (// Try to avoid misprobe of Crest Hires FLI Designer and Cosmos Design format + buf->len == 16386 || // Face Painter buf->len == 10004) - return DM_PROBE_SCORE_FALSE; - - for (n = 0, i = 3; i < buf->len; i++) - if (buf->data[i] == buf->data[2]) n++; - - if (n > 50) - return DM_PROBE_SCORE_GOOD; - if (n > 25) - return DM_PROBE_SCORE_AVG; - if (n > 10) - return DM_PROBE_SCORE_MAYBE; - - return DM_PROBE_SCORE_FALSE; + score /= 3; + + return score; }