Mercurial > hg > dmlib
comparison tools/lib64gfx.c @ 1774:88354355b8e1
Move dmC64ProbeBMP() to more logical place in the source.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 12 Jun 2018 15:36:00 +0300 |
parents | 52e31cfc1e36 |
children | 4e4d54135baf |
comparison
equal
deleted
inserted
replaced
1773:9336bfb5b6d1 | 1774:88354355b8e1 |
---|---|
671 int res; | 671 int res; |
672 if ((res = dmGrowBufAlloc(dst, BUF_SIZE_INITIAL, BUF_SIZE_GROW)) != DMERR_OK) | 672 if ((res = dmGrowBufAlloc(dst, BUF_SIZE_INITIAL, BUF_SIZE_GROW)) != DMERR_OK) |
673 return res; | 673 return res; |
674 | 674 |
675 return dmEncodeGenericRLE(dst, src, cfg); | 675 return dmEncodeGenericRLE(dst, src, cfg); |
676 } | |
677 | |
678 | |
679 // Perform probing of the given data buffer, trying to determine | |
680 // if it contains a supported "C64" image format. Returns the | |
681 // "probe score", see libgfx.h for list of values. If a match | |
682 // is found, pointer to format description is set to *pfmt. | |
683 int dmC64ProbeBMP(const Uint8 *buf, const size_t len, const DMC64ImageFormat **pfmt) | |
684 { | |
685 int scoreMax = DM_PROBE_SCORE_FALSE, scoreIndex = -1; | |
686 | |
687 for (int i = 0; i < ndmC64ImageFormats; i++) | |
688 { | |
689 const DMC64ImageFormat *fmt = &dmC64ImageFormats[i]; | |
690 int score = DM_PROBE_SCORE_FALSE; | |
691 if (fmt->probe == NULL && fmt->size > 0 && fmt->addr > 0) | |
692 { | |
693 // Generic probe just checks matching size and load address | |
694 if (len == fmt->size && dmCompareAddr16(buf, 0, fmt->addr)) | |
695 score = DM_PROBE_SCORE_GOOD; | |
696 } | |
697 else | |
698 if (fmt->probe != NULL) | |
699 score = fmt->probe(buf, len, fmt); | |
700 | |
701 if (score > scoreMax) | |
702 { | |
703 scoreMax = score; | |
704 scoreIndex = i; | |
705 } | |
706 } | |
707 | |
708 if (scoreIndex >= 0) | |
709 { | |
710 *pfmt = &dmC64ImageFormats[scoreIndex]; | |
711 return scoreMax; | |
712 } | |
713 else | |
714 return DM_PROBE_SCORE_FALSE; | |
715 } | 676 } |
716 | 677 |
717 | 678 |
718 int dmC64SanityCheckEncDecOp(const int i, const DMC64EncDecOp *op, const DMC64Image *img) | 679 int dmC64SanityCheckEncDecOp(const int i, const DMC64EncDecOp *op, const DMC64Image *img) |
719 { | 680 { |
1472 | 1433 |
1473 err: | 1434 err: |
1474 dmGrowBufFree(buf); | 1435 dmGrowBufFree(buf); |
1475 return res; | 1436 return res; |
1476 } | 1437 } |
1438 | |
1439 | |
1440 // Perform probing of the given data buffer, trying to determine | |
1441 // if it contains a supported "C64" image format. Returns the | |
1442 // "probe score", see libgfx.h for list of values. If a match | |
1443 // is found, pointer to format description is set to *pfmt. | |
1444 int dmC64ProbeBMP(const Uint8 *buf, const size_t len, const DMC64ImageFormat **pfmt) | |
1445 { | |
1446 int scoreMax = DM_PROBE_SCORE_FALSE, scoreIndex = -1; | |
1447 | |
1448 for (int i = 0; i < ndmC64ImageFormats; i++) | |
1449 { | |
1450 const DMC64ImageFormat *fmt = &dmC64ImageFormats[i]; | |
1451 int score = DM_PROBE_SCORE_FALSE; | |
1452 if (fmt->probe == NULL && fmt->size > 0 && fmt->addr > 0) | |
1453 { | |
1454 // Generic probe just checks matching size and load address | |
1455 if (len == fmt->size && dmCompareAddr16(buf, 0, fmt->addr)) | |
1456 score = DM_PROBE_SCORE_GOOD; | |
1457 } | |
1458 else | |
1459 if (fmt->probe != NULL) | |
1460 score = fmt->probe(buf, len, fmt); | |
1461 | |
1462 if (score > scoreMax) | |
1463 { | |
1464 scoreMax = score; | |
1465 scoreIndex = i; | |
1466 } | |
1467 } | |
1468 | |
1469 if (scoreIndex >= 0) | |
1470 { | |
1471 *pfmt = &dmC64ImageFormats[scoreIndex]; | |
1472 return scoreMax; | |
1473 } | |
1474 else | |
1475 return DM_PROBE_SCORE_FALSE; | |
1476 } |