I've got a persistent warning across all the compilers I've tried.
It has to do with the
srf var
in the "What have you tried" section.
Basically the compiler doesn't know that
srf
can't be very big.
Specifically, it is limited to the difference in bit depth between one pixel and another which is practically limited to 63 max for a 64-bit word, 31 for a 32-bit word, etc. I have
static_asserts
elsewhere that limit
bit_depth
.
I know it will never overflow, but (hopefully without supressing warnings) how do I tell the compiler it can't be greater than some value such that this warning won't appear?
What I have tried:
template <typename ChannelLhs,typename ChannelRhs>
constexpr inline static typename ChannelRhs::int_type convert_channel_depth(typename ChannelLhs::int_type v) {
typename ChannelRhs::int_type rv=0;
if(ChannelLhs::bit_depth==0 || ChannelRhs::bit_depth==0) return 0;
const uint8_t srf = (int)ChannelLhs::bit_depth-(int)ChannelRhs::bit_depth;
if(0<srf) {
rv = (typename ChannelRhs::int_type)(v>>(0>srf?0:srf));
rv = clamp(rv,ChannelRhs::min,ChannelRhs::max);
} else if(0>srf) {
float vs = v*ChannelLhs::scaler;
rv = clamp((typename ChannelRhs::int_type)
(vs*ChannelRhs::scale+.5),ChannelRhs::min,ChannelRhs::max);
} else
rv = (typename ChannelRhs::int_type)(v);
return rv;
}