#include #include #include #include"mxfont.h" #include"bitmap.h" struct Color { unsigned char r,g,b,w; }; int GetFX(int mx,int x, int nw) { float xp = (float)x * (float)mx / (float)nw; return (int)xp; } int GetFZ(int my, int y, int nh) { float yp = (float)y * (float)my / (float)nh; return (int)yp; } int bmp2c(const char *source, const char *out) { int width,height; FILE *fptr = 0, *optr = 0; long offset, size; short type, bitcount; int i = 0; int x, y,q; struct Color *bits = 0; fptr = fopen(source,"rb"); if(!fptr) return 0; fread(&type, sizeof(short), 1, fptr); if(type != 0x4D42) { fclose(fptr); return 0; } fseek(fptr, 10, SEEK_SET); fread(&offset, sizeof(long), 1, fptr); fseek(fptr, 4, SEEK_CUR); fread(&width, sizeof(long), 1, fptr); fread(&height, sizeof(long), 1, fptr); fseek(fptr, 2, SEEK_CUR); fread(&bitcount, sizeof(short), 1, fptr); if(bitcount != 24) { fclose(fptr); return 0; } fseek(fptr, 4, SEEK_CUR); fread(&size, sizeof(long), 1, fptr); fseek(fptr,16,SEEK_CUR); optr = fopen(out,"w"); if(!optr) return 0; bits = (struct Color*) malloc (sizeof(struct Color)*(width*height)); for(y = height-1; y > -1; y--) { for(x = 0; x < width; x++) { static struct Color c; q = x + y * (width); bits[q].b = fgetc(fptr); bits[q].g = fgetc(fptr); bits[q].r = fgetc(fptr); bits[q].w = 0; } for(i = 0; i < width % 4; i++) fgetc(fptr); } fprintf(optr, "struct bits { unsigned char r,g,b; };\n"); fprintf(optr, "struct bits data_bits[] = { "); { int i; for(i = 0; i < width*height; i++) { fprintf(optr, "{0x%x,0x%x,0x%x},", bits[i].r, bits[i].g, bits[i].b); } } fprintf(optr, "\n 0 };"); fprintf(optr, "\nunsigned long data_length = 0x%x;\n", width*height); fprintf(optr, "\nunsigned long data_w = 0x%x;\n", width); fprintf(optr, "\nunsigned long data_h = 0x%x;\n", height); free(bits); fclose(fptr); fclose(optr); return 1; } SDL_Surface *front = 0; SDL_Event e; int main(int argc, char **argv) { int active = 1; if(argc != 3) return 0; bmp2c(argv[1], argv[2]); SDL_Init(SDL_INIT_VIDEO); front = SDL_SetVideoMode(480,272,0,0); printf("Successfully converted..\n"); while(active == 1) { SDL_FillRect(front, 0, 0); if(SDL_PollEvent(&e)) { switch(e.type) { case SDL_QUIT: active = 0; break; } } SDL_UpdateRect(front, 0, 0, 480, 272); } return 0; }