使用intel ijl庫 RGB轉Jpg
BOOL CRawXXX:: EncodeJpegUseIJL(char *dstfile,int *len, int width, int height, char* srcdata, int imageChannels, int quality)
{
BOOL res = FALSE;
JPEG_CORE_PROPERTIES image;
IJLERR err;
ZeroMemory( &image, sizeof( JPEG_CORE_PROPERTIES ) );
IJLIOTYPE iotype;
try
{
if( ijlInit( &image ) != IJL_OK )
{
OutputDebugString( "Can't initialize Intel(R) JPEG library" );
return FALSE;
}
image.DIBWidth = width;
image.DIBHeight = height;
image.DIBBytes = (unsigned char*)srcdata;
if (!len || *len == 0)
{
image.JPGFile = dstfile;
iotype = IJL_JFILE_WRITEWHOLEIMAGE;
}
else
{
image.JPGBytes = (unsigned char*)dstfile;
image.JPGSizeBytes = *len;
iotype = IJL_JBUFF_WRITEWHOLEIMAGE;
}
image.JPGWidth = width;
image.JPGHeight = abs(height);
image.jquality = quality;
switch(imageChannels)
{
case 1:
image.DIBColor = IJL_G;
image.DIBChannels = 1;
image.DIBPadBytes = IJL_DIB_PAD_BYTES(image.DIBWidth,1);
image.JPGColor = IJL_G;
image.JPGChannels = 1;
image.JPGSubsampling = IJL_NONE;
break;
case 3:
image.DIBColor = IJL_BGR;
image.DIBChannels = 3;
image.DIBPadBytes = IJL_DIB_PAD_BYTES(image.DIBWidth,3);
image.JPGColor = IJL_YCBCR;
image.JPGChannels = 3;
image.JPGSubsampling = IJL_411;
break;
case 4:
image.DIBColor = IJL_RGBA_FPX;
image.DIBChannels = 4;
image.DIBPadBytes = IJL_DIB_PAD_BYTES(image.DIBWidth,4);
image.JPGColor = IJL_YCBCRA_FPX;
image.JPGChannels = 4;
image.JPGSubsampling = IJL_4114;
break;
default:
break;
}
if( (err = ijlWrite( &image, iotype )) != IJL_OK )
{
OutputDebugString( "Can't write image(%d)");
}
if (len)
*len = image.JPGSizeBytes;
if( ijlFree( &image ) != IJL_OK )
{
OutputDebugString( "Can't free Intel(R) JPEG library" );
}
res = TRUE;
}
catch (...)
{
OutputDebugString( "EncodeJpegUseIJL unknown error" );
}
return res;
}
引數說明:
引數分別是:[輸出引數]壓縮後的緩衝區、大小,[輸入]bmp寬、高,bmp緩衝區,影象位(一般寫 3),壓縮質量1-99。
呼叫方式:
char *bjpgData=new char[pRgb888.width*pRgb888.height*3];
int lSize=1628*1236*3;
if(EncodeJpegUseIJL((char*)bjpgData,&lSize,pRgb888.width,pRgb888.height*(-1),(char*)pRgb888.buffer,3,80))
{
//壓縮成功了
TRACE("rgb to jpg success\n");
}
//儲存影象
SYSTEMTIME t;
GetLocalTime(&t);
char filename[128];
sprintf(filename, "%04d-%02d-%02d-%02d-%02d-%02d-%03d.jpg",
t.wYear, t.wMonth, t.wDay,
t.wHour, t.wMinute, t.wSecond, t.wMilliseconds);
FILE *fp = fopen(filename, "wb");
fwrite(bjpgData, lSize, 1, fp);
fclose(fp);
封裝後的函式如下:
//ijl bmp to jpg 其中ijlInit等函式的定義
int CImgXXX:rgb24_to_jpeg_ijl(unsigned char *data,int image_width, int image_height, char *filename, int quality )
{
JPEG_CORE_PROPERTIES jcprops;
IJLERR jerr;
jerr = ijlInit(&jcprops);
if(IJL_OK != jerr)
{
/*MessageBox(ijlErrorStr(jerr),"ijlInit function called failed!",MB_OK);*/
ijlFree(&jcprops);
return -1;
}
long LineSize = (image_width *3+3)/4*4;
//initialize the compression parameters describing the kind of Bitmap we are encoding from
jcprops.DIBChannels = 3;
jcprops.DIBColor = IJL_BGR;//Color space of uncompressed data.
jcprops.DIBHeight = image_height;
jcprops.DIBWidth = image_width;
jcprops.DIBPadBytes = IJL_DIB_PAD_BYTES(jcprops.DIBWidth,jcprops.JPGChannels);
//
jcprops.JPGWidth = image_width;
jcprops.JPGHeight =image_height;
jcprops.JPGFile = filename;
int w,h;
w = image_width;
h = image_height;
BYTE * JPEGimgdata = new BYTE[image_width*image_height*3];
for(int i=0;i<h;i++)
{
memcpy(JPEGimgdata+i*LineSize,data+(h-i-1)*LineSize,LineSize);
}
jcprops.DIBBytes = JPEGimgdata;
//write the entire JPEG image. this create a JFIF file.
jerr = ijlWrite(&jcprops,IJL_JFILE_WRITEWHOLEIMAGE);
if(IJL_OK != jerr)
{
//MessageBox(ijlErrorStr(jerr),"ijlWrite function called failed!",MB_OK);
//release the IJL
ijlFree(&jcprops);
//release file
delete[] JPEGimgdata;
JPEGimgdata = NULL;
return -1;
}
//release the IJL
ijlFree(&jcprops);
delete[] JPEGimgdata;
JPEGimgdata = NULL;
return 0;
}
相關文章
- 使用ijl庫Jpg轉RGB
- JPEG轉RGB Bmp(IJG庫 jpeg.lib)
- JPG轉TXT的教程
- JPG轉CAD,JPG圖片如何轉換成CAD圖紙?
- php中RGB轉十六進位制、十六進位制轉RGBPHP
- js 正則判斷顏色值,HEX轉RGB,HSL轉RGBJS
- heic格式批量轉jpg怎麼轉?
- jfif怎麼改成jpg jfif格式怎麼轉換成jpg格式
- RGB與YIQ的轉換
- RGB轉jpeg(opencv或IJG)OpenCV
- livp怎麼轉jpg 如何將live照片格式在電腦上轉換為jpg
- 怎麼把jpg圖片轉為Word文件 怎麼把Word轉換成jpg
- heic檔案如何轉換jpg?
- RGB2YUV 的verilog實現(RGB轉YUV)
- png轉jpg,常用格式怎麼互相轉換
- YUV <——> RGB 轉換演算法演算法
- webp格式轉換成jpg怎麼設定 電腦webp線上轉換jpg方法介紹Web
- 圖片heic怎麼轉換jpg?
- 將UIView轉成UIImage,將UIImage轉成PNG/JPGUIView
- 圖片格式怎麼轉換,如何轉換jpg
- heic格式轉換jpg怎麼轉?兩步搞定
- Java實現emf轉jpg png 圖片轉換Java
- jpeg轉化jpg怎麼操作 jpeg怎麼線上免費改為jpg格式
- 如何使用Super Vectorizer在 Mac 上將 PNG、JPG等轉換為 SVGMacSVG
- YUV格式到RGB格式的轉換
- heic格式轉換jpg工具——轉易俠heic轉換器
- CAD工程圖紙轉jpg格式教程
- 圖片格式轉換,JPG圖片轉換成PDF
- win10怎麼png轉jpg格式 win10系統png怎麼轉換成jpg圖片Win10
- 如何使用Mac預覽程式將png轉換為jpg格式的技巧分享Mac
- 使用IPicture介面讀取和顯示BMP,GIF,JPG,ICO,EMF,WMF影像 (轉)
- heic格式轉換jpg免費怎麼轉?轉易俠可以
- win10 png怎麼修改成jpg_win10如何把png轉換成jpgWin10
- png圖片怎麼轉換成jpg 電腦上怎麼把png格式改成jpg
- Metal實現YUV轉RGB渲染視訊
- png格式批量轉換jpg有什麼方法
- heic檔案怎麼線上轉換成jpg?
- 如何將HEIC轉換為JPG / JPEG或PNG?