--- CV/CV.xs 2021/07/15 00:41:44 1.60 +++ CV/CV.xs 2021/07/25 11:24:48 1.61 @@ -453,6 +453,35 @@ RETVAL = "image/png"; else if (data_len >= sizeof (jxl_header) && memcmp (data, jxl_header, sizeof (jxl_header)) == 0) RETVAL = "image/jxl"; + else if (data_len >= 13 + && data[0] == 'G' + && data[1] == 'I' + && data[2] == 'F' + && data[3] == '8' + //&& (data[4] == '7' || data[4] == '9') + && data[5] == 'a') + { + RETVAL = "image/gif"; + + // now see if its animated - we require the netscape application header for this + int ofs = 13; + + if (data[10] & 0x80) + ofs += (1 << ((data[10] & 7) + 1)) * 3; + + if (data_len >= ofs + 2 + 1 + 11) + { + // skip a rare first graphic control extension block + // we assume there is exactly one block + if (data[ofs] == 0x21 && data[ofs + 1] == 0xf9) + ofs += 3 + data[ofs + 2] + 1; + + if (data_len >= ofs + 2 + 1 + 11) + if (!memcmp (data + ofs, "\x21\xff\x0bNETSCAPE2.0", sizeof ("\x21\xff\x0bNETSCAPE2.0") - 1)) + RETVAL = "video/gif"; + } + } + else XSRETURN_UNDEF; }