comparison tools/gfxconv.c @ 1235:5b8245e5f785

Remove trailing whitespace.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 06 Mar 2015 13:40:47 +0200
parents 848a88ce7a57
children 5206e3d4e6b7
comparison
equal deleted inserted replaced
1234:beae399c6473 1235:5b8245e5f785
182 printf( 182 printf(
183 "Available input/output formats:\n" 183 "Available input/output formats:\n"
184 " Ext | I | O | Description\n" 184 " Ext | I | O | Description\n"
185 "------+---+---+-----------------------------------------------\n" 185 "------+---+---+-----------------------------------------------\n"
186 ); 186 );
187 187
188 for (i = 0; i < nconvFormatList; i++) 188 for (i = 0; i < nconvFormatList; i++)
189 { 189 {
190 DMConvFormat *fmt = &convFormatList[i]; 190 DMConvFormat *fmt = &convFormatList[i];
191 printf("%-5s | %c | %c | %s\n", 191 printf("%-5s | %c | %c | %s\n",
192 fmt->fext ? fmt->fext : "", 192 fmt->fext ? fmt->fext : "",
361 dmErrorMsg("Invalid %s value '%s', could not parse source value '%s'.\n", msg, popt, opt); 361 dmErrorMsg("Invalid %s value '%s', could not parse source value '%s'.\n", msg, popt, opt);
362 goto error; 362 goto error;
363 } 363 }
364 value->triplet = FALSE; 364 value->triplet = FALSE;
365 } 365 }
366 366
367 // Trim whitespace 367 // Trim whitespace
368 split++; 368 split++;
369 while (*split && isspace(*split)) split++; 369 while (*split && isspace(*split)) split++;
370 370
371 // Parse destination value 371 // Parse destination value
372 if (!dmGetIntVal(split, &value->to)) 372 if (!dmGetIntVal(split, &value->to))
373 { 373 {
374 dmErrorMsg("Invalid %s value '%s', could not parse destination value '%s'.\n", msg, popt, split); 374 dmErrorMsg("Invalid %s value '%s', could not parse destination value '%s'.\n", msg, popt, split);
375 goto error; 375 goto error;
428 { 428 {
429 dmErrorMsg("Invalid %s value '%s', could not parse.\n", msg, opt); 429 dmErrorMsg("Invalid %s value '%s', could not parse.\n", msg, opt);
430 return FALSE; 430 return FALSE;
431 } 431 }
432 } 432 }
433 433
434 return TRUE; 434 return TRUE;
435 } 435 }
436 436
437 437
438 BOOL dmParseMapOptionString(char *opt, void *values, int *nvalues, const int nmax, const BOOL requireIndex, const char *msg) 438 BOOL dmParseMapOptionString(char *opt, void *values, int *nvalues, const int nmax, const BOOL requireIndex, const char *msg)
453 break; 453 break;
454 454
455 start = end + 1; 455 start = end + 1;
456 } 456 }
457 457
458 return TRUE; 458 return TRUE;
459 } 459 }
460 460
461 461
462 int dmParseColorRemapFile(const char *filename, DMMapValue *values, int *nvalue, const int nmax) 462 int dmParseColorRemapFile(const char *filename, DMMapValue *values, int *nvalue, const int nmax)
463 { 463 {
475 475
476 while (fgets(line, sizeof(line), fp)) 476 while (fgets(line, sizeof(line), fp))
477 { 477 {
478 char *start = line; 478 char *start = line;
479 while (*start && isspace(*start)) start++; 479 while (*start && isspace(*start)) start++;
480 480
481 if (*start != 0 && *start != ';') 481 if (*start != 0 && *start != ';')
482 { 482 {
483 if (!dmParseMapOptionMapItem(line, &values[*nvalue], nmax, "mapping file")) 483 if (!dmParseMapOptionMapItem(line, &values[*nvalue], nmax, "mapping file"))
484 goto error; 484 goto error;
485 else 485 else
529 case 'i': optInFormat = FFMT_IMAGE; break; 529 case 'i': optInFormat = FFMT_IMAGE; break;
530 default: 530 default:
531 dmErrorMsg("Invalid input format '%s'.\n", optArg); 531 dmErrorMsg("Invalid input format '%s'.\n", optArg);
532 return FALSE; 532 return FALSE;
533 } 533 }
534 534
535 char *tmp = strchr(optArg, ':'); 535 char *tmp = strchr(optArg, ':');
536 if (tmp != NULL) 536 if (tmp != NULL)
537 { 537 {
538 tmp++; 538 tmp++;
539 switch (optInFormat) 539 switch (optInFormat)
550 dmErrorMsg("Invalid input subformat for sprite/char: '%s', should be 'mc' or 'sc'.\n", 550 dmErrorMsg("Invalid input subformat for sprite/char: '%s', should be 'mc' or 'sc'.\n",
551 tmp); 551 tmp);
552 return FALSE; 552 return FALSE;
553 } 553 }
554 break; 554 break;
555 555
556 case FFMT_BITMAP: 556 case FFMT_BITMAP:
557 if (!dmGetC64FormatByExt(tmp, &optInFormat, &optInSubFormat)) 557 if (!dmGetC64FormatByExt(tmp, &optInFormat, &optInSubFormat))
558 { 558 {
559 dmErrorMsg("Invalid bitmap subformat '%s', see format list for valid bformats.\n", 559 dmErrorMsg("Invalid bitmap subformat '%s', see format list for valid bformats.\n",
560 tmp); 560 tmp);
563 break; 563 break;
564 } 564 }
565 } 565 }
566 } 566 }
567 break; 567 break;
568 568
569 case 2: 569 case 2:
570 optInMulticolor = TRUE; 570 optInMulticolor = TRUE;
571 break; 571 break;
572 572
573 case 3: 573 case 3:
574 optOutFilename = optArg; 574 optOutFilename = optArg;
575 break; 575 break;
576 576
577 case 4: 577 case 4:
578 if (!dmGetIntVal(optArg, &optInSkip)) 578 if (!dmGetIntVal(optArg, &optInSkip))
579 { 579 {
580 dmErrorMsg("Invalid skip value argument '%s'.\n", optArg); 580 dmErrorMsg("Invalid skip value argument '%s'.\n", optArg);
581 return FALSE; 581 return FALSE;
770 770
771 771
772 void dmPrintByte(FILE *out, int byte, int format, BOOL multicolor) 772 void dmPrintByte(FILE *out, int byte, int format, BOOL multicolor)
773 { 773 {
774 int i; 774 int i;
775 775
776 if (multicolor) 776 if (multicolor)
777 { 777 {
778 for (i = DM_ASC_NBITS; i; i -= 2) 778 for (i = DM_ASC_NBITS; i; i -= 2)
779 { 779 {
780 int val = (byte & (3ULL << (i - 2))) >> (i - 2); 780 int val = (byte & (3ULL << (i - 2))) >> (i - 2);
912 mapping[n] = map->to; 912 mapping[n] = map->to;
913 mapped[map->to] = TRUE; 913 mapped[map->to] = TRUE;
914 found = TRUE; 914 found = TRUE;
915 } 915 }
916 } 916 }
917 917
918 if (!found) 918 if (!found)
919 { 919 {
920 dmMsg(3, "No RGBA match found for map index %d, #%02x%02x%02x%02x\n", 920 dmMsg(3, "No RGBA match found for map index %d, #%02x%02x%02x%02x\n",
921 index, 921 index,
922 map->color.r, map->color.g, map->color.b, map->color.a); 922 map->color.r, map->color.g, map->color.b, map->color.a);
930 mapping[map->from] = map->to; 930 mapping[map->from] = map->to;
931 mapped[map->to] = TRUE; 931 mapped[map->to] = TRUE;
932 } 932 }
933 } 933 }
934 934
935 935
936 // Fill in the rest 936 // Fill in the rest
937 if (optRemapRemove) 937 if (optRemapRemove)
938 { 938 {
939 dmMsg(2, "Removing unused colors.\n"); 939 dmMsg(2, "Removing unused colors.\n");
940 for (index = 0; index < image->ncolors; index++) 940 for (index = 0; index < image->ncolors; index++)
969 for (index = 0; index < image->ncolors; index++) 969 for (index = 0; index < image->ncolors; index++)
970 { 970 {
971 if (mapping[index] + 1 > ncolors) 971 if (mapping[index] + 1 > ncolors)
972 ncolors = mapping[index] + 1; 972 ncolors = mapping[index] + 1;
973 } 973 }
974 974
975 // Copy palette entries 975 // Copy palette entries
976 for (index = 0; index < image->ncolors; index++) 976 for (index = 0; index < image->ncolors; index++)
977 { 977 {
978 if (mapping[index] >= 0) 978 if (mapping[index] >= 0)
979 { 979 {
1101 case IMGFMT_RAW: 1101 case IMGFMT_RAW:
1102 case IMGFMT_ARAW: 1102 case IMGFMT_ARAW:
1103 { 1103 {
1104 FILE *fp; 1104 FILE *fp;
1105 char *dataFilename; 1105 char *dataFilename;
1106 1106
1107 // Form data file filename 1107 // Form data file filename
1108 dataFilename = dm_strdup_fext(filename, "%s.inc"); 1108 dataFilename = dm_strdup_fext(filename, "%s.inc");
1109 if (dataFilename == NULL) 1109 if (dataFilename == NULL)
1110 return DMERR_MALLOC; 1110 return DMERR_MALLOC;
1111 1111
1411 { 1411 {
1412 dmErrorMsg("Could not read full bufferful (%d bytes) of data at 0x%x.\n", 1412 dmErrorMsg("Could not read full bufferful (%d bytes) of data at 0x%x.\n",
1413 bufSize, dataOffs); 1413 bufSize, dataOffs);
1414 error = TRUE; 1414 error = TRUE;
1415 } 1415 }
1416 1416
1417 fprintf(outFile, "---- : -------------- #%d\n", itemCount); 1417 fprintf(outFile, "---- : -------------- #%d\n", itemCount);
1418 1418
1419 switch (optInFormat) 1419 switch (optInFormat)
1420 { 1420 {
1421 case FFMT_CHAR: 1421 case FFMT_CHAR:
1457 if (optItemCount <= 0) 1457 if (optItemCount <= 0)
1458 { 1458 {
1459 dmErrorMsg("Single-image output requires count to be set (-n).\n"); 1459 dmErrorMsg("Single-image output requires count to be set (-n).\n");
1460 goto error; 1460 goto error;
1461 } 1461 }
1462 1462
1463 outIWidth = optPlanedWidth; 1463 outIWidth = optPlanedWidth;
1464 outIHeight = (optItemCount / optPlanedWidth); 1464 outIHeight = (optItemCount / optPlanedWidth);
1465 if (optItemCount % optPlanedWidth) 1465 if (optItemCount % optPlanedWidth)
1466 outIHeight++; 1466 outIHeight++;
1467 1467
1468 outImage = dmImageAlloc(outWidthPX * outIWidth, outIHeight * outHeight); 1468 outImage = dmImageAlloc(outWidthPX * outIWidth, outIHeight * outHeight);
1469 } 1469 }
1470 1470
1471 outImage->constpal = TRUE; 1471 outImage->constpal = TRUE;
1472 outImage->pal = dmC64Palette; 1472 outImage->pal = dmC64Palette;
1473 outImage->ncolors = C64_NCOLORS; 1473 outImage->ncolors = C64_NCOLORS;
1474 outImage->ctransp = 255; 1474 outImage->ctransp = 255;
1475 1475
1476 while (!feof(inFile) && (optItemCount < 0 || itemCount < optItemCount)) 1476 while (!feof(inFile) && (optItemCount < 0 || itemCount < optItemCount))
1477 { 1477 {
1478 dmMemset(bufData, 0, bufSize); 1478 dmMemset(bufData, 0, bufSize);
1479 1479
1480 if (fread(bufData, 1, bufSize, inFile) != bufSize) 1480 if (fread(bufData, 1, bufSize, inFile) != bufSize)
1497 if (outFilename == NULL) 1497 if (outFilename == NULL)
1498 { 1498 {
1499 dmErrorMsg("Could not allocate memory for filename template?\n"); 1499 dmErrorMsg("Could not allocate memory for filename template?\n");
1500 goto error; 1500 goto error;
1501 } 1501 }
1502 1502
1503 ret = dmWriteImage(optOutFilename, outImage, &optSpec, optOutSubFormat, TRUE); 1503 ret = dmWriteImage(optOutFilename, outImage, &optSpec, optOutSubFormat, TRUE);
1504 if (ret != DMERR_OK) 1504 if (ret != DMERR_OK)
1505 { 1505 {
1506 dmErrorMsg("Error writing output image, %d: %s.\n", 1506 dmErrorMsg("Error writing output image, %d: %s.\n",
1507 ret, dmErrorStr(ret)); 1507 ret, dmErrorStr(ret));
1515 { 1515 {
1516 outX = 0; 1516 outX = 0;
1517 outY++; 1517 outY++;
1518 } 1518 }
1519 } 1519 }
1520 1520
1521 itemCount++; 1521 itemCount++;
1522 } 1522 }
1523 1523
1524 if (!optSequential) 1524 if (!optSequential)
1525 { 1525 {
1528 { 1528 {
1529 dmError(ret, "Error writing output image, %d: %s.\n", 1529 dmError(ret, "Error writing output image, %d: %s.\n",
1530 ret, dmErrorStr(ret)); 1530 ret, dmErrorStr(ret));
1531 } 1531 }
1532 } 1532 }
1533 1533
1534 dmImageFree(outImage); 1534 dmImageFree(outImage);
1535 } 1535 }
1536 else 1536 else
1537 if (optOutFormat == FFMT_BITMAP) 1537 if (optOutFormat == FFMT_BITMAP)
1538 { 1538 {
1632 if (forced == NULL && cfmt != NULL) 1632 if (forced == NULL && cfmt != NULL)
1633 { 1633 {
1634 dmMsg(1,"Probed %s format image, type %d, %s\n", 1634 dmMsg(1,"Probed %s format image, type %d, %s\n",
1635 cfmt->name, cfmt->type, cfmt->fext); 1635 cfmt->name, cfmt->type, cfmt->fext);
1636 } 1636 }
1637 1637
1638 if (res == DMERR_OK) 1638 if (res == DMERR_OK)
1639 optInFormat = FFMT_BITMAP; 1639 optInFormat = FFMT_BITMAP;
1640 else 1640 else
1641 { 1641 {
1642 dmErrorMsg("Could not decode input image.\n"); 1642 dmErrorMsg("Could not decode input image.\n");
1669 int res = dmGetErrno(); 1669 int res = dmGetErrno();
1670 dmErrorMsg("Could not seek to file position %d (0x%x): %s\n", 1670 dmErrorMsg("Could not seek to file position %d (0x%x): %s\n",
1671 optInSkip, optInSkip, dmErrorStr(res)); 1671 optInSkip, optInSkip, dmErrorStr(res));
1672 goto error; 1672 goto error;
1673 } 1673 }
1674 1674
1675 int inFormat = dmGetConvFormat(optInFormat, optInSubFormat), 1675 int inFormat = dmGetConvFormat(optInFormat, optInSubFormat),
1676 outFormat = dmGetConvFormat(optOutFormat, optOutSubFormat); 1676 outFormat = dmGetConvFormat(optOutFormat, optOutSubFormat);
1677 1677
1678 if (inFormat != -1 && outFormat != -1) 1678 if (inFormat != -1 && outFormat != -1)
1679 { 1679 {
1680 char *inFmtName = convFormatList[inFormat].name, 1680 char *inFmtName = convFormatList[inFormat].name,
1681 *inFmtExt = convFormatList[inFormat].fext, 1681 *inFmtExt = convFormatList[inFormat].fext,
1682 *outFmtName = convFormatList[outFormat].name, 1682 *outFmtName = convFormatList[outFormat].name,
1693 { 1693 {
1694 case FFMT_SPRITE: 1694 case FFMT_SPRITE:
1695 case FFMT_CHAR: 1695 case FFMT_CHAR:
1696 dmDumpSpritesAndChars(inFile); 1696 dmDumpSpritesAndChars(inFile);
1697 break; 1697 break;
1698 1698
1699 case FFMT_BITMAP: 1699 case FFMT_BITMAP:
1700 { 1700 {
1701 DMImage *outImage = NULL; 1701 DMImage *outImage = NULL;
1702 int res = DMERR_OK; 1702 int res = DMERR_OK;
1703 1703
1741 1741
1742 default: 1742 default:
1743 dmErrorMsg("Unsupported output format for bitmap/image conversion.\n"); 1743 dmErrorMsg("Unsupported output format for bitmap/image conversion.\n");
1744 break; 1744 break;
1745 } 1745 }
1746 1746
1747 dmImageFree(outImage); 1747 dmImageFree(outImage);
1748 } 1748 }
1749 break; 1749 break;
1750 1750
1751 case FFMT_IMAGE: 1751 case FFMT_IMAGE:
1766 else 1766 else
1767 dmErrorMsg("Unsupported input image format for bitmap/image conversion.\n"); 1767 dmErrorMsg("Unsupported input image format for bitmap/image conversion.\n");
1768 1768
1769 if (res != DMERR_OK || outImage == NULL) 1769 if (res != DMERR_OK || outImage == NULL)
1770 break; 1770 break;
1771 1771
1772 switch (optOutFormat) 1772 switch (optOutFormat)
1773 { 1773 {
1774 case FFMT_IMAGE: 1774 case FFMT_IMAGE:
1775 res = dmWriteImage(optOutFilename, outImage, &optSpec, optOutSubFormat, TRUE); 1775 res = dmWriteImage(optOutFilename, outImage, &optSpec, optOutSubFormat, TRUE);
1776 break; 1776 break;
1788 if (res != DMERR_OK) 1788 if (res != DMERR_OK)
1789 { 1789 {
1790 dmErrorMsg("Error writing output (%s), probably unsupported output format for bitmap/image conversion.\n", 1790 dmErrorMsg("Error writing output (%s), probably unsupported output format for bitmap/image conversion.\n",
1791 dmErrorStr(res)); 1791 dmErrorStr(res));
1792 } 1792 }
1793 1793
1794 dmImageFree(outImage); 1794 dmImageFree(outImage);
1795 } 1795 }
1796 break; 1796 break;
1797 } 1797 }
1798 1798