Please read this first:
- This tiny program does not implement full BMP format
- It will only work in BMP files saved by GIMP program with 16 colours and no RLE compression
- The resulting PAL and PAT files are the palette and pattern raw data in MSX format, but they have no heading
- Compile using GCC:
gcc bmp2msx.c -obmp2msx
- Probably it will work also in Windows/Mac with GIMP files, but it hasn't been tested
- This code is pure crap, I know it, so don't bother to comment it aloud
// BMP -> raw SCREEN 5/6 converter (palette and pattern files)
// Eduardo Robsy Petrus, 2010
// v.0.1
// Use with GIMP BMP files with 16 colours and no RLE compression
// Make sure that the image has even pixel width
#include<stdio.h>
FILE *input,*output;
int i,j,x,y,k;
unsigned char buffer[1024*128];
int main(int argc, char *argv[])
{
// Print tool name
printf("BMP2MSX v.0.1 - converts GIMP 16-colour BMP to MSX Screen 5/6\n");
// Check if there is a filename parameter
if (argc!=2)
{
// If not, print brief instructions
printf("Usage: bmp2msx [file.bmp]\n");
return 0;
}
// Try to open the file
if ((input=fopen(argv[1],"r"))==NULL)
{
printf("Cannot open %s\n",argv[1]);
return 1;
}
// Read all file to buffer
for (i=0;!feof(input);buffer[i++]=fgetc(input));
i--;
fclose(input);
// Create palette file
output=fopen("output.pal","w");
for (i=0;i<16;i++)
{
j=((buffer[0x35+i*4+3]/32)*16)+(buffer[0x35+i*4+1]/32);
fputc(j,output);
j=buffer[0x35+i*4+2]/32;
fputc(j,output);
}
fclose(output);
// Create pattern file
output=fopen("output.pat","w");
x=(buffer[0x12]+buffer[0x13]*256)/2;
y=buffer[0x16]+buffer[0x17]*256;
printf("%i x %i pixels\n",x,y);
for (j=y-1;j>=0;j--)
for (i=0;i<x;i++)
{
k=buffer[buffer[2]+j*x+i];
fputc(k,output);
}
fclose(output);
return;
}
A very easy process to convert images:
- Open/Edit the image in GIMP
- Convert to indexed image (image > mode > indexed), set 16 as maximum colours and enable dithering if you need it
- Save as BMP file with no RLE compression
- Use the provided command-line tool to convert it easily
- Generate the required code to render the image back in MSX!