#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2021 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License #ifndef NUCLEX_PIXELS_PIXELFORMATS_CHANNELHELPERS_H #define NUCLEX_PIXELS_PIXELFORMATS_CHANNELHELPERS_H #include "Nuclex/Pixels/Config.h" #include "Nuclex/Pixels/PixelFormat.h" #include "Nuclex/Pixels/Half.h" #include "Nuclex/Pixels/UInt128.h" #include "PixelFormatDescription.h" #include "BitAdjust.h" #include "BitMask.h" #include // for std::conditional namespace Nuclex { namespace Pixels { namespace PixelFormats { // ------------------------------------------------------------------------------------------- // /// Integer type that can hold a pixel of the specified pixel format /// Pixel format for which to provide the type template using PixelTypeFromFormat = typename PixelFormatDescription::PixelType; // ------------------------------------------------------------------------------------------- // /// Whether the pixel format is signed (allows negative color values) /// Pixel format that will be checked template constexpr bool IsSignedFormat = ( (PixelFormatDescription::DataType == PixelFormatDataType::SignedInteger) || (PixelFormatDescription::DataType == PixelFormatDataType::FloatingPoint) ); // ------------------------------------------------------------------------------------------- // /// Whether the pixel format uses floating point channels /// Pixel format that will be checked template constexpr bool IsFloatFormat = ( (PixelFormatDescription::DataType == PixelFormatDataType::FloatingPoint) ); // ------------------------------------------------------------------------------------------- // /// Floating point type a channel is using based on its bit count /// Number of bits allocated to this channel template using ChannelFloatType = typename std::conditional< (bitCount >= 64), double, typename std::conditional<(bitCount >= 32), float, Nuclex::Pixels::Half>::type >::type; // ------------------------------------------------------------------------------------------- // /// Whether the red color channel needs to be converted /// Pixel format of the source pixel /// Pixel format of the target pixel template constexpr bool NeedConvertChannel1 = ( !std::is_same< typename PixelFormatDescription::Channel1, std::nullptr_t >::value && !std::is_same< typename PixelFormatDescription::Channel1, std::nullptr_t >::value ); // ------------------------------------------------------------------------------------------- // /// Whether the green color channel needs to be converted /// Pixel format of the source pixel /// Pixel format of the target pixel template constexpr bool NeedConvertChannel2 = ( !std::is_same< typename PixelFormatDescription::Channel2, std::nullptr_t >::value && !std::is_same< typename PixelFormatDescription::Channel2, std::nullptr_t >::value ); // ------------------------------------------------------------------------------------------- // /// Whether the blue color channel needs to be converted /// Pixel format of the source pixel /// Pixel format of the target pixel template constexpr bool NeedConvertChannel3 = ( !std::is_same< typename PixelFormatDescription::Channel3, std::nullptr_t >::value && !std::is_same< typename PixelFormatDescription::Channel3, std::nullptr_t >::value ); // ------------------------------------------------------------------------------------------- // /// Whether the alpha channel needs to be converted /// Pixel format of the source pixel /// Pixel format of the target pixel template constexpr bool NeedConvertChannel4 = ( !std::is_same< typename PixelFormatDescription::Channel4, std::nullptr_t >::value && !std::is_same< typename PixelFormatDescription::Channel4, std::nullptr_t >::value ); // ------------------------------------------------------------------------------------------- // /// Whether the specified pixel format contains an alpha channel /// /// Pixel format that will be checked for an alpha channel /// template constexpr bool HasAlphaChannel = !std::is_same< typename PixelFormatDescription::Channel4, std::nullptr_t >::value; // ------------------------------------------------------------------------------------------- // /// The larger of the source and target pixel types /// First format to find the larger pixel type in /// Second format to find the larger pixel type in template using LargerPixelType = typename std::conditional< ( sizeof(typename PixelFormatDescription::PixelType) >= sizeof(typename PixelFormatDescription::PixelType) ), typename PixelFormatDescription::PixelType, typename PixelFormatDescription::PixelType >::type; // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Pixels::PixelFormats #endif // NUCLEX_PIXELS_PIXELFORMATS_CHANNELHELPERS_H