-
Notifications
You must be signed in to change notification settings - Fork 163
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 invalid conversion from RGB8 to CMYK32 due to overflow #470
Fix invalid conversion from RGB8 to CMYK32 due to overflow #470
Conversation
f8ded25
to
0e0e5b1
Compare
4390df4
to
bc52e32
Compare
The fix is still not correct as it does not convert well for negative values of signed pixel types like Basically, RGB color value |
Correct calculation to correctly map CMYK 0 to minimum and 1 to maximum of input and output channel types. If float-point division is necessary, use double instead of float which may be too narrow for large operands. cmyk32_pixel_t is based on uint32_t which multiplication by its maximum may yield result too large to fit 32-bit float. For example, (uint32_t(c) - uint32_t(k)) * float(s) for c = 4294967295, k = 0, s = 1.0 results in 4294967300 value which does not fit uint32_t. Fixes boostorg#406
bc52e32
to
e545e38
Compare
* develop: Collect release notes for Boost 1.74 Fix missing header in numeric/kernel.hpp to make it self-contained (#502) Use perfect forwading from apply_operation to visit (#491) Fix typos and replace mpl with mp11 in tutorial (#494) Implemented mechanism to reverse kernel_2d (#489) added missing const& in extend_boundary parameters (#490) Add initializing image constructor (#486) Fix interleaved_view factory using point<std::ptrdiff_t> for dimension (#487) RELEASES.md: Remove beta tag [ci skip] Replace Boost.Variant with Boost.Variant2 (#474) Fix error plane_view_t is not a class or namespace name (#481) Fix image constructor from other image (#477) Fix overflow in RGB to CMYK32 conversion (#470)
Description
Correct calculation to correctly map CMYK 0 to minimum and 1 to maximum of input and output channel types.
If float-point division is necessary, use double instead of float which may be too narrow for large operands.
cmyk32_pixel_t
is based onuint32_t
which multiplication by its maximum may yield result too large to fit 32-bit float.For example,
(uint32_t(c) - uint32_t(k)) * float(s)
forc = 4294967295, k = 0, s = 1.0
results in
4294967300
value which does not fituint32_t
.FIXME: The original calculation was broken for signed CMYK target types. This has not been corrected yet, see #479
References
Tasklist
currently there are no related tests, to be added