OSDN Git Service

Add IImgMergeWindow::SetColorDistanceThreshold() and GetColorDistanceThreshold()
authorsdottaka <sdottaka@sourceforge.net>
Fri, 26 Sep 2014 14:12:59 +0000 (23:12 +0900)
committersdottaka <sdottaka@sourceforge.net>
Fri, 26 Sep 2014 14:12:59 +0000 (23:12 +0900)
src/CImgMergeWindow.hpp
src/WinIMerge.cpp
src/WinIMerge.rc
src/WinIMergeLib.h
src/resource.h

index 765091f..c9cb4d8 100644 (file)
@@ -411,6 +411,7 @@ public:
                , m_currentDiffIndex(-1)\r
                , m_oldSplitPosX(-4)\r
                , m_oldSplitPosY(-4)\r
+               , m_colorDistanceThreshold(0.0)\r
        {\r
                for (int i = 0; i < 3; ++i)\r
                {\r
@@ -671,6 +672,17 @@ public:
                return maxpage;\r
        }\r
 \r
+       double GetColorDistanceThreshold() const\r
+       {\r
+               return m_colorDistanceThreshold;\r
+       }\r
+\r
+       void SetColorDistanceThreshold(double threshold)\r
+       {\r
+               m_colorDistanceThreshold = threshold;\r
+               CompareImages();\r
+       }\r
+\r
        int  GetDiffBlockSize() const\r
        {\r
                return m_diffBlockSize;\r
@@ -1478,7 +1490,7 @@ private:
                                {\r
                                        const BYTE *scanline1 = m_imgOrig32[pane1].getScanLine(h1 - y - 1);\r
                                        const BYTE *scanline2 = m_imgOrig32[pane2].getScanLine(h2 - y - 1);\r
-                                       if (w1 == w2)\r
+                                       if (w1 == w2 && m_colorDistanceThreshold == 0.0)\r
                                        {\r
                                                if (memcmp(scanline1, scanline2, w1 * 4) == 0)\r
                                                        continue;\r
@@ -1489,12 +1501,25 @@ private:
                                                        diff(x / m_diffBlockSize, by) = -1;\r
                                                else\r
                                                {\r
-                                                       if (scanline1[x * 4 + 0] != scanline2[x * 4 + 0] ||\r
-                                                           scanline1[x * 4 + 1] != scanline2[x * 4 + 1] ||\r
-                                                           scanline1[x * 4 + 2] != scanline2[x * 4 + 2] ||\r
-                                                           scanline1[x * 4 + 3] != scanline2[x * 4 + 3])\r
+                                                       if (m_colorDistanceThreshold > 0.0)\r
+                                                       {\r
+                                                               int bdist = scanline1[x * 4 + 0] - scanline2[x * 4 + 0];\r
+                                                               int gdist = scanline1[x * 4 + 1] - scanline2[x * 4 + 1];\r
+                                                               int rdist = scanline1[x * 4 + 2] - scanline2[x * 4 + 2];\r
+                                                               int adist = scanline1[x * 4 + 3] - scanline2[x * 4 + 3];\r
+                                                               int colorDistance2 = rdist * rdist + gdist * gdist + bdist * bdist + adist * adist;\r
+                                                               if (colorDistance2 > m_colorDistanceThreshold * m_colorDistanceThreshold)\r
+                                                                       diff(x / m_diffBlockSize, by) = -1;\r
+                                                       }\r
+                                                       else\r
                                                        {\r
-                                                               diff(x / m_diffBlockSize, by) = -1;\r
+                                                               if (scanline1[x * 4 + 0] != scanline2[x * 4 + 0] ||\r
+                                                                       scanline1[x * 4 + 1] != scanline2[x * 4 + 1] ||\r
+                                                                       scanline1[x * 4 + 2] != scanline2[x * 4 + 2] ||\r
+                                                                       scanline1[x * 4 + 3] != scanline2[x * 4 + 3])\r
+                                                               {\r
+                                                                       diff(x / m_diffBlockSize, by) = -1;\r
+                                                               }\r
                                                        }\r
                                                }\r
                                        }\r
@@ -1971,6 +1996,7 @@ private:
        COLORREF m_selDiffColor;\r
        COLORREF m_diffColor;\r
        double   m_diffColorAlpha;\r
+       double   m_colorDistanceThreshold;\r
        int m_currentPage[3];\r
        int m_currentDiffIndex;\r
        int m_diffCount;\r
index c49ff47..fad8981 100644 (file)
@@ -170,6 +170,19 @@ void UpdateMenuState(HWND hWnd)
        }\r
        CheckMenuRadioItem(hMenu, ID_VIEW_DIFFBLOCKSIZE_1, ID_VIEW_DIFFBLOCKSIZE_32, id, MF_BYCOMMAND);\r
        CheckMenuItem(hMenu, ID_VIEW_USEBACKCOLOR, m_pImgMergeWindow->GetUseBackColor() ? MF_CHECKED : MF_UNCHECKED);\r
+       int threshold = static_cast<int>(m_pImgMergeWindow->GetColorDistanceThreshold());\r
+       if (threshold == 0)\r
+               id = ID_VIEW_THRESHOLD_0;\r
+       else\r
+       {\r
+               id = ID_VIEW_THRESHOLD_2;\r
+               while (threshold > 2)\r
+               {\r
+                       ++id;\r
+                       threshold >>= 1;\r
+               }\r
+       }\r
+       CheckMenuRadioItem(hMenu, ID_VIEW_THRESHOLD_0, ID_VIEW_THRESHOLD_64, id, MF_BYCOMMAND);\r
 }\r
 \r
 void UpdateStatusBar()\r
@@ -404,6 +417,19 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
                        m_pImgMergeWindow->SetDiffBlockSize(1 << (wmId - ID_VIEW_DIFFBLOCKSIZE_1));\r
                        UpdateMenuState(hWnd);\r
                        break;\r
+               case ID_VIEW_THRESHOLD_0:\r
+                       m_pImgMergeWindow->SetColorDistanceThreshold(0);\r
+                       UpdateMenuState(hWnd);\r
+                       break;\r
+               case ID_VIEW_THRESHOLD_2:\r
+               case ID_VIEW_THRESHOLD_4:\r
+               case ID_VIEW_THRESHOLD_8:\r
+               case ID_VIEW_THRESHOLD_16:\r
+               case ID_VIEW_THRESHOLD_32:\r
+               case ID_VIEW_THRESHOLD_64:\r
+                       m_pImgMergeWindow->SetColorDistanceThreshold((1 << (wmId - ID_VIEW_THRESHOLD_2)) * 2.0);\r
+                       UpdateMenuState(hWnd);\r
+                       break;\r
                case ID_VIEW_SPLITHORIZONTALLY:\r
                        m_pImgMergeWindow->SetHorizontalSplit(!m_pImgMergeWindow->GetHorizontalSplit());\r
                        UpdateMenuState(hWnd);\r
index 1a12612..9631a6e 100644 (file)
@@ -124,6 +124,16 @@ BEGIN
             MENUITEM "1&6",                         ID_VIEW_DIFFBLOCKSIZE_16\r
             MENUITEM "&32",                         ID_VIEW_DIFFBLOCKSIZE_32\r
         END\r
+        POPUP "&Ignore Color Difference (Color Distance Threshold)"\r
+        BEGIN\r
+            MENUITEM "&0",                          ID_VIEW_THRESHOLD_0\r
+            MENUITEM "&2",                          ID_VIEW_THRESHOLD_2\r
+            MENUITEM "&4",                          ID_VIEW_THRESHOLD_4\r
+            MENUITEM "&8",                          ID_VIEW_THRESHOLD_8\r
+            MENUITEM "1&6",                         ID_VIEW_THRESHOLD_16\r
+            MENUITEM "&32",                         ID_VIEW_THRESHOLD_32\r
+            MENUITEM "64",                          ID_VIEW_THRESHOLD_64\r
+        END\r
         MENUITEM "Split &Horizontally",         ID_VIEW_SPLITHORIZONTALLY\r
         MENUITEM SEPARATOR\r
         MENUITEM "&Set Background Color",       ID_VIEW_USEBACKCOLOR\r
index 93d53e0..e772a5c 100644 (file)
@@ -80,6 +80,8 @@ struct IImgMergeWindow
        virtual void SetUseBackColor(bool useBackColor) = 0;\r
        virtual double GetZoom() const = 0;\r
        virtual void SetZoom(double zoom) = 0;\r
+       virtual double GetColorDistanceThreshold() const = 0;\r
+       virtual void SetColorDistanceThreshold(double threshold) = 0;\r
        virtual int  GetDiffBlockSize() const = 0;\r
        virtual void SetDiffBlockSize(int blockSize) = 0;\r
        virtual OVERLAY_MODE GetOverlayMode() const = 0;\r
index 27acb46..aeb5915 100644 (file)
 #define ID_VIEW_ZOOM_100                32782\r
 #define ID_VIEW_ZOOM_200                32783\r
 #define ID_VIEW_ZOOM_400                32784\r
-#define ID_VIEW_OVERLAY_NONE            32791\r
-#define ID_VIEW_OVERLAY_XOR             32792\r
-#define ID_VIEW_OVERLAY_ALPHABLEND      32793\r
-#define ID_VIEW_VIEWDIFFERENCES         32795\r
+#define ID_VIEW_OVERLAY_NONE            32785\r
+#define ID_VIEW_OVERLAY_XOR             32786\r
+#define ID_VIEW_OVERLAY_ALPHABLEND      32787\r
+#define ID_VIEW_VIEWDIFFERENCES         32788\r
+#define ID_VIEW_THRESHOLD_0             32789\r
+#define ID_VIEW_THRESHOLD_2             32790\r
+#define ID_VIEW_THRESHOLD_4             32791\r
+#define ID_VIEW_THRESHOLD_8             32792\r
+#define ID_VIEW_THRESHOLD_16            32793\r
+#define ID_VIEW_THRESHOLD_32            32794\r
+#define ID_VIEW_THRESHOLD_64            32795\r
 #define ID_MERGE_NEXTDIFFERENCE         32796\r
 #define ID_MERGE_PREVIOUSDIFFERENCE     32797\r
 #define ID_MERGE_FIRSTDIFFERENCE        32798\r