comparison tools/lib64gfx.c @ 2200:dcd26cdc395e

Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose(). Add in sorting of the C64 formats list.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 14 Jun 2019 00:00:27 +0300
parents 28871f500e84
children 9f3fb4004c20
comparison
equal deleted inserted replaced
2199:f331cc750b37 2200:dcd26cdc395e
1700 else 1700 else
1701 return DM_PROBE_SCORE_FALSE; 1701 return DM_PROBE_SCORE_FALSE;
1702 } 1702 }
1703 1703
1704 1704
1705 void dmC64InitializeFormats(void) 1705 BOOL dmLib64GFXInitialized = FALSE;
1706 { 1706 DMC64ImageFormat **dmC64ImageFormatsSorted = NULL;
1707
1708
1709 int dmC64ImageFormatCompare(const void *va, const void *vb)
1710 {
1711 const DMC64ImageFormat
1712 *fmta = *(DMC64ImageFormat **) va,
1713 *fmtb = *(DMC64ImageFormat **) vb;
1714
1715 int res = fmta->format->type - fmtb->format->type;
1716 if (res == 0)
1717 return strcmp(fmta->name, fmtb->name);
1718 else
1719 return res;
1720 }
1721
1722
1723 int dmLib64GFXInit(void)
1724 {
1725 // Safety check
1726 if (dmLib64GFXInitialized)
1727 dmLib64GFXClose();
1728
1729 dmLib64GFXInitialized = TRUE;
1730
1731 if ((dmC64ImageFormatsSorted = dmCalloc(ndmC64ImageFormats, sizeof(dmC64ImageFormatsSorted[0]))) == NULL)
1732 return DMERR_MALLOC;
1733
1707 for (int i = 0; i < ndmC64ImageFormats; i++) 1734 for (int i = 0; i < ndmC64ImageFormats; i++)
1708 { 1735 {
1709 DMC64ImageFormat *fmt = &dmC64ImageFormats[i]; 1736 DMC64ImageFormat *fmt = &dmC64ImageFormats[i];
1710 if (fmt->format == NULL) 1737 if (fmt->format == NULL)
1711 fmt->format = &fmt->formatDef; 1738 fmt->format = &fmt->formatDef;
1712 } 1739
1713 } 1740 dmC64ImageFormatsSorted[i] = fmt;
1741 }
1742
1743 qsort(dmC64ImageFormatsSorted, ndmC64ImageFormats,
1744 sizeof(DMC64ImageFormat *), dmC64ImageFormatCompare);
1745
1746 return DMERR_OK;
1747 }
1748
1749
1750 void dmLib64GFXClose(void)
1751 {
1752 dmFreeR(&dmC64ImageFormatsSorted);
1753 dmLib64GFXInitialized = FALSE;
1754 }