Ijl是intel的jpg压缩库,函数如下:
//ijl 库压缩
//ijl库
BOOL BeginIJL(JPEG_CORE_PROPERTIES *jcprops)
{
IJLERR jerr = IJL_OK;
jerr = ijlInit(jcprops);
if(jerr != IJL_OK){
printf("INIT IJL ERR -- %s\n", ijlErrorStr(jerr));
return FALSE;
}
return TRUE;
}
void EndIJL(JPEG_CORE_PROPERTIES *jcprops)
{
ijlFree(jcprops);
return;
}
//
BOOL EncodeToJPEGBuffer(
JPEG_CORE_PROPERTIES *jcprops,
BYTE *lpRawBuffer,
DWORD dwWidth,
DWORD dwHeight,
BYTE *lpJPEGBuffer,
DWORD *lpjpgBufferSize,
int quality)
{
BOOL bres;
IJLERR jerr = IJL_OK;
DWORD rawBufSize;
//JPEG_CORE_PROPERTIES jcprops;
bres = TRUE;
rawBufSize = dwWidth * dwHeight * 2;
jcprops->DIBWidth = dwWidth;
jcprops->DIBHeight = dwHeight;
jcprops->DIBBytes = lpRawBuffer;
jcprops->DIBPadBytes = 0;
jcprops->DIBChannels = 3;
jcprops->DIBColor =IJL_YCBCR;
jcprops->DIBSubsampling = IJL_422;
jcprops->JPGWidth = dwWidth;
jcprops->JPGHeight = dwHeight;
jcprops->JPGFile = NULL;
jcprops->JPGBytes = lpJPEGBuffer;
jcprops->JPGSizeBytes = rawBufSize;
jcprops->JPGChannels = 3;
jcprops->JPGColor = IJL_YCBCR;
jcprops->JPGSubsampling = IJL_422;
jcprops->jquality = quality;
jerr = ijlWrite(jcprops, IJL_JBUFF_WRITEWHOLEIMAGE);
if(jerr != IJL_OK){
printf("ijlWrite() failed -- %s\n", ijlErrorStr(jerr));
bres = FALSE;
goto ENCODE_ERROR;
}else{
*lpjpgBufferSize = jcprops->JPGSizeBytes;
}
ENCODE_ERROR:
//ijlFree(&jcprops);
return bres;
}
//
int CImgXXX::yuv422_to_jpeg_ijl(unsigned char *data, int image_width, int image_height, char *filename, int quality)
{
DWORD len = 0;
JPEG_CORE_PROPERTIES jcprops;
FILE *fp = NULL;
BYTE *out;
out=(BYTE *)malloc(image_width*image_height*2);
if(!BeginIJL(&jcprops)) return 0;
if(!EncodeToJPEGBuffer(&jcprops, data, image_width, image_height, out, &len,quality))
printf("encode error\n");
else{
printf("encode %d\n", len);
if ((fp = fopen(filename, "wb"))==NULL)
{
fprintf(stderr, "can't open %s/n", filename);
return -1;
}
fwrite((void *)out, 1, len, fp);
fclose(fp);
}
fclose(fp);
EndIJL(&jcprops);
return 0;
}
//
void CImgXXX::SaveYuv2Jpg(void *pYuvBuf,int image_width,int image_height)
{
CString str;
SYSTEMTIME st;
GetLocalTime(&st);
CString strtime;
strtime.Format("%4d.%2d.%2d-%2d.%2d.%2d-%3d",st.wYear,st.wMonth,st.wDay,st.wHour,st.wMinute,st.wSecond,st.wMilliseconds);
str="./pic/";
str+=strtime;
str+=".jpg";
//yuv422_to_jpeg((unsigned char *)pYuvBuf,image_width,image_height,str.GetBuffer(0),JPEG_QUALITY);
yuv422_to_jpeg_ijl((unsigned char *)pYuvBuf,image_width,image_height,str.GetBuffer(0),JPEG_QUALITY);
return;
}