Created
July 30, 2022 13:27
-
-
Save wmcbrine/dec624a45e5da319f2c32138195362d0 to your computer and use it in GitHub Desktop.
Convert Sinclair ZX Spectrum images to Portable Bitmap format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Convert Sinclair ZX Spectrum images to Portable Bitmap format | |
* by William McBrine <wmcbrine@gmail.com> | |
* October 16, 2005 | |
* Placed in the public domain | |
* | |
* This does only a monochrome conversion -- color is more complex. I'll | |
* call that one "zxtoppm", when I write it. | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#define SCREENSIZE 6144 | |
int main(int argc, char **argv) | |
{ | |
FILE *inp; | |
unsigned char rawbits[SCREENSIZE]; | |
unsigned blockloop, lineloop, rowloop; | |
size_t result; | |
if (argc > 1) { | |
inp = fopen(argv[1], "rb"); | |
if (!inp) | |
return EXIT_FAILURE; | |
} else | |
inp = stdin; | |
result = fread(rawbits, SCREENSIZE, 1, inp); | |
if (!result) | |
return EXIT_FAILURE; | |
if (argc > 1) | |
fclose(inp); | |
printf("P4\n256 192\n"); | |
for (blockloop = 0; blockloop < 3; blockloop++) | |
for (lineloop = 0; lineloop < 8; lineloop++) | |
for (rowloop = 0; rowloop < 8; rowloop++) | |
fwrite(rawbits + (blockloop << 11) + | |
(lineloop << 5) + (rowloop << 8), | |
32, 1, stdout); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment