我正在使用libjpeg创建jpeg
http://www.ijg.org/
#define COLOR_COMPONENTS (3)
#define COLOR_SPACE (JCS_RGB)
JSAMPLE image_buffer[WIDTH*HEIGHT *3] =
{
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
};
...
// inside libjpeg I set the values
cinfo.image_width = image_width; /* image width and height, in pixels */
cinfo.image_height = image_height;
cinfo.input_components = COLOR_COMPONENTS; /* # of color components per pixel */
cinfo.in_color_space = COLOR_SPACE; /* colorspace of input image */
/* Now use the library's routine to set default compression parameters.
* (You must set at least cinfo.in_color_space before calling this,
* since the defaults depend on the source color space.)
*/
jpeg_set_defaults(&cinfo);
但是,这不起作用:
#define COLOR_COMPONENTS (1)
#define COLOR_SPACE (JCS_GRAYSCALE)
JSAMPLE image_buffer[WIDTH*HEIGHT * 1] =
{
0x80, 0x80, 0x80, 0x80,
0x80, 0x00, 0x00, 0x80,
0x80, 0x00, 0x00, 0x80,
0x80, 0x80, 0x80, 0x80,
};
cinfo.input_components = ???
cinfo.in_color_space = ???
代码需要在低时钟CPU上运行。因此,我没有多余的周期来转换从灰度图像和RGB。
谢谢您!