From: 陳立格 <b89...@nt...> - 2013-05-11 15:16:44
|
郵件討論區留一個備份 於 2013/5/11 下午 10:58, 陳立格 提到: > 你好: > > 是的 真的可以這樣搞. > > 不過需要一些修改. > > 增加以下代碼 > > > turbojpeg.h : > > /** > * > * > * Compress an YUV image into a JPEG image. > * the input data is assumed as aligned as 4. > * NOTE : the function will not allocate output buffer(pJpegBuf). > */ > > DLLEXPORT int DLLCALL tjCompressYUV420(tjhandle handle, unsigned char > *pY, > unsigned char *pU, unsigned char *pV, int width, int height, > unsigned char *pJpegBuf, > unsigned long *pJpegSize, int jpegQual); > > > > turbojpeg.c: > > #define MAX_LINES (2*DCTSIZE) > #define DIV2(VAL) ((VAL)>>1) > > DLLEXPORT int DLLCALL tjCompressYUV420(tjhandle handle, unsigned char > *pY, > unsigned char *pU, unsigned char *pV, int width, int height, > unsigned char *pJpegBuf, > unsigned long *pJpegSize, int jpegQual) > { > int retval; > > getinstance(handle) > if((this->init&COMPRESS)==0) > _throw("tjCompress2(): Instance has not been initialized for > compression"); > > retval = 0; > if(setjmp(this->jerr.setjmp_buffer)) > { > /* If we get here, the JPEG code has signaled an error. */ > retval=-1; > goto bailout; > }/*if setjmp(this->jerr.setjmp_buffer)*/ > > > cinfo->image_width = width; > cinfo->image_height = height; > cinfo->input_components = 3; > cinfo->jpeg_color_space = JCS_YCbCr; > cinfo->data_precision = 8; > > jpeg_set_defaults(cinfo); > > cinfo->in_color_space = JCS_YCbCr; > cinfo->raw_data_in = TRUE; > > jpeg_set_quality (cinfo, jpegQual, TRUE); > > cinfo->comp_info[0].h_samp_factor = 2; > cinfo->comp_info[0].v_samp_factor = 2; > cinfo->comp_info[1].h_samp_factor = 1; > cinfo->comp_info[1].v_samp_factor = 1; > cinfo->comp_info[2].h_samp_factor = 1; > cinfo->comp_info[2].v_samp_factor = 1; > > *pJpegSize = tjBufSize(width, height, TJSAMP_420); > > jpeg_mem_dest_tj(cinfo, &pJpegBuf, pJpegSize, 0); > > jpeg_start_compress(cinfo, TRUE); > > > {/*variables block */ > > unsigned int i, j; > unsigned int widthStepY; > > unsigned int endHeight; > > JSAMPROW YArrow[MAX_LINES], UArrow[DCTSIZE], VArrow[DCTSIZE]; > JSAMPARRAY encodeYUV[3]; > unsigned char *pMovY, *pMovU, *pMovV; > > widthStepY = TJPAD(width); > endHeight = (height + (MAX_LINES - 1)/ MAX_LINES)*(MAX_LINES); > > pMovY = pY; pMovU = pU; pMovV = pV; > > for(j = 0; j< endHeight; j+= MAX_LINES){ > > for(i = 0;i < MAX_LINES; i++) > YArrow[i] = pMovY + i*widthStepY; > > for(i = 0;i < DCTSIZE; i++){ > UArrow[i] = pMovU + i*DIV2(widthStepY); > VArrow[i] = pMovV + i*DIV2(widthStepY); > }/*for i*/ > > encodeYUV[0] = YArrow; > encodeYUV[1] = UArrow; > encodeYUV[2] = VArrow; > > jpeg_write_raw_data(cinfo, encodeYUV, MAX_LINES); > > pMovY += MAX_LINES*widthStepY; > pMovU += DCTSIZE*DIV2(widthStepY); > pMovV += DCTSIZE*DIV2(widthStepY); > }/*for j*/ > > }/*variables block */ > > > jpeg_finish_compress(cinfo); > bailout: > > return retval; > }/*tjCompressYUV420*/ > > > 這樣就可以了 > > > > English: > > You should add turbojpeg.h and turbojpeg.c as above, that is what you > wish. but the proformance is not good as inputing RGB directly, the > RGB one is better. you should benchmark it. > > > > 於 2013/5/7 下午 11:53, netmonitoring 提到: >> Is it possible to save YUYV422 buffer as JPEG using LIBJPEG library >> without additional conversation to the RGB24/RGB32 color format? >> >> Are there examples? >> >> >> ------------------------------------------------------------------------------ >> Learn Graph Databases - Download FREE O'Reilly Book >> "Graph Databases" is the definitive new guide to graph databases and >> their applications. This 200-page book is written by three acclaimed >> leaders in the field. The early access version is available now. >> Download your free book today!http://p.sf.net/sfu/neotech_d2d_may >> >> >> _______________________________________________ >> Libjpeg-devel-6x mailing list >> Lib...@li... >> https://lists.sourceforge.net/lists/listinfo/libjpeg-devel-6x > |