comparison gfxconv.c @ 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 ca5ad51c6479
children 0e39e0bbb5ac
comparison
equal deleted inserted replaced
549:c8cc840a4fcf 550:12854cbd6fab
927 dmFree(used); 927 dmFree(used);
928 return DMERR_OK; 928 return DMERR_OK;
929 } 929 }
930 930
931 931
932 int dmWriteBitmap(const char *filename, DMC64Image *image, int iformat) 932 int dmWriteBitmap(const char *filename, DMC64Image *image, int iformat, BOOL enableFixUps)
933 { 933 {
934 return DMERR_OK; 934 FILE *outFile = NULL;
935 Uint8 *buf = NULL;
936 size_t bufSize;
937 int res = DMERR_OK;
938 const DMC64ImageFormat *fmt = &dmC64ImageFormats[iformat];
939
940 dmMsg(1, "Converting to %s format bitmap.\n", fmt->name);
941 if (image->type != fmt->type && enableFixUps)
942 {
943 // Try to do some simple fixups
944 if ((fmt->type & D64_FMT_FLI) && (image->type & D64_FMT_FLI) == 0)
945 {
946 dmMsg(1, "Upconverting multicolor to FLI.\n");
947 int i;
948 for (i = 1; i < C64_SCR_MAX_BANK; i++)
949 {
950 memcpy(image->color[i], image->color[0], C64_SCR_COLOR_SIZE);
951 memcpy(image->screen[i], image->screen[0], C64_SCR_SCREEN_SIZE);
952 }
953 }
954 }
955
956
957 if ((res = dmC64EncodeGenericBMP(&buf, &bufSize, image, fmt)) != DMERR_OK)
958 goto error;
959
960 dmMsg(2, "Result: %d bytes\n", bufSize);
961
962 if ((outFile = fopen(filename, "wb")) == NULL)
963 {
964 res = dmGetErrno();
965 dmError("Error opening output file '%s', %d: %s\n",
966 filename, res, dmErrorStr(res));
967 goto error;
968 }
969
970 if (!dm_fwrite_str(outFile, buf, bufSize))
971 {
972 res = dmGetErrno();
973 dmError("Error writing image data to '%s', %d: %s\n",
974 filename, res, dmErrorStr(res));
975 }
976
977 error:
978 if (outFile != NULL)
979 fclose(outFile);
980 dmFree(buf);
981 return res;
935 } 982 }
936 983
937 984
938 int dmWriteImage(const char *filename, DMImage *image, DMImageSpec *spec, int iformat, BOOL info) 985 int dmWriteImage(const char *filename, DMImage *image, DMImageSpec *spec, int iformat, BOOL info)
939 { 986 {
1563 res = dmWriteImage(optOutFilename, outImage, &optSpec, optOutSubFormat, TRUE); 1610 res = dmWriteImage(optOutFilename, outImage, &optSpec, optOutSubFormat, TRUE);
1564 break; 1611 break;
1565 1612
1566 1613
1567 case FFMT_BITMAP: 1614 case FFMT_BITMAP:
1568 res = dmWriteBitmap(optOutFilename, &cimage, optOutSubFormat); 1615 res = dmWriteBitmap(optOutFilename, &cimage, optOutSubFormat, TRUE);
1569 break; 1616 break;
1570 1617
1571 default: 1618 default:
1572 dmError("Unsupported output format for bitmap/image conversion.\n"); 1619 dmError("Unsupported output format for bitmap/image conversion.\n");
1573 break; 1620 break;