|
我现在做的东西是在linux环境下,使用摄相头取得图象,并将其存成JPEG格式的文件。
我的程序采集图象没有问题,已经能存成PPM格式,但在存储成JPEG格式时出了问题。
按照书上和网上的方法(都一样),将buffer中的影像数据压缩成JPEG,我写了代码:
int write_jpeg(char *filename,unsigned char *img,int width,int height,int quality,int gray)
{
struct jpeg_compress_struct jcfg;
struct jpeg_error_mgr jerr;
FILE *fp;
unsigned char *line;
int line_length;
int i;
if ((fp = fopen(filename,"w")) == NULL)
{
fprintf(stderr,"write_jpeg:can't open %s\n",filename);
return -1;
}
jcfg.err = jpeg_std_error(&jerr); //jpeg_std_error
printf("here we have a test!\n");
jpeg_creat_compress(&jcfg);
//jpeg_creat_compress
jpeg_stdio_dest(&jcfg,fp); //jpeg_stdio_dest
jcfg.image_width = width;
jcfg.image_height = height;
jcfg.input_components = gray? 1 : 3;
jcfg.in_color_space = gray? JCS_GRAYSCALE : JCS_RGB;
jpeg_set_defaults(&jcfg); //jpeg_set_defaults
jpeg_set_quality(&jcfg,quality,TRUE); //jpeg_set_quality
jpeg_start_compress(&jcfg,TRUE); //jpeg_start_compress
line_length = gray ? width : width*3;
for(i = 0,line =img; i < height; i++,line +=line_length)
{
jpeg_write_scanlines(&jcfg, &line, 1); //jpeg_write_scanlines
}
jpeg_finish_compress(&jcfg); //jpeg_finish_compress
jpeg_destroy_compress(&jcfg); //jpeg_destroy_compress
fclose(fp);
return 0;
}
代码本身应该没什么问题,理论上需要包含“jpeglib.h”文件,但包含后编译时却说我所使用的函数(如jpeg_stdio_dest等)没定义,可是我查看/usr/include/中的jpeglib.h中时,发现这些函数是定义了的。为什么啊?
怎么回事啊?我折腾了几天了啊!
大家帮我看看吧!感谢了! |
|