代码:

/****************************************************************************
Ãû³Æ£º 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. 前端静态站点在阿里云自建 K8S DevOps 集群上优雅的进行 CI/CD

    目录 网站 域名 K8S DevOps 集群 私有 Gitlab 使用 Docker 编译站点 * Dockerfile * 构建编译 Image * 测试编译 Image * 推送镜像到 Aliyu ...

  2. FPGA 流水灯

    VerilogHDL那些事儿_建模篇(黑金FPGA开发板配套教程) 作者:akuei2 说明:参照该书将部分程序验证学习一遍 学习时间:2014年5月2号 主要收获: 1. 对FPGA有初步了解: 2 ...

  3. 一条 sql 的执行过程详解

    写操作执行过程 如果这条sql是写操作(insert.update.delete),那么大致的过程如下,其中引擎层是属于 InnoDB 存储引擎的,因为InnoDB 是默认的存储引擎,也是主流的,所以 ...

  4. 在html页中添加视频的几种方式

    1.avi格式代码片断如下: <object id="video" width="400" height="200" border=& ...

  5. PyQt(Python+Qt)学习随笔:QAbstractItemView的dragEnabled和dragDropMode属性的关系

    老猿Python博文目录 老猿Python博客地址 在<PyQt(Python+Qt)学习随笔:QAbstractItemView的dragEnabled属性的困惑>中,老猿觉得dragE ...

  6. Codeforces Edu Round 53 A-D

    A. Diverse Substring 找普遍性(特殊解即可). 最简单的便是存在一个区间\([i, i + 1] (1 <= i < n)\),且$str[i] $ $ != str[ ...

  7. 剑指Java高效编程教程

    教程介绍 所谓"武以快为尊,天下武功唯快不破".本课程剑指Java高效编程,致力于从"技术"和"工具"两大 维度提高编程效率,帮助广大程序员 ...

  8. IOS UITableView 加载未知宽高图片的解决方案

    在开发中遇到了UITableView列表 UITableViewCell装载图片但不知Image的宽高 问题. 在解决该问题的时候,首先想到的是异步加载图片 采用第三方框架SDWebImage 实现对 ...

  9. Python开发:一个直播弹幕机器人诞生过程,自动发送弹幕

    前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,如有问题请及时联系我们以作处理. Python爬取B站弹幕视频讲解 https://www.bilibili.com/vide ...

  10. css进阶 02-CSS布局

    02-CSS布局 #前言 #常见的布局属性 (1)display 确定元素的显示类型: block:块级元素. inline:行内元素. inline-block:对外的表现是行内元素(不会独占一行) ...