I never fail to be impressed by this
-
Disclaimer: The following is intended to run in embedded environments that may not have a compliant STL if they have the STL at all. Some of this code could be replaced on systems with The STL to use std:: functionality. Anyway, it's code I wrote, but it's not my code that really impresses me about this, but rather the C++ compiler.
static_assert(pixel_type::template equals>::value,
"this code needs to be ported for your display format");That's a compile time check to determine if a pixel format is exactly the same as the specified pixel format. Not impressed yet? Those pixel formats are arbitrarily defined:
// creates an RGB pixel by making each channel
// one third of the whole. Any remainder bits
// are added to the green channel
template
using rgb_pixel = pixel<
channel_traits,
channel_traits,
channel_traits;
// creates an RGBA pixel by making each channel
// one quarter of the whole. Any remainder bits
// are added to the green channel
template
using rgba_pixel = pixel<
channel_traits,
channel_traits,
channel_traits,
channel_traits
;
// creates a grayscale or monochome pixel
template
using gsc_pixel = pixel<
channel_traits
;
// creates a Y'UV pixel by making each channel
// one third of the whole. Any remainder bits
// are added to the Y' channel
template
using yuv_pixel = pixel<
channel_traits,
channel_traits,
channel_traits
;And furthermore
// defines a channel for a pixel
template<
// the channel name, like channel_name::R
typename Name,
// the bit depth
size_t BitDepth,
// the minimum value
bits::uintx Min=0,
// the maximum value
#if HTCW_MAX_WORD >= 64
bits::uintx Max= ((BitDepth==64)?0xFFFFFFFFFFFFFFFF:((1< Max= ((BitDepth==32)?0xFFFFFFFF:((1<