Mercurial > hg > dmlib
comparison tools/lib64util.c @ 2208:90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
lib64util for handling external palette file options and add support for
specifying one of the "internal" palettes or external (.act) palette file to
gfxconv and 64vw.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 14 Jun 2019 05:01:12 +0300 |
parents | cbac4912992c |
children | fa5e74384d87 |
comparison
equal
deleted
inserted
replaced
2207:1ea48084055e | 2208:90ec1ec89c56 |
---|---|
4 * (C) Copyright 2019 Tecnic Software productions (TNSP) | 4 * (C) Copyright 2019 Tecnic Software productions (TNSP) |
5 * | 5 * |
6 * Please read file 'COPYING' for information on license and distribution. | 6 * Please read file 'COPYING' for information on license and distribution. |
7 */ | 7 */ |
8 #include "lib64util.h" | 8 #include "lib64util.h" |
9 #include "dmfile.h" | |
9 | 10 |
10 | 11 |
11 char * dmC64GetImageTypeString(char *buf, const size_t len, const int type, const BOOL lng) | 12 char * dmC64GetImageTypeString(char *buf, const size_t len, const int type, const BOOL lng) |
12 { | 13 { |
13 static const char *fmtModesShort[] = { "*", "HiR", "MC", "ECM" }; | 14 static const char *fmtModesShort[] = { "*", "HiR", "MC", "ECM" }; |
102 "%-10s | %s\n", | 103 "%-10s | %s\n", |
103 pal->name, pal->desc); | 104 pal->name, pal->desc); |
104 } | 105 } |
105 fprintf(stdout, "\n"); | 106 fprintf(stdout, "\n"); |
106 } | 107 } |
108 | |
109 | |
110 BOOL argHandleC64PaletteOption(char *optArg, DMC64Palette **ppal, char **palFile) | |
111 { | |
112 if (strcasecmp(optArg, "help") == 0 || | |
113 strcasecmp(optArg, "list") == 0) | |
114 { | |
115 argShowC64PaletteHelp(); | |
116 return FALSE; | |
117 } | |
118 | |
119 for (int n = 0; n < ndmC64DefaultPalettes; n++) | |
120 { | |
121 DMC64Palette *pal = &dmC64DefaultPalettes[n]; | |
122 if (strcasecmp(pal->name, optArg) == 0) | |
123 { | |
124 *ppal = pal; | |
125 return TRUE; | |
126 } | |
127 } | |
128 | |
129 *palFile = optArg; | |
130 return TRUE; | |
131 } | |
132 | |
133 | |
134 int dmHandleExternalPalette(const char *filename, DMPalette **ppal) | |
135 { | |
136 DMResource *fp = NULL; | |
137 const DMImageFormat *ifmt = NULL; | |
138 const DMPaletteFormat *pfmt = NULL; | |
139 DMImage *inImage = NULL; | |
140 Uint8 *dataBuf = NULL; | |
141 size_t dataSize; | |
142 int index, res; | |
143 | |
144 dmMsg(1, "Probing file '%s' for palette data.\n", filename); | |
145 | |
146 if ((res = dmReadDataFile(NULL, filename, &dataBuf, &dataSize)) != DMERR_OK) | |
147 { | |
148 dmErrorMsg("No such palette '%s', and no such file found (%s).\n", | |
149 filename, dmErrorStr(res)); | |
150 goto done; | |
151 } | |
152 | |
153 if ((res = dmf_open_memio(NULL, filename, dataBuf, dataSize, &fp)) != DMERR_OK) | |
154 { | |
155 dmErrorMsg("Could not create MemIO handle for input.\n"); | |
156 goto done; | |
157 } | |
158 | |
159 if (dmImageProbeGeneric(dataBuf, dataSize, &ifmt, &index) > 0 && | |
160 ifmt->read != NULL) | |
161 { | |
162 dmMsg(1, "Probed image format %s (%s)\n", | |
163 ifmt->name, ifmt->fext); | |
164 | |
165 res = ifmt->read(fp, &inImage); | |
166 if (res != DMERR_OK) | |
167 { | |
168 dmErrorMsg("Could not read image file: %s\n", | |
169 dmErrorStr(res)); | |
170 goto done; | |
171 } | |
172 | |
173 res = dmPaletteCopy(ppal, inImage->pal); | |
174 } | |
175 else | |
176 if (dmPaletteProbeGeneric(dataBuf, dataSize, &pfmt, &index) > 0 && | |
177 pfmt->read != NULL) | |
178 { | |
179 dmMsg(1, "Probed palette format %s (%s)\n", | |
180 pfmt->name, pfmt->fext); | |
181 | |
182 res = pfmt->read(fp, ppal); | |
183 } | |
184 else | |
185 { | |
186 res = DMERR_NOT_SUPPORTED; | |
187 dmErrorMsg("Not an internal palette or recognized palette file '%s'.\n", | |
188 filename); | |
189 } | |
190 | |
191 done: | |
192 dmf_close(fp); | |
193 dmImageFree(inImage); | |
194 dmFree(dataBuf); | |
195 | |
196 return res; | |
197 } |