Mercurial > hg > dmlib
changeset 550:12854cbd6fab
Initial support for bitmap -> bitmap conversion in gfxconv.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 22 Nov 2012 23:10:18 +0200 |
parents | c8cc840a4fcf |
children | 0e39e0bbb5ac |
files | gfxconv.c |
diffstat | 1 files changed, 50 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/gfxconv.c Thu Nov 22 22:50:06 2012 +0200 +++ b/gfxconv.c Thu Nov 22 23:10:18 2012 +0200 @@ -929,9 +929,56 @@ } -int dmWriteBitmap(const char *filename, DMC64Image *image, int iformat) +int dmWriteBitmap(const char *filename, DMC64Image *image, int iformat, BOOL enableFixUps) { - return DMERR_OK; + FILE *outFile = NULL; + Uint8 *buf = NULL; + size_t bufSize; + int res = DMERR_OK; + const DMC64ImageFormat *fmt = &dmC64ImageFormats[iformat]; + + dmMsg(1, "Converting to %s format bitmap.\n", fmt->name); + if (image->type != fmt->type && enableFixUps) + { + // Try to do some simple fixups + if ((fmt->type & D64_FMT_FLI) && (image->type & D64_FMT_FLI) == 0) + { + dmMsg(1, "Upconverting multicolor to FLI.\n"); + int i; + for (i = 1; i < C64_SCR_MAX_BANK; i++) + { + memcpy(image->color[i], image->color[0], C64_SCR_COLOR_SIZE); + memcpy(image->screen[i], image->screen[0], C64_SCR_SCREEN_SIZE); + } + } + } + + + if ((res = dmC64EncodeGenericBMP(&buf, &bufSize, image, fmt)) != DMERR_OK) + goto error; + + dmMsg(2, "Result: %d bytes\n", bufSize); + + if ((outFile = fopen(filename, "wb")) == NULL) + { + res = dmGetErrno(); + dmError("Error opening output file '%s', %d: %s\n", + filename, res, dmErrorStr(res)); + goto error; + } + + if (!dm_fwrite_str(outFile, buf, bufSize)) + { + res = dmGetErrno(); + dmError("Error writing image data to '%s', %d: %s\n", + filename, res, dmErrorStr(res)); + } + +error: + if (outFile != NULL) + fclose(outFile); + dmFree(buf); + return res; } @@ -1565,7 +1612,7 @@ case FFMT_BITMAP: - res = dmWriteBitmap(optOutFilename, &cimage, optOutSubFormat); + res = dmWriteBitmap(optOutFilename, &cimage, optOutSubFormat, TRUE); break; default: