Mercurial > hg > dmlib
comparison tools/libgfx.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 | 1ea48084055e |
children | 7a0af15fbe97 |
comparison
equal
deleted
inserted
replaced
2207:1ea48084055e | 2208:90ec1ec89c56 |
---|---|
231 return DMERR_MALLOC; | 231 return DMERR_MALLOC; |
232 | 232 |
233 if (ncolors - pal->ncolors > 0) | 233 if (ncolors - pal->ncolors > 0) |
234 memset(&(pal->colors[pal->ncolors]), 0, sizeof(DMColor) * (ncolors - pal->ncolors)); | 234 memset(&(pal->colors[pal->ncolors]), 0, sizeof(DMColor) * (ncolors - pal->ncolors)); |
235 | 235 |
236 pal->ncolors = ncolors; | |
237 | |
236 return DMERR_OK; | 238 return DMERR_OK; |
237 } | 239 } |
238 | 240 |
239 | 241 |
240 int dmPaletteCopy(DMPalette **pdst, const DMPalette *src) | 242 int dmPaletteCopy(DMPalette **pdst, const DMPalette *src) |
327 | 329 |
328 return DMERR_OK; | 330 return DMERR_OK; |
329 } | 331 } |
330 | 332 |
331 | 333 |
332 #define ACT_MAGIC_ID 0x0010ffff | |
333 | |
334 | |
335 static int fmtProbeACT(const Uint8 *buf, const size_t len) | 334 static int fmtProbeACT(const Uint8 *buf, const size_t len) |
336 { | 335 { |
337 if (len == 0x304 && | 336 if (len == 0x304 && |
338 DM_BE32_TO_NATIVE(*(Uint32 *) (buf + 0x300)) == ACT_MAGIC_ID) | 337 buf[0x300] == 0) |
339 return DM_PROBE_SCORE_MAX; | 338 return DM_PROBE_SCORE_MAX; |
340 | 339 |
341 return DM_PROBE_SCORE_FALSE; | 340 return DM_PROBE_SCORE_FALSE; |
342 } | 341 } |
343 | 342 |
344 | 343 |
345 int dmReadACTPalette(DMResource *fp, DMPalette **pdst) | 344 int dmReadACTPalette(DMResource *fp, DMPalette **pdst) |
346 { | 345 { |
347 int res; | 346 int res; |
348 Uint32 magicID; | 347 Uint16 tmp1, tmp2; |
349 | 348 |
350 if ((res = dmPaletteAlloc(pdst, 256, -1)) != DMERR_OK) | 349 if ((res = dmPaletteAlloc(pdst, 256, -1)) != DMERR_OK) |
351 return res; | 350 return res; |
352 | 351 |
353 if ((res = dmPaletteReadData(fp, *pdst, 256)) != DMERR_OK) | 352 if ((res = dmPaletteReadData(fp, *pdst, 256)) != DMERR_OK) |
354 goto error; | 353 goto error; |
355 | 354 |
356 if (!dmf_read_be32(fp, &magicID)) | 355 if (!dmf_read_be16(fp, &tmp1) || |
356 !dmf_read_be16(fp, &tmp2)) | |
357 { | 357 { |
358 res = DMERR_FREAD; | 358 res = DMERR_FREAD; |
359 goto error; | 359 goto error; |
360 } | 360 } |
361 | 361 |
362 if (magicID != ACT_MAGIC_ID) | 362 if (tmp1 == 0 || tmp1 > 256) |
363 { | 363 { |
364 res = DMERR_INVALID_DATA; | 364 res = DMERR_INVALID_DATA; |
365 goto error; | 365 goto error; |
366 } | 366 } |
367 | |
368 if ((res = dmPaletteResize(pdst, tmp1)) != DMERR_OK) | |
369 goto error; | |
370 | |
371 (*pdst)->ctransp = tmp2 < 256 ? tmp2 : -1; | |
367 | 372 |
368 return res; | 373 return res; |
369 | 374 |
370 error: | 375 error: |
371 dmPaletteFree(*pdst); | 376 dmPaletteFree(*pdst); |
379 int res; | 384 int res; |
380 | 385 |
381 if ((res = dmPaletteWriteData(fp, ppal, ppal->ncolors, 256)) != DMERR_OK) | 386 if ((res = dmPaletteWriteData(fp, ppal, ppal->ncolors, 256)) != DMERR_OK) |
382 return res; | 387 return res; |
383 | 388 |
384 if (!dmf_write_be32(fp, ACT_MAGIC_ID)) | 389 if (!dmf_write_be16(fp, ppal->ncolors) || |
390 !dmf_write_be16(fp, ppal->ctransp >= 0 ? ppal->ctransp : 0xffff)) | |
385 return DMERR_FWRITE; | 391 return DMERR_FWRITE; |
386 | 392 |
387 return DMERR_OK; | 393 return DMERR_OK; |
388 } | 394 } |
389 | 395 |