Mercurial > hg > dmlib
comparison tools/libgfx.c @ 2209:7a0af15fbe97
Add support for 'raw' 768 byte palette files.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 14 Jun 2019 05:32:58 +0300 |
parents | 90ec1ec89c56 |
children | ef9b55c879d6 |
comparison
equal
deleted
inserted
replaced
2208:90ec1ec89c56 | 2209:7a0af15fbe97 |
---|---|
329 | 329 |
330 return DMERR_OK; | 330 return DMERR_OK; |
331 } | 331 } |
332 | 332 |
333 | 333 |
334 static int fmtProbeACT(const Uint8 *buf, const size_t len) | 334 static int fmtProbeACTPalette(const Uint8 *buf, const size_t len) |
335 { | 335 { |
336 if (len == 0x304 && | 336 if (len == 0x304 && |
337 buf[0x300] == 0) | 337 buf[0x300] == 0) |
338 return DM_PROBE_SCORE_MAX; | 338 return DM_PROBE_SCORE_MAX; |
339 | 339 |
387 return res; | 387 return res; |
388 | 388 |
389 if (!dmf_write_be16(fp, ppal->ncolors) || | 389 if (!dmf_write_be16(fp, ppal->ncolors) || |
390 !dmf_write_be16(fp, ppal->ctransp >= 0 ? ppal->ctransp : 0xffff)) | 390 !dmf_write_be16(fp, ppal->ctransp >= 0 ? ppal->ctransp : 0xffff)) |
391 return DMERR_FWRITE; | 391 return DMERR_FWRITE; |
392 | |
393 return DMERR_OK; | |
394 } | |
395 | |
396 | |
397 static int fmtProbeRAWPalette(const Uint8 *buf, const size_t len) | |
398 { | |
399 if (len == 0x300) | |
400 return DM_PROBE_SCORE_MAX; | |
401 | |
402 return DM_PROBE_SCORE_FALSE; | |
403 } | |
404 | |
405 | |
406 int dmReadRAWPalette(DMResource *fp, DMPalette **pdst) | |
407 { | |
408 int res; | |
409 | |
410 if ((res = dmPaletteAlloc(pdst, 256, -1)) != DMERR_OK) | |
411 return res; | |
412 | |
413 if ((res = dmPaletteReadData(fp, *pdst, 256)) != DMERR_OK) | |
414 goto error; | |
415 | |
416 return res; | |
417 | |
418 error: | |
419 dmPaletteFree(*pdst); | |
420 *pdst = NULL; | |
421 return res; | |
422 } | |
423 | |
424 | |
425 int dmWriteRAWPalette(DMResource *fp, const DMPalette *ppal) | |
426 { | |
427 int res; | |
428 | |
429 if ((res = dmPaletteWriteData(fp, ppal, ppal->ncolors, 256)) != DMERR_OK) | |
430 return res; | |
392 | 431 |
393 return DMERR_OK; | 432 return DMERR_OK; |
394 } | 433 } |
395 | 434 |
396 | 435 |
3029 // List of formats | 3068 // List of formats |
3030 // | 3069 // |
3031 const DMPaletteFormat dmPaletteFormatList[] = | 3070 const DMPaletteFormat dmPaletteFormatList[] = |
3032 { | 3071 { |
3033 { | 3072 { |
3034 "act", "ACT Palette", | 3073 "act", "Adobe Color Table palette", |
3035 DM_PALFMT_ACT, DM_FMT_RDWR, | 3074 DM_PALFMT_ACT, DM_FMT_RDWR, |
3036 fmtProbeACT, dmReadACTPalette, dmWriteACTPalette, | 3075 fmtProbeACTPalette, dmReadACTPalette, dmWriteACTPalette, |
3076 }, | |
3077 { | |
3078 "rpl", "RAW binary palette (RGB, 768 bytes)", | |
3079 DM_PALFMT_RAW, DM_FMT_RDWR, | |
3080 fmtProbeRAWPalette, dmReadRAWPalette, dmWriteRAWPalette, | |
3037 }, | 3081 }, |
3038 }; | 3082 }; |
3039 | 3083 |
3040 const int ndmPaletteFormatList = sizeof(dmPaletteFormatList) / sizeof(dmPaletteFormatList[0]); | 3084 const int ndmPaletteFormatList = sizeof(dmPaletteFormatList) / sizeof(dmPaletteFormatList[0]); |
3041 | 3085 |