comparison tools/gfxconv.c @ 2226:6037ba60730a

Add output format for "dumping" c64 bitmap image structs data into separate file(s) per data block.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 14 Jun 2019 18:08:13 +0300
parents 5477e792def3
children ba5141771d9a
comparison
equal deleted inserted replaced
2225:837c79747ea4 2226:6037ba60730a
31 FFMT_BITMAP, 31 FFMT_BITMAP,
32 FFMT_CHAR, 32 FFMT_CHAR,
33 FFMT_SPRITE, 33 FFMT_SPRITE,
34 34
35 FFMT_IMAGE, 35 FFMT_IMAGE,
36 FFMT_DUMP,
36 37
37 FFMT_LAST 38 FFMT_LAST
38 }; 39 };
39 40
40 41
89 { "ASCII text" , "asc" , DM_FMT_WR , FFMT_ASCII , 0 , NULL }, 90 { "ASCII text" , "asc" , DM_FMT_WR , FFMT_ASCII , 0 , NULL },
90 { "ANSI colored text" , "ansi" , DM_FMT_WR , FFMT_ANSI , 0 , NULL }, 91 { "ANSI colored text" , "ansi" , DM_FMT_WR , FFMT_ANSI , 0 , NULL },
91 { "C64 bitmap image" , "bitmap", DM_FMT_RDWR , FFMT_BITMAP , -1 , NULL }, 92 { "C64 bitmap image" , "bitmap", DM_FMT_RDWR , FFMT_BITMAP , -1 , NULL },
92 { "C64 character/font data" , "chr" , DM_FMT_RDWR , FFMT_CHAR , 0 , " (chr:mc/chr:sc for multi/singlecolor)" }, 93 { "C64 character/font data" , "chr" , DM_FMT_RDWR , FFMT_CHAR , 0 , " (chr:mc/chr:sc for multi/singlecolor)" },
93 { "C64 sprite data" , "spr" , DM_FMT_RDWR , FFMT_SPRITE , 0 , " (spr:mc/spr:sc for multi/singlecolor)" }, 94 { "C64 sprite data" , "spr" , DM_FMT_RDWR , FFMT_SPRITE , 0 , " (spr:mc/spr:sc for multi/singlecolor)" },
95 { "C64 bitmap image dump" , "dump" , DM_FMT_WR , FFMT_DUMP , 0 , NULL },
94 }; 96 };
95 97
96 static const int nbaseFormatList = sizeof(baseFormatList) / sizeof(baseFormatList[0]); 98 static const int nbaseFormatList = sizeof(baseFormatList) / sizeof(baseFormatList[0]);
97 99
98 100
1226 dmFree(used); 1228 dmFree(used);
1227 return res; 1229 return res;
1228 } 1230 }
1229 1231
1230 1232
1233 int dmDumpC64Block(const char *fprefix, const char *fext, const DMC64MemBlock *blk, const int index)
1234 {
1235 int res = DMERR_OK;
1236 if (blk != NULL && blk->data != NULL)
1237 {
1238 char *filename = dm_strdup_printf("%s_%s_%d.bin", fprefix, fext, index);
1239 if (filename == NULL)
1240 return DMERR_MALLOC;
1241
1242 res = dmWriteDataFile(NULL, filename, blk->data, blk->size);
1243 dmFree(filename);
1244 }
1245 return res;
1246 }
1247
1248
1249 int dmDumpC64Bitmap(const char *fprefix, const DMC64Image *img)
1250 {
1251 int res;
1252
1253 for (int i = 0; i < img->nblocks; i++)
1254 {
1255 res = dmDumpC64Block(fprefix, "bitmap", &img->bitmap[i], i);
1256 res = dmDumpC64Block(fprefix, "color", &img->color[i], i);
1257 res = dmDumpC64Block(fprefix, "screen", &img->screen[i], i);
1258 res = dmDumpC64Block(fprefix, "extradata", &img->extraData[i], i);
1259 }
1260
1261 return res;
1262 }
1263
1264
1231 int dmConvertC64Bitmap(DMC64Image **pdst, const DMC64Image *src, 1265 int dmConvertC64Bitmap(DMC64Image **pdst, const DMC64Image *src,
1232 const DMC64ImageFormat *dstFmt, const DMC64ImageFormat *srcFmt) 1266 const DMC64ImageFormat *dstFmt, const DMC64ImageFormat *srcFmt)
1233 { 1267 {
1234 DMC64Image *dst; 1268 DMC64Image *dst;
1235 DMC64MemBlock *srcBlk = NULL, *dstBlk = NULL; 1269 DMC64MemBlock *srcBlk = NULL, *dstBlk = NULL;
2169 else 2203 else
2170 { 2204 {
2171 // No palette file specified, use internal palette 2205 // No palette file specified, use internal palette
2172 if (optC64Palette == NULL) 2206 if (optC64Palette == NULL)
2173 optC64Palette = &dmC64DefaultPalettes[0]; 2207 optC64Palette = &dmC64DefaultPalettes[0];
2174 2208
2175 dmMsg(1, "Using internal palette '%s' (%s).\n", 2209 dmMsg(1, "Using internal palette '%s' (%s).\n",
2176 optC64Palette->name, optC64Palette->desc); 2210 optC64Palette->name, optC64Palette->desc);
2177 2211
2178 optC64Spec.cpal = optC64Palette; 2212 optC64Spec.cpal = optC64Palette;
2179 2213
2246 case FFMT_SPRITE: 2280 case FFMT_SPRITE:
2247 res = dmWriteSpritesAndChars(optOutFilename, outImage, 2281 res = dmWriteSpritesAndChars(optOutFilename, outImage,
2248 optOutType, optInMulticolor); 2282 optOutType, optInMulticolor);
2249 break; 2283 break;
2250 } 2284 }
2285 break;
2286
2287 case FFMT_DUMP:
2288 dmDumpC64Bitmap(optOutFilename, inC64Image);
2251 break; 2289 break;
2252 2290
2253 case FFMT_BITMAP: 2291 case FFMT_BITMAP:
2254 if ((res = dmConvertC64Bitmap(&outC64Image, inC64Image, 2292 if ((res = dmConvertC64Bitmap(&outC64Image, inC64Image,
2255 &dmC64ImageFormats[optOutFormat], inC64Fmt)) != DMERR_OK) 2293 &dmC64ImageFormats[optOutFormat], inC64Fmt)) != DMERR_OK)