Changeset - de6e00728a10
[Not reviewed]
default
0 3 0
Jason Maltzen - 12 months ago 2023-12-07 04:39:45
jason@hiddenachievement.com
Fixed scanning of RGB bars to correctly account for the right edge highlight. Fixes problems detecting high-value clipping.
3 files changed with 13 insertions and 10 deletions:
0 comments (0 inline, 0 general)
Services/ReactionScannerService.cs
Show inline comments
...
 
@@ -362,23 +362,23 @@ namespace DesertPaintCodex.Services
 
                    _swatchWidth = MinSwatchWidth;
 
                }
 
                return false;
 
            }
 
            
 
            // WE FOUND THE SWATCH!
 
            // Now we know where the color bars are.
 
            _lockedSwatchWidth = true;
 
            int redPixelCount = pixels.LengthOfColorAt(x, y + _redBarSpacing, PixelColor.IsRed);
 
            int redPixelCount = pixels.LengthOfColorAt(x, y + _redBarSpacing, _swatchWidth, PixelColor.IsRed);
 
            reactedColor.Red = (byte)Math.Round(redPixelCount * 255f / _swatchWidth);
 

	
 
            int greenPixelCount = pixels.LengthOfColorAt(x, y + _greenBarSpacing, PixelColor.IsGreen);
 
            int greenPixelCount = pixels.LengthOfColorAt(x, y + _greenBarSpacing, _swatchWidth, PixelColor.IsGreen);
 
            reactedColor.Green = (byte)Math.Round(greenPixelCount * 255f / _swatchWidth);
 

	
 
            int bluePixelCount = pixels.LengthOfColorAt(x, y + _blueBarSpacing, PixelColor.IsBlue);
 
            int bluePixelCount = pixels.LengthOfColorAt(x, y + _blueBarSpacing, _swatchWidth, PixelColor.IsBlue);
 
            reactedColor.Blue = (byte)Math.Round(bluePixelCount * 255f / _swatchWidth);
 
            WriteLog(LogVerbosity.Low, "Found the color swatch at {0}, {1}. Color={2} Red={3}px Green={4}px Blue={5}px", x, y, reactedColor, redPixelCount, greenPixelCount, bluePixelCount);
 
            return true;
 
        }
 

	
 
        public async Task<bool> CaptureReactionAsync(IProgress<float> progress)
 
        {
 
            _canceler = new CancellationTokenSource(); // You can't re-use these, sadly.
Util/PixelColor.cs
Show inline comments
 
using System;
 
using System.Drawing;
 
using DesertPaintCodex.Services;
 

	
 
namespace DesertPaintCodex.Util
 
{
 
    public class PixelColor
 
    {
 
        private const int ColorTolerance = 2;
 
        
 
        public static bool IsMatch(Color colorA, Color colorB)
...
 
@@ -22,21 +21,21 @@ namespace DesertPaintCodex.Util
 

	
 
        public static bool IsUiBackground(Color color)
 
        {
 
            return (color.R is >= 0x27 and <= 0x2F) && (color.G is >= 0x3B and <= 0x42) && (color.B is >= 0x41 and <= 0x48);
 
        }
 

	
 
        public static bool IsRed(Color color)
 
        {
 
            return (color.R > 0x9D) && (color.G < 0x60) && (color.B < 0x60);
 
            return (color.R > 0x9D) && (color.G < 0x64) && (color.B < 0x64);
 
        }
 
        public static bool IsGreen(Color color)
 
        {
 
            return (color.R < 0x60) && (color.G > 0x9D) && (color.B < 0x60);
 
            return (color.R < 0x64) && (color.G > 0x9D) && (color.B < 0x64);
 
        }
 
        public static bool IsBlue(Color color)
 
        {
 
            return (color.R < 0x60) && (color.G < 0x60) && (color.B > 0x9D);
 
            return (color.R < 0x64) && (color.G < 0x64) && (color.B > 0x9D);
 
        }
 

	
 
    }
 
}
...
 
\ No newline at end of file
Util/Pixels.cs
Show inline comments
...
 
@@ -32,22 +32,26 @@ namespace DesertPaintCodex.Util
 
            {
 
                Debug.WriteLine("Problem at position [" + x + ", " + y + "]");
 
            }
 
            
 
            return matchFunc(_bitmap.GetPixel(x * _pixelMultiplier, y * _pixelMultiplier));
 
        }
 

	
 
        // Compute length of horizontal bar starting at x,y using matching function
 
        public int LengthOfColorAt(int x, int y, Func<Color, bool> matchFunc)
 
        public int LengthOfColorAt(int x, int y, int scanWidth, Func<Color, bool> matchFunc)
 
        {
 
            int count = 0;
 
            for (int xVal = x; xVal < Width; ++xVal)
 
            for (int xVal = x; xVal < scanWidth + x; ++xVal)
 
            {
 
                if (!matchFunc(_bitmap.GetPixel(xVal * _pixelMultiplier, y * _pixelMultiplier))) break;
 
                Color c = _bitmap.GetPixel(xVal * _pixelMultiplier, y * _pixelMultiplier);
 
                if (!matchFunc(c))
 
                {
 
                    break;
 
                }
 
                ++count;
 
            }
 
            return count;
 
        }
 

	
 
        public bool IsSolidPatchAt(int x, int y, int patchWidth, int patchHeight)
 
        {
 
            if ((x + patchWidth >= Width) || (y + patchHeight >= Height)) return false;
0 comments (0 inline, 0 general)