eboot logo

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "xsc1.h"
#include "xsc1bd.h"
#define RGB565(r1,g1,b1,r0,g0,b0)            /
       ((((DWORD)(((BYTE)(r0)&0xf8)<<8)) |   /
         ((DWORD)(((BYTE)(g0)&0xfc)<<3)) |   /
         ((DWORD)((BYTE)(b0)&0xf8))>>3)<<16)|/
         (((DWORD)(((BYTE)(r1)&0xf8)<<8))|   /
         ((DWORD)(((BYTE)(g1)&0xfc)<<3)) |   /
         ((DWORD)((BYTE)(b1)&0xf8)>>3))
typedef struct selRGBQUAD {
        unsigned char    Blue;
        unsigned char    Green;
        unsigned char    Red;
        unsigned char    Reserved;
} BTQUAD;
#define FillPiexl        0xFFFFFFFF
#define BmpStartAddr      (FLASH_CFG_START+0x20000)
#define BmpMaxSize       0x80000
#define BmpMaxWidth      240                                   
#define BmpMaxHigh       320
DWORD   BmpWidth         = 0;
DWORD   Bmphigh          = 0;
0x
int checkBmpHead(unsigned char *pPos)
{
 BITMAPINFOHEADER m_bmpInfoHead;
 BITMAPFILEHEADER m_bmpfilehead;
 unsigned char * pCurrReadPos   = pPos;
 DWORD FileLen                  = 0;
 memcpy((unsigned char *)&m_bmpfilehead,pCurrReadPos,sizeof(BITMAPFILEHEADER));
 if(m_bmpfilehead.bfType != 0x4D42)
 {
  return (-1);
 }
 pCurrReadPos += sizeof(BITMAPFILEHEADER);
    memcpy((unsigned char *)&m_bmpInfoHead,pCurrReadPos,sizeof(BITMAPINFOHEADER));
    if(m_bmpInfoHead.biCompression != BI_RGB)
    {
     return (-1);
    }
 
 if(m_bmpInfoHead.biPlanes != 1)
 {
     return (-1);
 }
 //必须为256色
    if((m_bmpInfoHead.biClrUsed != 0)||(m_bmpInfoHead.biBitCount != 8))
    {
     return (-1);    
    }
 //文件大小不能超过0.5M
 FileLen = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + 256*sizeof(BTQUAD) + m_bmpInfoHead.biHeight * m_bmpInfoHead.biWidth ;
 if(FileLen > BmpMaxSize)
 {
  return (-1); 
 }
 BmpWidth         = m_bmpInfoHead.biWidth;
    Bmphigh          = m_bmpInfoHead.biHeight;
 return (1);  
}
int LoadWelcome(unsigned char *pFrameBuf,unsigned int buffersize)
{
 DWORD  i =0,j =0 ;
 unsigned char *quadStart  = 0;    
 BTQUAD *Currentquad       = 0;    
 BTQUAD *Nextquad          = 0;    
 unsigned char * pStart    = 0;
 DWORD* pvideobuffer ;
 DWORD* pLinStart          = 0;
 
 if(checkBmpHead((unsigned char*)BmpStartAddr) != 1)
 {
  return (-1);
 }
 pvideobuffer = (DWORD*)(pFrameBuf + buffersize -4);
 pStart    = (unsigned char*)(BmpStartAddr + sizeof(BITMAPFILEHEADER)+ sizeof(BITMAPINFOHEADER)+ 256* sizeof(BTQUAD));
 quadStart = (unsigned char *) (pStart - 256* sizeof(BTQUAD));
    //BMP上下,左右颠倒
   
 //图片居中,空白使用白色填充
 if(BmpWidth>BmpMaxWidth)
 {
     //只截取屏幕大小
  if(Bmphigh>BmpMaxHigh)
  {
      //截掉上半部分
   pStart += (((Bmphigh - BmpMaxHigh)/2)* BmpWidth);
   for( i =0;i   {
    //截掉左半部分
    pStart += ((BmpWidth - BmpMaxWidth)/2);
    if((BmpWidth - BmpMaxWidth)%4 != 0) pStart++;
    pLinStart = (DWORD*)(pvideobuffer - BmpMaxWidth/2);   
    for(j=0;j    {
              Currentquad = (BTQUAD *) ((unsigned char *)quadStart +  4*((unsigned char)(*pStart)));
              pStart++ ;
              Nextquad = (BTQUAD *) ((unsigned char *)quadStart + 4*((unsigned char)(*pStart)));
              *pLinStart = RGB565(Currentquad->Red,Currentquad->Green,Currentquad->Blue,
              Nextquad->Red,Nextquad->Green,Nextquad->Blue);
     pLinStart++;
              pStart++ ;
              pvideobuffer--;
    }
    pStart += ((BmpWidth - BmpMaxWidth)/2);    
    if((BmpWidth - BmpMaxWidth)%4 != 0) pStart++;   
   }
  }
  else
  {
    //填充上半部空白部分
    for( i =0;i<(BmpMaxHigh-Bmphigh)/2;i++)
    {
        for(j=0;j        {
           *pvideobuffer = FillPiexl;
            pvideobuffer--;
        }
    } 
             //填充中间部分图片数据
             for(i = 0;i             {
     //截掉左半部分
     pStart += (BmpWidth - BmpMaxWidth)/2;
      if((BmpWidth - BmpMaxWidth)%4 != 0) pStart++;
     pLinStart = (DWORD*)(pvideobuffer - BmpMaxWidth/2);
     for(j=0;j     {
               Currentquad = (BTQUAD *) ((unsigned char *)quadStart +  4*((unsigned char)(*pStart)));
               pStart++;
               Nextquad = (BTQUAD *) ((unsigned char *)quadStart + 4*((unsigned char)(*pStart)));
               *pLinStart = RGB565(Currentquad->Red,Currentquad->Green,Currentquad->Blue,
               Nextquad->Red,Nextquad->Green,Nextquad->Blue);
      pLinStart++;
               pStart++ ;
               pvideobuffer--;
     }
     pStart += (BmpWidth - BmpMaxWidth)/2;
     if((BmpWidth - BmpMaxWidth)%4 != 0) pStart++;
             }
    //填充下半部空白部分
    for( i =0;i<(BmpMaxHigh-Bmphigh)/2;i++)
    {
        for(j=0;j        {
           *pvideobuffer = FillPiexl;
            pvideobuffer--;
        }
    }
  }
 }
 else
 {
  //只截取屏幕大小
  if(Bmphigh>BmpMaxHigh)
  {
   //截取上半部分
   pStart += (((Bmphigh - BmpMaxHigh)/2)* BmpWidth);   
   for( i =0;i   {
    //Ìî³ä×ó°ë²¿¿Õ°×²¿·Ö
                for(j=0;j<(BmpMaxWidth-BmpWidth)/2;j += 2)
                {
                  *pvideobuffer = FillPiexl;
            pvideobuffer--;
                }
    pLinStart = (DWORD*)(pvideobuffer - BmpWidth/2);
    //填充左半部分空白  
    for(j=0;j    {
              Currentquad = (BTQUAD *) ((unsigned char *)quadStart +  4*((unsigned char)(*pStart)));
              pStart++ ;
              Nextquad = (BTQUAD *) ((unsigned char *)quadStart + 4*((unsigned char)(*pStart)));
              *pLinStart = RGB565(Currentquad->Red,Currentquad->Green,Currentquad->Blue,             
              Nextquad->Red,Nextquad->Green,Nextquad->Blue);
              pStart++ ;
     pLinStart++;
              pvideobuffer--;
    }
    //填充中间图片部分
                for(j=0;j<(BmpMaxWidth-BmpWidth)/2;j += 2)
                {
                  *pvideobuffer = FillPiexl;
            pvideobuffer--;
                }
   }
  }
  else
  {
    //填充右半部分空白
    for( i =0;i<(BmpMaxHigh-Bmphigh)/2;i++)
    {
        for(j=0;j        {
           *pvideobuffer = FillPiexl;
            pvideobuffer--;
        }
    }
             //填充上半部分空白
             for( i =0;i             {
    //填充中间图片数据
                for(j=0;j<(BmpMaxWidth-BmpWidth)/2;j += 2)
                {
                  *pvideobuffer = FillPiexl;
            pvideobuffer--;
                }
    pLinStart = (DWORD*)(pvideobuffer - BmpWidth/2);
    //填充左半部分空白  
    for(j=0;j    {
              Currentquad = (BTQUAD *) ((unsigned char *)quadStart +  4*((unsigned char)(*pStart)));
              pStart++ ;
              Nextquad = (BTQUAD *) ((unsigned char *)quadStart + 4*((unsigned char)(*pStart)));
              *pLinStart = RGB565(Currentquad->Red,Currentquad->Green,Currentquad->Blue,
              Nextquad->Red,Nextquad->Green,Nextquad->Blue);
     pLinStart++;
              pStart++ ;
              pvideobuffer--;
    }
    //填充图片数据
                for(j=0;j<(BmpMaxWidth-BmpWidth)/2;j += 2)
                {
                  *pvideobuffer = FillPiexl;
            pvideobuffer--;
                }
             }
             //填充右半部分空白
      for( i =0;i<(BmpMaxHigh-Bmphigh)/2;i++)
      {
  for(j=0;j  {
       *pvideobuffer = FillPiexl;
       pvideobuffer--;
  }
      }
 }
     }
     return (1);
本文来自Tony嵌入式论坛,原文地址:http://www.cevx.com/bbs/viewthread.php?tid=10312

你可能感兴趣的:(byte,include,嵌入式,struct,flash,bi)