Skip to content

Commit

Permalink
Disambiguate clamp calls in exrToDpx.cpp
Browse files Browse the repository at this point in the history
C++17 now has `std::clamp`[^1], so the calls to `clamp` in this file
cause the compiler to error with[^2]

      /tmp/ctl-20240930-89937-yvomao/CTL-ctl-1.5.3/OpenEXR_CTL/exrdpx/exrToDpx.cpp:172:19: error: call to 'clamp' is ambiguous
        172 |                 (unsigned int) (clamp (float (pixel.r), 0.0f, 1023.0f) + 0.5f);
            |                                 ^~~~~
      /Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk/usr/include/c++/v1/__algorithm/clamp.h:35:1: note: candidate function [with _Tp = float]
         35 | clamp(_LIBCPP_LIFETIMEBOUND const _Tp& __v,
            | ^
      /opt/homebrew/include/Imath/ImathFun.h:77:1: note: candidate function [with T = float]
         77 | clamp (T a, T l, T h) IMATH_NOEXCEPT
            | ^
      /tmp/ctl-20240930-89937-yvomao/CTL-ctl-1.5.3/OpenEXR_CTL/exrdpx/exrToDpx.cpp:175:19: error: call to 'clamp' is ambiguous
        175 |                 (unsigned int) (clamp (float (pixel.g), 0.0f, 1023.0f) + 0.5f);
            |                                 ^~~~~
      /Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk/usr/include/c++/v1/__algorithm/clamp.h:35:1: note: candidate function [with _Tp = float]
         35 | clamp(_LIBCPP_LIFETIMEBOUND const _Tp& __v,
            | ^
      /opt/homebrew/include/Imath/ImathFun.h:77:1: note: candidate function [with T = float]
         77 | clamp (T a, T l, T h) IMATH_NOEXCEPT
            | ^
      /tmp/ctl-20240930-89937-yvomao/CTL-ctl-1.5.3/OpenEXR_CTL/exrdpx/exrToDpx.cpp:178:19: error: call to 'clamp' is ambiguous
        178 |                 (unsigned int) (clamp (float (pixel.b), 0.0f, 1023.0f) + 0.5f);
            |                                 ^~~~~
      /Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk/usr/include/c++/v1/__algorithm/clamp.h:35:1: note: candidate function [with _Tp = float]
         35 | clamp(_LIBCPP_LIFETIMEBOUND const _Tp& __v,
            | ^
      /opt/homebrew/include/Imath/ImathFun.h:77:1: note: candidate function [with T = float]
         77 | clamp (T a, T l, T h) IMATH_NOEXCEPT
            | ^
      3 errors generated.
      make[2]: *** [OpenEXR_CTL/exrdpx/CMakeFiles/exrdpx.dir/exrToDpx.cpp.o] Error 1

Both this code and `Imath::clamp` long predate `std::clamp`, so it seems
to me that `Imath::clamp` is what's intended here.

This fixes a build failure at Homebrew while rebuilding CTL for OpenEXR
3.3.0.[^3]

[^1]: https://en.cppreference.com/w/cpp/algorithm/clamp
[^2]: Logs available at https://github.com/Homebrew/homebrew-core/actions/runs/11113893071/job/30879442929?pr=192399#step:3:375
[^3]: See Homebrew/homebrew-core#192399
  • Loading branch information
carlocab committed Oct 3, 2024
1 parent b30c769 commit a92f1bf
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions OpenEXR_CTL/exrdpx/exrToDpx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,13 @@ writePixels
const Rgba &pixel = pixels[y][x];

unsigned int r =
(unsigned int) (clamp (float (pixel.r), 0.0f, 1023.0f) + 0.5f);
(unsigned int) (Imath::clamp (float (pixel.r), 0.0f, 1023.0f) + 0.5f);

unsigned int g =
(unsigned int) (clamp (float (pixel.g), 0.0f, 1023.0f) + 0.5f);
(unsigned int) (Imath::clamp (float (pixel.g), 0.0f, 1023.0f) + 0.5f);

unsigned int b =
(unsigned int) (clamp (float (pixel.b), 0.0f, 1023.0f) + 0.5f);
(unsigned int) (Imath::clamp (float (pixel.b), 0.0f, 1023.0f) + 0.5f);

unsigned int word = (r << 22) | (g << 12) | (b << 2);

Expand Down

0 comments on commit a92f1bf

Please sign in to comment.