Skip to content

Commit

Permalink
Added 3'th LCH layer, increased number of vertices, more CPU needed
Browse files Browse the repository at this point in the history
  • Loading branch information
awawa-dev committed Oct 25, 2024
1 parent 9e75efe commit a74b418
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 123 deletions.
13 changes: 10 additions & 3 deletions include/lut-calibrator/BestResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ using namespace aliases;
using namespace ColorSpaceMath;
using namespace BoardUtils;

struct LchLists
{
std::list<double4> low;
std::list<double4> mid;
std::list<double4> high;
};

struct BestResult
{
YuvConverter::YUV_COEFS coef = YuvConverter::YUV_COEFS::BT601;
Expand All @@ -64,7 +71,7 @@ struct BestResult
double gammaHLG = 0;
double nits = 0;
bool lchEnabled = false;
std::pair<std::list<double4>, std::list<double4>> lchPrimaries;
LchLists lchPrimaries;

struct Signal
{
Expand All @@ -79,7 +86,7 @@ struct BestResult

void serializePrimaries(std::stringstream& out) const
{
for (const auto& p : { lchPrimaries.first, lchPrimaries.second })
for (const auto& p : { lchPrimaries.low, lchPrimaries.mid, lchPrimaries.high })
{
out << std::endl << "\t\t\tstd::list<double4>{" << std::endl << "\t\t\t\t";
for (const auto& v : p)
Expand Down Expand Up @@ -107,7 +114,7 @@ struct BestResult
out << "bestResult.gamma = ColorSpaceMath::HDR_GAMMA(" << std::to_string(gamma) << ");" << std::endl;
out << "bestResult.gammaHLG = " << std::to_string(gammaHLG) << ";" << std::endl;
out << "bestResult.lchEnabled = " << std::to_string(lchEnabled) << ";" << std::endl;
out << "bestResult.lchPrimaries = std::pair<std::list<double4>, std::list<double4>>{"; serializePrimaries(out); out << "\t\t};" << std::endl;
out << "bestResult.lchPrimaries = LchLists{"; serializePrimaries(out); out << "\t\t};" << std::endl;
out << "bestResult.nits = " << std::to_string(nits) << ";" << std::endl;
out << "bestResult.signal.range = YuvConverter::COLOR_RANGE(" << std::to_string(signal.range) << ");" << std::endl;
out << "bestResult.signal.yRange = " << std::to_string(signal.yRange) << ";" << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion include/lut-calibrator/CapturedColor.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
class CapturedColor
{
public:
enum LchPrimaries { NONE, LOW, HIGH };
enum LchPrimaries { NONE, LOW, MID, HIGH };

private:
int totalSamples = 0;
Expand Down
112 changes: 41 additions & 71 deletions sources/lut-calibrator/CapturedColor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,21 @@ void CapturedColor::setCoords(const byte3& index)
}
else
{
lchPrimary = LchPrimaries::NONE;
MAX_IND = (BoardUtils::MAX_INDEX * 3) / 4;
if (std::max(std::max(index.x, index.y), index.z) == MAX_IND &&
((std::min(index.x, index.z) == 0 && std::max(index.x, index.z) == MAX_IND && (index.y % (MAX_IND / 2) == 0)) ||
(std::min(index.x, index.y) == 0 && std::max(index.x, index.y) == MAX_IND && (index.z % (MAX_IND / 2) == 0)) ||
(std::min(index.y, index.z) == 0 && std::max(index.y, index.z) == MAX_IND && (index.x % (MAX_IND / 2) == 0)) ||
(index.x == MAX_IND && index.y == MAX_IND && index.z == MAX_IND / 2) ||
(index.x == MAX_IND && index.y == MAX_IND / 2 && index.z == MAX_IND)
))
{
lchPrimary = LchPrimaries::MID;
}
else
{
lchPrimary = LchPrimaries::NONE;
}
}
}
}
Expand Down Expand Up @@ -262,104 +276,60 @@ std::list<std::pair<double3, int>> CapturedColor::getInputYuvColors() const

int CapturedColor::getSourceError(const int3& _color) const
{
constexpr int LIMIT_MAX_UP = 248;
constexpr int LIMIT_MAX_DOWN = 232;
constexpr int LIMIT_MIDDLE_UP = 228;
constexpr int LIMIT_MIDDLE_DOWN = 220;

if ((arrayCoords.x == BoardUtils::MAX_INDEX - 1 && arrayCoords.x == arrayCoords.y && arrayCoords.y == arrayCoords.z &&
(_color.x > LIMIT_MAX_UP || _color.x < LIMIT_MAX_DOWN)))
return BoardUtils::MAX_CALIBRATION_ERROR;

if ((arrayCoords.x == BoardUtils::MAX_INDEX - 2 && arrayCoords.x == arrayCoords.y && arrayCoords.y == arrayCoords.z &&
(_color.x > LIMIT_MIDDLE_UP || _color.x < LIMIT_MIDDLE_DOWN)))
return BoardUtils::MAX_CALIBRATION_ERROR;

if (arrayCoords.x == BoardUtils::MAX_INDEX && arrayCoords.y == 0 && arrayCoords.z == 0 &&
_color.x < LIMIT_MIDDLE_DOWN)
return BoardUtils::MAX_CALIBRATION_ERROR;

if (arrayCoords.y == BoardUtils::MAX_INDEX && arrayCoords.x == 0 && arrayCoords.z == 0 &&
_color.y < LIMIT_MIDDLE_DOWN)
return BoardUtils::MAX_CALIBRATION_ERROR;

if (arrayCoords.z == BoardUtils::MAX_INDEX && arrayCoords.y == 0 && arrayCoords.x == 0 &&
_color.z < LIMIT_MIDDLE_DOWN)
return BoardUtils::MAX_CALIBRATION_ERROR;

if ((arrayCoords.x == BoardUtils::MAX_INDEX - 2 && arrayCoords.x == arrayCoords.y && arrayCoords.z == 0 &&
((_color.x + _color.y) > LIMIT_MIDDLE_UP * 2)))
return BoardUtils::MAX_CALIBRATION_ERROR;

if ((arrayCoords.x == BoardUtils::MAX_INDEX - 2 && arrayCoords.x == arrayCoords.z && arrayCoords.y == 0 &&
((_color.x + _color.z) > LIMIT_MIDDLE_UP * 2)))
return BoardUtils::MAX_CALIBRATION_ERROR;

if ((arrayCoords.y == BoardUtils::MAX_INDEX - 2 && arrayCoords.y == arrayCoords.z && arrayCoords.x == 0 &&
((_color.y + _color.z) > LIMIT_MIDDLE_UP * 2)))
return BoardUtils::MAX_CALIBRATION_ERROR;

if ((arrayCoords.x == BoardUtils::MAX_INDEX - 1 && arrayCoords.x == arrayCoords.y && arrayCoords.z == 0 &&
((_color.x + _color.y) > LIMIT_MAX_UP * 2)))
return BoardUtils::MAX_CALIBRATION_ERROR;

if ((arrayCoords.x == BoardUtils::MAX_INDEX - 1 && arrayCoords.x == arrayCoords.z && arrayCoords.y == 0 &&
((_color.x + _color.z) > LIMIT_MAX_UP * 2)))
return BoardUtils::MAX_CALIBRATION_ERROR;

if ((arrayCoords.y == BoardUtils::MAX_INDEX - 1 && arrayCoords.y == arrayCoords.z && arrayCoords.x == 0 &&
((_color.y + _color.z) > LIMIT_MAX_UP * 2)))
return BoardUtils::MAX_CALIBRATION_ERROR;

auto delta = linalg::abs( sourceRGB - _color);


if (sourceRGB.x == sourceRGB.y && sourceRGB.y == sourceRGB.z)
{
return (delta.x * delta.x * delta.x + delta.y * delta.y * delta.y + delta.z * delta.z * delta.z) * 100;
}
else if (sourceRGB.x == sourceRGB.y)
else if (
(arrayCoords.x == 0 || arrayCoords.x == BoardUtils::MAX_INDEX) &&
(arrayCoords.y == 0 || arrayCoords.y == BoardUtils::MAX_INDEX) &&
(arrayCoords.z == 0 || arrayCoords.z == BoardUtils::MAX_INDEX))
{
auto diff = std::abs(_color.x - _color.y);
if (_color.x > _color.y)
if (arrayCoords.x != BoardUtils::MAX_INDEX)
delta.x = (delta.x * 3) / 4;

if (arrayCoords.y != BoardUtils::MAX_INDEX)
delta.y = (delta.y * 3) / 4;

if (arrayCoords.z != BoardUtils::MAX_INDEX)
delta.z = (delta.z * 3) / 4;

return (delta.x * delta.x * delta.x + delta.y * delta.y * delta.y + delta.z * delta.z * delta.z) * 50;
}
else if (sourceRGB.x == sourceRGB.y)
{
if (_color.x >= _color.y)
{
delta.x = std::min(delta.x, diff);
delta.y = std::min(delta.y, diff);
return (delta.x * delta.x * delta.x + delta.y * delta.y * delta.y + delta.z * delta.z * delta.z) * 3 / 4;
}
else
{
delta.x = std::max(delta.x, diff);
delta.y = std::max(delta.y, diff);
return (delta.x * delta.x * delta.x + delta.y * delta.y * delta.y + delta.z * delta.z * delta.z) * 5 / 4;
}
}
else if (sourceRGB.x == sourceRGB.z)
{
auto diff = std::abs(_color.x - _color.z);

if (_color.z > _color.x)
if (_color.z >= _color.x)
{
delta.x = std::min(delta.x, diff);
delta.z = std::min(delta.z, diff);
return (delta.x * delta.x * delta.x + delta.y * delta.y * delta.y + delta.z * delta.z * delta.z) * 3 / 4;
}
else
{
delta.x = std::max(delta.x, diff);
delta.z = std::max(delta.z, diff);
return (delta.x * delta.x * delta.x + delta.y * delta.y * delta.y + delta.z * delta.z * delta.z) * 5 / 4;
}
}
else if (sourceRGB.y == sourceRGB.z)
{
auto diff = std::abs(_color.y - _color.z);

if (_color.z > _color.y)
if (_color.z >= _color.y)
{
delta.y = std::min(delta.y, diff);
delta.z = std::min(delta.z, diff);
return (delta.x * delta.x * delta.x + delta.y * delta.y * delta.y + delta.z * delta.z * delta.z) * 3 / 4;
}
else
{
delta.y = std::max(delta.y, diff);
delta.z = std::max(delta.z, diff);
return (delta.x * delta.x * delta.x + delta.y * delta.y * delta.y + delta.z * delta.z * delta.z) * 5 / 4;
}
}

Expand Down
Loading

0 comments on commit a74b418

Please sign in to comment.