cm: Use precomputed primaries conversion (#9814)
This commit is contained in:
parent
94bc132084
commit
49974d5e34
10 changed files with 164 additions and 136 deletions
|
|
@ -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);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue