ffffff
http://www.ibm.com/developerworks/cn/linux/l-cn-linuxglb/
http://blog.csdn.net/wocjj/article/details/7867191
int read_JPEG_file (char * filename)
{
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
FILE * infile; /* source file */
FILE * outfile; /* source file */
JSAMPARRAY buffer; /* Output row buffer */
int row_stride; /* physical row width in output buffer */
//unsigned int nWidth = 1280;
//unsigned int nHeight = 720;
unsigned char* pcOutBuf = NULL;
char* pcRowBuf = NULL;
if ((infile = fopen(filename, "rb")) == NULL)
{
fprintf(stderr, "can't open %s\n", filename);
return 0;
}
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&cinfo);
jpeg_stdio_src(&cinfo, infile);
(void) jpeg_read_header(&cinfo, TRUE);
printf("width=%d, height=%d\n", cinfo.image_width, cinfo.image_height);
printf("color components:%d, jpeg color space:%d\n", cinfo.num_components, cinfo.jpeg_color_space);
printf("decompress--->color components:%d, jpeg color space:%d\n", cinfo.out_color_components, cinfo.out_color_space);
//printf("out_width=%d, out_height=%d\n", cinfo.output_width, cinfo.output_height);
//printf("component=%d\n", cinfo.output_components);
cinfo.out_color_space=JCS_GRAYSCALE;
cinfo.out_color_components = 1;
//jpeg_set_colorspace(&cinfo, JCS_GRAYSCALE);
//执行jpeg_start_decompress后才能获取到上面的打印信息
(void) jpeg_start_decompress(&cinfo);
printf("out_width=%d, out_height=%d\n", cinfo.output_width, cinfo.output_height);
printf("component=%d\n", cinfo.output_components);
printf("decompress--->color components:%d, jpeg color space:%d\n", cinfo.out_color_components, cinfo.out_color_space);
row_stride = cinfo.output_width * cinfo.output_components;
pcOutBuf = (unsigned char*)malloc(cinfo.output_width*cinfo.output_height*cinfo.output_components);
pcRowBuf = (char*)malloc(row_stride);
if ((outfile = fopen("xxx.gray", "wb")) == NULL)
{
fprintf(stderr, "can't open %s\n", "xxx.gray");
return 0;
}
while (cinfo.output_scanline < cinfo.output_height)
{
(void) jpeg_read_scanlines(&cinfo, &pcRowBuf, 1);
memcpy(pcOutBuf, pcRowBuf, row_stride);
pcOutBuf += row_stride;
fwrite(pcRowBuf,1, row_stride, outfile);
// printf("cinfo.output_scanline=%d\n", cinfo.output_scanline);
}
fclose(infile);
fclose(outfile);
if (NULL != pcOutBuf)
free(pcOutBuf);
return 0;
}