libjpeg的安装与使用
1) 开发环境
内核版本: Linux-2.6.22
freetype版本: libjpeg-turbo-1.2.1
gcc版本: gcc-3.4.5
2) 步骤
1. 解压缩 tar xjf libjpeg-turbo-1.2.1.tar.bz2
2. 配置 ./configure --host=arm-linux --prefix=自定义安装目录
3. 编译安装 make install
注意: 安装完后会将libjpeg的头文件和库文件安装到自定义安装目录下如下图
4. 测试用例
为了避免编译时指定各个参数现在将生成的头文件和库文件拷贝到交叉工具链中,首先进入头文件所在目录并执行命令
cp * /opt/cross-tools/gcc-3.4.5-glibc-2.3.6/arm-linux/include
然后进入库文件所在目录并执行如下命令
cp * /opt/cross-tools/gcc-3.4.5-glibc-2.3.6/arm-linux/lib -d
同时将动态库拷贝到文件系统中
cp *so* /nfs/sysfs/fs_s3c2440/lib -d
jpg2rgb.c源文件如下:
#include <stdio.h>
#include "jpeglib.h"
#include <setjmp.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <linux/fb.h>
#include <string.h>
#include <stdlib.h>#define FB_DEVICE_NAME "/dev/fb0"
#define DBG_PRINTF printfstatic int g_fd;static struct fb_var_screeninfo g_tFBVar;
static struct fb_fix_screeninfo g_tFBFix;
static unsigned char *g_pucFBMem;
static unsigned int g_dwScreenSize;static unsigned int g_dwLineWidth;
static unsigned int g_dwPixelWidth;static int FBDeviceInit(void)
{int ret;g_fd = open(FB_DEVICE_NAME, O_RDWR);if (0 > g_fd){DBG_PRINTF("can't open %s\n", FB_DEVICE_NAME);}ret = ioctl(g_fd, FBIOGET_VSCREENINFO, &g_tFBVar);if (ret < 0){DBG_PRINTF("can't get fb's var\n");return -1;}ret = ioctl(g_fd, FBIOGET_FSCREENINFO, &g_tFBFix);if (ret < 0){DBG_PRINTF("can't get fb's fix\n");return -1;}g_dwScreenSize = g_tFBVar.xres * g_tFBVar.yres * g_tFBVar.bits_per_pixel / 8;g_pucFBMem = (unsigned char *)mmap(NULL , g_dwScreenSize, PROT_READ | PROT_WRITE, MAP_SHARED, g_fd, 0);if (0 > g_pucFBMem) {DBG_PRINTF("can't mmap\n");return -1;}g_dwLineWidth = g_tFBVar.xres * g_tFBVar.bits_per_pixel / 8;g_dwPixelWidth = g_tFBVar.bits_per_pixel / 8;return 0;
}static int FBShowPixel(int iX, int iY, unsigned int dwColor)
{unsigned char *pucFB;unsigned short *pwFB16bpp;unsigned int *pdwFB32bpp;unsigned short wColor16bpp; /* 565 */int iRed;int iGreen;int iBlue;if ((iX >= g_tFBVar.xres) || (iY >= g_tFBVar.yres)){DBG_PRINTF("out of region\n");return -1;}pucFB = g_pucFBMem + g_dwLineWidth * iY + g_dwPixelWidth * iX;pwFB16bpp = (unsigned short *)pucFB;pdwFB32bpp = (unsigned int *)pucFB;switch (g_tFBVar.bits_per_pixel){case 8:{*pucFB = (unsigned char)dwColor;break;}case 16:{iRed = (dwColor >> (16+3)) & 0x1f;iGreen = (dwColor >> (8+2)) & 0x3f;iBlue = (dwColor >> 3) & 0x1f;wColor16bpp = (iRed << 11) | (iGreen << 5) | iBlue;*pwFB16bpp = wColor16bpp;break;}case 32:{*pdwFB32bpp = dwColor;*pdwFB32bpp |= 0xff000000;break;}default :{DBG_PRINTF("can't support %d bpp\n", g_tFBVar.bits_per_pixel);return -1;}}return 0;
}static int FBCleanScreen(unsigned int dwBackColor)
{unsigned char *pucFB;unsigned short *pwFB16bpp;unsigned int *pdwFB32bpp;unsigned short wColor16bpp; /* 565 */int iRed;int iGreen;int iBlue;int i = 0;pucFB = g_pucFBMem;pwFB16bpp = (unsigned short *)pucFB;pdwFB32bpp = (unsigned int *)pucFB;switch (g_tFBVar.bits_per_pixel){case 8:{memset(g_pucFBMem, dwBackColor, g_dwScreenSize);break;}case 16:{iRed = (dwBackColor >> (16+3)) & 0x1f;iGreen = (dwBackColor >> (8+2)) & 0x3f;iBlue = (dwBackColor >> 3) & 0x1f;wColor16bpp = (iRed << 11) | (iGreen << 5) | iBlue;while (i < g_dwScreenSize){*pwFB16bpp = wColor16bpp;pwFB16bpp++;i += 2;}break;}case 32:{while (i < g_dwScreenSize){*pdwFB32bpp = dwBackColor;pdwFB32bpp++;i += 4;}break;}default :{DBG_PRINTF("can't support %d bpp\n", g_tFBVar.bits_per_pixel);return -1;}}return 0;
}static int FBShowLine(int iXStart, int iXEnd, int iY, unsigned char *pucRGBArray)
{int i = iXStart * 3;int iX;unsigned int dwColor;if (iY >= g_tFBVar.yres)return -1;if (iXStart >= g_tFBVar.xres)return -1;if (iXEnd >= g_tFBVar.xres){iXEnd = g_tFBVar.xres; }for (iX = iXStart; iX < iXEnd; iX++){/* 0xRRGGBB */dwColor = (pucRGBArray[i]<<16) + (pucRGBArray[i+1]<<8) + (pucRGBArray[i+2]<<0);i += 3;FBShowPixel(iX, iY, dwColor);}return 0;
}int main(int argc, char **argv)
{struct jpeg_decompress_struct cinfo;struct jpeg_error_mgr jerr;FILE * infile;int row_stride;unsigned char *buffer;if (argc != 2){printf("Usage: \n");printf("%s <jpg_file>\n", argv[0]);return -1;}if (FBDeviceInit()){return -1;}FBCleanScreen(0);//分配和初始化一个decompression结构体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获取jpg信息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);//设置解压参数,比如放大、缩小printf("enter scale M/N:\n");scanf("%d/%d", &cinfo.scale_num, &cinfo.scale_denom);printf("scale to : %d/%d\n", cinfo.scale_num, cinfo.scale_denom);//启动解压jpeg_start_decompress(&cinfo);printf("output_width = %d\n", cinfo.output_width);printf("output_height = %d\n", cinfo.output_height);printf("output_components = %d\n", cinfo.output_components);//一行数据长度row_stride = cinfo.output_width * cinfo.output_components;buffer = malloc(row_stride);//循环调用jpeg_read_scanlines来一行一行的获得解压的数据while (cinfo.output_scanline < cinfo.output_height) {(void) jpeg_read_scanlines(&cinfo, &buffer, 1);//写到LCD去FBShowLine(0, cinfo.output_width, cinfo.output_scanline, buffer);}//Release the JPEG decompression object free(buffer);jpeg_finish_decompress(&cinfo);jpeg_destroy_decompress(&cinfo);close(g_fd);return 0;
}
运行: ./jpeg2rgb 1.jpg
编译测试文件jpg2rgb.c arm-linux-gcc jpg2rgb.c -o jpg2rgb -ljpeg
libjpeg的安装与使用相关推荐
- LibJpeg的安装与修复颜色错误图像错位保姆级教程
0. 直接跳到第4部分(安装),请直接前往卸载已编译好的库 已编译并修复的jpeglib库-C++文档类资源-CSDN文库 1. 下载 官方下载链接 jpeg-9c版下载链接 (本文版本) 本文使用j ...
- php libjpeg,Linux 安装php-5.2.17出现 libjpeg.(a|so) not found
在Linux安装php,提示错误:libjpeg.(a|so) not found , 原因总结:libiconv 没有安装,下载libiconv-1.13.1.tar.gz不指定路径安装了以后好了. ...
- libjpeg 库的安装
libjpeg 库的安装 一.环境简介:ubuntu11.04 以root用户登陆(对不是以root用户登陆的,这不影响!) 二.安装 1.到 libjpeg 的官网下载 libjpeg 的 U ...
- libjpeg php,使用GD和libjpeg支持编译PHP
我编译自己的PHP,部分是为了更多地了解PHP如何组合在一起,部分原因是我总是发现我需要默认情况下不可用的模块,这样我可以控制它. 我的问题是,我无法在PHP中获得JPEG支持.使用CentOS 5. ...
- 切图工具GraphicsMagick安装
安装GraphicsMagick前需要先安装zlib.libpng*和libjpeg*,安装libjpeg*需要安装libtool* 及 libtool-ltdl-devel支持 准备工作: 检查当前 ...
- CentOS 7.6 源码安装搭建LNMP架构(Nginx、MYSQL、PHP)
LNMP架构 LNMP是什么 搭建环境 搭建准备 LNMP软件包 搭建nginx 搭建mysql数据库 搭建php 搭建Discuz!论坛 LNMP是什么 LNMP:Linux系统下Nginx+MyS ...
- lammps 编译安装测试说明
科学计算软件编译安装测试方法说明 --- lammps 篇 (提供免费测试) 官网地址:http://lammps.sandia.gov/ 下载最新稳定版本:http://lammps.sandia. ...
- 在Mac OS X中配置Apache + PHP + MySQL
内容如下: 1. 启动Apache 2. 设置虚拟主机 3. 运行PHP 4. 安装MySQL 5. 使用phpMyAdmin 6. 配置PHP的MCrypt扩展库 7. GD库安装 8. 增加 ...
- arm linux 识别新硬盘_嵌入式Linux系列第13篇:USB摄像头拍照
1.引言 本篇介绍USB摄像头的使用,实现的功能是通过摄像头进行拍照,生成jpg格式图片. 2.环境介绍 2.1.硬件 1) NUC972开发板 2) USB摄像头 2.2.软件 1) Uboot继续 ...
最新文章
- SpringBoot 连接mysql踩到的坑
- 对现有代码的分析方法随想
- 【OpenCV 例程200篇】87. 频率域钝化掩蔽
- 【Spring Cloud】网关 - Zuul(1.x)
- perl cgi session php,如何使用Perl中的CGI :: Session处理Web会话?
- 面向对象封装的web服务器
- windows安装python
- 广州的11个辖区_广州11月展览大全,有12个免费
- 离散数学_构造推理的证明
- 一个Scrapy爬虫实例
- 【Arch】Android 7 Nougat源码目录结构分析
- Mybatis的代码
- [Xilinx ZYNQ] #4 Petalinux 入门 [黑金资料 基础教程s1 整理]
- 2021-2025年中国智能储藏加热器行业市场供需与战略研究报告
- ccf公共钥匙盒python_CCF python 201709-2 公共钥匙盒
- 最新 | Windows和信创终端都能顺滑使用宁盾802.1X账密认证了
- std::thread vs CreateThread
- 一文读懂IaaS、PaaS、SaaS的含义及区别
- `Computer-Algorithm` 最小生成树MST,Prim,Kruskal,次小生成树
- SECS/GEM之SECS Driver开发源代码
热门文章
- postgreSQl请求方式
- python安装与程序_二、Python安装和第一个程序
- python编写一个函数判断一个数是否为素数是则返回yes_编写函数,判断一个整数是否为素数,并编写主程序调用该函数。_学小易找答案...
- 传输线的物理基础(七):传输线的一阶模型
- 线性代数——二次型化为标准型的总结
- Eversipn STT-MRAM的MJT细胞
- P1309 瑞士轮(C++)
- 各种输入方法总结(C++)
- 2种简易方法求100以内的素数(质数)
- 海康大华宇视等等安防监控摄像头转成WebRTC流实现Web浏览器超低延迟无插件直播新方案