diff options
| author | UjinT34 <41110182+UjinT34@users.noreply.github.com> | 2025-04-29 22:29:40 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-29 21:29:40 +0200 |
| commit | 49974d5e34292ede24351c8638fe060b382bbda0 (patch) | |
| tree | 162b1dab426dd3d152cc76fb5f42f6d10cf09968 /src/protocols | |
| parent | 94bc1320843e4f45c4b8d3fd3cd08f8914b5fa13 (diff) | |
cm: Use precomputed primaries conversion (#9814)
Diffstat (limited to 'src/protocols')
| -rw-r--r-- | src/protocols/ColorManagement.cpp | 22 | ||||
| -rw-r--r-- | src/protocols/types/ColorManagement.cpp | 28 | ||||
| -rw-r--r-- | src/protocols/types/ColorManagement.hpp | 62 |
3 files changed, 82 insertions, 30 deletions
diff --git a/src/protocols/ColorManagement.cpp b/src/protocols/ColorManagement.cpp index 91dc0eac..29d9d248 100644 --- a/src/protocols/ColorManagement.cpp +++ b/src/protocols/ColorManagement.cpp @@ -8,8 +8,6 @@ using namespace NColorManagement; -static uint64_t lastImageID = 0; // FIXME use for deduplication - CColorManager::CColorManager(SP<CWpColorManagerV1> resource) : m_resource(resource) { if UNLIKELY (!good()) return; @@ -191,14 +189,13 @@ CColorManager::CColorManager(SP<CWpColorManagerV1> resource) : m_resource(resour } RESOURCE->self = RESOURCE; - RESOURCE->settings.id = ++lastImageID; RESOURCE->settings.windowsScRGB = true; RESOURCE->settings.primariesNamed = NColorManagement::CM_PRIMARIES_SRGB; RESOURCE->settings.primariesNameSet = true; RESOURCE->settings.primaries = NColorPrimaries::BT709; RESOURCE->settings.transferFunction = NColorManagement::CM_TRANSFER_FUNCTION_EXT_LINEAR; RESOURCE->settings.luminances.reference = 203; - RESOURCE->resource()->sendReady(RESOURCE->settings.id); + RESOURCE->resource()->sendReady(RESOURCE->settings.updateId()); }); m_resource->setOnDestroy([this](CWpColorManagerV1* r) { PROTO::colorManagement->destroyResource(this); }); @@ -239,9 +236,7 @@ CColorManagementOutput::CColorManagementOutput(SP<CWpColorManagementOutputV1> re RESOURCE->m_resource->sendFailed(WP_IMAGE_DESCRIPTION_V1_CAUSE_NO_OUTPUT, "No output"); else { RESOURCE->settings = m_monitor->imageDescription; - if (RESOURCE->settings.id) - RESOURCE->settings.id = ++lastImageID; - RESOURCE->m_resource->sendReady(RESOURCE->settings.id); // FIXME: create correct id + RESOURCE->m_resource->sendReady(RESOURCE->settings.updateId()); } }); } @@ -383,10 +378,7 @@ CColorManagementFeedbackSurface::CColorManagementFeedbackSurface(SP<CWpColorMana m_currentPreferred = RESOURCE; m_currentPreferred->settings = g_pCompositor->getPreferredImageDescription(); - if (!m_currentPreferred->settings.id) - m_currentPreferred->settings.id = ++lastImageID; - - RESOURCE->resource()->sendReady(++lastImageID); // FIXME: create correct id + RESOURCE->resource()->sendReady(m_currentPreferred->settings.updateId()); }); m_resource->setGetPreferredParametric([this](CWpColorManagementSurfaceFeedbackV1* r, uint32_t id) { @@ -419,7 +411,7 @@ CColorManagementFeedbackSurface::CColorManagementFeedbackSurface(SP<CWpColorMana return; } - RESOURCE->resource()->sendReady(++lastImageID); // FIXME: create correct id + RESOURCE->resource()->sendReady(m_currentPreferred->settings.updateId()); }); } @@ -467,8 +459,7 @@ CColorManagementIccCreator::CColorManagementIccCreator(SP<CWpImageDescriptionCre RESOURCE->self = RESOURCE; RESOURCE->settings = settings; - settings.id = ++lastImageID; - RESOURCE->resource()->sendReady(settings.id); // FIXME: create correct id + RESOURCE->resource()->sendReady(settings.updateId()); PROTO::colorManagement->destroyResource(this); }); @@ -522,8 +513,7 @@ CColorManagementParametricCreator::CColorManagementParametricCreator(SP<CWpImage RESOURCE->self = RESOURCE; RESOURCE->settings = settings; - settings.id = ++lastImageID; - RESOURCE->resource()->sendReady(settings.id); // FIXME: create correct id + RESOURCE->resource()->sendReady(settings.updateId()); PROTO::colorManagement->destroyResource(this); }); diff --git a/src/protocols/types/ColorManagement.cpp b/src/protocols/types/ColorManagement.cpp index 9daff1e2..e6b470d0 100644 --- a/src/protocols/types/ColorManagement.cpp +++ b/src/protocols/types/ColorManagement.cpp @@ -1,7 +1,11 @@ #include "ColorManagement.hpp" +#include <map> namespace NColorManagement { - const SPCPRimaries& getPrimaries(ePrimaries name) { + static uint32_t lastImageID = 0; + static std::map<uint32_t, SImageDescription> knownDescriptionIds; // expected to be small + + const SPCPRimaries& getPrimaries(ePrimaries name) { switch (name) { case CM_PRIMARIES_SRGB: return NColorPrimaries::BT709; case CM_PRIMARIES_BT2020: return NColorPrimaries::BT2020; @@ -17,4 +21,26 @@ namespace NColorManagement { } } + // TODO make image descriptions immutable and always set an id + + uint32_t SImageDescription::findId() const { + for (auto it = knownDescriptionIds.begin(); it != knownDescriptionIds.end(); ++it) { + if (it->second == *this) + return it->first; + } + + const auto newId = ++lastImageID; + knownDescriptionIds.insert(std::make_pair(newId, *this)); + return newId; + } + + uint32_t SImageDescription::getId() const { + return id > 0 ? id : findId(); + } + + uint32_t SImageDescription::updateId() { + id = 0; + id = findId(); + return id; + } }
\ No newline at end of file diff --git a/src/protocols/types/ColorManagement.hpp b/src/protocols/types/ColorManagement.hpp index 143f47ca..48d8dd31 100644 --- a/src/protocols/types/ColorManagement.hpp +++ b/src/protocols/types/ColorManagement.hpp @@ -1,6 +1,13 @@ #pragma once #include "color-management-v1.hpp" +#include <hyprgraphics/color/Color.hpp> + +#define SDR_MIN_LUMINANCE 0.2 +#define SDR_MAX_LUMINANCE 80.0 +#define HDR_MIN_LUMINANCE 0.005 +#define HDR_MAX_LUMINANCE 10000.0 +#define HLG_MAX_LUMINANCE 1000.0 namespace NColorManagement { enum ePrimaries : uint8_t { @@ -47,19 +54,7 @@ namespace NColorManagement { return (eTransferFunction)tf; } - struct SPCPRimaries { - struct xy { //NOLINT(readability-identifier-naming) - float x = 0; - float y = 0; - - bool operator==(const xy& p2) const { - return x == p2.x && y == p2.y; - } - } red, green, blue, white; - bool operator==(const SPCPRimaries& p2) const { - return red == p2.red && green == p2.green && blue == p2.blue && white == p2.white; - } - }; + typedef Hyprgraphics::SPCPRimaries SPCPRimaries; namespace NColorPrimaries { static const auto DEFAULT_PRIMARIES = SPCPRimaries{}; @@ -185,5 +180,46 @@ namespace NColorManagement { return NColorManagement::getPrimaries(primariesNamed); return primaries; } + + float getTFMinLuminance() const { + switch (transferFunction) { + case CM_TRANSFER_FUNCTION_EXT_LINEAR: return 0; + case CM_TRANSFER_FUNCTION_ST2084_PQ: + case CM_TRANSFER_FUNCTION_HLG: return HDR_MIN_LUMINANCE; + case CM_TRANSFER_FUNCTION_GAMMA22: + case CM_TRANSFER_FUNCTION_GAMMA28: + case CM_TRANSFER_FUNCTION_BT1886: + case CM_TRANSFER_FUNCTION_ST240: + case CM_TRANSFER_FUNCTION_LOG_100: + case CM_TRANSFER_FUNCTION_LOG_316: + case CM_TRANSFER_FUNCTION_XVYCC: + case CM_TRANSFER_FUNCTION_EXT_SRGB: + case CM_TRANSFER_FUNCTION_ST428: + case CM_TRANSFER_FUNCTION_SRGB: + default: return SDR_MIN_LUMINANCE; + } + }; + + float getTFMaxLuminance() const { + switch (transferFunction) { + case CM_TRANSFER_FUNCTION_ST2084_PQ: return HDR_MAX_LUMINANCE; + case CM_TRANSFER_FUNCTION_HLG: return HLG_MAX_LUMINANCE; + case CM_TRANSFER_FUNCTION_GAMMA22: + case CM_TRANSFER_FUNCTION_GAMMA28: + case CM_TRANSFER_FUNCTION_BT1886: + case CM_TRANSFER_FUNCTION_ST240: + case CM_TRANSFER_FUNCTION_LOG_100: + case CM_TRANSFER_FUNCTION_LOG_316: + case CM_TRANSFER_FUNCTION_XVYCC: + case CM_TRANSFER_FUNCTION_EXT_SRGB: + case CM_TRANSFER_FUNCTION_ST428: + case CM_TRANSFER_FUNCTION_SRGB: + default: return SDR_MAX_LUMINANCE; + } + }; + + uint32_t findId() const; + uint32_t getId() const; + uint32_t updateId(); }; }
\ No newline at end of file |
