当前位置:网站首页>Wei Dongshan Digital Photo Frame Project Learning (5) Transplantation of libjpeg-turbo
Wei Dongshan Digital Photo Frame Project Learning (5) Transplantation of libjpeg-turbo
2022-08-03 03:02:00 【qq_3322997】
韦东山 数码相框 项目学习(五)libjpeg-turbo的移植
效果图
能够在100ask STM32MP157show oneJPG图片

一、下载源码
首先去libjpeg-turbo官网下载源码,这里我们使用1.2.1版本的libjpeg-turbo
libjpeg-turbo-1.2.1
把压缩包上传到服务器,Then execute the following command to decompress
tar xvf libjpeg-turbo-1.2.1.tar.gz
There will be one more in the same level directorylibjpeg-turbo-1.2.1的目录,如下图所示
二、交叉编译
Then go into this folder,使用如下命令进行配置
./configure --host=arm-buildroot-linux-gnueabihf --prefix=$PWD/tmp
Then execute the following two commands in sequence
make
make install
After these two commands are run,会在当前目录下生成一个tmp目录,这个tmpWe are in the directorylibjpeg-turboCross-compile the generated header files and library files, etc
三、复制文件
现在,We need to copy the header and library files to the header and library directories of our cross-compilation toolchain,There is also the library file directory of the development board
My cross-compilation toolchain is in /home/tao/learn/100ask/100ask_stm32mp157_pro-sdk/ToolChain/arm-buildroot-linux-gnueabihf_sdk-buildroot/bin这个目录下,进入到这个目录,然后返回上一层目录,搜索stdio.hheader files to find our header files directory
cd /home/tao/learn/100ask/100ask_stm32mp157_pro-sdk/ToolChain/arm-buildroot-linux-gnueabihf_sdk-buildroot/bin
cd ..
find -name 'stdio.h'
Then there is the following output
很明显,The third one is more reliable,Put the two paths together,This is the header file directory of our cross-compilation toolchain
/home/tao/learn/100ask/100ask_stm32mp157_pro-sdk/ToolChain/arm-buildroot-linux-gnueabihf_sdk-buildroot/arm-buildroot-linux-gnueabihf/sysroot/usr/include/
With the header file directory,It's easy to think that the library file directory is the same level as the header file directory,所以,The library file directory is
/home/tao/learn/100ask/100ask_stm32mp157_pro-sdk/ToolChain/arm-buildroot-linux-gnueabihf_sdk-buildroot/arm-buildroot-linux-gnueabihf/sysroot/usr/lib/
再次回到tmp目录下
Execute the following two commands to copy the corresponding content into our cross-compilation toolchain
# 复制头文件
cp include/* /home/tao/learn/100ask/100ask_stm32mp157_pro-sdk/ToolChain/arm-buildroot-linux-gnueabihf_sdk-buildroot/arm-buildroot-linux-gnueabihf/sysroot/usr/include/ -rd
# 复制库文件
cp lib/* /home/tao/learn/100ask/100ask_stm32mp157_pro-sdk/ToolChain/arm-buildroot-linux-gnueabihf_sdk-buildroot/arm-buildroot-linux-gnueabihf/sysroot/usr/lib/ -rd
Then copy the library files to the development board,大功告成
demo代码
Put both codes in the same directory,执行makecommand to compile and generate oneexample_libjpeg 的测试程序,Get this app with oneJPG文件复制到开发板上,Run the following command to get thereLCD上显示图片
./example_libjpeg-turbo light.jpg
Makefile
# 1. 使用不同的开发板内核时, 一定要修改KERN_DIR
# 2. KERN_DIR中的内核要事先配置、编译, 为了能编译内核, 要先设置下列环境变量:
# 2.1 ARCH, 比如: export ARCH=arm64
# 2.2 CROSS_COMPILE, 比如: export CROSS_COMPILE=aarch64-linux-gnu-
# 2.3 PATH, 比如: export PATH=$PATH:/home/book/100ask_roc-rk3399-pc/ToolChain-6.3.1/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin
# 注意: 不同的开发板不同的编译器上述3个环境变量不一定相同,
# 请参考各开发板的高级用户使用手册
KERN_DIR = /home/tao/learn/100ask/100ask_stm32mp157_pro-sdk/Linux-5.4
all:
$(CROSS_COMPILE)gcc -o example_libjpeg-turbo example.c -ljpeg
clean:
rm -rf example_libjpeg
example.c
example.c
#include <stdio.h>
#include "jpeglib.h"
#include <setjmp.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/fb.h>
#include <sys/mman.h>
#include <string.h>
#include <stdlib.h>
#define DBG_PRINT printf
static int g_iFdFb;
static struct fb_var_screeninfo g_tVar;
static int g_iScreenSize = 0;
static int g_iLineWidth = 0;
static int g_iPixelWidth = 0;
static unsigned char *g_pucFbMem = NULL;
static int FbDeviceInit(void)
{
int ret = 0;
/* 打开fb0 */
g_iFdFb = open("/dev/fb0", O_RDWR);
if(g_iFdFb < 0)
{
DBG_PRINT("can't open /dev/fb0");
return -1;
}
/* 获取参数 */
if(ioctl(g_iFdFb, FBIOGET_VSCREENINFO, &g_tVar))
{
DBG_PRINT("can't get screen var\n");
ret = -1;
goto fail_get_var;
}
g_iScreenSize = g_tVar.xres * g_tVar.yres * g_tVar.bits_per_pixel / 8;
g_iLineWidth = g_tVar.xres * g_tVar.bits_per_pixel / 8;
g_iPixelWidth = g_tVar.bits_per_pixel / 8;
/* 映射内存 */
g_pucFbMem = (unsigned char *)mmap(NULL, g_iScreenSize, PROT_WRITE | PROT_READ, MAP_SHARED,
g_iFdFb, 0);
if(g_pucFbMem == (unsigned char *)-1)
{
DBG_PRINT("can't mmap to g_pucFbMem\n");
ret = -1;
goto fail_mmap_fb0;
}
fail_mmap_fb0:
fail_get_var:
close(g_iFdFb);
return ret;
}
static int FbScreenClean(unsigned int dwBackColor)
{
int i;
unsigned char *pucPen8 = (unsigned char *)g_pucFbMem;
unsigned short *pwPen16 = (unsigned short *)pucPen8;
unsigned int *pdwPen32 = (unsigned int *)pucPen8;
unsigned char red, green, blue;
switch(g_tVar.bits_per_pixel)
{
case 8:
{
memset(pucPen8, dwBackColor, g_iScreenSize);
break;
}
case 16:
{
/* 565 */
red = (dwBackColor >> 16) & 0xff;
green = (dwBackColor >> 8) & 0xff;
blue = (dwBackColor >> 0) & 0xff;
dwBackColor = (red >> 3) << 11 | (green >> 2) << 5 | (blue >> 3) << 0;
i = 0;
for(i = 0; i < g_iScreenSize; i += 2)
{
*pwPen16 = dwBackColor;
pwPen16++;
}
break;
}
case 32:
{
i = 0;
for(i = 0; i < g_iScreenSize; i += 4)
{
*pdwPen32 = dwBackColor;
pdwPen32++;
}
break;
}
default:
{
DBG_PRINT("can't support this bits_per_pixel\n");
return -1;
break;
}
}
return 0;
}
static int FbDrawPixel(int iX, int iY, unsigned int dwColor)
{
unsigned char *pucPen8 = (unsigned char *)g_pucFbMem + iY * g_iLineWidth + iX * g_iPixelWidth;
unsigned short *pwPen16 = (unsigned short *)pucPen8;
unsigned int *pdwPen32 = (unsigned int *)pucPen8;
unsigned char red, green, blue;
switch(g_tVar.bits_per_pixel)
{
case 8:
{
*pucPen8 = dwColor;
break;
}
case 16:
{
/* 565 */
red = (dwColor >> 16) & 0xff;
green = (dwColor >> 8) & 0xff;
blue = (dwColor >> 0) & 0xff;
dwColor = (red >> 3) << 11 | (green >> 2) << 5 | (blue >> 3) << 0;
*pwPen16 = dwColor;
break;
}
case 32:
{
*pdwPen32 = dwColor;
break;
}
default:
{
DBG_PRINT("can't support this bits_per_pixel\n");
return -1;
break;
}
}
return 0;
}
static int FbShowLine(int iStartX, int iEndX, int iY, unsigned char *pucBuffer)
{
int i = iStartX * 3;
unsigned int dwColor = 0;
int iX;
if(iY > g_tVar.yres)
return -1;
if(iStartX > g_tVar.xres)
return -1;
if(iEndX > g_tVar.xres)
iEndX = g_tVar.xres;
for(iX = iStartX; iX <= iEndX; iX ++)
{
dwColor = (pucBuffer[i] << 16) | (pucBuffer[i + 1] << 8) | (pucBuffer[i + 2]);
FbDrawPixel(iX, iY, dwColor);
i += 3;
}
}
int main(int argc, char **argv)
{
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
FILE * infile;
int row_stride;
unsigned char *buffer; /* Output row buffer */
unsigned int dwBackColor;
if(argc != 2)
{
printf("Useage: %s <jpeg_file>\n", argv[0]);
return -1;
}
if(FbDeviceInit())
{
printf("FbDeviceInit err\n");
return -1;
}
dwBackColor = 0x00000000;
FbScreenClean(dwBackColor);
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&cinfo);
if ((infile = fopen(argv[1], "rb")) == NULL) {
fprintf(stderr, "can't open %s\n", argv[1]);
return -1;
}
jpeg_stdio_src(&cinfo, infile);
jpeg_read_header(&cinfo, TRUE);
printf("image_width = %d\n", cinfo.image_width);
printf("image_height = %d\n", cinfo.image_height);
printf("num_components = %d\n", cinfo.num_components);
jpeg_start_decompress(&cinfo);
printf("output_width = %d\n", cinfo.output_width);
printf("output_height = %d\n", cinfo.output_height);
printf("out_color_components = %d\n", cinfo.out_color_components);
printf("output_components = %d\n", cinfo.output_components);
row_stride = cinfo.output_width * cinfo.output_components;
buffer = malloc(row_stride);
while(cinfo.output_scanline < cinfo.output_height)
{
jpeg_read_scanlines(&cinfo, &buffer, 1);
// printf("%d %d %d\n", 0, cinfo.output_width, cinfo.output_scanline);
FbShowLine(0, cinfo.output_width, cinfo.output_scanline, buffer);
}
jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
return 0;
}
边栏推荐
- Violent recursion to dynamic programming 06 (the sword refers to Offer II 095. Longest common subsequence)
- WRF-Chem模式调试、运行、结果后处理等遇到的各种问题
- 45部署LVS-DR群集
- iNFTnews | 元宇宙的潜力:一股推动社会进步的力量
- 软件定义网络实验之自定义拓扑开发
- PyCharm中常用的快捷键用法详解
- v-if条件判断及v-show
- 能添加任意贴图超级复布局的初级智能文本提示器(超级版)
- 增删改查这么多年,最后栽在MySQL的架构设计上!
- ”QSqlDatabasePrivate::removeDatabase: connection ‘test-connect‘ is still in use“数据库多次打开报错
猜你喜欢

什么情况下DigiCert证书会引起发生安全警报?

个人开发者必备,免费 API 网关工具推荐

梅科尔工作室-14天华为培训三

暴力递归到动态规划 06 (剑指 Offer II 095. 最长公共子序列)

SAP ABAP OData 服务如何支持修改(Update)操作试读版

怎么从零编写一个 v3 版本的 chrome 浏览器插件实现 CSDN 博客网站的暗黑和明亮主题切换?

visual studio 2012 为啥这么优秀

Violent recursion to dynamic programming 06 (the sword refers to Offer II 095. Longest common subsequence)

【UE4】搭建局域网内VR直播 UE4.27

DJI内推码(2022年8月2日更新)
随机推荐
Introduction to agile development
OpenWRT设置ipv6网络
”QSqlDatabasePrivate::removeDatabase: connection ‘test-connect‘ is still in use“数据库多次打开报错
JVM内部结构图及各模块运行机制总结
Excel 如何比较两列字符串是否相同?
monkey 压测
.NET in-depth analysis of the LINQ framework (four: IQueryable, IQueryProvider interface details)
mysql binlog日期解析成yyyy-MM-dd
超级复杂可贴图布局的初级智能文本提示器
5.软件测试-----自动化测试
torchvision.datasets.ImageFolder使用详解
MATLAB绘制填充图(X轴上下两种颜色)
公司代码学习笔记
软件定义网络实验之SDN网络简单管理及开发
pytest:如何调用 pytest
236. 二叉树的最近公共祖先
WRF-Chem模式调试、运行、结果后处理等遇到的各种问题
使用VSCode中遇到的问题及解决办法
暴力递归到动态规划 08(小马走象棋)
数据中台建设(八):数据服务体系建设