Code:
/*----------------------------------------------------------------
width*height schwarz-weiss bitmap in nokia 3310 daten wandeln
compiler: bcc32
OS: XP
robocat, 13.04.07
----------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
// define glcd size here
unsigned int width=128;
unsigned int height=64;
int main()
{
FILE *pDatei;
unsigned int size,i,x,y;
unsigned char buf[128],*file1,*file2;
long pos1,pos2;
pDatei = fopen("C:\\martin.bmp", "rb");
if(pDatei == NULL)
{
printf("Fehler beim Oeffnen der Quell-Datei!\n");
printf("Programm beendet.\n");
while(1);
}
fseek(pDatei,0,SEEK_END);
pos2=ftell(pDatei);
fseek(pDatei,10,SEEK_SET);
fread(&pos1,4,1,pDatei);
fseek(pDatei,pos1,SEEK_SET);
size=pos2-pos1;
file1=(unsigned char*)malloc(size);
fread(file1,1,size,pDatei);
fclose(pDatei);
file2=(unsigned char*)malloc(width*height/8);
memset(file2,0,width*height/8);
for(x=0;x<width;x++)
{
for(y=0;y<height;y++)
{
if(!(*(file1+y*width/8+x/8)>>(7-(x%8)))&1==1)
{
*(file2+((height/8-1)-y/8)*width+x)|=1<<(7-(y%8));
}
}
}
pDatei = fopen("C:\\martin.txt", "w");
if(pDatei == NULL)
{
printf("Fehler beim Oeffnen der Ziel-Datei!\n");
printf("Programm beendet.\n");
free(file1);
free(file2);
while(1);
}
sprintf((char*)buf,"unsigned char picture[]={");
fwrite (buf,strlen((const char*)buf),1,pDatei);
for(i=0;i<width*height/8;i++)
{
if(i%8==0)fwrite("\n",1,1,pDatei);
sprintf((char*)buf,"%u,",*(file2+i));
fwrite(buf,strlen((const char*)buf),1,pDatei);
}
fseek(pDatei,-1,SEEK_END);
fwrite ("};\n",3,1,pDatei);
fclose(pDatei);
free(file1);
free(file2);
printf("OK");
while(1);
}
das ist der code mit den richtigen casts. keine ahnung warum mein compiler da so kleinlich ist.... ^^
Lesezeichen