palremap.c 970 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. int main(int argc, char **argv) {
  4. if(argc<3) {
  5. fprintf(stderr, "Usage: %s <infile> <outfile>\n", argv[0]);
  6. return 1;
  7. }
  8. FILE *in, *out;
  9. if((in=fopen(argv[1], "rb"))==NULL) {
  10. perror("Could not open input file");
  11. return 1;
  12. }
  13. if((out=fopen(argv[2], "wb"))==NULL) {
  14. perror("Could not open output file");
  15. return 1;
  16. }
  17. while(1) {
  18. uint8_t c=fgetc(in);
  19. if(feof(in))break;
  20. // if(c>=1 && c<=48) {
  21. // c+=207;
  22. // }
  23. // shift palette by 32
  24. // keep color 0
  25. // leave room for sprite pal 3 and 7 (176-192 and 240-255)
  26. if(c) {
  27. if(c>224) { // move upper colors to start
  28. c-=224;
  29. } else if(c==224) { // remap 224 to 32, not 0
  30. c=32;
  31. } else { // shift colors, leave gap 176-191
  32. // relocate 0xd0-0xdf (which would be
  33. // remapped to 0x00-0x0f) to 0xb0-0xbf
  34. c+=32;
  35. if(c>=176) {
  36. c+=16;
  37. if(c<16) c=0xb0+c;
  38. }
  39. }
  40. }
  41. fputc(c, out);
  42. }
  43. fclose(out);
  44. fclose(in);
  45. return 0;
  46. }