diff --git a/Services/ReactionScannerService.cs b/Services/ReactionScannerService.cs --- a/Services/ReactionScannerService.cs +++ b/Services/ReactionScannerService.cs @@ -367,13 +367,13 @@ namespace DesertPaintCodex.Services // 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; diff --git a/Util/PixelColor.cs b/Util/PixelColor.cs --- a/Util/PixelColor.cs +++ b/Util/PixelColor.cs @@ -1,6 +1,5 @@ using System; using System.Drawing; -using DesertPaintCodex.Services; namespace DesertPaintCodex.Util { @@ -27,15 +26,15 @@ namespace DesertPaintCodex.Util 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); } } diff --git a/Util/Pixels.cs b/Util/Pixels.cs --- a/Util/Pixels.cs +++ b/Util/Pixels.cs @@ -37,12 +37,16 @@ namespace DesertPaintCodex.Util } // Compute length of horizontal bar starting at x,y using matching function - public int LengthOfColorAt(int x, int y, Func matchFunc) + public int LengthOfColorAt(int x, int y, int scanWidth, Func 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;