Changeset - 532e5f429c0f
[Not reviewed]
default
0 1 0
Tess Snider (Malkyne) - 7 years ago 2018-04-26 04:48:53
this@malkyne.org
DPL should no longer scan entire screenshot, when the Pigment Lab dialog
has already been found, unless it has been moved.
1 file changed with 35 insertions and 5 deletions:
0 comments (0 inline, 0 general)
ReactionRecorder.cs
Show inline comments
...
 
@@ -47,8 +47,12 @@ namespace DesertPaintLab
 
        int greenBarSpacing = DEFAULT_GREEN_BAR_SPACING;
 
        int blueBarSpacing = DEFAULT_BLUE_BAR_SPACING;
 
        int pixelMultiplier = 1;
 

	
 
        bool firstRun = true;
 
        int lastSwatchX = -1;
 
        int lastSwatchY = -1;
 

	
 
        private static ReactionRecorder _instance;
 
        public static ReactionRecorder Instance
 
        {
 
            get {
...
 
@@ -250,17 +254,14 @@ namespace DesertPaintLab
 

	
 
            return result;
 
        }
 

	
 
        unsafe public bool CaptureReaction(byte* pixBytes, int screenshotWidth, int screenshotHeight, int stride, ref PaintColor reactedColor, ref int redPixelStart)
 
        unsafe private bool TestPosition(int x, int y, byte* pixBytes, int screenshotWidth, int screenshotHeight, int stride, ref PaintColor reactedColor, ref int redPixelStart)
 
        {
 
            byte pixel_r, pixel_g, pixel_b;
 
            int pixelStart, otherPixelStart;
 
            bool colorMatch = true;
 
            for (int x = 0; x < screenshotWidth - colorBarWidth; ++x)
 
            {
 
                for (int y = 0; y < (screenshotHeight - (blueBarSpacing + 1)  /*53*/); ++y)
 
                {
 

 
                    // Look for the color swatch.
 
                    pixelStart = (y * stride) + (x * 3);
 
                    pixel_r = pixBytes[pixelStart];
 
                    pixel_g = pixBytes[pixelStart + 1];
...
 
@@ -344,8 +345,37 @@ namespace DesertPaintLab
 
                            WriteLog("Found the color swatch at {0}, {1}. Color={2}", x, y, reactedColor);
 
                            return true;
 
                        }
 
                    }
 
            return false;
 
        }
 

	
 
        unsafe public bool CaptureReaction(byte* pixBytes, int screenshotWidth, int screenshotHeight, int stride, ref PaintColor reactedColor, ref int redPixelStart)
 
        {
 
            if (!firstRun)
 
            {
 
                // If this is not the first run, let's check the last location, to see if the UI is still there.
 
                if (TestPosition(lastSwatchX, lastSwatchY, pixBytes, screenshotWidth, screenshotHeight, stride, ref reactedColor, ref redPixelStart))
 
                {
 
                    return true;
 
                }
 
                else
 
                {
 
                    firstRun = true;
 
                }
 
            }
 

	
 
            for (int x = 0; x < screenshotWidth - colorBarWidth; ++x)
 
            {
 
                for (int y = 0; y < (screenshotHeight - (blueBarSpacing + 1)  /*53*/); ++y)
 
                {
 
                    if (TestPosition(x, y, pixBytes, screenshotWidth, screenshotHeight, stride, ref reactedColor, ref redPixelStart))
 
                    {
 
                        lastSwatchX = x;
 
                        lastSwatchY = y;
 
                        firstRun = false;
 
                        return true;
 
                    }
 
                }
 
            }
 
            return false;
 
        }
0 comments (0 inline, 0 general)