嵌入式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 ...
随机推荐
- Verilog 分频器
verilog设计进阶 时间:2014年5月6日星期二 主要收获: 1. 自己动手写了第一个verilog程序. 题目: 利用10M的时钟,设计一个单周期形状如下的周期波形. 思考: 最开始的想法是: ...
- rest-framework 解析器
一 解析器的作用: 根据请求头 content-type 选择对应的解析器对请求体内容进行处理. 有application/json,x-www-form-urlencoded,form-data等格 ...
- Abp(net core)+easyui+efcore实现仓储管理系统——出库管理之七(五十六)
abp(net core)+easyui+efcore实现仓储管理系统目录 abp(net core)+easyui+efcore实现仓储管理系统--ABP总体介绍(一) abp(net core)+ ...
- PyQt(Python+Qt)学习随笔:QTreeWidget树型部件中的QTreeWidgetItem项构造方法
老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 QTreeWidget树型部件的项是单独的类对象,这个类就是QTreeWidgetItem. QTr ...
- Python正则表达式re.search(r'\*{3,8}','*****')和re.search('\*{3,8}','*****')的匹配结果为什么相同?
老猿做过如下测试: >>> re.search(r'\*{3,100}','*****') <re.Match object; span=(0, 5), match='**** ...
- 分布式存储系统-HDFS
1 HDFS 架构 HDFS作为分布式文件管理系统,Hadoop的基础.HDFS整体架构包括:NameNode.DataNode.Secondary NameNode,如图: HDFS采用主从式的分布 ...
- Day1 【Scrum 冲刺博客】
(因发作业当天没注意看作业内容,第一天的冲刺博客和第二天的同时发!!!不好意思!!!) 各个成员在 Alpha 阶段认领的任务 方晓莹 搭建社区管理系统的前端框架 登录页开发 管理员模块个人中心开发 ...
- Codeforces Round #682 Div2 简要题解
Contest link A.Specific Tastes of Andre Problem link 题意 构造一个长度为 \(n\) 的序列,使得每个非空子序列的和都被其长度整除. 思路 直接每 ...
- Python排序函数用法
Python排序函数完美体现了Python语言的简洁性,对于List对象,我们可以直接调用sort()函数(这里称为"方法"更合适)来进行排序,而对于其他可迭代对象(如set,di ...
- python学习之路 初识xml
import requests from xml.etree import ElementTree as ET r = requests.get('http://www.webxml.com.cn// ...