Boost GIL


Modules | Classes | Functions

Converting from one channel type to anotherConversion is done as a simple linear mapping of one channel range to the other, such that the minimum/maximum value of the source maps to the minimum/maximum value of the destination. One implication of this is that the value 0 of signed channels may not be preserved! More...

Modules

 channel_converter_unsigned
 Convert one unsigned/floating point channel to another. Converts both the channel type and range.
 

Classes

struct  channel_converter< SrcChannelV, DstChannelV >
 A unary function object converting between channel types. More...
 
struct  default_channel_converter
 Same as channel_converter, except it takes the destination channel by reference, which allows us to move the templates from the class level to the method level. This is important when invoking it on heterogeneous pixels. More...
 

Functions

template<typename DstChannel , typename SrcChannel >
channel_traits< DstChannel >::value_type channel_convert (const SrcChannel &src)
 Converting from one channel type to another.
 

Detailed Description

Converting from one channel type to another

Conversion is done as a simple linear mapping of one channel range to the other, such that the minimum/maximum value of the source maps to the minimum/maximum value of the destination. One implication of this is that the value 0 of signed channels may not be preserved!

When creating new channel models, it is often a good idea to provide specializations for the channel conversion algorithms, for example, for performance optimizations. If the new model is an integral type that can be signed, it is easier to define the conversion only for the unsigned type (channel_converter_unsigned) and provide specializations of detail::channel_convert_to_unsigned and detail::channel_convert_from_unsigned to convert between the signed and unsigned type.

Example:

// float32_t is a floating point channel with range [0.0f ... 1.0f]
float32_t src_channel = channel_traits<float32_t>::max_value();
assert(src_channel == 1);
// uint8_t is 8-bit unsigned integral channel (aliased from unsigned char)
uint8_t dst_channel = channel_convert<uint8_t>(src_channel);
assert(dst_channel == 255); // max value goes to max value