代码:

/****************************************************************************
Ãû³Æ£º 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的更多相关文章

  1. 嵌入式Linux开发板

    嵌入式Linux开发板开发介绍: iTOP-4412嵌入式Linux开发板搭载三星Exynos四核处理器,配备1GB内存,4GB固态硬盘EMMC存储,独家配备三星S5M8767电源管理,配备Andro ...

  2. 嵌入式 Linux下永久生效环境变量bashrc

    嵌入式 Linux下永久生效环境变量bashrc 1) .bashrc文件 在linux系统普通用户目录(cd /home/xxx)或root用户目录(cd /root)下,用指令ls -al可以看到 ...

  3. 制作自己的嵌入式Linux电脑_转

    制作自己的嵌入式Linux电脑 http://os.51cto.com/art/201409/450334.htm 原文链接:http://blog.jobbole.com/75414/ 包含器件选择 ...

  4. 用Windows+VirtualBox搭建嵌入式Linux开发环境

    Windows+VirtualBox的嵌入式Linux开发环境的搭建 最近一直在学习Linux的设备驱动编写,一直是在物理机上安装的Ubuntu进行的,但是在Ubuntu12.04的系统中,已经不能用 ...

  5. 嵌入式Linux的调试技术

    本节我们研究嵌入式Linux的调试技术,对于复杂的Linux驱动及HAL等程序库,需要使用各种方法对其进行调试.刚开始讲了打印内核调试信息:printk,这个函数的用法与printf函数类似,只不过p ...

  6. 嵌入式linux应用程序移植方法总结

    嵌入式linux应用程序移植方法总结 前段时间一直在做openCapwap的移植和调试工作,现在工作已接近尾声,编写本文档对前段工作进行一个总结,分享下openCapwap移植过程中的经验和感悟.江浩 ...

  7. 驱动开发学习笔记. 0.06 嵌入式linux视频开发之预备知识

    驱动开发读书笔记. 0.06  嵌入式linux视频开发之预备知识 由于毕业设计选择了嵌入式linux视频开发相关的项目,于是找了相关的资料,下面是一下预备知识 UVC : UVC,全称为:USB v ...

  8. 嵌入式linux开发环境构建

    2.1硬件环境构建 2.1.1主机与目标板结合的交叉开发模式 在主机上编辑.编译软件,然后再目标办上运行.验证程序. 对于S3C2440.S3C2410开发板,进行嵌入式Linux开发时一般可以分为以 ...

  9. 嵌入式Linux驱动开发日记

    嵌入式Linux驱动开发日记 主机硬件环境 开发机:虚拟机Ubuntu12.04 内存: 1G 硬盘:80GB 目标板硬件环境 CPU: SP5V210 (开发板:QT210) SDRAM: 512M ...

  10. 嵌入式Linux 修改启动LOGO

    1.嵌入式 Linux LOGO显示原理      嵌入式Linux是直接在FrameBuffer的基础上.直接显示一个ppm格式的图象.     它 kernel/drivers/video/fbc ...

随机推荐

  1. 记安装Wampsever

    遇到的问题: Wampsever 启动所有服务后图标为黄色 localhost 问题:显示 IIS Windows 在用 localhost 访问本机的php文件和用ip地址(不是127.0.0.1) ...

  2. MySQL数据库入门学习

    一. 前言 作为一名大二在校生,因为正在学习网页设计,考虑到后台问题,所以便自学了数据库,可能给大家总结的不是很全,但是一些必要的点肯定会讲到.现在市场上有很多图形化的数据库, 二. MySQL基础知 ...

  3. moviepy音视频剪辑:使用rotate函数实现视频变换处理以及参数expand取值为True时的花屏问题解决方案

    ☞ ░ 前往老猿Python博文目录 ░ 一.rotate函数功能介绍 moviepy的rotate函数用于将剪辑逆时针旋转指定的角度或弧度. 调用语法:rotate(clip, angle, uni ...

  4. PyQt(Python+Qt)学习随笔:QAbstractItemView的tabKeyNavigation属性

    老猿Python博文目录 老猿Python博客地址 tabKeyNavigation属性为bool类型,用于控制视图中是否启用tab键和backtab(shift+tab)进行数据项之间的导航切换. ...

  5. 【软件测试部署基础】yarn的认识

    1. yarn是什么 Yarn 是 Facebook, Google, Exponent 和 Tilde 开发的一款新的 JavaScript 包管理工具.其主要是为了弥补 npm 的一些少量的缺陷而 ...

  6. Error.name 六种值对应的信息

    1 EvalErroe:eval()  的使用与定义不一致 2 RangrError: 数值越界 3 ReferenceError:非法或不能识别的引用数值 4 SyntaxError:发生语法解析错 ...

  7. Springboot集成xxl-Job

    一.前言 xxl-job一个轻量级的分布的调度中间件,详情介绍自己到官网看:https://www.xuxueli.com/xxl-job/ 二.客户端(执行器) 引入依赖compile group: ...

  8. Java程序员普遍存在的面试问题以及应对之道(新书第一章节摘录)

    其实大多数Java开发确实能胜任日常的开发工作,但不少候选人却无法在面试中打动面试官.因为要在短时间的面试中全面展示自己的实力,这很需要技巧,而从当前大多数Java开发的面试现状来看,会面试的候选人不 ...

  9. POI2009 KON-Ticket Inspector

    题目链接 Description 一辆火车依次经过 \(n\) 个车站,顺序是 \(1, 2, 3, ..., n - 1, n\).给定 \(A_{i, j}\) 表示从 \(i\) 站上车,\(j ...

  10. Codeforces Edu Round 60 A-E

    A. Best Subsegment 显然,选择数列中的最大值当做区间(长度为\(1\)).只要尝试最大值这个区间是否能扩展(左右两边值是否跟它一样就行了) #include <cstdio&g ...