一、軟體取模參考

二、軟體代碼
//4096色/16位真彩色/18位真彩色/24位真彩色/32位真彩色
//圖像資料頭結構體
__packed typedef struct _HEADCOLOR
{
unsigned char scan;
unsigned char gray;
unsigned short w;
unsigned short h;
unsigned char is565;
unsigned char rgb;
}HEADCOLOR;
//scan: 掃描模式
//Bit7: 0:自左至右掃描,1:自右至左掃描。
//Bit6: 0:自頂至底掃描,1:自底至頂掃描。
//Bit5: 0:位元組内象素資料從高位到低位排列,1:位元組内象素資料從低位到高位排列。
//Bit4: 0:WORD類型高低位位元組順序與PC相同,1:WORD類型高低位位元組順序與PC相反。
//Bit3~2: 保留。
//Bit1~0: [00]水準掃描,[01]垂直掃描,[10]資料水準,位元組垂直,[11]資料垂直,位元組水準。
//gray: 灰階值
// 灰階值,1:單色,2:四灰,4:十六灰,8:256色,12:4096色,16:16位彩色,24:24位彩色,32:32位彩色。
//w: 圖像的寬度。
//h: 圖像的高度。
//is565: 在4096色模式下為0表示使用[16bits(WORD)]格式,此時圖像資料中每個WORD表示一個象素;為1表示使用[12bits(連續位元組流)]格式,此時連續排列的每12Bits代表一個象素。
//在16位彩色模式下為0表示R G B顔色分量所占用的位數都為5Bits,為1表示R G B顔色分量所占用的位數分别為5Bits,6Bits,5Bits。
//在18位彩色模式下為0表示"6Bits in Low Byte",為1表示"6Bits in High Byte"。
//在24位彩色和32位彩色模式下is565無效。
//rgb: 描述R G B顔色分量的排列順序,rgb中每2Bits表示一種顔色分量,[00]表示空白,[01]表示Red,[10]表示Green,[11]表示Blue。
void image_display(u16 x,u16 y,u8 * imgx);//在指定位置顯示圖檔
void image_show(u16 xsta,u16 ysta,u16 xend,u16 yend,u8 scan,u8 *p);//在指定區域開始顯示圖檔
u16 image_getcolor(u8 mode,u8 *str);//擷取顔色
//從8位資料獲得16位顔色
//mode:0,低位在前,高位在後.
// 1,高位在前,低位在後.
//str:資料
u16 image_getcolor(u8 mode,u8 *str)
{
u16 color;
if(mode)
{
color=((u16)*str++)<<8;
color|=*str;
}else
{
color=*str++;
color|=((u16)*str)<<8;
}
return color;
}
//在液晶上畫圖(僅支援:從左到右,從上到下 or 從上到下,從左到右 的掃描方式!)
//xsta,ysta,width,height:畫圖區域
//scan:見image2lcd V2.9的說明.
//*p:圖像資料
void image_show(u16 xsta,u16 ysta,u16 width,u16 height,u8 scan,u8 *p)
{
u32 i;
u32 len=0;
if((scan&0x03)==0)//水準掃描
{
LCD_Scan_Dir(L2R_U2D);//從左到右,從上到下
LCD_Set_Window(xsta,ysta,width,height);
LCD_SetCursor(xsta,ysta);//設定光标位置
}else //垂直掃描
{
LCD_Scan_Dir(U2D_L2R);//從上到下,從左到右
LCD_Set_Window(xsta,ysta,width,height);
LCD_SetCursor(xsta,ysta);//設定光标位置
}
LCD_WriteRAM_Prepare(); //開始寫入GRAM
len=width*height; //寫入的資料長度
for(i=0;i<len;i++)
{
LCD_WR_DATA(image_getcolor(scan&(1<<4),p));
p+=2;
}
LCD_Set_Window(0,0,lcddev.width,lcddev.height);
}
//在指定的位置顯示一個圖檔
//此函數可以顯示image2lcd軟體生成的任意16位真彩色圖檔.
//限制:1,尺寸不能超過螢幕的區域.
// 2,生成資料時不能勾選:高位在前(MSB First)
// 3,必須包含圖檔資訊頭資料
//x,y:指定位置
//imgx:圖檔資料(必須包含圖檔資訊頭,"4096色/16位真彩色/18位真彩色/24位真彩色/32位真彩色”的圖像資料頭)
//注意:針對STM32,不能選擇image2lcd的"高位在前(MSB First)"選項,否則imginfo的資料将不正确!!
void image_display(u16 x,u16 y,u8 * imgx)
{
HEADCOLOR *imginfo;
u8 ifosize=sizeof(HEADCOLOR);//得到HEADCOLOR結構體的大小
imginfo=(HEADCOLOR*)imgx;
image_show(x,y,imginfo->w,imginfo->h,imginfo->scan,imgx+ifosize);
}
三、函數調用
int main(void)
{
HEADCOLOR *imginfo;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//設定系統中斷優先級分組2
delay_init(168); //初始化延時函數
uart_init(115200); //初始化序列槽波特率為115200
imginfo=(HEADCOLOR*)gImage_image2; //得到檔案資訊
LCD_Init(); //初始化LCD FSMC接口
image_display(0,400,(u8*)gImage_image2);//在指定位址顯示圖檔
while(1)
{
delay_ms(10);
}
}