# HG changeset patch # User Matti Hamalainen # Date 1506247984 -10800 # Node ID 3a94c0e8297fef4b73e6869a37a15e869670f5cf # Parent 95e416830490fd691463b324474eba15e16bee64 Cleanups. diff -r 95e416830490 -r 3a94c0e8297f tools/lib64gfx.c --- a/tools/lib64gfx.c Sat Sep 23 01:26:31 2017 +0300 +++ b/tools/lib64gfx.c Sun Sep 24 13:13:04 2017 +0300 @@ -180,23 +180,6 @@ } -static int fmtProbeDrazPaint20Packed(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) -{ - const char *ident = (const char *) buf + 2; - - if (len > 22 && - dmCompareAddr16(buf, 0, fmt->addr) && - strncmp(ident, "DRAZPAINT ", 10) == 0 && - ident[11] == '.' && ( - (ident[10] == '1' && ident[12] == '4') || - (ident[10] == '2' && ident[12] == '0') - )) - return DM_PROBE_SCORE_MAX; - - return DM_PROBE_SCORE_FALSE; -} - - static int dmDecodeGenericRLE(Uint8 **mem, Uint8 **pdstEnd, const Uint8 *src, const Uint8 *srcEnd, const Uint8 rleMarker) { Uint8 *dst, *dstEnd; @@ -227,6 +210,32 @@ } +static BOOL fmtSetFLIType(DMC64Image *img, const struct _DMC64EncDecOp *op, const Uint8 *buf, const size_t len) +{ + (void) buf; + (void) len; + img->fliType = op->bank; + return TRUE; +} + + +static int fmtProbeDrazPaint20Packed(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) +{ + const char *ident = (const char *) buf + 2; + + if (len > 22 && + dmCompareAddr16(buf, 0, fmt->addr) && + strncmp(ident, "DRAZPAINT ", 10) == 0 && + ident[11] == '.' && ( + (ident[10] == '1' && ident[12] == '4') || + (ident[10] == '2' && ident[12] == '0') + )) + return DM_PROBE_SCORE_MAX; + + return DM_PROBE_SCORE_FALSE; +} + + static int fmtDecodeDrazPaintPacked(DMC64Image *img, const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) { int res; @@ -285,6 +294,7 @@ return DM_PROBE_SCORE_AVG; if (n > 10) return DM_PROBE_SCORE_MAYBE; + return DM_PROBE_SCORE_FALSE; } @@ -317,18 +327,11 @@ } -static BOOL fmtSetFLIType(DMC64Image *img, const struct _DMC64EncDecOp *op, const Uint8 *buf, const size_t len) -{ - (void) buf; - (void) len; - img->fliType = op->bank; - return TRUE; -} - +#define XX2_MIN_SIZE 4000 static int fmtProbeFormatXX2(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) { - if (len >= 4000 && len <= 4008 && + if (len >= XX2_MIN_SIZE && len <= XX2_MIN_SIZE + 8 && dmCompareAddr16(buf, 0, fmt->addr)) return DM_PROBE_SCORE_MAYBE; @@ -339,8 +342,11 @@ static int fmtDecodeFormatXX2(DMC64Image *img, const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) { int res; - size_t nlen = len < 4000 ? 4000 : len; - Uint8 *mem = dmMalloc(nlen); + // If there is only data for less than XX2_MIN_SIZE bytes, + // allocate a buffer of that size and copy data there. + // Otherwise allocate len bytes. + size_t nlen = len < XX2_MIN_SIZE ? XX2_MIN_SIZE : len; + Uint8 *mem = dmMalloc0(nlen); if (mem == NULL) return DMERR_MALLOC; @@ -354,6 +360,9 @@ +// +// Array with data for supported formats +// const DMC64ImageFormat dmC64ImageFormats[] = { {