Avatar
分类
最新评论
最新留言
链接
is this a bug in libjpeg source code?
Just for a work task, I need use libjpeg to compress my YUV data into a jpeg file.
I ran "sudo apt-get source libjpeg62" from my Ubuntu and read the code.
I need to set color space parameters into the structure libjpeg needs.
But it seems something wrong here:
354 /*
355 * Select an appropriate JPEG colorspace for in_color_space.
356 */
357
358 GLOBAL(void)
359 jpeg_default_colorspace (j_compress_ptr cinfo)
360 {
361 switch (cinfo->in_color_space) {
362 case JCS_GRAYSCALE:
363 jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
364 break;
365 case JCS_RGB:
366 jpeg_set_colorspace(cinfo, JCS_YCbCr);
367 break;
368 case JCS_YCbCr:
369 jpeg_set_colorspace(cinfo, JCS_YCbCr);
370 break;
371 case JCS_CMYK:
372 jpeg_set_colorspace(cinfo, JCS_CMYK); /* By default, no translation */
373 break;
374 case JCS_YCCK:
375 jpeg_set_colorspace(cinfo, JCS_YCCK);
376 break;
377 case JCS_UNKNOWN:
378 jpeg_set_colorspace(cinfo, JCS_UNKNOWN);
379 break;
380 default:
381 ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
382 }
383 }
355 * Select an appropriate JPEG colorspace for in_color_space.
356 */
357
358 GLOBAL(void)
359 jpeg_default_colorspace (j_compress_ptr cinfo)
360 {
361 switch (cinfo->in_color_space) {
362 case JCS_GRAYSCALE:
363 jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
364 break;
365 case JCS_RGB:
366 jpeg_set_colorspace(cinfo, JCS_YCbCr);
367 break;
368 case JCS_YCbCr:
369 jpeg_set_colorspace(cinfo, JCS_YCbCr);
370 break;
371 case JCS_CMYK:
372 jpeg_set_colorspace(cinfo, JCS_CMYK); /* By default, no translation */
373 break;
374 case JCS_YCCK:
375 jpeg_set_colorspace(cinfo, JCS_YCCK);
376 break;
377 case JCS_UNKNOWN:
378 jpeg_set_colorspace(cinfo, JCS_UNKNOWN);
379 break;
380 default:
381 ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
382 }
383 }
Pls red highlight code lines.
I absolutely believe here is a but because they pass same parameter with two different cases.
I can proof by following code of jpeg_set_colorspace().
425 case JCS_RGB:
426 cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */
427 cinfo->num_components = 3;
428 SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, 0,0);
429 SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0);
430 SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, 0,0);
431 break;
432 case JCS_YCbCr:
433 cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
434 cinfo->num_components = 3;
435 /* JFIF specifies component IDs 1,2,3 */
436 /* We default to 2x2 subsamples of chrominance */
437 SET_COMP(0, 1, 2,2, 0, 0,0);
438 SET_COMP(1, 2, 1,1, 1, 1,1);
439 SET_COMP(2, 3, 1,1, 1, 1,1);
440 break;
426 cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */
427 cinfo->num_components = 3;
428 SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, 0,0);
429 SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0);
430 SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, 0,0);
431 break;
432 case JCS_YCbCr:
433 cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
434 cinfo->num_components = 3;
435 /* JFIF specifies component IDs 1,2,3 */
436 /* We default to 2x2 subsamples of chrominance */
437 SET_COMP(0, 1, 2,2, 0, 0,0);
438 SET_COMP(1, 2, 1,1, 1, 1,1);
439 SET_COMP(2, 3, 1,1, 1, 1,1);
440 break;
They use different matrix.
I tried to submit this bug to author but I can't find out his email address.
Wikipedia.org mentioned the libjpeg's profile but no email address.
libjpeg | |
---|---|
Developed by | Independent JPEG Group |
Latest release | 6b / 27 March 1998 |
Written in | C |
Type | library |
License | Free, can be used in commercial applications without royalty, with acknowledgement. |
Website | ijg.org |
If someone know that pls let me know. If I am wrong pls let me know.