
.. _program_listing_file_Src_GraphicsEngineVulkan_common_SrgbConversion.hpp:

Program Listing for File SrgbConversion.hpp
===========================================

|exhale_lsh| :ref:`Return to documentation for file <file_Src_GraphicsEngineVulkan_common_SrgbConversion.hpp>` (``Src/GraphicsEngineVulkan/common/SrgbConversion.hpp``)

.. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS

.. code-block:: cpp

   #pragma once
   
   #include <algorithm>
   #include <cmath>
   #include <cstdint>
   
   namespace Kataglyphis {
   
   // The decode an eR8G8B8A8Srgb sample applies.
   inline auto srgbChannelToLinear(uint8_t encoded) -> float
   {
       const float value = static_cast<float>(encoded) / 255.0F;
       return value <= 0.04045F ? value / 12.92F : std::pow((value + 0.055F) / 1.055F, 2.4F);
   }
   
   // The encode back to the nearest sRGB byte, clamped to [0, 1] first.
   inline auto linearToSrgbByte(float linear) -> unsigned char
   {
       const float v = std::clamp(linear, 0.0F, 1.0F);
       const float encoded = v <= 0.0031308F ? v * 12.92F : 1.055F * std::pow(v, 1.0F / 2.4F) - 0.055F;
       return static_cast<unsigned char>(std::lround(encoded * 255.0F));
   }
   
   }// namespace Kataglyphis
