QImage如何压缩成Jpeg?在线等,急!

qhgary 2003-12-11 11:56:08
请问如何将QImage的文件压缩成Jpeg格式(无文件头,用于传输的,不是写进文件)以及如何反向解压成QImage,谢谢,非常着急,希望得到高手指点
...全文
223 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
qhgary 2003-12-12
  • 打赏
  • 举报
回复
可是这样的话好象实际操作起来比较麻烦,因为是要在代码中完成的啊,怎么好象jpeg的codec这么难找啊,我本来以为应该很多的啊,结果都是针对jpeg文件的
wwwunix 2003-12-12
  • 打赏
  • 举报
回复
filesystem是我自己mount的内存印象,就跟buffer到buffer的速度一样
开个RAM DISC就可以了。
icedust 2003-12-11
  • 打赏
  • 举报
回复
这个我也问过别的人,反正我自己是不懂具体怎么个编码算法的,(呵呵,算法看得头疼啊)

我还是基于文件级的,只不过用的filesystem是我自己mount的内存印象,就跟buffer到buffer的速度一样,不需要通过硬盘的,这样速度还可以
qhgary 2003-12-11
  • 打赏
  • 举报
回复
非常感谢热心的高手,我也看过jpeglib.h,里面好象必须设置destination,而且参数必须是FILE*,我现在想法是能够对一个buffer(raw image, RGB or BGR)直接进行JPEG压缩,并且能够反向解码,而且最好高效的,不是对文件操作,我不需要读jpeg文件,也不用写进文件,只是buffer到buffer的操作,谢谢
icedust 2003-12-11
  • 打赏
  • 举报
回复
给你一段我写的代码,需要#include <jpeglib.h>
link时候加上-ljpeg即可
typedef struct my_error_mgr * my_error_ptr;
/*
* Here's the routine that will replace the standard error_exit method:
*/
METHODDEF(void)
my_error_exit (j_common_ptr cinfo)
{
/* cinfo->err really points to a my_error_mgr struct, so coerce pointer */
my_error_ptr myerr = (my_error_ptr) cinfo->err;
/* Always display the message. */
/* We could postpone this until after returning, if we chose. */
(*cinfo->err->output_message) (cinfo);
/* Return control to the setjmp point */
longjmp(myerr->setjmp_buffer, 1);
}

int count_for_jpeg;
int add_scanline_to_rgbbuffer(unsigned char* linebuffer,int length,unsigned char* rgbbuffer)
{
// fprintf(stderr,"length = %d\n",length);
memcpy((rgbbuffer+length*(count_for_jpeg++)),linebuffer,length);
return 0;
}
int DecompressJpeg(const char* input,unsigned char* rgbbuffer)//input为jpeg文件名,rgbbuffer为解码后的rgb原始数据
{
count_for_jpeg = 0;
struct jpeg_decompress_struct cinfo;

struct my_error_mgr jerr;
/* More stuff */
FILE * infile; /* source file */
JSAMPARRAY buffer; /* Output row buffer */
int row_stride; /* physical row width in output buffer */

char* filename = (char*)input;
if ((infile = fopen(filename, "rb")) == NULL)
{
fprintf(stderr, "can't open %s\n", filename);
return -1;
}
/* Step 1: allocate and initialize JPEG decompression object */

/* We set up the normal JPEG error routines, then override error_exit. */
cinfo.err = jpeg_std_error(&jerr.pub);
jerr.pub.error_exit = my_error_exit;
/* Establish the setjmp return context for my_error_exit to use. */
if (setjmp(jerr.setjmp_buffer))
{
/* If we get here, the JPEG code has signaled an error.
* We need to clean up the JPEG object, close the input file, and return.
*/
fprintf(stderr,"Error setjmp()\n");
jpeg_destroy_decompress(&cinfo);
return -1;
}
/* Now we can initialize the JPEG decompression object. */
jpeg_create_decompress(&cinfo);

/* Step 2: specify data source (eg, a file) */
jpeg_stdio_src(&cinfo, infile);

/* Step 3: read file parameters with jpeg_read_header() */
(void) jpeg_read_header(&cinfo, TRUE);

/* Step 5: Start decompressor */
(void) jpeg_start_decompress(&cinfo);

/* JSAMPLEs per row in output buffer */
row_stride = cinfo.output_width * cinfo.output_components;
/* Make a one-row-high sample array that will go away when done with image */
buffer = (*cinfo.mem->alloc_sarray)
((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);

/* Step 6: while (scan lines remain to be read) */
//fprintf(stderr,"cinfo.output_scanline = %d,cinfo.output_height = %d\n",cinfo.output_scanline,cinfo.output_height);
while (cinfo.output_scanline < cinfo.output_height)
{
//fprintf(stderr,"cinfo.output_scanline = %d,cinfo.output_height = %d\n",cinfo.output_scanline,cinfo.output_height);
(void) jpeg_read_scanlines(&cinfo, buffer, 1);
/* Assume put_scanline_someplace wants a pointer and sample count. */
add_scanline_to_rgbbuffer(buffer[0], row_stride,rgbbuffer);
}

/* Step 7: Finish decompression */
(void) jpeg_finish_decompress(&cinfo);

/* Step 8: Release JPEG decompression object */
jpeg_destroy_decompress(&cinfo);
fclose(infile);

return 0;
}

给分吧,呵呵
qhgary 2003-12-11
  • 打赏
  • 举报
回复
filesystem是我自己mount的内存印象,就跟buffer到buffer的速度一样

具体怎么操作?怎么印象?

23,120

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧