Skip to content
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

Fix conversion from RGB to signed CMYK #522

Merged
merged 6 commits into from
Oct 10, 2020
Merged

Fix conversion from RGB to signed CMYK #522

merged 6 commits into from
Oct 10, 2020

Conversation

harshitpant1
Copy link
Contributor

@harshitpant1 harshitpant1 commented Oct 8, 2020

Description

Conversion of RGB pixels based on unsigned integral channels to CMYK based on signed integral channels was/is broken (issue #479). It happend because relations used for color correction like c' = (c - k) * s etc. didn't work well for signed integral channels.

This correction is attempted by doing all color correction calculations of pixel values based on unsigned integral channels then(after the calculations are finished) converting those values to signed ones.

References

Principles of Digital Image Processing - Fundamental Techniques (Book name provided in color_convert.hpp)

Tasklist

  • Add test case(s)
  • Ensure all CI builds pass
  • Review and approve

Copy link
Member

@mloskot mloskot left a comment

Choose a reason for hiding this comment

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

Thank you for the attempt to fix it.

Please, if you could DO ensure any new features or changes to existing behaviours are covered with test cases. IOW, please add a tests for the bug fix (see some samples in #479).

include/boost/gil/color_convert.hpp Outdated Show resolved Hide resolved
include/boost/gil/color_convert.hpp Outdated Show resolved Hide resolved
@mloskot mloskot added status/work-in-progress Do NOT merge yet until this label has been removed! cat/bug But reports and bug fixes labels Oct 8, 2020
@harshitpant1
Copy link
Contributor Author

@mloskot can you please have a look at the tests I just added.

@harshitpant1 harshitpant1 marked this pull request as ready for review October 9, 2020 17:41
Copy link
Member

@mloskot mloskot left a comment

Choose a reason for hiding this comment

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

Good work with the tests!

I added two nitpick comments.

We also need to update the build configuration, so we can build and run the test program locally and with the the CI builds, so if you could do this:

For Boost.Build, add run default_color_converter_rgb_to_cmyk.cpp ; below this line

run default_color_converter_impl.cpp ;

For CMake, remove ) from this line and add default_color_converter_rgb_to_cmyk) below this line:

default_color_converter_impl)

dst_t const y = channel_invert(channel_convert<dst_t>(b)); // y = 1 - b
dst_t const k = (std::min)(c, (std::min)(m, y)); // k = minimum(c, m, y)
using uint_t = typename channel_type<cmyk8_pixel_t>::type;
uint_t c = channel_invert(channel_convert<uint_t>(r)); // c = 1 - r
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: trailing space after r should be removed

uint_t c = channel_invert(channel_convert<uint_t>(r)); // c = 1 - r
uint_t m = channel_invert(channel_convert<uint_t>(g)); // m = 1 - g
uint_t y = channel_invert(channel_convert<uint_t>(b)); // y = 1 - b
uint_t k = (std::min)(c,(std::min)(m,y)); //k = minimum(c, m, y)
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: missing space before k in //k

@mloskot
Copy link
Member

mloskot commented Oct 10, 2020

The CI are failing because of

libs\gil\test\core\color\default_color_converter_rgb_to_cmyk.cpp(10):
  fatal error C1083: Cannot open include file: 'test_fixture.hpp':
  No such file or directory

I think you can remove include of this header from the test, as you don't seem to be using any fixture.

@harshitpant1
Copy link
Contributor Author

I guess I should have been more attentive and avoided that issue/fail.
The CI checks are successful now.
Thanks for your help.

@mloskot
Copy link
Member

mloskot commented Oct 10, 2020

We all learn from mistakes. As you see, submitting a PR is an effort.

I'm on mobile now and can't verify the result, but I'll take it from the CI, and I'll merge.

Thank you!

@mloskot mloskot removed the status/work-in-progress Do NOT merge yet until this label has been removed! label Oct 10, 2020
@mloskot mloskot added this to the Boost 1.75+ milestone Oct 10, 2020
@harshitpant1
Copy link
Contributor Author

Thank you as well.

@mloskot mloskot changed the title Fix conversion of rgb to signed cmyk(boostorg#479) Fix conversion from RGB to signed CMYK Nov 10, 2020
@mloskot mloskot modified the milestones: Boost 1.75, Boost 1.76+ Jan 22, 2021
@mloskot mloskot mentioned this pull request May 12, 2022
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cat/bug But reports and bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants