Skip to content

Instantly share code, notes, and snippets.

@wmcbrine
Created Jul 30, 2022
Embed
What would you like to do?
Convert Sinclair ZX Spectrum images to Portable Bitmap format
/* 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