我對libjpeg jpeg_read_scanlines
的工作方式感到困惑。我的理解是,它逐行解壓JPEG,並創建一個解壓縮的像素緩衝區。困惑於libjpeg:jpeg_read_scanlines
典型用法是一樣的東西:
jpeg_decompress_struct cinfo;
...
unsigned char* image = new unsigned char[cinfo.image_width * cinfo.image_height];
unsigned char* ptr = image;
int row_stride = cinfo.image_width;
while (cinfo.output_scanline < cinfo.image_height)
{
jpeg_read_scanlines(&cinfo, &ptr, 1);
ptr += row_stride;
}
問:我感到困惑的輸出緩衝區大小。在所有的example code我看到哪個使用jpeg_read_scanlines
,輸出緩衝區的大小是width X height
,其中寬度和高度指的是JPEG文件的尺寸。所以對於一個10x10的JPEG文件,我們會有一個100字節的輸出緩衝區。
但是...不是每個RGB像素的大小3個字節(24位)?那麼不應該將未壓縮的數據實際上設爲width X height X 3
字節?
爲什麼不是這樣?
我注意到在使用jpeg_write_scanlines
的代碼時,要壓縮的緩衝區是ISwidth X height X 3
。那麼爲什麼使用jpeg_read_scanlines
的緩衝區只有width X height
?
您正在閱讀的例子不正確。注意'row_stride'變量。 – 2013-02-27 03:58:10
@n.m。在示例代碼中,'row_stride'是'cinfo.output_width * cinfo.output_components;'。因爲'cinfo.output_components'是'1',row_stride等同於'cinfo.output_width' – Channel72 2013-02-27 04:12:58
灰度圖像只有1。 – 2013-02-27 04:44:12