⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bmp_show.c

📁 s3c2410 linux操作系统下LCD的驱动代码
💻 C
📖 第 1 页 / 共 2 页
字号:
      }             
    for(i=FIRST_DISPLAY_ADDR;i<512;i++)
        {        
                  if(RGB_16bit1.NUMBER==0)     
                        {  RGB_16bit1.first = BMP_RAM_BUFFER[i];  RGB_16bit1.NUMBER++;}
                  else if(RGB_16bit1.NUMBER==1) 
                        {  RGB_16bit1.second = BMP_RAM_BUFFER[i];  RGB_16bit1.NUMBER++;}         
                  if(RGB_16bit1.NUMBER==2){  //do not use   else if
                        RGB_16bit1.NUMBER = 0;
                        RGB_LCD =  RGB_16bit1.first | (RGB_16bit1.second <<8);                                        
                        LCD_BUFER[y0-BMP_Lines+BITMAP_INFO_HEADER1.biHeight-1][x0+BMP_Piex_PerLine]= RGB_LCD; 
                        BMP_Piex_PerLine ++;  
                           if(BMP_Piex_PerLine == BITMAP_INFO_HEADER1.biWidth){
                                BMP_Piex_PerLine=0;
                                BMP_Lines++;
                                if(BMP_Lines== BITMAP_INFO_HEADER1.biHeight) return ;
                                i += blank;
                                if(i>511) {  FIRST_DISPLAY_ADDR = i - 512*PAGE_PER_BLOCK;   return ; } 
                           } 
                        }                                                                                                        
      }//end for
    FIRST_DISPLAY_ADDR=0;
}




void Display_OneBlockOf_BMP_16(void)
{    
    U8  blank; // Windows规定一个扫描行所占的字节数必须是4的倍数(即以long为单位),不足的以0填充.这一点相当重要 
    U16 x0,y0;
    U16 RGB_LCD; 
    U16 i; 
    static BMP_Piex_PerLine = 0;
    static BMP_Lines = 0 ;  
    static RGB_16bit RGB_16bit1; 
    static U16 FIRST_DISPLAY_ADDR=0; 
    static U8 first_time=0;
    
    if((BITMAP_INFO_HEADER1.biWidth*BITMAP_INFO_HEADER1.biBitCount/8) % 4 !=0 )  
    blank =4- (BITMAP_INFO_HEADER1.biWidth*BITMAP_INFO_HEADER1.biBitCount/8) % 4 ; 
    else blank=0; 
    x0 = (SCR_XSIZE_TFT_240_320 - BITMAP_INFO_HEADER1.biWidth)/2; //  求得bmp图片方的起始点,使图片在虚拟显示空间的当中。
    y0 = (SCR_YSIZE_TFT_240_320 - BITMAP_INFO_HEADER1.biHeight)/2;
      
    if (first_time == 0) {
         FIRST_DISPLAY_ADDR = BITMAP_FILE_HEADER1.bfOffBits;
         first_time =1;
         RGB_16bit1.NUMBER = 0; 
      }             
    for(i=FIRST_DISPLAY_ADDR;i<512*PAGE_PER_BLOCK;i++)
        {        
                  if(RGB_16bit1.NUMBER==0)     
                        {  RGB_16bit1.first = BMP_RAM_BUFFER[i];  RGB_16bit1.NUMBER++;}
                  else if(RGB_16bit1.NUMBER==1) 
                        {  RGB_16bit1.second = BMP_RAM_BUFFER[i];  RGB_16bit1.NUMBER++;}         
                  if(RGB_16bit1.NUMBER==2){  //do not use   else if
                        RGB_16bit1.NUMBER = 0;
                        RGB_LCD =  RGB_16bit1.first | (RGB_16bit1.second <<8);                                        
                        LCD_BUFER[y0-BMP_Lines+BITMAP_INFO_HEADER1.biHeight-1][x0+BMP_Piex_PerLine]= RGB_LCD; 
                        BMP_Piex_PerLine ++;  
                           if(BMP_Piex_PerLine == BITMAP_INFO_HEADER1.biWidth){
                                BMP_Piex_PerLine=0;
                                BMP_Lines++;
                                if(BMP_Lines== BITMAP_INFO_HEADER1.biHeight) return ;
                                i += blank;
                                if(i>512*PAGE_PER_BLOCK-1) {  FIRST_DISPLAY_ADDR = i - 512*PAGE_PER_BLOCK;   return ; } 
                           } 
                        }                                                                                                        
      }//end for
    FIRST_DISPLAY_ADDR=0;
}




void display_bmp_blockbyblock(U32 bmp_start_address)
{   
    U8 ERROR =1 ;
    U32 bmp_size;
    U8 *bmp_address ;
    U32 bmp_start_address0;
    bmp_start_address0 = bmp_start_address;
    Lcd_ClearScr(0xffff);
    //==========================[get bmp imformation]===========================================
    if(bmp_start_address>=0x30000000 & bmp_start_address<=0x34000000 )
          bmp_address = (LPSTR)bmp_start_address;
    else if(bmp_start_address<=0x04000000)
         {bmp_address = (LPSTR)BMP_RAM_BUFFER;
          ReadOnePageFromNandFlash(bmp_start_address,BMP_RAM_BUFFER);
         }
    else {Uart_Printf("The bmp addresss is out of range !!!"); return;}
    
    Get_Bmp_Imformation(bmp_address);
   
    //==============================[disply]============================
    if (BITMAP_FILE_HEADER1.bfType!= 0x4d42)  {
          Uart_Printf("It is not a BMP picture ! ERROR!!!!! \n\n\n");
          ERROR =0;
         }
    else{ 
          if(BITMAP_INFO_HEADER1.biWidth >SCR_XSIZE_TFT_240_320 | BITMAP_INFO_HEADER1.biHeight > SCR_YSIZE_TFT_240_320)
               { Uart_Printf("The BMP picture is out of the max display range 640*480!! \n\n\n");
                 ERROR =0;
          }
          else if(BITMAP_INFO_HEADER1.biBitCount !=16 && BITMAP_INFO_HEADER1.biBitCount !=24 ){
                 Uart_Printf("The colordepth picture is too low !!! Only support 16BIT(R5G6B5) and 24BIT BMP!!!\n\n");
                 ERROR =0; 
          }
          else{ 
                Uart_Printf("The size of the picture is %dbyte in %d*%d!\n",BITMAP_FILE_HEADER1.bfSize,BITMAP_INFO_HEADER1.biWidth,BITMAP_INFO_HEADER1.biHeight);    
                Uart_Printf("The colordepth of the picture is %dbit\n",BITMAP_INFO_HEADER1.biBitCount);
                        
                    for(bmp_size=0 ; bmp_size<=BITMAP_FILE_HEADER1.bfSize ; )
                     {
                        bmp_start_address0 = Load_OneBlockOf_BMP(bmp_start_address0); //装载一页显示缓存
                        if(BITMAP_INFO_HEADER1.biBitCount == 24)    Display_OneBlockOf_BMP_24();
                        else                                        Display_OneBlockOf_BMP_16();
                        bmp_size +=512*32;
                     }       
               }       
     }  //end if
   // =====================[end ]================================
    if( ERROR > 0 ) { //移动窗口,显示。   
              Uart_Printf("The bmp is showed !\n");        
             // Lcd_MoveViewPort(SCR_XSIZE_TFT_240_320/4,SCR_YSIZE_TFT_240_320/4); 
        }
    else{ Uart_Printf("The bmp is not showed !\n");  }
}


























//=============================[加载整个BMP到内存,再到显示缓存的方案]=============================================

void Load_BMP_Whole( U32  bmp_start_address)
{
    int bad_block;
    int i; 
    U8* bmp_start_address1 ;
    U32 bmp_size;
    U32 RAM_BUFFER_offset = 0;
    bmp_start_address1 =(U8* )bmp_start_address;
    
    if(bmp_start_address>=0x30000000 & bmp_start_address<=0x34000000 )
        {
          for(i=0;i<BITMAP_FILE_HEADER1.bfSize;i++)  BMP_RAM_BUFFER[i]=*(bmp_start_address1++);               
         }          
    else if(bmp_start_address<=0x04000000)
         {  for(bmp_size=0 ; bmp_size<=BITMAP_FILE_HEADER1.bfSize ; ) 
               {
                bad_block = ReadOneBlockFromNandFlash(bmp_start_address,BMP_RAM_BUFFER+RAM_BUFFER_offset);
                bmp_start_address +=512*PAGE_PER_BLOCK*(1 + bad_block);
                RAM_BUFFER_offset +=512*PAGE_PER_BLOCK;
                bmp_size += 512*PAGE_PER_BLOCK;                  
               }
              
         } 
}

void Display_BMP_24(void)
 {
    U8  blank; // Windows规定一个扫描行所占的字节数必须是4的倍数(即以long为单位),不足的以0填充.这一点相当重要 
    U16 x0,y0;
    U16 RGB_LCD; 
    U16 i,j; 
    static RGB_24bit RGB_24bit1; 
    U32 addr=0;
     
    if((BITMAP_INFO_HEADER1.biWidth*BITMAP_INFO_HEADER1.biBitCount/8) % 4 !=0 )  
       blank =4- (BITMAP_INFO_HEADER1.biWidth*BITMAP_INFO_HEADER1.biBitCount/8) % 4 ; 
    else blank=0;   

    x0 = (SCR_XSIZE_TFT_240_320 - BITMAP_INFO_HEADER1.biWidth)/2; //  求得bmp图片方的起始点,使图片在虚拟显示空间的当中。
    y0 = (SCR_YSIZE_TFT_240_320 - BITMAP_INFO_HEADER1.biHeight)/2;
      
    addr = BITMAP_FILE_HEADER1.bfOffBits;           
    for(i=0;i<BITMAP_INFO_HEADER1.biHeight;i++)
      { for(j=0;j<BITMAP_INFO_HEADER1.biWidth;j++)
          {        
              RGB_24bit1.B = BMP_RAM_BUFFER[addr++];    
              RGB_24bit1.G = BMP_RAM_BUFFER[addr++];   
              RGB_24bit1.R = BMP_RAM_BUFFER[addr++];   
                       
              RGB_LCD = ( RGB_24bit1.B >>3 ) | ((RGB_24bit1.G >>2)<<5) | ((RGB_24bit1.R >>3)<<11);                                        
              LCD_BUFER[y0-i+BITMAP_INFO_HEADER1.biHeight-1][x0+j]= RGB_LCD; 
          }   
       addr += blank;                                                                                                        
     }//end for
 }


void Display_BMP_16(void)
 {
    U8  blank; // Windows规定一个扫描行所占的字节数必须是4的倍数(即以long为单位),不足的以0填充.这一点相当重要 
    U16 x0,y0;
    U16 RGB_LCD; 
    U16 i,j; 
    static RGB_16bit RGB_16bit1; 
    U32 addr=0; 
    
    if((BITMAP_INFO_HEADER1.biWidth*BITMAP_INFO_HEADER1.biBitCount/8) % 4 !=0 )  
       blank =4- (BITMAP_INFO_HEADER1.biWidth*BITMAP_INFO_HEADER1.biBitCount/8) % 4 ; 
    else blank=0; 
    
    x0 = (SCR_XSIZE_TFT_240_320 - BITMAP_INFO_HEADER1.biWidth)/2; //  求得bmp图片方的起始点,使图片在虚拟显示空间的当中。
    y0 = (SCR_YSIZE_TFT_240_320 - BITMAP_INFO_HEADER1.biHeight)/2;
      
    addr = BITMAP_FILE_HEADER1.bfOffBits;            
    for(i=0;i<BITMAP_INFO_HEADER1.biHeight;i++)
    { 
       for(j=0;j<BITMAP_INFO_HEADER1.biWidth;j++)
        {     RGB_16bit1.first  = BMP_RAM_BUFFER[addr++]; 
              RGB_16bit1.second = BMP_RAM_BUFFER[addr++];  
              RGB_LCD =  RGB_16bit1.first | (RGB_16bit1.second <<8);                                        
              LCD_BUFER[y0-i+BITMAP_INFO_HEADER1.biHeight-1][x0+j]= RGB_LCD; 
        }   
       addr += blank;                                                                                                        
    }//end for
 }





void display_bmp_single(U32 bmp_start_address)
{   
    U8 ERROR =1 ;
    U8 *bmp_address ;
    U32 bmp_start_address0;
    bmp_start_address0 = bmp_start_address;
    Lcd_ClearScr(0xffff);
    //==========================[get bmp imformation]===========================================
    if(bmp_start_address>=0x30000000 & bmp_start_address<=0x34000000 )
          bmp_address = (LPSTR)bmp_start_address;
    else if(bmp_start_address<=0x04000000)
         {bmp_address = (LPSTR)BMP_RAM_BUFFER;
          ReadOnePageFromNandFlash(bmp_start_address,BMP_RAM_BUFFER);
         }
    else {Uart_Printf("The bmp addresss is out of range !!!"); return;}
    
    Get_Bmp_Imformation(bmp_address);
   
    //==============================[disply]============================
    if (BITMAP_FILE_HEADER1.bfType!= 0x4d42)  {
          Uart_Printf("It is not a BMP picture ! ERROR!!!!! \n\n\n");
          ERROR =0;
         }
    else{ 
          if(BITMAP_INFO_HEADER1.biWidth >SCR_XSIZE_TFT_240_320 | BITMAP_INFO_HEADER1.biHeight > SCR_YSIZE_TFT_240_320)
               { Uart_Printf("The BMP picture is out of the max display range 640*480!! \n\n\n");
                 ERROR =0;
          }
          else if(BITMAP_INFO_HEADER1.biBitCount !=16 && BITMAP_INFO_HEADER1.biBitCount !=24 ){
                 Uart_Printf("The colordepth picture is too low !!! Only support 16BIT(R5G6B5) and 24BIT BMP!!!\n\n");
                 ERROR =0; 
          }
          else{ 
                Uart_Printf("The size of the picture is %dbyte in %d*%d!\n",BITMAP_FILE_HEADER1.bfSize,BITMAP_INFO_HEADER1.biWidth,BITMAP_INFO_HEADER1.biHeight);    
                Uart_Printf("The colordepth of the picture is %dbit\n",BITMAP_INFO_HEADER1.biBitCount);       
                Load_BMP_Whole(bmp_start_address);
                if(BITMAP_INFO_HEADER1.biBitCount == 24)    Display_BMP_24();
                else                                        Display_BMP_16();     
                         
               }       
      }  //end if
   // =====================[end ]================================
    if( ERROR > 0 ) { //移动窗口,显示。   
              Uart_Printf("The bmp is showed !\n");        
              //Lcd_MoveViewPort(SCR_XSIZE_TFT_240_320/4,SCR_YSIZE_TFT_240_320/4); 
        }
    else{ Uart_Printf("The bmp is not showed !\n");  }
}



//=============================[加载整个BMP到内存,再到显示缓存的方案]=============================================





⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -