http://www.blog.edu.cn/uploadfile/20041126154711934.RAR
http://www.blog.edu.cn/uploadfile/20041126154711934.RARhttp://www.blog.edu.cn/uploadfile/20041126154711934.RARhttp://www.blog.edu.cn/uploadfile/20041126154711934.RAR在远程渲染系统中服务器端必须将渲染得到的图像压缩为JPEG后传输。我前天在网上找到了IGP的jpeg库代码,但是在VC下编译总是出错。这个问题困扰了我整整两天,今天终于找到了正确的编译方法。现在总结如下:
第一步:修改一些IGC源文件(来自
http://www.bcbdev.com/articles/jpeg.htm):
/******************* Changes to jpeglib.h **************************/ #ifndef JPEGLIB_H #define JPEGLIB_H /* HJH modification: added extern "C" { when __cplusplus detected */ #ifdef __cplusplus extern "C" { #endif ... /* near bottom of the file */ /* HJH modification: add closing } for extern "C" { */ #ifdef __cplusplus } #endif #endif /* JPEGLIB_H */ /******************* Changes to jmorecfg.h **************************/ /* jmorecfg.h line 160 */ /* X11/xmd.h correctly defines INT32 */ /* HJH modification: jmorecfg.h already contained a test for XMD_H and xmd.h My change adds a test for _BASETSD_H_ because the windows header file basestd.h already defines INT32 */ #if !defined(XMD_H) && !defined(_BASETSD_H_) typedef long INT32; #endif /* jmorecfg.h line 220 */ /* HJH modification: several of the windows header files already define FAR because of this, the code below was changed so that it only tinkers with the FAR define if FAR is still undefined */ #ifndef FAR #ifdef NEED_FAR_POINTERS #define FAR far #else #define FAR #endif #endif
最后需要修改jconfig.h文件
/* HJH Note: Here is one key addition that I had to make. The jpeg library uses #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */ typedef unsigned char boolean; #endif #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
* a type called boolean. It defines boolean here. However, RPCNDR.H * yet another Microsoft header, also defines boolean. The ifndef * ensures that we don't attempt to redefine boolean if rpcndr.h has * already defined it. Note that we use unsigned char instead of int * like jmorecfg.h does, because we want to match what's in the SDK * header. See jconfig.vc for more info, it does the same thing. */
第二步:编译(来自IGP解压后的文件夹中的install.doc):
1. Copy jconfig.vc to jconfig.h, makelib.ds to jpeg.mak, and
makeapps.ds to apps.mak. (Note that the renaming is critical!)
2. Click on the .mak files to construct project workspaces.
(If you are using DevStudio more recent than 4.2, you'll probably
get a message saying that the makefiles are being updated.)
3. Build the library project, then the applications project.
4. Move the application .exe files from `app`/Release to an
appropriate location on your path.
5. To perform the self-test, execute the command line
NMAKE /f makefile.vc test
实际上只需要执行前三步就可以。在release文件夹中可以得到最后编译的结果jpeg.lib库文件。
1. Copy jconfig.vc to jconfig.h, makelib.ds to jpeg.mak, and
makeapps.ds to apps.mak. (Note that the renaming is critical!)
2. Click on the .mak files to construct project workspaces.
(If you are using DevStudio more recent than 4.2, you'll probably
get a message saying that the makefiles are being updated.)
3. Build the library project, then the applications project.
4. Move the application .exe files from `app`/Release to an
appropriate location on your path.
5. To perform the self-test, execute the command line
NMAKE /f makefile.vc test
实际上只需要执行前三步就可以。在release文件夹中可以得到最后编译的结果jpeg.lib库文件。
第三步:在自己的代码中包含
#pragma comment(lib, "jpeg.lib")
和
#i nclude "jpeglib.h"
#pragma comment(lib, "jpeg.lib")
和
#i nclude "jpeglib.h"
Done!
使用ijg 解码到缓冲区[原创]
今天开发一个程序需要使用IJG的库,这个库倒是用了很多年了,关于编码的处理范例中使用的是输出到文件流
查看文档 发现这个章节:Compressed data handling (source and destination managers)里面有实现的描述
The JPEG compression library sends its compressed data to a "destination
manager" module. The default destination manager just writes the data to a
stdio stream, but you can provide your own manager to do something else.
Similarly, the decompression library calls a "source manager" to obtain the
compressed data; you can provide your own source manager if you want the data
to come from somewhere other than a stdio stream.
manager" module. The default destination manager just writes the data to a
stdio stream, but you can provide your own manager to do something else.
Similarly, the decompression library calls a "source manager" to obtain the
compressed data; you can provide your own source manager if you want the data
to come from somewhere other than a stdio stream.
OK!看来问题便简单了
主要步骤:
init_destination (j_compress_ptr cinfo)
Initialize destination. This is called by jpeg_start_compress()
before any data is actually written. It must initialize
next_output_byte and free_in_buffer. free_in_buffer must be
initialized to a positive value.
Initialize destination. This is called by jpeg_start_compress()
before any data is actually written. It must initialize
next_output_byte and free_in_buffer. free_in_buffer must be
initialized to a positive value.
empty_output_buffer (j_compress_ptr cinfo)
This is called whenever the buffer has filled (free_in_buffer
reaches zero). In typical applications, it should write out the
*entire* buffer (use the saved start address and buffer length;
ignore the current state of next_output_byte and free_in_buffer).
Then reset the pointer & count to the start of the buffer, and
return TRUE indicating that the buffer has been dumped.
free_in_buffer must be set to a positive value when TRUE is
returned. A FALSE return should only be used when I/O suspension is
desired (this operating mode is discussed in the next section).
This is called whenever the buffer has filled (free_in_buffer
reaches zero). In typical applications, it should write out the
*entire* buffer (use the saved start address and buffer length;
ignore the current state of next_output_byte and free_in_buffer).
Then reset the pointer & count to the start of the buffer, and
return TRUE indicating that the buffer has been dumped.
free_in_buffer must be set to a positive value when TRUE is
returned. A FALSE return should only be used when I/O suspension is
desired (this operating mode is discussed in the next section).
term_destination (j_compress_ptr cinfo)
Terminate destination --- called by jpeg_finish_compress() after all
data has been written. In most applications, this must flush any
data remaining in the buffer. Use either next_output_byte or
free_in_buffer to determine how much data is in the buffer.
Terminate destination --- called by jpeg_finish_compress() after all
data has been written. In most applications, this must flush any
data remaining in the buffer. Use either next_output_byte or
free_in_buffer to determine how much data is in the buffer.
王老师: 您好! 我想可能我的学习方法有问题。我已经看了将近一个月的ijg库的jpeg解码程序, 可是到现在我还是没有真正理解,对怎样用到自己的嵌入式开发中还是觉得无处下手。 djpeg.c可以将jpeg文件转换成bmp文件,但是我们的系统并不能识别bmp图,只 能转换成原始的数据流。我现在很迷茫,您能不能指点一下,我该补充哪些方面的知 识,希望您能就自己的经验建议一种好的学习方法,让我少走一些弯路。 另外有一些概念需要您给解释一下:upsampling和dithering.one-pass color quantization和 two-pass color quantization. 十分感谢!! |
2004-12-03 12:14 回复 |
djpeg.c只是对ijg库的包装(包装成一个可执行的命令行程序),对bmp图像的处理等都是 外围封装部分。你如果想得到原始的数据流,只要使用ijg库本身的接口来开发就可以了, 没有必要关心djpeg程序。 ijg库本身的使用方法在jconfig.doc中有详细说明,example.c、djpeg.c等程序中又有示例 代码,具体的接口在jpeglib.h中都可以查到。如果仅是使用ijg库的话,似乎没有你说的那么难。 从你以前的来信中,我的感觉是,你的C语言功力还需要提高,否则可能驾驭不了ijg这样比 较复杂的C语言函数库。此外,如果你想深入到JPEG算法内部(比如,你说的upsampling、 quantization等都是JPEG算法中的常用术语),你可能还需要再熟悉一些JPEG算法的细节, 比如参考一下相关的图书和资料。 祝你成功! |