diff options
| author | UjinT34 <41110182+UjinT34@users.noreply.github.com> | 2026-04-16 21:19:25 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-04-16 19:19:25 +0100 |
| commit | 66ea2e2c9ed4e9257521e6706fbd21feb7e3cc5b (patch) | |
| tree | 6c0c9842245917e9828874263cd11d6f556a0a48 /src/helpers/cm | |
| parent | 4cce7f60a9c8772d18ffb43cb74aa227ab4b3bc4 (diff) | |
renderer: Various CM fixes, part 8 of refactors (#13860)
Part 8 of Ujin's refactors.
Diffstat (limited to 'src/helpers/cm')
| -rw-r--r-- | src/helpers/cm/ColorManagement.cpp | 30 | ||||
| -rw-r--r-- | src/helpers/cm/ColorManagement.hpp | 60 |
2 files changed, 88 insertions, 2 deletions
diff --git a/src/helpers/cm/ColorManagement.cpp b/src/helpers/cm/ColorManagement.cpp index 829adbe7..5e4725d4 100644 --- a/src/helpers/cm/ColorManagement.cpp +++ b/src/helpers/cm/ColorManagement.cpp @@ -1,10 +1,12 @@ #include "ColorManagement.hpp" #include "../../macros.hpp" +#include "helpers/TransferFunction.hpp" #include <hyprutils/memory/UniquePtr.hpp> #include <map> #include <vector> using namespace NColorManagement; +using namespace NTransferFunction; namespace NColorManagement { // expected to be small @@ -110,6 +112,20 @@ WP<const CPrimaries> CImageDescription::getPrimaries() const { return CPrimaries::from(m_primariesId); } +bool CImageDescription::needsCM(WP<const CImageDescription> target) const { + if (m_id == target->m_id) + return false; + + return m_imageDescription.icc.present || target->m_imageDescription.icc.present // TODO compare ICC + || m_imageDescription.transferFunction != target->m_imageDescription.transferFunction // + //|| m_imageDescription.transferFunctionPower != target->m_imageDescription.transferFunctionPower // TODO unsupported + || m_imageDescription.getPrimaries() != target->m_imageDescription.getPrimaries() // + // || m_imageDescription.masteringPrimaries != target->m_imageDescription.masteringPrimaries // TODO unused + || m_imageDescription.luminances != target->m_imageDescription.luminances // + // || m_imageDescription.masteringLuminances != target->m_imageDescription.masteringLuminances // TODO unused + ; +} + static Mat3x3 diag3(const std::array<float, 3>& s) { return Mat3x3{std::array<float, 9>{s[0], 0, 0, 0, s[1], 0, 0, 0, s[2]}}; } @@ -190,4 +206,16 @@ Mat3x3 NColorManagement::adaptBradford(Hyprgraphics::CColor::xy srcW, Hyprgraphi result.multiply(diag3(scale)).multiply(Bradford); return result; -}
\ No newline at end of file +} + +PImageDescription NColorManagement::getDefaultImageDescription() { + const auto TF = fromConfig(); + switch (TF) { + case TF_AUTO: + case TF_GAMMA22: + case TF_FORCED_GAMMA22: return DEFAULT_GAMMA22_IMAGE_DESCRIPTION; + case TF_DEFAULT: + case TF_SRGB: return DEFAULT_SRGB_IMAGE_DESCRIPTION; + default: UNREACHABLE(); + } +} diff --git a/src/helpers/cm/ColorManagement.hpp b/src/helpers/cm/ColorManagement.hpp index dccbb972..183a8544 100644 --- a/src/helpers/cm/ColorManagement.hpp +++ b/src/helpers/cm/ColorManagement.hpp @@ -1,11 +1,13 @@ #pragma once #include "color-management-v1.hpp" +#include <format> #include <hyprgraphics/color/Color.hpp> #include "../../helpers/memory/Memory.hpp" #include "../../helpers/math/Math.hpp" #include <filesystem> +#include <string> #include <vector> #include <expected> @@ -78,6 +80,24 @@ namespace NColorManagement { default: return sc<eTransferFunction>(tf); } } + inline std::string tfToString(eTransferFunction tf) { + switch (tf) { + case CM_TRANSFER_FUNCTION_BT1886: return "TF:BT1886"; + case CM_TRANSFER_FUNCTION_GAMMA22: return "TF:GAMMA22"; + case CM_TRANSFER_FUNCTION_GAMMA28: return "TF:GAMMA28"; + case CM_TRANSFER_FUNCTION_ST240: return "TF:ST240"; + case CM_TRANSFER_FUNCTION_EXT_LINEAR: return "TF:EXT_LINEAR"; + case CM_TRANSFER_FUNCTION_LOG_100: return "TF:LOG_100"; + case CM_TRANSFER_FUNCTION_LOG_316: return "TF:LOG_316"; + case CM_TRANSFER_FUNCTION_XVYCC: return "TF:XVYCC"; + case CM_TRANSFER_FUNCTION_SRGB: return "TF:SRGB"; + case CM_TRANSFER_FUNCTION_EXT_SRGB: return "TF:EXT_SRGB"; + case CM_TRANSFER_FUNCTION_ST2084_PQ: return "TF:ST2084_PQ"; + case CM_TRANSFER_FUNCTION_ST428: return "TF:ST428"; + case CM_TRANSFER_FUNCTION_HLG: return "TF:HLG"; + default: return "TF:ERROR"; + } + } using SPCPRimaries = Hyprgraphics::SPCPRimaries; @@ -320,6 +340,7 @@ namespace NColorManagement { uint64_t id() const; WP<const CPrimaries> getPrimaries() const; + bool needsCM(WP<const CImageDescription> target) const; private: CImageDescription(const SImageDescription& imageDescription, const uint64_t imageDescriptionId); @@ -330,7 +351,9 @@ namespace NColorManagement { using PImageDescription = WP<const CImageDescription>; - static const auto DEFAULT_IMAGE_DESCRIPTION = CImageDescription::from(SImageDescription{ + PImageDescription getDefaultImageDescription(); + + static const auto DEFAULT_GAMMA22_IMAGE_DESCRIPTION = CImageDescription::from(SImageDescription{ .transferFunction = NColorManagement::CM_TRANSFER_FUNCTION_GAMMA22, .primariesNameSet = true, .primariesNamed = NColorManagement::CM_PRIMARIES_SRGB, @@ -338,6 +361,14 @@ namespace NColorManagement { .luminances = {.min = SDR_MIN_LUMINANCE, .max = 80, .reference = 80}, }); + static const auto DEFAULT_SRGB_IMAGE_DESCRIPTION = CImageDescription::from(SImageDescription{ + .transferFunction = NColorManagement::CM_TRANSFER_FUNCTION_SRGB, + .primariesNameSet = true, + .primariesNamed = NColorManagement::CM_PRIMARIES_SRGB, + .primaries = NColorManagement::getPrimaries(NColorManagement::CM_PRIMARIES_SRGB), + .luminances = {.min = SDR_MIN_LUMINANCE, .max = 80, .reference = 80}, + }); + static const auto DEFAULT_HDR_IMAGE_DESCRIPTION = CImageDescription::from(SImageDescription{ .transferFunction = NColorManagement::CM_TRANSFER_FUNCTION_ST2084_PQ, .primariesNameSet = true, @@ -363,3 +394,30 @@ namespace NColorManagement { .luminances = {.min = 0, .max = 10000, .reference = 80}, }); } + +template <typename CharT> +struct std::formatter<Hyprgraphics::SPCPRimaries, CharT> : std::formatter<CharT> { + template <typename FormatContext> + auto format(const Hyprgraphics::SPCPRimaries& primaries, FormatContext& ctx) const { + return std::format_to(ctx.out(), "[r={},{} g={},{} b={},{} w={},{}]", primaries.red.x, primaries.red.y, primaries.green.x, primaries.green.y, primaries.blue.x, + primaries.blue.y, primaries.white.x, primaries.white.y); + } +}; + +template <typename CharT> +struct std::formatter<NColorManagement::SImageDescription::SPCLuminances, CharT> : std::formatter<CharT> { + template <typename FormatContext> + auto format(const NColorManagement::SImageDescription::SPCLuminances& luminances, FormatContext& ctx) const { + return std::format_to(ctx.out(), "[{}-{}({})]", luminances.min, luminances.max, luminances.reference); + } +}; + +template <typename CharT> +struct std::formatter<NColorManagement::SImageDescription, CharT> : std::formatter<CharT> { + template <typename FormatContext> + auto format(const NColorManagement::SImageDescription& imageDescription, FormatContext& ctx) const { + return std::format_to(ctx.out(), "[{}{}, primaries={}, luminances={}]", NColorManagement::tfToString(imageDescription.transferFunction), + imageDescription.transferFunctionPower != 1.0f ? std::format("^{}", imageDescription.transferFunctionPower) : "", imageDescription.getPrimaries(), + imageDescription.luminances); + } +}; |
