diff options
| author | UjinT34 <41110182+UjinT34@users.noreply.github.com> | 2025-03-14 02:15:18 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-14 00:15:18 +0100 |
| commit | 8c97cb7858e5d6c35d1a055930904346fb4248db (patch) | |
| tree | 87d7e30393f9177d035183f273be54f03b9451d5 /src/protocols | |
| parent | e86d3a14e46d19d8a47f8ceb6410546715d45f10 (diff) | |
renderer: add simple color management (#9506)
Adds proper color management and transformations for CM surfaces.
Diffstat (limited to 'src/protocols')
| -rw-r--r-- | src/protocols/ColorManagement.cpp | 75 | ||||
| -rw-r--r-- | src/protocols/XXColorManagement.cpp | 45 | ||||
| -rw-r--r-- | src/protocols/types/ColorManagement.hpp | 35 |
3 files changed, 95 insertions, 60 deletions
diff --git a/src/protocols/ColorManagement.cpp b/src/protocols/ColorManagement.cpp index 1a95c8bf..b6aee17b 100644 --- a/src/protocols/ColorManagement.cpp +++ b/src/protocols/ColorManagement.cpp @@ -14,46 +14,47 @@ CColorManager::CColorManager(SP<CWpColorManagerV1> resource) : m_resource(resour if UNLIKELY (!good()) return; + m_resource->sendSupportedFeature(WP_COLOR_MANAGER_V1_FEATURE_PARAMETRIC); + m_resource->sendSupportedFeature(WP_COLOR_MANAGER_V1_FEATURE_SET_PRIMARIES); + m_resource->sendSupportedFeature(WP_COLOR_MANAGER_V1_FEATURE_SET_LUMINANCES); + if (PROTO::colorManagement->m_debug) { m_resource->sendSupportedFeature(WP_COLOR_MANAGER_V1_FEATURE_ICC_V2_V4); - m_resource->sendSupportedFeature(WP_COLOR_MANAGER_V1_FEATURE_PARAMETRIC); - m_resource->sendSupportedFeature(WP_COLOR_MANAGER_V1_FEATURE_SET_PRIMARIES); m_resource->sendSupportedFeature(WP_COLOR_MANAGER_V1_FEATURE_SET_TF_POWER); - m_resource->sendSupportedFeature(WP_COLOR_MANAGER_V1_FEATURE_SET_LUMINANCES); m_resource->sendSupportedFeature(WP_COLOR_MANAGER_V1_FEATURE_SET_MASTERING_DISPLAY_PRIMARIES); m_resource->sendSupportedFeature(WP_COLOR_MANAGER_V1_FEATURE_EXTENDED_TARGET_VOLUME); m_resource->sendSupportedFeature(WP_COLOR_MANAGER_V1_FEATURE_WINDOWS_SCRGB); } m_resource->sendSupportedPrimariesNamed(WP_COLOR_MANAGER_V1_PRIMARIES_SRGB); - if (PROTO::colorManagement->m_debug) { - m_resource->sendSupportedPrimariesNamed(WP_COLOR_MANAGER_V1_PRIMARIES_BT2020); // HDR for fullscreen only + m_resource->sendSupportedPrimariesNamed(WP_COLOR_MANAGER_V1_PRIMARIES_BT2020); + m_resource->sendSupportedPrimariesNamed(WP_COLOR_MANAGER_V1_PRIMARIES_PAL_M); + m_resource->sendSupportedPrimariesNamed(WP_COLOR_MANAGER_V1_PRIMARIES_PAL); + m_resource->sendSupportedPrimariesNamed(WP_COLOR_MANAGER_V1_PRIMARIES_NTSC); + m_resource->sendSupportedPrimariesNamed(WP_COLOR_MANAGER_V1_PRIMARIES_GENERIC_FILM); + m_resource->sendSupportedPrimariesNamed(WP_COLOR_MANAGER_V1_PRIMARIES_DCI_P3); + m_resource->sendSupportedPrimariesNamed(WP_COLOR_MANAGER_V1_PRIMARIES_DISPLAY_P3); + m_resource->sendSupportedPrimariesNamed(WP_COLOR_MANAGER_V1_PRIMARIES_ADOBE_RGB); - m_resource->sendSupportedPrimariesNamed(WP_COLOR_MANAGER_V1_PRIMARIES_PAL_M); - m_resource->sendSupportedPrimariesNamed(WP_COLOR_MANAGER_V1_PRIMARIES_PAL); - m_resource->sendSupportedPrimariesNamed(WP_COLOR_MANAGER_V1_PRIMARIES_NTSC); - m_resource->sendSupportedPrimariesNamed(WP_COLOR_MANAGER_V1_PRIMARIES_GENERIC_FILM); + if (PROTO::colorManagement->m_debug) { m_resource->sendSupportedPrimariesNamed(WP_COLOR_MANAGER_V1_PRIMARIES_CIE1931_XYZ); - m_resource->sendSupportedPrimariesNamed(WP_COLOR_MANAGER_V1_PRIMARIES_DCI_P3); - m_resource->sendSupportedPrimariesNamed(WP_COLOR_MANAGER_V1_PRIMARIES_DISPLAY_P3); - m_resource->sendSupportedPrimariesNamed(WP_COLOR_MANAGER_V1_PRIMARIES_ADOBE_RGB); } m_resource->sendSupportedTfNamed(WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_SRGB); - if (PROTO::colorManagement->m_debug) { - m_resource->sendSupportedTfNamed(WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_ST2084_PQ); // HDR for fullscreen only + m_resource->sendSupportedTfNamed(WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_GAMMA22); + m_resource->sendSupportedTfNamed(WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_GAMMA28); + m_resource->sendSupportedTfNamed(WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_EXT_LINEAR); + m_resource->sendSupportedTfNamed(WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_ST2084_PQ); + m_resource->sendSupportedTfNamed(WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_HLG); + if (PROTO::colorManagement->m_debug) { m_resource->sendSupportedTfNamed(WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_BT1886); - m_resource->sendSupportedTfNamed(WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_GAMMA22); - m_resource->sendSupportedTfNamed(WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_GAMMA28); m_resource->sendSupportedTfNamed(WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_ST240); - m_resource->sendSupportedTfNamed(WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_EXT_LINEAR); m_resource->sendSupportedTfNamed(WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_LOG_100); m_resource->sendSupportedTfNamed(WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_LOG_316); m_resource->sendSupportedTfNamed(WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_XVYCC); m_resource->sendSupportedTfNamed(WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_EXT_SRGB); m_resource->sendSupportedTfNamed(WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_ST428); - m_resource->sendSupportedTfNamed(WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_HLG); } m_resource->sendSupportedIntent(WP_COLOR_MANAGER_V1_RENDER_INTENT_PERCEPTUAL); @@ -162,11 +163,6 @@ CColorManager::CColorManager(SP<CWpColorManagerV1> resource) : m_resource(resour m_resource->setCreateParametricCreator([](CWpColorManagerV1* r, uint32_t id) { LOGM(TRACE, "New parametric creator for id={}", id); - if (!PROTO::colorManagement->m_debug) { - r->error(WP_COLOR_MANAGER_V1_ERROR_UNSUPPORTED_FEATURE, "Parametric creator is not supported"); - return; - } - const auto RESOURCE = PROTO::colorManagement->m_vParametricCreators.emplace_back( makeShared<CColorManagementParametricCreator>(makeShared<CWpImageDescriptionCreatorParamsV1>(r->client(), r->version(), id))); @@ -536,6 +532,10 @@ CColorManagementParametricCreator::CColorManagementParametricCreator(SP<CWpImage switch (tf) { case WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_SRGB: break; case WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_ST2084_PQ: break; + case WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_EXT_LINEAR: break; + case WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_GAMMA22: break; + case WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_GAMMA28: break; + case WP_COLOR_MANAGER_V1_TRANSFER_FUNCTION_HLG: break; default: r->error(WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_INVALID_TF, "Unsupported transfer function"); return; } @@ -566,11 +566,6 @@ CColorManagementParametricCreator::CColorManagementParametricCreator(SP<CWpImage return; } - if (!PROTO::colorManagement->m_debug && primaries != WP_COLOR_MANAGER_V1_PRIMARIES_SRGB) { - r->error(WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_INVALID_PRIMARIES_NAMED, "Unsupported primaries"); - return; - } - switch (primaries) { case WP_COLOR_MANAGER_V1_PRIMARIES_SRGB: case WP_COLOR_MANAGER_V1_PRIMARIES_BT2020: @@ -580,14 +575,18 @@ CColorManagementParametricCreator::CColorManagementParametricCreator(SP<CWpImage case WP_COLOR_MANAGER_V1_PRIMARIES_GENERIC_FILM: case WP_COLOR_MANAGER_V1_PRIMARIES_DCI_P3: case WP_COLOR_MANAGER_V1_PRIMARIES_DISPLAY_P3: - case WP_COLOR_MANAGER_V1_PRIMARIES_ADOBE_RGB: - settings.primariesNameSet = true; - settings.primariesNamed = convertPrimaries((wpColorManagerV1Primaries)primaries); - settings.primaries = getPrimaries(settings.primariesNamed); - valuesSet |= PC_PRIMARIES; - break; - default: r->error(WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_INVALID_PRIMARIES_NAMED, "Unsupported primaries"); - } + case WP_COLOR_MANAGER_V1_PRIMARIES_ADOBE_RGB: break; + default: + if (!PROTO::colorManagement->m_debug) { + r->error(WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_INVALID_PRIMARIES_NAMED, "Unsupported primaries"); + return; + } + } + + settings.primariesNameSet = true; + settings.primariesNamed = convertPrimaries((wpColorManagerV1Primaries)primaries); + settings.primaries = getPrimaries(settings.primariesNamed); + valuesSet |= PC_PRIMARIES; }); m_resource->setSetPrimaries( [this](CWpImageDescriptionCreatorParamsV1* r, int32_t r_x, int32_t r_y, int32_t g_x, int32_t g_y, int32_t b_x, int32_t b_y, int32_t w_x, int32_t w_y) { @@ -618,10 +617,6 @@ CColorManagementParametricCreator::CColorManagementParametricCreator(SP<CWpImage r->error(WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_INVALID_LUMINANCE, "Invalid luminances"); return; } - if (!PROTO::colorManagement->m_debug) { - r->error(WP_COLOR_MANAGER_V1_ERROR_UNSUPPORTED_FEATURE, "Luminances aren't supported"); - return; - } settings.luminances = SImageDescription::SPCLuminances{.min = min, .max = max_lum, .reference = reference_lum}; valuesSet |= PC_LUMINANCES; }); diff --git a/src/protocols/XXColorManagement.cpp b/src/protocols/XXColorManagement.cpp index 57d4c5fd..36ace0f2 100644 --- a/src/protocols/XXColorManagement.cpp +++ b/src/protocols/XXColorManagement.cpp @@ -3,6 +3,7 @@ #include "ColorManagement.hpp" #include "color-management-v1.hpp" #include "types/ColorManagement.hpp" +#include "xx-color-management-v4.hpp" using namespace NColorManagement; @@ -40,20 +41,22 @@ CXXColorManager::CXXColorManager(SP<CXxColorManagerV4> resource_) : resource(res resource->sendSupportedFeature(XX_COLOR_MANAGER_V4_FEATURE_SET_LUMINANCES); resource->sendSupportedPrimariesNamed(XX_COLOR_MANAGER_V4_PRIMARIES_SRGB); - // resource->sendSupportedPrimariesNamed(XX_COLOR_MANAGER_V4_PRIMARIES_PAL_M); - // resource->sendSupportedPrimariesNamed(XX_COLOR_MANAGER_V4_PRIMARIES_PAL); - // resource->sendSupportedPrimariesNamed(XX_COLOR_MANAGER_V4_PRIMARIES_NTSC); - // resource->sendSupportedPrimariesNamed(XX_COLOR_MANAGER_V4_PRIMARIES_GENERIC_FILM); + resource->sendSupportedPrimariesNamed(XX_COLOR_MANAGER_V4_PRIMARIES_PAL_M); + resource->sendSupportedPrimariesNamed(XX_COLOR_MANAGER_V4_PRIMARIES_PAL); + resource->sendSupportedPrimariesNamed(XX_COLOR_MANAGER_V4_PRIMARIES_NTSC); + resource->sendSupportedPrimariesNamed(XX_COLOR_MANAGER_V4_PRIMARIES_GENERIC_FILM); resource->sendSupportedPrimariesNamed(XX_COLOR_MANAGER_V4_PRIMARIES_BT2020); // resource->sendSupportedPrimariesNamed(XX_COLOR_MANAGER_V4_PRIMARIES_CIE1931_XYZ); - // resource->sendSupportedPrimariesNamed(XX_COLOR_MANAGER_V4_PRIMARIES_DCI_P3); - // resource->sendSupportedPrimariesNamed(XX_COLOR_MANAGER_V4_PRIMARIES_DISPLAY_P3); - // resource->sendSupportedPrimariesNamed(XX_COLOR_MANAGER_V4_PRIMARIES_ADOBE_RGB); + resource->sendSupportedPrimariesNamed(XX_COLOR_MANAGER_V4_PRIMARIES_DCI_P3); + resource->sendSupportedPrimariesNamed(XX_COLOR_MANAGER_V4_PRIMARIES_DISPLAY_P3); + resource->sendSupportedPrimariesNamed(XX_COLOR_MANAGER_V4_PRIMARIES_ADOBE_RGB); - // resource->sendSupportedTfNamed(XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_GAMMA22); + resource->sendSupportedTfNamed(XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_GAMMA22); + resource->sendSupportedTfNamed(XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_GAMMA28); + resource->sendSupportedTfNamed(XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_HLG); resource->sendSupportedTfNamed(XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_SRGB); resource->sendSupportedTfNamed(XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_ST2084_PQ); - // resource->sendSupportedTfNamed(XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_LINEAR); + resource->sendSupportedTfNamed(XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_LINEAR); resource->sendSupportedIntent(XX_COLOR_MANAGER_V4_RENDER_INTENT_PERCEPTUAL); // resource->sendSupportedIntent(XX_COLOR_MANAGER_V4_RENDER_INTENT_RELATIVE); @@ -396,8 +399,12 @@ CXXColorManagementParametricCreator::CXXColorManagementParametricCreator(SP<CXxI } switch (tf) { - case XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_SRGB: break; - case XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_ST2084_PQ: break; + case XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_GAMMA22: + case XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_GAMMA28: + case XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_HLG: + case XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_SRGB: + case XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_ST2084_PQ: + case XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_LINEAR: break; default: r->error(XX_IMAGE_DESCRIPTION_CREATOR_PARAMS_V4_ERROR_INVALID_TF, "Unsupported transfer function"); return; } @@ -422,15 +429,17 @@ CXXColorManagementParametricCreator::CXXColorManagementParametricCreator(SP<CXxI switch (primaries) { case XX_COLOR_MANAGER_V4_PRIMARIES_SRGB: - settings.primariesNameSet = true; - settings.primariesNamed = convertPrimaries(getWPPrimaries(XX_COLOR_MANAGER_V4_PRIMARIES_SRGB)); - settings.primaries = NColorPrimaries::BT709; - valuesSet |= PC_PRIMARIES; - break; + case XX_COLOR_MANAGER_V4_PRIMARIES_PAL_M: + case XX_COLOR_MANAGER_V4_PRIMARIES_PAL: + case XX_COLOR_MANAGER_V4_PRIMARIES_NTSC: + case XX_COLOR_MANAGER_V4_PRIMARIES_GENERIC_FILM: case XX_COLOR_MANAGER_V4_PRIMARIES_BT2020: + case XX_COLOR_MANAGER_V4_PRIMARIES_DCI_P3: + case XX_COLOR_MANAGER_V4_PRIMARIES_DISPLAY_P3: + case XX_COLOR_MANAGER_V4_PRIMARIES_ADOBE_RGB: settings.primariesNameSet = true; - settings.primariesNamed = convertPrimaries(getWPPrimaries(XX_COLOR_MANAGER_V4_PRIMARIES_BT2020)); - settings.primaries = NColorPrimaries::BT2020; + settings.primariesNamed = convertPrimaries(getWPPrimaries((xxColorManagerV4Primaries)primaries)); + settings.primaries = getPrimaries(settings.primariesNamed); valuesSet |= PC_PRIMARIES; break; default: r->error(XX_IMAGE_DESCRIPTION_CREATOR_PARAMS_V4_ERROR_INVALID_PRIMARIES, "Unsupported primaries"); diff --git a/src/protocols/types/ColorManagement.hpp b/src/protocols/types/ColorManagement.hpp index 8c0643c1..143f47ca 100644 --- a/src/protocols/types/ColorManagement.hpp +++ b/src/protocols/types/ColorManagement.hpp @@ -48,10 +48,17 @@ namespace NColorManagement { } struct SPCPRimaries { - struct { + 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; + } }; namespace NColorPrimaries { @@ -102,6 +109,7 @@ namespace NColorManagement { .blue = {.x = 0.150, .y = 0.060}, .white = {.x = 0.314, .y = 0.351}, }; + static const auto DISPLAY_P3 = SPCPRimaries{ .red = {.x = 0.680, .y = 0.320}, .green = {.x = 0.265, .y = 0.690}, @@ -125,6 +133,9 @@ namespace NColorManagement { int fd = -1; uint32_t length = 0; uint32_t offset = 0; + bool operator==(const SIccFile& i2) const { + return fd == i2.fd; + } } icc; bool windowsScRGB = false; @@ -135,7 +146,8 @@ namespace NColorManagement { bool primariesNameSet = false; ePrimaries primariesNamed = CM_PRIMARIES_SRGB; // primaries are stored as FP values with the same scale as standard defines (0.0 - 1.0) - // wayland protocol expects int32_t values multiplied by 10000 + // wayland protocol expects int32_t values multiplied by 1000000 + // xx protocol expects int32_t values multiplied by 10000 // drm expects uint16_t values multiplied by 50000 // frog protocol expects drm values SPCPRimaries primaries, masteringPrimaries; @@ -146,13 +158,32 @@ namespace NColorManagement { float min = 0.2; // 0.2 cd/m² uint32_t max = 80; // 80 cd/m² uint32_t reference = 80; // 80 cd/m² + bool operator==(const SPCLuminances& l2) const { + return min == l2.min && max == l2.max && reference == l2.reference; + } } luminances; struct SPCMasteringLuminances { float min = 0; uint32_t max = 0; + bool operator==(const SPCMasteringLuminances& l2) const { + return min == l2.min && max == l2.max; + } } masteringLuminances; uint32_t maxCLL = 0; uint32_t maxFALL = 0; + + bool operator==(const SImageDescription& d2) const { + return (id != 0 && id == d2.id) || + (icc == d2.icc && windowsScRGB == d2.windowsScRGB && transferFunction == d2.transferFunction && transferFunctionPower == d2.transferFunctionPower && + ((primariesNameSet && primariesNamed == d2.primariesNameSet) || (primaries == d2.primaries)) && masteringPrimaries == d2.masteringPrimaries && + luminances == d2.luminances && masteringLuminances == d2.masteringLuminances && maxCLL == d2.maxCLL && maxFALL == d2.maxFALL); + } + + const SPCPRimaries& getPrimaries() const { + if (primariesNameSet || primaries == SPCPRimaries{}) + return NColorManagement::getPrimaries(primariesNamed); + return primaries; + } }; }
\ No newline at end of file |
