Hi,
I want to encode YCbCr422(DIB) to JPEG by using IJL without converting it to 24-bits RGB image. However, the create JPEG imagegreen tonecompared with original image. Similar question was registered as same title (Sep.20.2005). I also used similar code as following.
jCprops.DIBWidth = Wid;
jCprops.DIBHeight = Hei;
jCprops.DIBBytes = pYCbCr;
jCprops.DIBPadBytes = 0;
jCprops.DIBChannels = 3;
jCprops.DIBColor = IJL_YCBCR;
jCprops.DIBSubsampling = IJL_422;
jCprops.JPGWidth = Wid;
jCprops.JPGHeight = Hei;
jCprops.JPGChannels = 3;
jCprops.JPGColor = IJL_YCBCR;
jCprops.JPGSubsampling = IJL_422;
jCprops.jquality = 100;
链接已复制
6 回复数
There was sample code attached to one these old threads. It seems it was lost within a time and movement from one forum engine to another.
Code like this should work for YUY2 compression/decompression
[cpp]int ijl_compress_from_ycbycr( BYTE* buffer, int width, int height, char* name) { int res = 0; IJLERR jerr; JPEG_CORE_PROPERTIES jcprops; jerr = ijlInit(&jcprops); if(IJL_OK != jerr) { printf("ijlInit() failed - %sn",ijlErrorStr(jerr)); res = 1; goto Exit; } jcprops.DIBWidth = width; jcprops.DIBHeight = -height; jcprops.DIBChannels = 3; jcprops.DIBBytes = buffer; jcprops.DIBPadBytes = 0; jcprops.DIBColor = IJL_YCBCR; jcprops.DIBSubsampling = IJL_422; jcprops.JPGFile = name; jcprops.JPGWidth = width; jcprops.JPGHeight = height; jcprops.JPGChannels = 3; jcprops.JPGColor = IJL_YCBCR; jcprops.JPGSubsampling = IJL_422; jcprops.jquality = 75; jerr = ijlWrite(&jcprops,IJL_JFILE_WRITEWHOLEIMAGE); if(IJL_OK != jerr) { printf("ijlInit() failed - %sn",ijlErrorStr(jerr)); res = 1; goto Exit; } Exit: jerr = ijlFree(&jcprops); if(IJL_OK != jerr) { printf("ijlFree() failed - %sn",ijlErrorStr(jerr)); res = 1; } return res; } // ijl_compress_from_ycbycr() int ijl_decompress_to_ycbycr( char* name, BYTE** buffer, int* width, int* height) { int res; BYTE* dib_buffer = NULL; int dib_buffer_size; IJLERR jerr; JPEG_CORE_PROPERTIES jcprops; jerr = ijlInit(&jcprops); if(IJL_OK != jerr) { printf("ijlInit() failed - %sn",ijlErrorStr(jerr)); res = 1; goto Exit; } jcprops.JPGFile = name; jerr = ijlRead(&jcprops,IJL_JFILE_READPARAMS); if(IJL_OK != jerr) { printf("ijlRead() failed - %sn",ijlErrorStr(jerr)); res = 1; goto Exit; } if(jcprops.JPGSubsampling != IJL_422 || jcprops.JPGChannels != 3) { printf("only JPEG with 422 sampling can be decoded as YCBYCR DIB with 422 samplingn"); res = 1; goto Exit; } dib_buffer_size = jcprops.JPGWidth * jcprops.JPGHeight * jcprops.JPGChannels; dib_buffer = new BYTE [dib_buffer_size]; if(NULL == dib_buffer) { printf("can't allocate memoryn"); res = 1; goto Exit; } jcprops.DIBWidth = jcprops.JPGWidth; jcprops.DIBHeight = -jcprops.JPGHeight; jcprops.DIBChannels = 2; // NOTE: we must set nchannels = 2 to decode as YCBYCR jcprops.DIBBytes = dib_buffer; jcprops.DIBPadBytes = 0; jcprops.DIBColor = IJL_YCBCR; jcprops.DIBSubsampling = IJL_422; jerr = ijlRead(&jcprops,IJL_JFILE_READWHOLEIMAGE); if(IJL_OK != jerr) { printf("ijlRead() failed - %sn",ijlErrorStr(jerr)); res = 1; goto Exit; } res = 0; *buffer = dib_buffer; *width = jcprops.JPGWidth; *height = jcprops.JPGHeight; Exit: jerr = ijlFree(&jcprops); if(IJL_OK != jerr) { printf("ijlFree() failed - %sn",ijlErrorStr(jerr)); res = 1; } if(res == 1) { if(NULL != dib_buffer) { delete[] dib_buffer; } } return res; } // ijl_decompress_to_ycbycr() [/cpp]
Regards,
Vladimir
Thanks for the quick response. My code is same as you. I attached some files. (width : 680, height : 500)
1. 680500.ybr : Original data. file type is YCBCR422.
2. 680500.jpg : Encode by IJL. Green tone color
3. 680500_2.jpg : Encode by another library. Gray tone.
Iwould liketo get a result like 680500_2.jpg by using IJL.
By the way, I have another question. Does 'iplYCrCb2RGB' suppor converting from YBR422 to RGB? I think the function is availible only for converting from YBRFull to RGB. My assumption is right?
Best Regards.
DaeYoung
I see no attached files. Note, after you create folder and put file to it you need to set check mark and choose attach file option.
If you want to convert YCbCr422 to RGB you maywant to use function ippiYCbCr422ToRGB_8u_P3C3R.
Regards,
Vladimir
Vladimir
