我使用libjpeg将jpeg图像从磁盘解码到堆上分配的内存缓冲区。我使用jpeg_read_scanlines从文件中读取和解码每条扫描线。这是完美的工作,将每个像素解码为24位RGB值。
问题是我使用了一个额外的第三方库,它需要一个BGR格式的缓冲区(而不是RGB)。当使用这个库时,我得到了奇怪的结果,因为通道的顺序是错误的。
因此,我想找到一种方法使libjpeg解码为BGR格式,而不是RGB格式。我已经在网上搜索过了,找不到如何配置libjpeg来做到这一点?我知道我可以对内存缓冲区进行额外的遍历,并手动重新排序颜色通道,但是我正在开发的应用程序对时间要求极高,必须尽可能地快速和高效。
发布于 2011-04-11 19:17:10
为您提供以下几种解决方案:
JCS_EXT_BGR和JCS_EXT_BGRX colorspaces.此外,你说你在追求速度,但你操纵的是BGR数据(而不是BGRX)。这对我来说没有多大意义,因为在32位边界上对齐像素可能会快得多。
发布于 2013-10-05 18:51:44
正如Antun Tun所说,配置在jmorecfg.h中。在我的libjpeg (v7)版本中,它在第320行:
#define RGB_RED 0 /* Offset of Red in an RGB scanline element */
#define RGB_GREEN 1 /* Offset of Green */
#define RGB_BLUE 2 /* Offset of Blue */因此,您只需将其更改为:
#define RGB_RED 2 /* Offset of Red in an RGB scanline element */
#define RGB_GREEN 1 /* Offset of Green */
#define RGB_BLUE 0 /* Offset of Blue */你就完事了。评论还说:
/*
* RESTRICTIONS:
* 1. The sample applications cjpeg,djpeg do NOT support modified RGB formats.
* 2. These macros only affect RGB<=>YCbCr color conversion, so they are not
* useful if you are using JPEG color spaces other than YCbCr or grayscale.
* 3. The color quantizer modules will not behave desirably if RGB_PIXELSIZE
* is not 3 (they don't understand about dummy color components!). So you
* can't use color quantization if you change that value.
*/发布于 2013-02-17 00:01:17
JPEGLIB指出,您必须修改jmorecfg.h才能更改通常的R G B值顺序。这是指向document:http://www.opensource.apple.com/source/tcl/tcl-20/tcl_ext/tkimg/tkimg/libjpeg/libjpeg.doc的链接,它位于数据格式部分
https://stackoverflow.com/questions/5619810
复制相似问题