s3c6410 jpeg编码 linux,S3C6410 裸机硬件JPEG解码

主函数的部分代码

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

*函数         : static PIC_ERROR OpenPictureFile(const char *FileName,u8 *buff,u32 FileMaxSize)

*功能         : 打开一张,并将数据读取到内存

*参数         : FileName:文件名,路径指针;buff:读取缓冲区;FileMaxSize:文件最大限制

*返回         : PIC_ERROR

*依赖     :  FATFS文件系统支持

*作者         : cp1300@139.com

*时间     : 20121207

*最后修改时间 : 20121209

*说明     : 调用FATFS打开图片文件

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

int OpenPictureFile(const char *FileName,u8 *buff,u32 FileMaxSize)

{

FIL file;

UINT cnt;

int status;

int error = 0;

status = f_open(&file,FileName,FA_READ);    //只读方式打开文件

if(status != FR_OK)          //打开文件错误

{

uart_printf("open \"%s\" error!\r\n",FileName);

error = 1;

}

else

{

//获取文件大小

uart_printf("file size : %dB\r\n",file.fsize);  //输出文件大小

if(file.fsize > FileMaxSize)

{

uart_printf("file size > %d\r\n",FileMaxSize);

error = 2;

}

else

{

status = f_read(&file,buff,file.fsize,&cnt); //读取文件

uart_printf("Read File Num=%d\r\n",cnt);

if(cnt == file.fsize)       //判断文件是否读取完毕

{

uart_printf("read file end!\r\n");

error =  0;

}

else

{

uart_printf("read file error!\r\n");

error = 3;

}

}

}

f_close(&file);

return error;

}

void YUV422ToRGB565(u8 *YUVBuff,u16 width,u16 height)

{

u16 x,y;

u32 RGBdata;

u32 cnt = 0;

u8 Y,U = 0,V = 0;

int R,G,B;

for(y = 0;y < height;y ++)

{

for(x = 0;x < width;x ++ )

{

Y = YUVBuff[cnt << 1];

if((cnt % 2) == 0)

{

U = YUVBuff[(cnt << 1) + 1];

V = YUVBuff[(cnt << 1) + 3];

}

R = Y + (1.370705 * (V - 128));

G = Y - (0.698001 * (V - 128)) - (0.337633 * (U-128));

B = Y + (1.732446 * (U - 128));

R = (R > 255) ? 255 : ((R < 0) ? 0 : R);

G = (G > 255) ? 255 : ((G < 0) ? 0 : G);

B = (B > 255) ? 255 : ((B < 0) ? 0 : B);

//RGBdata = (u32)(R << 16) | (G << 8) | B;

R >>= 3;

G >>= 2;

B >>= 3;

RGBdata = (R << 11) + (G << 5) + B;

LCD_DrawPoint(x,y,(u16)RGBdata);

//LCD_DrawPoint(x,y,RGB888toRGB565(RGBdata));

cnt ++;

}

}

}

u8 buff[10*1024*1024];

u8 image[10*1024*1024];

//主函数

int main(void)

{

OS_CPU_SR  cpu_sr;

int result;

JPEG_INFO JpegInfo;

u32 p;

u32 i;

UART0_Init(DISABLE,115200);     //初始化串口,失能中断接收,波特率115200

LCD_Init();         //初始化LCD

LED_Init();         //初始化LED

RunTimeInit();

JPEG_Init();

result = Explorer_Init();     //初始化资源管理器

if(result == 0)

{

lcd_printf("Disk Init OK!\n");

}

else

{

lcd_printf("Disk Init Error(%d)!\n",result);

}

p = (u32)buff;

if((u32)buff % 16)

{

p = (p / 16 + 1) * 16;

}

OpenPictureFile("0:/system/ui/ico/设置.jpg",(u8 *)p,10*1024*1024);

result = JPEG_DecodeOneFrame(p,(u32)image,31654, &JpegInfo);

uart_printf("decode jpeg file %d\r\n",result);

if(result == 0)

{

YUV422ToRGB565(image,JpegInfo.Width,JpegInfo.Height);

 }0b1331709591d260c1c78e86d0c51c18.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值