Mercurial > hg > dmlib
comparison tools/gfxconv.c @ 1440:a602488830fc
Cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 10 May 2018 02:25:42 +0300 |
parents | c1dee757de9d |
children | 260c413304f3 |
comparison
equal
deleted
inserted
replaced
1439:c1dee757de9d | 1440:a602488830fc |
---|---|
1612 | 1612 |
1613 | 1613 |
1614 int main(int argc, char *argv[]) | 1614 int main(int argc, char *argv[]) |
1615 { | 1615 { |
1616 FILE *inFile = NULL; | 1616 FILE *inFile = NULL; |
1617 const DMC64ImageFormat *cfmt = NULL; | 1617 const DMC64ImageFormat *inC64Fmt = NULL; |
1618 DMC64Image *cimage = NULL; | 1618 DMC64Image *inC64Image = NULL; |
1619 Uint8 *dataBuf = NULL; | 1619 Uint8 *dataBuf = NULL; |
1620 size_t dataSize; | 1620 size_t dataSize; |
1621 int i; | 1621 int i; |
1622 | 1622 |
1623 // Default colors | 1623 // Default colors |
1684 forced = &dmC64ImageFormats[optForcedFormat]; | 1684 forced = &dmC64ImageFormats[optForcedFormat]; |
1685 dmMsg(0,"Forced %s format image, type %d, %s\n", | 1685 dmMsg(0,"Forced %s format image, type %d, %s\n", |
1686 forced->name, forced->type, forced->fext); | 1686 forced->name, forced->type, forced->fext); |
1687 } | 1687 } |
1688 | 1688 |
1689 res = dmC64DecodeBMP(&cimage, dataBuf, dataSize, optInSkip, optInSkip + 2, &cfmt, forced); | 1689 res = dmC64DecodeBMP(&inC64Image, dataBuf, dataSize, optInSkip, optInSkip + 2, &inC64Fmt, forced); |
1690 if (forced == NULL && cfmt != NULL) | 1690 if (forced == NULL && inC64Fmt != NULL) |
1691 { | 1691 { |
1692 dmMsg(1,"Probed %s format image, type %d, %s\n", | 1692 dmMsg(1,"Probed %s format image, type %d, %s\n", |
1693 cfmt->name, cfmt->type, cfmt->fext); | 1693 inC64Fmt->name, inC64Fmt->type, inC64Fmt->fext); |
1694 } | 1694 } |
1695 | 1695 |
1696 if (res == DMERR_OK) | 1696 if (res == DMERR_OK) |
1697 optInFormat = FFMT_BITMAP; | 1697 optInFormat = FFMT_BITMAP; |
1698 else | 1698 else |
1739 *inFmtExt = convFormatList[inFormat].fext, | 1739 *inFmtExt = convFormatList[inFormat].fext, |
1740 *outFmtName = convFormatList[outFormat].name, | 1740 *outFmtName = convFormatList[outFormat].name, |
1741 *outFmtExt = convFormatList[outFormat].fext; | 1741 *outFmtExt = convFormatList[outFormat].fext; |
1742 | 1742 |
1743 if (optInFormat == FFMT_BITMAP) | 1743 if (optInFormat == FFMT_BITMAP) |
1744 inFmtExt = cfmt->name; | 1744 inFmtExt = inC64Fmt->name; |
1745 | 1745 |
1746 dmMsg(1, "Attempting conversion %s (%s) -> %s (%s)\n", | 1746 dmMsg(1, "Attempting conversion %s (%s) -> %s (%s)\n", |
1747 inFmtName, inFmtExt, outFmtName, outFmtExt); | 1747 inFmtName, inFmtExt, outFmtName, outFmtExt); |
1748 } | 1748 } |
1749 | 1749 |
1766 } | 1766 } |
1767 | 1767 |
1768 switch (optOutFormat) | 1768 switch (optOutFormat) |
1769 { | 1769 { |
1770 case FFMT_IMAGE: | 1770 case FFMT_IMAGE: |
1771 res = dmC64ConvertBMP2Image(&outImage, cimage, cfmt); | 1771 res = dmC64ConvertBMP2Image(&outImage, inC64Image, inC64Fmt); |
1772 | 1772 |
1773 if (res != DMERR_OK || outImage == NULL) | 1773 if (res != DMERR_OK || outImage == NULL) |
1774 { | 1774 { |
1775 dmErrorMsg("Error in bitmap to image conversion.\n"); | 1775 dmErrorMsg("Error in bitmap to image conversion.\n"); |
1776 goto error; | 1776 goto error; |
1777 } | 1777 } |
1778 | 1778 |
1779 res = dmWriteImage(optOutFilename, outImage, &optSpec, optOutSubFormat, TRUE); | 1779 res = dmWriteImage(optOutFilename, outImage, &optSpec, optOutSubFormat, TRUE); |
1780 break; | 1780 break; |
1781 | 1781 |
1782 | |
1783 case FFMT_BITMAP: | 1782 case FFMT_BITMAP: |
1784 res = dmWriteBitmap(optOutFilename, cimage, optOutSubFormat, TRUE); | 1783 res = dmWriteBitmap(optOutFilename, inC64Image, optOutSubFormat, TRUE); |
1785 break; | 1784 break; |
1786 | 1785 |
1787 case FFMT_CHAR: | 1786 case FFMT_CHAR: |
1788 case FFMT_SPRITE: | 1787 case FFMT_SPRITE: |
1789 res = dmC64ConvertBMP2Image(&outImage, cimage, cfmt); | 1788 res = dmC64ConvertBMP2Image(&outImage, inC64Image, inC64Fmt); |
1790 | 1789 |
1791 if (res != DMERR_OK || outImage == NULL) | 1790 if (res != DMERR_OK || outImage == NULL) |
1792 { | 1791 { |
1793 dmErrorMsg("Error in bitmap to template image conversion.\n"); | 1792 dmErrorMsg("Error in bitmap to template image conversion.\n"); |
1794 goto error; | 1793 goto error; |
1806 } | 1805 } |
1807 break; | 1806 break; |
1808 | 1807 |
1809 case FFMT_IMAGE: | 1808 case FFMT_IMAGE: |
1810 { | 1809 { |
1811 DMImage *outImage = NULL; | 1810 DMImage *inImage = NULL; |
1812 int res = DMERR_OK; | 1811 int res = DMERR_OK; |
1813 | 1812 |
1814 if (optOutFilename == NULL) | 1813 if (optOutFilename == NULL) |
1815 { | 1814 { |
1816 dmErrorMsg("Output filename not set, required for image formats.\n"); | 1815 dmErrorMsg("Output filename not set, required for image formats.\n"); |
1818 } | 1817 } |
1819 | 1818 |
1820 // Read input | 1819 // Read input |
1821 DMImageFormat *ifmt = &dmImageFormatList[optInSubFormat]; | 1820 DMImageFormat *ifmt = &dmImageFormatList[optInSubFormat]; |
1822 if (ifmt->readFILE != NULL) | 1821 if (ifmt->readFILE != NULL) |
1823 res = ifmt->readFILE(inFile, &outImage); | 1822 res = ifmt->readFILE(inFile, &inImage); |
1824 else | 1823 else |
1825 dmErrorMsg("Unsupported input image format for bitmap/image conversion.\n"); | 1824 dmErrorMsg("Unsupported input image format for bitmap/image conversion.\n"); |
1826 | 1825 |
1827 if (res != DMERR_OK || outImage == NULL) | 1826 if (res != DMERR_OK || inImage == NULL) |
1828 break; | 1827 break; |
1829 | 1828 |
1830 switch (optOutFormat) | 1829 switch (optOutFormat) |
1831 { | 1830 { |
1832 case FFMT_IMAGE: | 1831 case FFMT_IMAGE: |
1833 res = dmWriteImage(optOutFilename, outImage, &optSpec, optOutSubFormat, TRUE); | 1832 res = dmWriteImage(optOutFilename, inImage, &optSpec, optOutSubFormat, TRUE); |
1834 break; | 1833 break; |
1835 | 1834 |
1836 case FFMT_CHAR: | 1835 case FFMT_CHAR: |
1837 case FFMT_SPRITE: | 1836 case FFMT_SPRITE: |
1838 res = dmWriteSpritesAndChars(optOutFilename, outImage, optOutFormat, optInMulticolor); | 1837 res = dmWriteSpritesAndChars(optOutFilename, inImage, optOutFormat, optInMulticolor); |
1839 break; | 1838 break; |
1840 | 1839 |
1841 default: | 1840 default: |
1842 dmErrorMsg("Unsupported output format for bitmap/image conversion.\n"); | 1841 dmErrorMsg("Unsupported output format for bitmap/image conversion.\n"); |
1843 break; | 1842 break; |
1847 { | 1846 { |
1848 dmErrorMsg("Error writing output (%s), probably unsupported output format for bitmap/image conversion.\n", | 1847 dmErrorMsg("Error writing output (%s), probably unsupported output format for bitmap/image conversion.\n", |
1849 dmErrorStr(res)); | 1848 dmErrorStr(res)); |
1850 } | 1849 } |
1851 | 1850 |
1852 dmImageFree(outImage); | 1851 dmImageFree(inImage); |
1853 } | 1852 } |
1854 break; | 1853 break; |
1855 } | 1854 } |
1856 | 1855 |
1857 error: | 1856 error: |
1858 if (inFile != NULL) | 1857 if (inFile != NULL) |
1859 fclose(inFile); | 1858 fclose(inFile); |
1860 | 1859 |
1861 dmFree(dataBuf); | 1860 dmFree(dataBuf); |
1862 dmC64ImageFree(cimage); | 1861 dmC64ImageFree(inC64Image); |
1863 | 1862 |
1864 return 0; | 1863 return 0; |
1865 } | 1864 } |