نوشته اصلی توسط
lpln852
تو تابتون از fread استفاده می کنید یا fget ؟
اینم تابعی که می خواستید(باتشکر از اقایmehdi NXP در انجمن ECA)
همانطور که می بینید ازfget استفاده شده
کد:
void lcd_show_bmp(int x,int y,char *name){
unsigned char info[70];
int offset,width,height,bpp,comp,color,r,g,b;
int counter_x, counter_y,a;
FILE *f;
f = fopen (name,"r");
if(f!=NULL){
fread(info,1,70,f);
offset=(info[13]<<24)|(info[12]<<16)|(info[11]<<8)|(info[10]);
width =(info[21]<<24)|(info[20]<<16)|(info[19]<<8)|(info[18]);
height=(info[25]<<24)|(info[24]<<16)|(info[23]<<8)|(info[22]);
bpp =(info[29]<<8 )|(info[28]);
comp =(info[33]<<24)|(info[32]<<16)|(info[31]<<8)|(info[30]);
fseek(f,offset,SEEK_SET);
//*******************************************************************************
if(bpp==32){
for(counter_y=y;counter_y <height+y;counter_y++){
for(counter_x =x;counter_x < width+x;counter_x++){
r=fgetc(f)>>3;
b=fgetc(f)>>3;
g=fgetc(f)>>2;
r=fgetc(f)>>3;
LCD_SetTextColor((r<<11)|(g<<5)|(b));
LCD_PutPixel(counter_x,319-counter_y);
}
}
}
//*******************************************************************************
if(bpp==24){
for(counter_y=y;counter_y <height+y;counter_y++){
for(counter_x =x;counter_x < width+x;counter_x++){
b=fgetc(f)>>3;
g=fgetc(f)>>2;
r=fgetc(f)>>3;
LCD_SetTextColor((r<<11)|(g<<5)|(b));
LCD_PutPixel(counter_x,319-counter_y);
}
}
}
//*******************************************************************************
if(bpp==16){
if(comp==3){
for(counter_y=y;counter_y <height+y;counter_y++){
for(counter_x =x;counter_x < width+x;counter_x++){
color=fgetc(f);
color|=fgetc(f)<<8;
r=color & ((info[57]<<24)|(info[56]<<16)|(info[55]<<8)|(info[54]));
a=((info[61]<<24)|(info[60]<<16)|(info[59]<<8)|(info[58]));
g=color & a;
if(a<(32<<5)) {g=g<<1;r=r<<1;}
b=color & ((info[65]<<24)|(info[64]<<16)|(info[63]<<8)|(info[62]));
LCD_SetTextColor(r|g|b);
LCD_PutPixel(counter_x,319-counter_y);
}
}
}
if(comp==0){
for(counter_y=y;counter_y <height+y;counter_y++){
for(counter_x =x;counter_x < width+x;counter_x++){
color=fgetc(f);
color|=fgetc(f)<<8;
LCD_SetTextColor(color);
LCD_PutPixel(counter_x,319-counter_y);
}
}
}
}
//*******************************************************************************
if(bpp==1){
for(a=height;a>0;a--){
b=width/8;
if(width%8) b++;
for(r=0;r<b;r++){
color=fgetc(f);
for(g=0;g<8;g++){
if((color>>(7-g))&1) LCD_SetTextColor(Black);
else LCD_SetTextColor(White);
LCD_PutPixel((r*8)+g+x,319-(height-a+y));
}
}
}
}