BUG: updated JPEG IO#2975
Merged
dzenanz merged 8 commits intoInsightSoftwareConsortium:masterfrom Dec 21, 2021
Merged
Conversation
issakomi
commented
Dec 17, 2021
issakomi
commented
Dec 17, 2021
issakomi
commented
Dec 17, 2021
dzenanz
reviewed
Dec 17, 2021
issakomi
commented
Dec 18, 2021
| case 4: | ||
| // TODO | ||
| m_PixelType = IOPixelEnum::RGBA; | ||
| itkWarningMacro("JPEG image may be opened incorrectly"); |
Member
Author
There was a problem hiding this comment.
4 components JPEG is not RGBA.
https://en.wikipedia.org/wiki/File:Channel_digital_image_CMYK_color.jpg
Member
Author
There was a problem hiding this comment.
Here is how Gimp handles this
switch (cinfo.output_components)
{
case 1:
image_type = GIMP_GRAY;
layer_type = GIMP_GRAY_IMAGE;
break;
case 3:
image_type = GIMP_RGB;
layer_type = GIMP_RGB_IMAGE;
break;
case 4:
if (cinfo.out_color_space == JCS_CMYK)
{
image_type = GIMP_RGB;
layer_type = GIMP_RGB_IMAGE;
break;
}
/*fallthrough*/
default:
g_message ("Don't know how to load JPEG images "
"with %d color channels, using colorspace %d (%d).",
cinfo.output_components, cinfo.out_color_space,
cinfo.jpeg_color_space);
return -1;
break;
}CMYK data is additionally processed later.
Member
Author
There was a problem hiding this comment.
CMYK is already done, will be added in separate PR. The files are not unusual, Photoshop has the option to export CMYK jpegs. They have (checked it):
cinfo.out_color_space == JCS_CMYK
cinfo.jpeg_color_space == JCS_YCCK
Current "RGBA" part is bug.
Important specially for external library. Not supported.
UINT input doesn't work, output is broken image
JPEG defines JPEG_MAX_DIMENSION in jmorecfg.h (65500L) System library may have modified jmorecfg.h too.
Ensure there is no overflow in ReadImageInformation
Only componets number 1 to 4 was handled, may be more. Give warnings about unsupported cases.
Set 'row_pointers' volatile and delete on jump Don't flush twice Warn about upsupported components
issakomi
commented
Dec 18, 2021
| } | ||
| jpeg_write_scanlines(&cinfo, row_pointers, height); | ||
|
|
||
| if (fflush(fp) == EOF) |
Member
Author
There was a problem hiding this comment.
I have checked, fflush is called here in term_destination (j_compress_ptr cinfo) called by jpeg_finish_compress(&cinfo);
dzenanz
approved these changes
Dec 20, 2021
dzenanz
approved these changes
Dec 20, 2021
Several minor changes as requested. Improved check for overflow to usually avoid 2 multiplications.
dzenanz
approved these changes
Dec 20, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Commits are intentionally not squashed.
Follow-up of #2933