# HG changeset patch # User Matti Hamalainen # Date 1528650063 -10800 # Node ID dd57dd9430cb232a2342e17bd2226073e552d912 # Parent 2dbb2b63f6b3b53254c88c3e1bba03c7fec06e2a Improve ECI packed format probing. diff -r 2dbb2b63f6b3 -r dd57dd9430cb tools/lib64fmts.c --- a/tools/lib64fmts.c Sun Jun 10 20:00:46 2018 +0300 +++ b/tools/lib64fmts.c Sun Jun 10 20:01:03 2018 +0300 @@ -772,12 +772,24 @@ static int fmtProbeECIPacked(const Uint8 *buf, const size_t len, 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 (len > 128 && dmCompareAddr16(buf, 0, fmt->addr)) + if (len < 128 || !dmCompareAddr16(buf, 0, fmt->addr)) + return DM_PROBE_SCORE_FALSE; + + for (n = 0, i = 3; i < len; i++) + if (buf[i] == buf[2]) n++; + + if (n > 50) + return DM_PROBE_SCORE_GOOD; + if (n > 25) return DM_PROBE_SCORE_AVG; - else - return DM_PROBE_SCORE_FALSE; + if (n > 10) + return DM_PROBE_SCORE_MAYBE; + + return DM_PROBE_SCORE_FALSE; }