嵌入式Linux-Bmp转jpeg
代码:
/****************************************************************************
Ãû³Æ£º jpeg.c
¹ŠÄÜ£º linuxÏÂbmpת»¯Îªjpeg³ÌÐòÔŽŽúÂë
ÈÕÆÚ£º 2010.01.26
×¢Ò⣺ ±àÒëʱŒÓ¡°-ljpeg¡±(gcc -o bmp2jpg jpeg.c -ljpeg) *****************************************************************************/ #include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <linux/videodev.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/timeb.h>
#include <jpeglib.h> #define JPEG_QUALITY 90 //͌ƬÖÊÁ¿ int Bmp2Jpg(const char *bmp_file, const char *jeg_file, const int width, const int height)
{
FILE *fd;
int ret;
unsigned char *data;
long sizeImage;
int depth = 3;
JSAMPROW * row_pointer;
long rgb_index = 0;
int i=0;
struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr;
FILE *outfile; // Read bmp image data
sizeImage = width*height*3;
data = (unsigned char*)malloc(sizeImage);
fd = fopen(bmp_file, "rb");
if(!fd)
{
printf("ERROR1: Can not open the image.\n");
free(data);
return -1;
} fseek(fd, 54, SEEK_SET);
ret = fread(data, sizeof(unsigned char)*sizeImage, 1, fd);
if(ret == 0)
{
if(ferror(fd))
{
printf("\nERROR2: Can not read the pixel data.\n");
free(data);
fclose(fd);
return -1;
}
} //Convert BMP to JPG
cinfo.err = jpeg_std_error(&jerr);
//* Now we can initialize the JPEG compression object.
jpeg_create_compress(&cinfo); if ((outfile = fopen(jeg_file, "wb")) == NULL)
{
fprintf(stderr, "can't open %s\n", jeg_file);
return -1;
}
jpeg_stdio_dest(&cinfo, outfile); cinfo.image_width = width; //* image width and height, in pixels
cinfo.image_height = height;
cinfo.input_components = depth; //* # of color components per pixel
cinfo.in_color_space = JCS_RGB; //* colorspace of input image
jpeg_set_defaults(&cinfo); //Now you can set any non-default parameters you wish to.
//Here we just illustrate the use of quality (quantization table) scaling: jpeg_set_quality(&cinfo, JPEG_QUALITY, TRUE ); //* limit to baseline-JPEG values
jpeg_start_compress(&cinfo, TRUE); //Ò»ŽÎÐŽÈë
int j=0;
row_pointer = malloc(height*width*3);
char * line[300]; for(i=0;i<height;i++)
{
unsigned char * lineData = NULL;
lineData = malloc(width*3);
line[i]=lineData;
for(j=0;j<width;j++)
{
lineData[j*3+2] = data[rgb_index];
rgb_index ++;
lineData[j*3+1] = data[rgb_index];
rgb_index ++;
lineData[j*3+0] = data[rgb_index];
rgb_index ++;
}
row_pointer[height-i-1] = lineData;
}
jpeg_write_scanlines(&cinfo, row_pointer, height);
jpeg_finish_compress(&cinfo);
jpeg_destroy_compress(&cinfo);
for (i=0; i<height; i++)
{
free(line[i]);
}
free(row_pointer);
free(data);
fclose(fd);
fclose(outfile); return 0;
} int main( int argc ,char *argv[])
{
int i = strlen(argv[1]);
char bmp_path[20];
char jpg_path[20]; memcpy(bmp_path,argv[1],i);
memcpy(jpg_path,argv[1],i); jpg_path[i-3] = 'j';
jpg_path[i-2] = 'p';
jpg_path[i-1] = 'g';
jpg_path[i] = 0; Bmp2Jpg(bmp_path,jpg_path,348,259);
return 0; }
嵌入式Linux-Bmp转jpeg的更多相关文章
- 嵌入式Linux开发板
嵌入式Linux开发板开发介绍: iTOP-4412嵌入式Linux开发板搭载三星Exynos四核处理器,配备1GB内存,4GB固态硬盘EMMC存储,独家配备三星S5M8767电源管理,配备Andro ...
- 嵌入式 Linux下永久生效环境变量bashrc
嵌入式 Linux下永久生效环境变量bashrc 1) .bashrc文件 在linux系统普通用户目录(cd /home/xxx)或root用户目录(cd /root)下,用指令ls -al可以看到 ...
- 制作自己的嵌入式Linux电脑_转
制作自己的嵌入式Linux电脑 http://os.51cto.com/art/201409/450334.htm 原文链接:http://blog.jobbole.com/75414/ 包含器件选择 ...
- 用Windows+VirtualBox搭建嵌入式Linux开发环境
Windows+VirtualBox的嵌入式Linux开发环境的搭建 最近一直在学习Linux的设备驱动编写,一直是在物理机上安装的Ubuntu进行的,但是在Ubuntu12.04的系统中,已经不能用 ...
- 嵌入式Linux的调试技术
本节我们研究嵌入式Linux的调试技术,对于复杂的Linux驱动及HAL等程序库,需要使用各种方法对其进行调试.刚开始讲了打印内核调试信息:printk,这个函数的用法与printf函数类似,只不过p ...
- 嵌入式linux应用程序移植方法总结
嵌入式linux应用程序移植方法总结 前段时间一直在做openCapwap的移植和调试工作,现在工作已接近尾声,编写本文档对前段工作进行一个总结,分享下openCapwap移植过程中的经验和感悟.江浩 ...
- 驱动开发学习笔记. 0.06 嵌入式linux视频开发之预备知识
驱动开发读书笔记. 0.06 嵌入式linux视频开发之预备知识 由于毕业设计选择了嵌入式linux视频开发相关的项目,于是找了相关的资料,下面是一下预备知识 UVC : UVC,全称为:USB v ...
- 嵌入式linux开发环境构建
2.1硬件环境构建 2.1.1主机与目标板结合的交叉开发模式 在主机上编辑.编译软件,然后再目标办上运行.验证程序. 对于S3C2440.S3C2410开发板,进行嵌入式Linux开发时一般可以分为以 ...
- 嵌入式Linux驱动开发日记
嵌入式Linux驱动开发日记 主机硬件环境 开发机:虚拟机Ubuntu12.04 内存: 1G 硬盘:80GB 目标板硬件环境 CPU: SP5V210 (开发板:QT210) SDRAM: 512M ...
- 嵌入式Linux 修改启动LOGO
1.嵌入式 Linux LOGO显示原理 嵌入式Linux是直接在FrameBuffer的基础上.直接显示一个ppm格式的图象. 它 kernel/drivers/video/fbc ...
随机推荐
- 【2020.11.28提高组模拟】T2 序列(array)
序列(array) 题目描述 给定一个长为 \(m\) 的序列 \(a\). 有一个长为 \(m\) 的序列 \(b\),需满足 \(0\leq b_i \leq n\),\(\sum_{i=1}^ ...
- Netty源码解析 -- PoolChunk实现原理
本文主要分享Netty中PoolChunk如何管理内存. 源码分析基于Netty 4.1.52 内存管理算法 首先说明PoolChunk内存组织方式. PoolChunk的内存大小默认是16M,Net ...
- linux搭建harbor与使用
条件:安装docker&docker-compose 如未安装,请看:linux离线安装docker + docker-compose harbor 1.下载 下载地址:https://git ...
- 第3.3节 强大的Python列表
一. 列表切片操作补充 列表切片支持所有序列切片的方法,以倒序切片和步长大于1的情况再举例验证一下: l=[1,2,3,4,5] l[::2] #结果[1, 3, 5] l[-1::2] #结果[5] ...
- Linux 挂载,卸载光盘
首先我们点击虚拟机 点击设置 选择CD 接着我们将设备状态两个勾都勾选,并且ISO映像文件选择我们需要挂载的光盘 点击了确定之后,我们到centos7的命令行下 1,创建挂载目录 mkdir /mnt ...
- Linux 服务分类
一,服务分类 1,服务简介与分类 1,服务的分类 启动与自启动 1,服务启动:就是在当前系统中让服务运行,并提供功能 2,服务自启动:自启动是指让服务在系统开机或重启动之后,随着系统的启动而自动启动的 ...
- FM解析(因子分解机,2010)
推荐参考:(知乎) https://zhuanlan.zhihu.com/p/37963267 要点理解: 1.fm应用场景,为什么提出了fm(和lr的不同点) ctr预测,特征组合,fm的隐向量分解 ...
- js 面试题正则相关
正则相关[i不区分大小写,g匹配全部数据] var str = "Hello word! I think word is good."; 1.替换str中的word为javascr ...
- jquery和zepto有何区别?
1.针对移动端程序,Zepto有一些基本的触摸事件可以用来做触摸屏交互(tap事件.swipe事件),Zepto是不支持IE浏览器的. 2.DOM操作的区别:添加id时jQuery不会生效而Zepto ...
- Social Infrastructure Information Systems Division, Hitachi Programming Contest 2020 C题题解
首先,我们将题目理解成若\(i\)与\(j\)距离恰好为\(3\),则不可能\(p_i \equiv p_j \equiv 1 \space or \space 2 (\bmod 3)\).这就相当于 ...