Mercurial > hg > dmlib
comparison tools/gfxconv.c @ 1609:c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Also do necessary changes in gfxconv due to these API changes.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 14 May 2018 12:42:24 +0300 |
parents | d91d2a67eda5 |
children | 36d073c45327 |
comparison
equal
deleted
inserted
replaced
1608:7f9fe2a9a87e | 1609:c29adf5ce240 |
---|---|
1089 dmMsg(2, "%s output.\n", str); | 1089 dmMsg(2, "%s output.\n", str); |
1090 } | 1090 } |
1091 } | 1091 } |
1092 | 1092 |
1093 | 1093 |
1094 #define DMCOL(x) (((x) >> 4) & 0xf) | |
1095 | |
1096 void dmWriteIFFMasterRAWPalette(FILE *fp, | |
1097 const DMImage *img, int ncolors, | |
1098 const char *indent, const char *type) | |
1099 { | |
1100 for (int i = 0; i < ncolors; i++) | |
1101 { | |
1102 int color; | |
1103 if (i < img->ncolors) | |
1104 { | |
1105 color = (DMCOL(img->pal[i].r) << 8) | | |
1106 (DMCOL(img->pal[i].g) << 4) | | |
1107 (DMCOL(img->pal[i].b)); | |
1108 } | |
1109 else | |
1110 color = 0; | |
1111 | |
1112 fprintf(fp, "%s%s $%04X\n", | |
1113 indent != NULL ? indent : "\t", | |
1114 type != NULL ? type : "dc.w", | |
1115 color); | |
1116 } | |
1117 } | |
1118 | |
1119 | |
1094 int dmWriteImage(const char *filename, DMImage *pimage, DMImageConvSpec *spec, int iformat, BOOL info) | 1120 int dmWriteImage(const char *filename, DMImage *pimage, DMImageConvSpec *spec, int iformat, BOOL info) |
1095 { | 1121 { |
1096 int res = DMERR_OK; | 1122 int res = DMERR_OK; |
1097 | 1123 |
1098 if (info) | 1124 if (info) |
1784 | 1810 |
1785 case FFMT_IMAGE: | 1811 case FFMT_IMAGE: |
1786 { | 1812 { |
1787 DMImage *inImage = NULL; | 1813 DMImage *inImage = NULL; |
1788 int res = DMERR_OK; | 1814 int res = DMERR_OK; |
1815 DMResource *fp; | |
1789 | 1816 |
1790 if (optOutFilename == NULL) | 1817 if (optOutFilename == NULL) |
1791 { | 1818 { |
1792 dmErrorMsg("Output filename not set, required for image formats.\n"); | 1819 dmErrorMsg("Output filename not set, required for image formats.\n"); |
1820 goto error; | |
1821 } | |
1822 | |
1823 if ((res = dmf_open_memio(NULL, optInFilename, dataBuf, dataSize, &fp)) != DMERR_OK) | |
1824 { | |
1825 dmErrorMsg("Could not create MemIO handle for input.\n"); | |
1793 goto error; | 1826 goto error; |
1794 } | 1827 } |
1795 | 1828 |
1796 // Read input | 1829 // Read input |
1797 DMImageFormat *ifmt = &dmImageFormatList[optInSubFormat]; | 1830 DMImageFormat *ifmt = &dmImageFormatList[optInSubFormat]; |
1798 if (ifmt->readFILE != NULL) | 1831 if (ifmt->readFILE != NULL) |
1799 res = ifmt->readFILE(inFile, &inImage); | 1832 res = ifmt->readFILE(fp, &inImage); |
1800 else | 1833 else |
1801 dmErrorMsg("Unsupported input image format for bitmap/image conversion.\n"); | 1834 dmErrorMsg("Unsupported input image format for bitmap/image conversion.\n"); |
1835 | |
1836 dmf_close(fp); | |
1802 | 1837 |
1803 if (res != DMERR_OK || inImage == NULL) | 1838 if (res != DMERR_OK || inImage == NULL) |
1804 break; | 1839 break; |
1805 | 1840 |
1806 switch (optOutFormat) | 1841 switch (optOutFormat) |
1829 } | 1864 } |
1830 break; | 1865 break; |
1831 } | 1866 } |
1832 | 1867 |
1833 error: | 1868 error: |
1834 if (inFile != NULL) | |
1835 fclose(inFile); | |
1836 | |
1837 dmFree(dataBufOrig); | 1869 dmFree(dataBufOrig); |
1838 dmC64ImageFree(inC64Image); | 1870 dmC64ImageFree(inC64Image); |
1839 dmC64ImageFree(outC64Image); | 1871 dmC64ImageFree(outC64Image); |
1840 | 1872 |
1841 return 0; | 1873 return 0; |