JPEG轉RGB Bmp(IJG庫 jpeg.lib)
JPEG轉RGB是RGB壓縮的逆過程,從壓縮後的影象資料,然後進過熵編碼器,在經過量化器(逆),然後在經過逆DCT變換,得到解壓後的影象資料,我們在使用jpeg.lib庫進行解壓,解壓的函式如下:
//讀取JPEG檔案
//引數:
//lpstrFileName——包含JPEG檔案的全路徑名
//uWidth——影象的寬度
//uHeight——影象的高度
//返回值為解壓後的資料緩衝區指標
BYTE* CJpeg::ReadJPEGFile(LPCSTR lpstrFileName, UINT *uWidth, UINT *uHeight)
{
*uWidth=0;
*uHeight=0;
//定義JPEG檔案的解壓資訊
struct jpeg_decompress_struct cinfo;
//定義JPEG檔案的錯誤資訊
struct my_error_mgr jerr;
//定義緩衝區
FILE * infile;
JSAMPARRAY buffer;
int row_stride;
char buf[250];
//開啟JPEG檔案
if ((infile = fopen(lpstrFileName, "rb")) == NULL)
{
sprintf(buf, "JPEG :\nCan't open %s\n", lpstrFileName);
m_strJPEGError = buf;
return NULL;
}
//為JPEG檔案解壓物件分配記憶體並對其初始
cinfo.err = jpeg_std_error(&jerr.pub);
jerr.pub.error_exit = my_error_exit;
if (setjmp(jerr.setjmp_buffer))
{
jpeg_destroy_decompress(&cinfo);
fclose(infile);
return NULL;
}
jpeg_create_decompress(&cinfo);
//設定資料來源
jpeg_stdio_src(&cinfo, infile);
//讀取JPEG檔案引數
(void) jpeg_read_header(&cinfo, TRUE);
//開始解壓
(void) jpeg_start_decompress(&cinfo);
BYTE *dataBuf;
dataBuf=(BYTE *)new BYTE[cinfo.output_width * 3 * cinfo.output_height];//存放解壓後的資料
if (dataBuf==NULL)
{
m_strJPEGError = "JpegFile :\nOut of memory";
jpeg_destroy_decompress(&cinfo);
fclose(infile);
return NULL;
}
*uWidth = cinfo.output_width;
*uHeight = cinfo.output_height;
row_stride = cinfo.output_width * cinfo.output_components;
buffer = (*cinfo.mem->alloc_sarray)
((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1); //分配記憶體
//讀取掃描線
while (cinfo.output_scanline < cinfo.output_height)
{
(void) jpeg_read_scanlines(&cinfo, buffer, 1);
if (cinfo.out_color_components==3)
{
j_putRGBScanline(buffer[0],
*uWidth,
dataBuf,
cinfo.output_scanline-1);
}
else if (cinfo.out_color_components==1)
{
j_putGrayScanlineToRGB(buffer[0],
*uWidth,
dataBuf,
cinfo.output_scanline-1);
}
}
//完成解壓
(void) jpeg_finish_decompress(&cinfo);
//釋放JPEG解壓物件
jpeg_destroy_decompress(&cinfo);
fclose(infile);
return dataBuf;
}
//
// stash a scanline
//
void j_putRGBScanline(BYTE *jpegline,
int widthPix,
BYTE *outBuf,
int row)
{
int offset = row * widthPix * 3;
int count;
for (count=0;count<widthPix;count++) {
BYTE iRed, iBlu, iGrn;
LPBYTE oRed, oBlu, oGrn;
iRed = *(jpegline + count * 3 + 0);
iGrn = *(jpegline + count * 3 + 1);
iBlu = *(jpegline + count * 3 + 2);
oRed = outBuf + offset + count * 3 + 0;
oGrn = outBuf + offset + count * 3 + 1;
oBlu = outBuf + offset + count * 3 + 2;
*oRed = iRed;
*oGrn = iGrn;
*oBlu = iBlu;
}
}
//
// stash a gray scanline
//
void j_putGrayScanlineToRGB(BYTE *jpegline,
int widthPix,
BYTE *outBuf,
int row)
{
int offset = row * widthPix * 3;
int count;
for (count=0;count<widthPix;count++)
{
BYTE iGray;
LPBYTE oRed, oBlu, oGrn;
// get our grayscale value
iGray = *(jpegline + count);
oRed = outBuf + offset + count * 3;
oGrn = outBuf + offset + count * 3 + 1;
oBlu = outBuf + offset + count * 3 + 2;
*oRed = iGray;
*oGrn = iGray;
*oBlu = iGray;
}
}
相關文章
- RGB轉jpeg(opencv或IJG)OpenCV
- C++圖片格式轉換:BMP轉JPEGC++
- BMP、GIF、JPEG、PNG、SVG、WebP區別SVGWeb
- 使用ijl庫Jpg轉RGB
- 使用intel ijl庫 RGB轉JpgIntel
- 讀取BMP影象每一畫素點RGB資料
- Linux下JPEG庫安裝指令碼(轉)Linux指令碼
- 將24位BMP真彩圖轉換成BMP灰度圖
- BMP檔案結構 (轉)
- php中RGB轉十六進位制、十六進位制轉RGBPHP
- js 正則判斷顏色值,HEX轉RGB,HSL轉RGBJS
- bmp是什麼格式的檔案 怎麼把jpg轉換為bmp
- RGB與YIQ的轉換
- jpeg轉化jpg怎麼操作 jpeg怎麼線上免費改為jpg格式
- RGB2YUV 的verilog實現(RGB轉YUV)
- BMP點陣圖格式詳解--轉載
- YUV <——> RGB 轉換演算法演算法
- bmp to jpg(32位bmp也可處理)
- 如何將HEIC轉換為JPG / JPEG或PNG?
- YUV格式到RGB格式的轉換
- JPEG Jackal pro for Mac(jpeg圖片壓縮神器)Mac
- Yuv420轉Jpeg(C語言實現)C語言
- 配置PHP使之能同時支援GIF和JPEG (轉)PHP
- Metal實現YUV轉RGB渲染視訊
- JPEG 壓縮原理
- SILKYPIX JPEG Photography 11E Mac(JPEG圖片處理工具)Mac
- 怎麼將bmp格式圖片轉換jpg格式的
- BMP點陣圖檔案結構及VC操作 (轉)
- JavaScript rgb與十六進位制格式轉換JavaScript
- python--顏色的RGB轉BGR(opencv)PythonOpenCV
- 【視訊處理】YUV與RGB格式轉換
- 怎麼把Excel 表格轉成PNG、JPEG、GIF圖片格式 ?Excel
- Jpeg的檔案資訊
- BMP點陣圖檔案結構及平滑縮放 (轉)
- 【LaTeX入門】08、將png、bmp、jpg轉換成eps
- php8 Imagick庫缺失jpeg、png、tiff等格式的問題PHP
- BMP檔案結構
- BMP檔案詳解