Skip to content

Adds color conversion to SRGB for images with CMYK palette #25277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

krisdante
Copy link
Contributor

@krisdante krisdante commented Oct 24, 2019

Description (*)

Adds color conversion to SRGB for images with CMYK and Unrecognizable color palette

For ImageMagic, when the original image was in CMYK palette, the final image after
resize was kind of "in negative". I decided to force conversion to RGB, but when
converting to RGB from CMYK with IMagixk - colors were not natural.
So I picked SRGB (I found this hint in StackOverflow)

Fixed Issues (if relevant)

  1. CMYK images are rendered with inverted colors #22375 : CMYK images are rendered with inverted colors

Manual testing scenarios (*)

See the issue for a detailed path to reproduce / test

Questions or comments

It might be that "normal" RGB images will get converted to SRGB in some cases. I tested a few RGB images and I do not see the quality problem.

I fixed a few lines in this file were phpcs was complaining.

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

… color palette

For ImageMagic, when the original image was in CMYK palette, the final image after
resize was kind of "in negative". I decided to force conversion to RGB, but when
converting to RGB from CMYK with IMagixk - colors were not natural.
So I picked SRGB (I found this hint in StackOverflow)
@krisdante krisdante requested a review from buskamuza as a code owner October 24, 2019 19:44
@m2-assistant
Copy link

m2-assistant bot commented Oct 24, 2019

Hi @krisdante. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.3-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Guide documentation.

@krisdante
Copy link
Contributor Author

Those Exceptions (Code style failing) were there before. I think migrating that is a separate topic and I will do that with another pull request.

@sidolov sidolov changed the base branch from 2.3-develop to 2.4-develop December 5, 2019 17:17
@ihor-sviziev ihor-sviziev self-assigned this Mar 3, 2020
@ihor-sviziev
Copy link
Contributor

@magento run Functional Tests CE, Functional Tests B2B, Functional Tests EE

Copy link
Contributor

@ihor-sviziev ihor-sviziev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @krisdante,
Your change looks good to me. Could you cover your changes with unit test?

/**
* Converts colorspace to RGB when required
*/
protected function ensureColorspace()
Copy link
Contributor

@ihor-sviziev ihor-sviziev Mar 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make this method private and add return type, like this.

Suggested change
protected function ensureColorspace()
private function ensureColorspace(): void

@ihor-sviziev ihor-sviziev added the Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests label Mar 4, 2020
@ihor-sviziev
Copy link
Contributor

Hi @krisdante,
Will you be able to update your PR?

@krisdante
Copy link
Contributor Author

I need to think about it. The tricky part with unit testing that is that you cannot check colours programatically. They will be fine. They are just displayed brokenly to a human eye when wrong colour space conversion will happen.
The test here was to upload the image attached to this bug, and check if it is looking good in Magento.
It is really hard to program this as integration test.

@krisdante
Copy link
Contributor Author

Also merging this before #26036 would be nice.

@ihor-sviziev ihor-sviziev added Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests and removed Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests labels Mar 27, 2020
Copy link
Contributor

@ihor-sviziev ihor-sviziev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to think about it. The tricky part with unit testing that is that you cannot check colours programatically. They will be fine. They are just displayed brokenly to a human eye when wrong colour space conversion will happen.
The test here was to upload the image attached to this bug, and check if it is looking good in Magento.
It is really hard to program this as integration test.

@krisdante yeah, that's good point for sure, but I didn't see any integration tests for image magic, but this would be really good thing if you could write it!
By unit test we could just check that your code was executed and in case if you'll write integration - it will be enough. If you'll have any issues with integration tests - unit test we still could write without any issues.

Also I wrote few comments to existing functionality, please check them

Could you update your PR accordingly?

case \Imagick::COLORSPACE_CMYK:
case \Imagick::COLORSPACE_UNDEFINED:
$this->_imageHandler->transformImageColorspace(\Imagick::COLORSPACE_SRGB);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
break;

$colorspace = $this->_imageHandler->getColorspace();
switch ($colorspace) {
case \Imagick::COLORSPACE_RGB:
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could just remove this case.

@ihor-sviziev
Copy link
Contributor

Hi @krisdante,
Will you be able to update your PR?

@ihor-sviziev
Copy link
Contributor

@krisdante I am closing this PR now due to inactivity.
Please reopen and update if you wish to continue.
Thank you for the collaboration!

@m2-assistant
Copy link

m2-assistant bot commented Apr 16, 2020

Hi @krisdante, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants