From f520940f9914528e33732826666fa6719985b5b0 Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Thu, 20 Apr 2023 08:24:23 +0900 Subject: [PATCH] Fix issue #29: Image compare: Increase color distance threshold (CD Threshold) --- src/WinIMergeLib/ImgToolWindow.hpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/WinIMergeLib/ImgToolWindow.hpp b/src/WinIMergeLib/ImgToolWindow.hpp index 6c3a56c..f8207ac 100644 --- a/src/WinIMergeLib/ImgToolWindow.hpp +++ b/src/WinIMergeLib/ImgToolWindow.hpp @@ -53,7 +53,7 @@ class CImgToolWindow : public IImgToolWindow SetDlgItemText(m_hWnd, IDC_DIFF_BLOCKSIZE_STATIC, buf); wsprintf(buf, _T("(%d)"), static_cast(m_pImgMergeWindow->GetDiffColorAlpha() * 100)); SetDlgItemText(m_hWnd, IDC_DIFF_BLOCKALPHA_STATIC, buf); - wsprintf(buf, _T("(%d)"), static_cast(m_pImgMergeWindow->GetColorDistanceThreshold())); + wsprintf(buf, _T("(%d)"), static_cast(m_pImgMergeWindow->GetColorDistanceThreshold() + 0.5)); SetDlgItemText(m_hWnd, IDC_DIFF_CDTHRESHOLD_STATIC, buf); wsprintf(buf, _T("(%d)"), static_cast(m_pImgMergeWindow->GetOverlayAlpha() * 100)); SetDlgItemText(m_hWnd, IDC_OVERLAY_ALPHA_STATIC, buf); @@ -63,7 +63,7 @@ class CImgToolWindow : public IImgToolWindow SendDlgItemMessage(m_hWnd, IDC_DIFF_HIGHLIGHT, BM_SETCHECK, m_pImgMergeWindow->GetShowDifferences() ? BST_CHECKED : BST_UNCHECKED, 0); SendDlgItemMessage(m_hWnd, IDC_DIFF_BLOCKSIZE_SLIDER, TBM_SETPOS, TRUE, m_pImgMergeWindow->GetDiffBlockSize()); SendDlgItemMessage(m_hWnd, IDC_DIFF_BLOCKALPHA_SLIDER, TBM_SETPOS, TRUE, static_cast(m_pImgMergeWindow->GetDiffColorAlpha() * 100)); - SendDlgItemMessage(m_hWnd, IDC_DIFF_CDTHRESHOLD_SLIDER, TBM_SETPOS, TRUE, static_cast(m_pImgMergeWindow->GetColorDistanceThreshold())); + SendDlgItemMessage(m_hWnd, IDC_DIFF_CDTHRESHOLD_SLIDER, TBM_SETPOS, TRUE, static_cast(ColorDistanceToSliderValue(m_pImgMergeWindow->GetColorDistanceThreshold()))); SendDlgItemMessage(m_hWnd, IDC_OVERLAY_ALPHA_SLIDER, TBM_SETPOS, TRUE, static_cast(m_pImgMergeWindow->GetOverlayAlpha() * 100)); SendDlgItemMessage(m_hWnd, IDC_ZOOM_SLIDER, TBM_SETPOS, TRUE, static_cast(m_pImgMergeWindow->GetZoom() * 8 - 8)); SendDlgItemMessage(m_hWnd, IDC_DIFF_INSERTION_DELETION_DETECTION_MODE, CB_SETCURSEL, m_pImgMergeWindow->GetInsertionDeletionDetectionMode(), 0); @@ -224,6 +224,22 @@ class CImgToolWindow : public IImgToolWindow } } + double SliderValueToColorDistance(int val) + { + if (val < 80) + return val * 100.0 / 80; + const double a = (sqrt(255 * 255 + 255 * 255 + 255 * 255) - 100) / pow(100 - 80, 2); + return 100.0 + a * pow(val - 80, 2); + } + + int ColorDistanceToSliderValue(double val) + { + if (val < 100) + return static_cast(val * 80 / 100); + const double a = (sqrt(255 * 255 + 255 * 255 + 255 * 255) - 100) / pow(100 - 80, 2); + return static_cast(sqrt((val - 100) / a) + 80); + } + void OnHScroll(HWND hwnd, HWND hwndCtl, UINT code, int pos) { int val = static_cast(SendMessage(hwndCtl, TBM_GETPOS, 0, 0)); @@ -236,7 +252,7 @@ class CImgToolWindow : public IImgToolWindow m_pImgMergeWindow->SetDiffBlockSize(val); break; case IDC_DIFF_CDTHRESHOLD_SLIDER: - m_pImgMergeWindow->SetColorDistanceThreshold(val); + m_pImgMergeWindow->SetColorDistanceThreshold(SliderValueToColorDistance(val)); break; case IDC_OVERLAY_ALPHA_SLIDER: m_pImgMergeWindow->SetOverlayAlpha(val / 100.0);