ijg库(http://www.ijg.org/)是用于处理jpeg解码和压缩的库,最新版本为2014发布的版本,可以在官网中下载jpegsr9a.zip

使用vs中个nmake 进行编译,对于这个版本的库,在编译的时候需要注意这几个点:

1.  可以在cmd中使用命令进行编译(前提是,将 nmake的路径配置到环境变量中path下了)形如:

设置三个变量:

变量名              变量值

include             D:\Program Files\Microsoft Visual Studio 10.0\VC\include\

lib         D:\Program Files\Microsoft Visual Studio 10.0\VC\lib\

path                 D:\Program Files\Microsoft Visual Studio 10.0\VC\bin\

设置好这些变量之后,nmake就可以在cmd中使用了.  进入到ijg源码文件夹中,然后运行

输入    nmake -f   makefile.vc setup-v10   编译,

(1)一般情况下,这个版本都会出现一个“无法找到文件 win32.mak”,将

#include<win32.mak>注释掉就可以了(这个注释,!include<win32.mak>)

(2)再次输入上述的命令,会出现ren jconfig.vc jconfig.h  无法找到 返回0x01的情况

这时候,新建一个jconfig.h文件,将jconfig.txt中的文件原封不动的移入到这个新建的文件中即可.

(3)再次运行上述的命令,便可以成功了!

这样就可以生成windows下的vcproject工程文件了,然后使用vs打开jpeg.pxxxx 即可运行生成静态库jpeg.lib,然后取出文件中的  这几个三个头文件

jconfig.h, jpeglib.h,jmorecfg.h 和jpeg.lib就可以了.

#progma comment("lib","jpeg.lib") //使用这条宏引入静态库即可使用:

下面是一个例子:

 #include<Windows.h>
#include <stdio.h>
#include "jpeglib.h"
#include <setjmp.h> //struct picture{
// JSAMPLE * image_buffer; /* Points to large array of R,G,B-order data */
// int image_height; /* Number of rows in image */
// int image_width; /* Number of columns in image */
// int quality;
// char *destpath;
//
//}; JSAMPLE * image_buffer; /* Points to large array of R,G,B-order data */
int image_height; /* Number of rows in image */
int image_width; /* Number of columns in image */
int quality;
char *destpath; struct my_error_mgr {
struct jpeg_error_mgr pub; /* "public" fields */ jmp_buf setjmp_buffer; /* for return to caller */
}; typedef struct my_error_mgr * my_error_ptr; METHODDEF(void)
my_error_exit (j_common_ptr cinfo)
{
my_error_ptr myerr = (my_error_ptr) cinfo->err;
(*cinfo->err->output_message) (cinfo);
longjmp(myerr->setjmp_buffer, );
} GLOBAL(int)
read_JPEG_file (char * filename)
{ struct jpeg_decompress_struct cinfo;
struct my_error_mgr jerr;
FILE * infile; /* source file */
JSAMPARRAY buffer; /* Output row buffer */
int row_stride; /* physical row width in output buffer */ if ((infile = fopen(filename, "rb")) == NULL) {
fprintf(stderr, "can't open %s\n", filename);
return ;
}
cinfo.err = jpeg_std_error(&jerr.pub);
jerr.pub.error_exit = my_error_exit;
if (setjmp(jerr.setjmp_buffer)) {
jpeg_destroy_decompress(&cinfo);
fclose(infile);
return ;
}
jpeg_create_decompress(&cinfo);
jpeg_stdio_src(&cinfo, infile);
(void) jpeg_read_header(&cinfo, TRUE);
(void) jpeg_start_decompress(&cinfo);
row_stride = cinfo.output_width * cinfo.output_components;
buffer = (*cinfo.mem->alloc_sarray)
((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, ); //write
struct jpeg_compress_struct wcinfo;
struct jpeg_error_mgr wjerr;
/* More stuff */
FILE * outfile; /* target file */
JSAMPROW row_pointer[]; /* pointer to JSAMPLE row[s] */
int wrow_stride; /* physical row width in image buffer */ wcinfo.err = jpeg_std_error(&wjerr);
jpeg_create_compress(&wcinfo);
if ((outfile = fopen(destpath, "wb")) == NULL) {
fprintf(stderr, "can't open %s\n", destpath);
// exit(1);
}
jpeg_stdio_dest(&wcinfo, outfile);
wcinfo.image_width = image_width>cinfo.image_width?cinfo.image_width:image_width; /* image width and height, in pixels */
wcinfo.image_height = image_height>cinfo.image_height?cinfo.image_height:image_height;
wcinfo.input_components = ; /* # of color components per pixel */
wcinfo.in_color_space = JCS_RGB; /* colorspace of input image */
jpeg_set_defaults(&wcinfo);
jpeg_set_quality(&wcinfo, quality, TRUE /* limit to baseline-JPEG values */);
jpeg_start_compress(&wcinfo, TRUE);
wrow_stride = image_width * ; /* JSAMPLEs per row in image_buffer */ int cmod=cinfo.image_height/wcinfo.image_height; while (cinfo.output_scanline < cinfo.output_height) {
(void) jpeg_read_scanlines(&cinfo, buffer, );
if(cinfo.output_scanline%cmod==)
(void) jpeg_write_scanlines(&wcinfo,buffer, );
} (void) jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
fclose(infile); jpeg_finish_compress(&wcinfo);
jpeg_destroy_compress(&wcinfo);
fclose(outfile);
return ;
} int main(int argc, char * argd[]){ destpath="D:\\jpeg_123.jpg";
image_height =;
image_width=;
quality=;
read_JPEG_file("D:\\123.jpg");
// write_JPEG_file("D:\\jpeg_123.jpg",100);
system("pause");
return ;
}

ijg库的使用的几点注意的更多相关文章

  1. ijg库解码超大型jpeg图片

    1. ijg库解码超大型jpeg图片(>100M)的时候,如何避免内存溢出. 采用边解码边压缩的策略,每次解码一行或者若干行图片数据,然后对于这些解码的数据,进行DQT(量化处理,过滤掉高频的数 ...

  2. USB Video Class及其实现

    1 Video Class 基础概念Usb协议中,除了通用的软硬件电气接口规范等,还包含了各种各样的Class协议,用来为不同的功能定义各自的标准接口和具体的总线上的数据交互格式和内容.这些Class ...

  3. vs2015下编译免费开源的jpeg库,ijg的jpeg.lib

    vs2015下编译免费开源的jpeg库,ijg的jpeg.lib 1. 去Independent JPEG Group官网www.ijg.org下载jpegsrc,我下载的版本是jpegsrc9c.z ...

  4. 编译 ijg JPEG V8 库 GIF 库

    libjpeg-turbo-1.2.1太老了,不支持,从内存解压,这里编译支持 jpeg_mem_src 的 JPEG V9 wget http://www.ijg.org/files/jpegsrc ...

  5. jpeg库编译 - windows平台

    一.准备: 下载最新的jpeg库源码:http://www.ijg.org/files/jpegsr9a.zip二.编译 1. 解压到指定目录 2. 打开VS2010命令行窗口(为了得到VS2010的 ...

  6. 烂泥:centos单独编译安装gd库

    本文由秀依林枫提供友情赞助,首发于烂泥行天下. 这几天一直在弄一个商城系统,该系统的源码及数据库都已经上传并创建完毕.但是在安装该系统时,却提示缺少gd库.如下: 使用php探针查看,发现php确实没 ...

  7. phpize 扩展GD库 安装 ! 环境--centos 7 +nginx 1.7.11+php 5.6.7

    使用phpize编译GD库安装,先安装前置库libjpeg libpng zlib  freetype等 都是下面php编译的几个选项 先看php编译的选项: --with-gd=DIR       ...

  8. linux下编译qt5.6.0静态库——configure配置

    linux下编译qt5.6.0静态库 linux下编译qt5.6.0静态库 configure生成makefile 安装选项 Configure选项 第三方库: 附加选项: QNX/Blackberr ...

  9. 编译libjpeg库

    最近在写车牌识别软件,需要用到BMP转成JPG的功能,自然就想到借助libjpeg来实现 OS: win7 64位 编译器: VS2008 1. 下载源代码下载地址:http://www.ijg.or ...

随机推荐

  1. Display Voxel Gird and PCA

    https://github.com/yhexie/NDTEX 最近科研没有思路,写点代码加强基础知识的学习吧. 下面写了一个点云体素分割,PCA计算体素内点云的特征值和特征向量.

  2. RDIFramework.NET ━ 9.2 员工管理 ━ Web部分

    RDIFramework.NET ━ .NET快速信息化系统开发框架 9.2  员工管理 -Web部分 员工(职员)管理主要是对集团.企事业内部员工进行管理.在后面的章节可以看到有一个用户管理,这两者 ...

  3. android webview 底层实现的逻辑

    其实在不同版本上,webview底层是有所不同的. 先提供个地址给大家查:http://grepcode.com/file/repository.grepcode.com/java/ext/com.g ...

  4. SQL系统视图表

    SQL系统视图表 )) + '学年' + ss.Name AS listtext, sc.SchoolId FROM dbo.SchoolCalendar AS sc INNER JOIN dbo.S ...

  5. 【001:转载 eclipse中颜色的设置】

    转自于:http://www.cnblogs.com/arci/archive/2011/01/23/1942646.html Eclipse颜色设置 参考配色方案: http://www.cs.cm ...

  6. Android EditText 密码框默认是小圆点 怎么改成其它的(*)?

    text.setTransformationMethod(new AsteriskPasswordTransformationMethod()); public class AsteriskPassw ...

  7. Android中插件开发篇之----应用换肤原理解析

    一.前言 今天又到周末了,感觉时间过的很快呀.又要写blog了.那么今天就来看看应用的换肤原理解析.在之前的一篇博客中我说道了Android中的插件开发篇的基础:类加载器的相关知识.没看过的同学可以转 ...

  8. didFinishLaunchingWithOptions

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launc ...

  9. HMI开发与控件

    =>控件是什么概念? 百度曰,控件是对数据和方法的封装.控件可以有自己的属性和方法.属性是控件数据的简单访问者. 对于HMI开发来说,使用控件可以快速获取到用户的交互(包括按下.释放.点击.拖动 ...

  10. IOS详解TableView——内置刷新,EGO,以及搜索显示控制器

    内置刷新 内置刷新是苹果IOS6以后才推出的一个API,主要是针对TableViewController增加了一个属性,refreshControl,所以如果想用这个内置下拉刷新的话,最好给你的Tab ...