Skip to content

Commit

Permalink
Add more test vertexes (959), change to square errors
Browse files Browse the repository at this point in the history
  • Loading branch information
awawa-dev committed Oct 26, 2024
1 parent a74b418 commit 4cb7d44
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 35 deletions.
2 changes: 1 addition & 1 deletion include/lut-calibrator/BestResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ struct BestResult
out << "bestResult.signal.upYLimit = " << std::to_string(signal.upYLimit) << ";" << std::endl;
out << "bestResult.signal.downYLimit = " << std::to_string(signal.downYLimit) << ";" << std::endl;
out << "bestResult.signal.yShift = " << std::to_string(signal.yShift) << ";" << std::endl;
out << "bestResult.minError = " << std::to_string(std::round(minError * 100.0) / 300000.0) << ";" << std::endl;
out << "bestResult.minError = " << std::to_string(std::round(minError * 100.0) / 30000.0) << ";" << std::endl;
out << "*/" << std::endl;
}
};
2 changes: 1 addition & 1 deletion include/lut-calibrator/BoardUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace BoardUtils
{
class CapturedColors;

constexpr long long int MAX_CALIBRATION_ERROR = 5000000;
constexpr long long int MAX_CALIBRATION_ERROR = 500000;

constexpr int SCREEN_BLOCKS_X = 48;
constexpr int SCREEN_BLOCKS_Y = 30;
Expand Down
2 changes: 1 addition & 1 deletion sources/led-drivers/schemas/schema-philipshue.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
"type": "boolean",
"format": "checkbox",
"title":"edt_dev_spec_candyGamma_title",
"default" : true,
"default" : false,
"propertyOrder" : 10
},
"restoreOriginalState": {
Expand Down
40 changes: 26 additions & 14 deletions sources/lut-calibrator/CapturedColor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,11 @@ std::list<std::pair<double3, int>> CapturedColor::getInputYuvColors() const
int CapturedColor::getSourceError(const int3& _color) const
{
auto delta = linalg::abs( sourceRGB - _color);

int error = std::min((delta.x * delta.x + delta.y * delta.y + delta.z * delta.z), (int)BoardUtils::MAX_CALIBRATION_ERROR);

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;
return error * 20;
}
else if (
(arrayCoords.x == 0 || arrayCoords.x == BoardUtils::MAX_INDEX) &&
Expand All @@ -297,42 +297,54 @@ int CapturedColor::getSourceError(const int3& _color) const
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;
return error * 5;
}
else if (sourceRGB.x == sourceRGB.y)
{
if (_color.x >= _color.y)
{
if (_color.x == _color.y)
{
return error / 4;
}
else if (_color.x > _color.y)
{
return (delta.x * delta.x * delta.x + delta.y * delta.y * delta.y + delta.z * delta.z * delta.z) * 3 / 4;
return error * 4 / 5;
}
else
{
return (delta.x * delta.x * delta.x + delta.y * delta.y * delta.y + delta.z * delta.z * delta.z) * 5 / 4;
return error * 6 / 5;
}
}
else if (sourceRGB.x == sourceRGB.z)
{
if (_color.z >= _color.x)
if (_color.z == _color.x)
{
return (delta.x * delta.x * delta.x + delta.y * delta.y * delta.y + delta.z * delta.z * delta.z) * 3 / 4;
return error / 4;
}
else if (_color.z > _color.x)
{
return error * 3 / 4;
}
else
{
return (delta.x * delta.x * delta.x + delta.y * delta.y * delta.y + delta.z * delta.z * delta.z) * 5 / 4;
return error * 5 / 4;
}
}
else if (sourceRGB.y == sourceRGB.z)
{
if (_color.z >= _color.y)
if (_color.z == _color.y)
{
return error / 4;
}
else if (_color.z > _color.y)
{
return (delta.x * delta.x * delta.x + delta.y * delta.y * delta.y + delta.z * delta.z * delta.z) * 3 / 4;
return error * 4 / 5;
}
else
{
return (delta.x * delta.x * delta.x + delta.y * delta.y * delta.y + delta.z * delta.z * delta.z) * 5 / 4;
return error * 6 / 5;
}
}


return (delta.x* delta.x* delta.x + delta.y * delta.y * delta.y + delta.z * delta.z * delta.z);
return error;
}
45 changes: 27 additions & 18 deletions sources/lut-calibrator/LutCalibrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -895,20 +895,29 @@ void CalibrationWorker::run()
auto& sample = *(*v).first;

auto minError = MAX_CALIBRATION_ERROR;
auto sampleList = sample.getInputYuvColors();

for (auto iter = sampleList.cbegin(); iter != sampleList.cend(); ++iter)
if (sample.U() == 128 && sample.V() == 128)
{
auto srgb = hdr_to_srgb(yuvConverter, (*iter).first, byte2{ sample.U(), sample.V() }, aspect, coefMatrix, HDR_GAMMA(gamma), gammaHLG, NITS, altConvert, bt2020_to_sRgb, tryBt2020Range, bestResult.signal, coloredAspectMode, colorAspect);
(*v).second = hdr_to_srgb(yuvConverter, sample.yuv(), byte2{ sample.U(), sample.V() }, aspect, coefMatrix, HDR_GAMMA(gamma), gammaHLG, NITS, altConvert, bt2020_to_sRgb, tryBt2020Range, bestResult.signal, coloredAspectMode, colorAspect);
auto SRGB = to_int3((*v).second * 255.0);
minError = sample.getSourceError(SRGB);
}
else
{
auto sampleList = sample.getInputYuvColors();
for (auto iter = sampleList.cbegin(); iter != sampleList.cend(); ++iter)
{
auto srgb = hdr_to_srgb(yuvConverter, (*iter).first, byte2{ sample.U(), sample.V() }, aspect, coefMatrix, HDR_GAMMA(gamma), gammaHLG, NITS, altConvert, bt2020_to_sRgb, tryBt2020Range, bestResult.signal, coloredAspectMode, colorAspect);

auto SRGB = to_int3(srgb * 255.0);
auto SRGB = to_int3(srgb * 255.0);

auto sampleError = sample.getSourceError(SRGB);
auto sampleError = sample.getSourceError(SRGB);

if (sampleError < minError)
{
(*v).second = srgb;
minError = sampleError;
if (sampleError < minError)
{
(*v).second = srgb;
minError = sampleError;
}
}
}

Expand Down Expand Up @@ -992,9 +1001,9 @@ void CalibrationWorker::run()
bestResult.lchEnabled = (lchFavour);
bestResult.lchPrimaries = selectedLchPrimaries;
printf("New local best score: %.3f (classic: %.3f, LCH: %.3f %s) for thread: %i. Gamma: %s, coef: %s, kr/kb: %s, yuvCorrection: %s\n",
bestResult.minError / 3000.0,
currentError / 3000.0,
lcHError / 3000.0,
bestResult.minError / 300.0,
currentError / 300.0,
lcHError / 300.0,
(bestResult.lchEnabled) ? "ON" : "OFF",
id,
QSTRING_CSTR(gammaToString(HDR_GAMMA(gamma))),
Expand All @@ -1012,7 +1021,7 @@ void CalibrationWorker::run()
}

if (bestResult.minError < MAX_CALIBRATION_ERROR)
printf("Finished thread: %i. Score: %.3f\n", id, bestResult.minError / 3000.0);
printf("Finished thread: %i. Score: %.3f\n", id, bestResult.minError / 300.0);
else
printf("Finished thread: %i. Could not find anything\n", id);

Expand All @@ -1034,7 +1043,7 @@ void LutCalibrator::fineTune(bool precise)
for (int b = MAX_IND; b >= 0; b--)
{

if ((r % 4 == 0 && g % 4 == 0 && b % 2 == 0) || (r == b && b == g) || (r == g && r > 0) || (r == b && r > 0)
if ((r % 4 == 0 && g % 4 == 0 && b % 2 == 0) || (r <= 6 && g <= 6 && b <= 6) || (r == b && b == g) || (r == g && r > 0) || (r == b && r > 0)
|| _capturedColors->all[r][g][b].isLchPrimary(nullptr) != CapturedColor::LchPrimaries::NONE)
{

Expand Down Expand Up @@ -1132,7 +1141,7 @@ void LutCalibrator::fineTune(bool precise)
printf("Processing gamma: %s, gammaHLG: %f, coef: %s. Current best gamma: %s, gammaHLG: %f, coef: %s (d:%s). Score: %.3f\n",
QSTRING_CSTR(gammaToString(HDR_GAMMA(gamma))), gammaHLG, QSTRING_CSTR(_yuvConverter->coefToString(YuvConverter::YUV_COEFS(coef))),
QSTRING_CSTR(gammaToString(HDR_GAMMA(bestResult->gamma))), bestResult->gammaHLG, QSTRING_CSTR(_yuvConverter->coefToString(YuvConverter::YUV_COEFS(bestResult->coef))),
QSTRING_CSTR(vecToString(bestResult->coefDelta)),bestResult->minError / 3000.0);
QSTRING_CSTR(vecToString(bestResult->coefDelta)),bestResult->minError / 300.0);

const int halfKDelta = (precise) ? 16 : 8;
const int krDelta = std::ceil((halfKDelta * 2.0) / QThreadPool::globalInstance()->maxThreadCount());
Expand Down Expand Up @@ -1206,7 +1215,7 @@ void LutCalibrator::calibration()
totalTime2 = InternalClock::now() - totalTime2;

// write result
Debug(_log, "Score: %.3f", bestResult->minError / 3000.0);
Debug(_log, "Score: %.3f", bestResult->minError / 300.0);
Debug(_log, "LCH: %s", (bestResult->lchEnabled) ? "Enabled" : "Disabled");
Debug(_log, "The first phase time: %.3fs", totalTime / 1000.0);
Debug(_log, "The second phase time: %.3fs", totalTime2 / 1000.0);
Expand Down Expand Up @@ -1276,7 +1285,7 @@ void LutCalibrator::calibration()
for (int g = MAX_IND; g >= 0; g--)
for (int b = MAX_IND; b >= 0; b--)
{
if ((r % 4 == 0 && g % 4 == 0 && b % 2 == 0) || (r == b && b == g) || (r == g && r > 0) || (r == b && r > 0)
if ((r % 4 == 0 && g % 4 == 0 && b % 2 == 0) || (r <= 6 && g <= 6 && b <= 6) || (r == b && b == g) || (r == g && r > 0) || (r == b && r > 0)
|| _capturedColors->all[r][g][b].isLchPrimary(nullptr) != CapturedColor::LchPrimaries::NONE)
{
auto sample = _capturedColors->all[r][g][b];
Expand All @@ -1291,7 +1300,7 @@ void LutCalibrator::calibration()
currentError += microError;
}
}
Debug(_log, "The control score: %.3f", currentError / 3000.0);
Debug(_log, "The control score: %.3f", currentError / 300.0);

// reload LUT
emit GlobalSignals::getInstance()->SignalRequestComponent(hyperhdr::Components::COMP_HDR, -1, false);
Expand Down

0 comments on commit 4cb7d44

Please sign in to comment.