palremap.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. /* Mapping table. This table specifies the target index in the
  4. output file. */
  5. int map_idx [120] = {
  6. 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,
  7. 0x2c, 0x2d, 0x2e, 0x2f, 0x34, 0x35, 0x36, 0x37,
  8. 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
  9. 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b,
  10. 0x4c, 0x4d, 0x4e, 0x4f, 0x54, 0x55, 0x56, 0x57,
  11. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
  12. 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,
  13. 0x6c, 0x6d, 0x6e, 0x6f, 0x74, 0x75, 0x76, 0x77,
  14. 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
  15. 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
  16. 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
  17. 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
  18. 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
  19. 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
  20. 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf
  21. };
  22. /* remap colors in a 256 color bitmap */
  23. int main(int argc, char **argv) {
  24. if(argc<3) {
  25. fprintf(stderr, "Usage: %s <infile> <outfile>\n", argv[0]);
  26. return 1;
  27. }
  28. FILE *in, *out;
  29. if((in=fopen(argv[1], "rb"))==NULL) {
  30. perror("Could not open input file");
  31. return 1;
  32. }
  33. if((out=fopen(argv[2], "wb"))==NULL) {
  34. perror("Could not open output file");
  35. return 1;
  36. }
  37. while(1) {
  38. uint8_t c=fgetc(in);
  39. if(feof(in))break;
  40. /* new palette mapping:
  41. 0-31: fonts, tile stuff
  42. 32-35: 4bit palette 2
  43. 36-47: logo
  44. 48-51: 4bit palette 3
  45. 52-63: logo
  46. 64-67: 4bit palette 4
  47. 68-79: logo
  48. 80-83: 4bit palette 5
  49. 84-95: logo
  50. 96-99: 4bit palette 6
  51. 100-111: logo
  52. 112-115: 4bit palette 7
  53. 116-175: logo
  54. 176-191: sprites (misc overlays, cursor, etc.)
  55. 192-255: sprites (logo gfx overlays)
  56. */
  57. if(c < 120) {
  58. c = map_idx[c];
  59. } else {
  60. c = 0;
  61. }
  62. fputc(c, out);
  63. }
  64. fclose(out);
  65. fclose(in);
  66. return 0;
  67. }