# HG changeset patch # User Matti Hamalainen # Date 1528806960 -10800 # Node ID 88354355b8e18757110ccff36b56dea3aa2c50e9 # Parent 9336bfb5b6d1c8cf9876019d913eea945aeb21b3 Move dmC64ProbeBMP() to more logical place in the source. diff -r 9336bfb5b6d1 -r 88354355b8e1 tools/lib64gfx.c --- a/tools/lib64gfx.c Tue Jun 12 14:31:09 2018 +0300 +++ b/tools/lib64gfx.c Tue Jun 12 15:36:00 2018 +0300 @@ -676,45 +676,6 @@ } -// Perform probing of the given data buffer, trying to determine -// if it contains a supported "C64" image format. Returns the -// "probe score", see libgfx.h for list of values. If a match -// is found, pointer to format description is set to *pfmt. -int dmC64ProbeBMP(const Uint8 *buf, const size_t len, const DMC64ImageFormat **pfmt) -{ - int scoreMax = DM_PROBE_SCORE_FALSE, scoreIndex = -1; - - for (int i = 0; i < ndmC64ImageFormats; i++) - { - const DMC64ImageFormat *fmt = &dmC64ImageFormats[i]; - int score = DM_PROBE_SCORE_FALSE; - if (fmt->probe == NULL && fmt->size > 0 && fmt->addr > 0) - { - // Generic probe just checks matching size and load address - if (len == fmt->size && dmCompareAddr16(buf, 0, fmt->addr)) - score = DM_PROBE_SCORE_GOOD; - } - else - if (fmt->probe != NULL) - score = fmt->probe(buf, len, fmt); - - if (score > scoreMax) - { - scoreMax = score; - scoreIndex = i; - } - } - - if (scoreIndex >= 0) - { - *pfmt = &dmC64ImageFormats[scoreIndex]; - return scoreMax; - } - else - return DM_PROBE_SCORE_FALSE; -} - - int dmC64SanityCheckEncDecOp(const int i, const DMC64EncDecOp *op, const DMC64Image *img) { switch (op->type) @@ -1474,3 +1435,42 @@ dmGrowBufFree(buf); return res; } + + +// Perform probing of the given data buffer, trying to determine +// if it contains a supported "C64" image format. Returns the +// "probe score", see libgfx.h for list of values. If a match +// is found, pointer to format description is set to *pfmt. +int dmC64ProbeBMP(const Uint8 *buf, const size_t len, const DMC64ImageFormat **pfmt) +{ + int scoreMax = DM_PROBE_SCORE_FALSE, scoreIndex = -1; + + for (int i = 0; i < ndmC64ImageFormats; i++) + { + const DMC64ImageFormat *fmt = &dmC64ImageFormats[i]; + int score = DM_PROBE_SCORE_FALSE; + if (fmt->probe == NULL && fmt->size > 0 && fmt->addr > 0) + { + // Generic probe just checks matching size and load address + if (len == fmt->size && dmCompareAddr16(buf, 0, fmt->addr)) + score = DM_PROBE_SCORE_GOOD; + } + else + if (fmt->probe != NULL) + score = fmt->probe(buf, len, fmt); + + if (score > scoreMax) + { + scoreMax = score; + scoreIndex = i; + } + } + + if (scoreIndex >= 0) + { + *pfmt = &dmC64ImageFormats[scoreIndex]; + return scoreMax; + } + else + return DM_PROBE_SCORE_FALSE; +} diff -r 9336bfb5b6d1 -r 88354355b8e1 tools/lib64gfx.h --- a/tools/lib64gfx.h Tue Jun 12 14:31:09 2018 +0300 +++ b/tools/lib64gfx.h Tue Jun 12 15:36:00 2018 +0300 @@ -280,6 +280,8 @@ // // Miscellaneous functions // +int dmC64ProbeBMP(const Uint8 *buf, const size_t len, const DMC64ImageFormat **fmt); + char * dmC64GetImageTypeString(char *buf, const size_t len, const int type, const BOOL lng); void dmC64ImageDump(FILE *fh, const DMC64Image *img, const DMC64ImageFormat *fmt); @@ -304,7 +306,6 @@ int dmC64SanityCheckEncDecOp(const int i, const DMC64EncDecOp *op, const DMC64Image *img); BOOL dmC64GetOpSize(const DMC64EncDecOp *op, const DMC64ImageFormat *fmt, size_t *size); -int dmC64ProbeBMP(const Uint8 *buf, const size_t len, const DMC64ImageFormat **fmt); int dmC64DecodeGenericBMP(DMC64Image *img, const DMGrowBuf *buf, const DMC64ImageFormat *fmt); int dmC64EncodeGenericBMP(const BOOL allocate, DMGrowBuf *buf, const DMC64Image *img, const DMC64ImageFormat *fmt);