Skip to content

Commit

Permalink
Simple BMP convertor to binary image compatible with CGA
Browse files Browse the repository at this point in the history
  • Loading branch information
tisnik committed Jul 10, 2024
1 parent 4846148 commit bfbd44f
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions pc-dos/convert.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <stdio.h>

#define PIXELS 320*200

int main(void) {
FILE *fin;
FILE *fout;
int i;

fin = fopen("1.bmp", "r");
fseek(fin, 1162, SEEK_SET);

fout = fopen("image.bin", "w");

for (i=0; i<PIXELS/4; i++) {
unsigned char pixels[4];
unsigned int out;
fread(pixels, 4, 1, fin);

out = pixels[3] & 0x03 |
((pixels[2] & 0x03) << 2) |
((pixels[1] & 0x03) << 4) |
((pixels[0] & 0x03) << 6);
printf("%x ", out);
fputc(out, fout);
}

fclose(fin);
fclose(fout);
}

0 comments on commit bfbd44f

Please sign in to comment.