資源簡介
基于gec6818開發板的jpeg,bmp圖片輪播顯示及jpeg圖片的壓縮,最好在Linux虛擬機下解壓,不然軟連接文件會失效,無法找到jpeg庫。
代碼片段和文件信息
#include?
#include?
#include?
#include?
#include?
#include?
#include?
off_t?get_file_size(const?char?*pathname)
{
struct?stat?file_stat;
int?retval;
retval?=?stat(pathname??&file_stat);
if(retval?==?-1)
{
perror(“get?file?size?error\n“);
return?-1;
}
return?file_stat.st_size;
}
int?display_format_bmp(unsigned?int?x_s?unsigned?int?y_s?const?char?*pathname?unsigned?int?*lcd_ptr?unsigned?int?mul)
{
off_t??file_size;
FILE?*pic_fp;
ssize_t?rd_ret;
char?*pic_buf;
char?file_head[54];
unsigned?int?bmp_width?bmp_height;
unsigned?int?x_end?y_end;
unsigned?int?x?y;
char?*draw_ptr;
unsigned?int?color;
file_size?=?get_file_size(pathname);
if(file_size?==?-1)
return?-1;
printf(“file_size=%ld\n“?file_size);
pic_buf?=?malloc(file_size-54);
if(pic_buf?==?NULL)
{
perror(“alloc?pic_buf?memory?error\n“);
return?-1;
}
pic_fp?=?fopen(pathname?“r“);
if(pic_fp?==?NULL)
{
perror(“open?picture?error\n“);
return?-1;
}
rd_ret?=?fread(file_head?54?1?pic_fp);
if(ferror(pic_fp))
{
perror(“read?picture?head?error\n“);
return?-1;
}
rd_ret?=?fread(pic_buf?file_size-54?1?pic_fp);
if(ferror(pic_fp))
{
perror(“read?picture?color?data?error\n“);
return?-1;
}
fclose(pic_fp);
/*?寬度??*/
bmp_width?=file_head[18];
bmp_width|=file_head[19]<<8;
printf(“bmp_width=%d\r\n“bmp_width);
/*?高度??*/
bmp_height?=file_head[22];
bmp_height|=file_head[23]<<8;
printf(“bmp_height=%d\r\n“bmp_height);
x_end?=?x_s?+?bmp_width/mul;
y_end?=?y_s?+?bmp_height/mul;
printf(“x_end=%u?y_end=%u\n“?x_end?y_end);
for(y=y_s;?y {
draw_ptr?=?pic_buf+((y-y_s)*mul*bmp_width*3);
for(?x=x_s;?x {
if(x<800)
{
color?=?(*draw_ptr)?|?(*(draw_ptr+1)<<8)?|(*(draw_ptr+2)<<16);
lcd_draw_point(x?479-y?color?lcd_ptr);
}
draw_ptr?+=?3*mul;
}
}
free(pic_buf);
return?0;
}
- 上一篇:高等數學浙江省賽試卷及答案2010-2017
- 下一篇:lammps使用手冊
評論
共有 條評論