硬件准备

BF518开发板

产品链接:https://item.taobao.com/item.htm?id=39906148347&spm=a1z10.5-c.w4002-5192690539.11.22951471QbeGrA

BF518仿真器

产品链接:https://item.taobao.com/item.htm?id=38007242820&spm=a1z10.5-c.w4002-5192690539.11.6e614901nd1XEO

代码实现了将 480*272 尺寸的 JPEG 数据解码为 RGB888 数据功能,调用了 JPEG 解码库函数。

JPEG 图像数据以.dat 文件的方式,通过编译代码时,自动加载到windowsBuffer_t 空间中,运行代码会将 JPEG 格式的数据解码并存入 TempBuffer 数组中。

代码调用了一个 JPG 解码库,该解码库可以解 480*272 尺寸的 JPG 文件,将 JPG 文件解码为同尺寸的 RGB888 格式的数据文件。

JPG 解码函数:

jpg_scaling_rgb24(TempBuffer,480,272,windowsBuffer_t);

将 windowsBuffer_t 内存中的 JPEG 数据解码后存入 DisplayBuffer 中,解码图像的尺寸为 480*272.

在 image view 工具中看到解码后的数据图像:

CPU

#include #include

void Set_PLL(int pmsel,int pssel) { int new_PLL_CTL; *pPLL_DIV = pssel; asm(“ssync;”); new_PLL_CTL = (pmsel & 0x3f) << 9; *pSIC_IWR |= 0xffffffff; if (new_PLL_CTL != *pPLL_CTL) { *pPLL_CTL = new_PLL_CTL; asm(“ssync;”); asm(“idle;”); } }

void InitPorts(void) { *pPORTG_FER |= PG11|PG12|PG13|PG14|PG15; ssync(); *pPORTG_MUX = 0x5000; ssync();

*pPORTF_FER = 0xffff; //ppi d0~d15

ssync();

*pPORTF_MUX = 0x0555;

ssync();

}

void Init_SDRAM(void) { *pEBIU_SDRRC = 0x00000817; *pEBIU_SDBCTL = 0x00000025; *pEBIU_SDGCTL = 0x0091998d; ssync(); }

void Init_EBIU(void) { *pEBIU_AMBCTL0 = 0x7bb07bb0; *pEBIU_AMBCTL1 = 0x7bb07bb0; *pEBIU_AMGCTL = 0x010f; }

MAIN

#include

section (“sdram0_bank2”)unsigned char windowsBuffer_t[234240]={ #include “1.dat” }; section (“sdram0_bank2”)unsigned char TempBuffer[234240];

int main() { Set_PLL(16,4); Init_SDRAM(); Init_EBIU(); jpg_scaling_rgb24(TempBuffer,480,272,windowsBuffer_t);

return 0;

}

zoom

#include “bmp.h” #include “data_type.h” #include “zoom.h” #include

/*************************************************************************** //macro definition **************************************************************************/ #define WIDTHBYTES(i) ((i+31)/324)

/*************************************************************************** TYPE DEFINITIONS ***************************************************************************/ struct bmp_info_ { /0x424D,“BM”/ UINT16 bfType; UINT16 bfSize; UINT32 biWidth; UINT32 biHeight; UINT16 biBitCount; }; typedef struct bmp_info_ bmp_info;

/*************************************************************************** GLOBAL ***************************************************************************/ static bmp_info bf; static avctx_t bmp_avctx;

/*************************************************************************** PROTOTYPES ***************************************************************************/ int gain_bmp_info(UINT8 * buf); int bmp_zoom(unsigned char * desc_buf,int desc_w,int desc_h,unsigned char * src_buf);

/***************************************************************************

jpg&jpeg file to rgb data

***************************************************************************/

int jpg_scaling_rgb24(UINT8 * output,int new_w,int new_h,UINT8 * input) {

UINT32 w=480;

UINT32 h=272;

int color_components=1;

int file_len=MAXBUFFSIZE;

/*fill a jpg file data to inbuf and get len*/

JpegFileToRGB(output,&w,&h,&color_components,input,file_len);

return 0;

} /***************************************************************************

bmp file to rgb data

***************************************************************************/ int bmp_scaling_rgb(UINT8 * output,int new_w,int new_h,UINT8 * input) { int data_size; if(gain_bmp_info(input)) { return -1; } bmp_decode_frame(&bmp_avctx, output, &data_size, input, MAXBUFFSIZE); bmp_zoom(input,new_w,new_h,output); gbrtorgb24(output,input,new_w,new_h); return 0; } int gain_bmp_info(UINT8 * buf) { memcpy(&bf.bfSize,(buf),2); if(bf.bfSize!=0x4d42) { printf(“This is not a bmp file!\n”); return -1; } memcpy(&bf.bfSize,(buf+2),4); if(bf.bfSize>MAXBUFFSIZE) { printf(“Can’t process bmp file more than %d bytes!\n”,MAXBUFFSIZE); return -1; } memcpy(&bf.biWidth,(buf+0x12),4); memcpy(&bf.biHeight,(buf+0x16),4); memcpy(&bf.biBitCount,(buf+0x1c),2); if(bf.biBitCount!=1 && bf.biBitCount!=2 && bf.biBitCount!=4 && bf.biBitCount!=8 && bf.biBitCount!=16 && bf.biBitCount!=24 && bf.biBitCount!=32) { printf(“Can’t process bmp of this color depth!\n”); return -1; } return 0; }

int bmp_zoom(unsigned char * desc_buf,int desc_w,int desc_h,unsigned char * src_buf) { UINT8 * lpPtr; UINT8 * lpTempPtr; int x0,y0,x1,y1; float x_ratio,y_ratio; int SrcBufSize,DstBufSize,LineBytes,DstLineBytes; int i=0;

if(bf.biWidth==desc_w && bf.biHeight==desc_h)

{

memcpy(desc_buf,src_buf,bf.biWidth*bf.biHeight*(bf.biBitCount/8));

}

else

{

/*x1,y1表示新图像素坐标,与x0,y0在旧图中的坐标对应*/

/*num1=old/new=1/zoomRatio*/

x_ratio=(float) bf.biWidth/desc_w;

y_ratio=(float) bf.biHeight/desc_h;

//规范新图每行的宽度,4字节对齐

DstLineBytes=(UINT32)WIDTHBYTES(desc_w*bf.biBitCount);

LineBytes=(UINT32)WIDTHBYTES(bf.biWidth*bf.biBitCount);

SrcBufSize=LineBytes*bf.biHeight;

DstBufSize=DstLineBytes*desc_h;

for(y1=0;y1

{

for(x1=0;x1

{

x0= (UINT32)(x1*x_ratio);

y0= (UINT32)(y1*y_ratio);

if( (x0>=0) && (x0=0) && (y0

{

/*lpPtr指向原图缓存*//*lpTempPtr指向新图缓存*/

/*SrcBufSize源图整个文件除去文件头信息的字节数*/

/*LineBytes每行字节数*/

lpPtr=(UINT8 *)src_buf+(SrcBufSize-LineBytes-y0*LineBytes)+(x0*bf.biBitCount/8);

lpTempPtr=(UINT8 *)desc_buf+(DstBufSize-DstLineBytes-y1*DstLineBytes)+(x1*bf.biBitCount/8);

for(i=0;i

{

*lpTempPtr++=*lpPtr++;

}

}

}

}

}

return 0;

}

/***************************************************************************

bmp to rgb reference

*************************************************************************/ /------------------------------------------------- gbrtorgb24 - 改变颜色排列顺序,翻转图像。 -------------------------------------------------/ /bmp_to_rgb将bmp的像素点阵转为rgb排列/ void gbrtorgb24(UINT8 * rgb_buf,UINT8 * bmp_buf,int width,int heigh) { int i,j; int a,b;

for(i=0;i

{

for(j=0;j

{

a=bmp_buf[i*(width*3)+(j*3)];

b=bmp_buf[i*(width*3)+(j*3+2)];

bmp_buf[i*(width*3)+(j*3)]=b;

bmp_buf[i*(width*3)+(j*3+2)]=a;

}

}

for(i=0;i

{

for(j=0;j<(width*3);j++)

{

rgb_buf[i*(width*3)+j]=bmp_buf[(heigh-1-i)*(width*3)+j];

}

}

} /------------------------------------------------- reversal_pic - 翻转图像180度。 -------------------------------------------------/

void reversal_pic(UINT8 * rgb_buf,UINT8 * bmp_buf,int width,int heigh) { int i,j; for(i=0;i

参考链接

评论可见,请评论后查看内容,谢谢!!!评论后请刷新页面。