diff --git a/MainWindow.cs b/MainWindow.cs --- a/MainWindow.cs +++ b/MainWindow.cs @@ -106,9 +106,11 @@ public partial class MainWindow : Gtk.Wi rootWindow = Gdk.Global.DefaultRootWindow; // get its width and height - int screenWidth; - int screenHeight; - rootWindow.GetSize(out screenWidth, out screenHeight); + int detectedScreenWidth; + int detectedScreenHeight; + rootWindow.GetSize(out detectedScreenWidth, out detectedScreenHeight); + int screenWidth = detectedScreenWidth; + int screenHeight = detectedScreenHeight; int pixelMultiplier = 1; if ( DesertPaintLab.AppSettings.Load() == true ) @@ -123,6 +125,8 @@ public partial class MainWindow : Gtk.Wi this.DebugAction.Visible = enableDebugMenu; ScreenCheckDialog screenCheckDialog = new ScreenCheckDialog(); + // TODO: screenCheckDialog.DetectedWidth = detectedScreenWidth; + // TODO: screenCheckDialog.DetectedHeight = detectedScreenHeight; screenCheckDialog.ScreenWidth = screenWidth; screenCheckDialog.ScreenHeight = screenHeight; screenCheckDialog.GamePixelWidth = pixelMultiplier; diff --git a/ReactionRecorder.cs b/ReactionRecorder.cs --- a/ReactionRecorder.cs +++ b/ReactionRecorder.cs @@ -190,8 +190,13 @@ namespace DesertPaintLab unsafe private bool IsPossibleSwatchUpperLeft(byte* pixBytes, int x, int y, int stride) { - int testPixelStart = (y * stride) + (x * 3); - + int testPixelStart = (y * stride) + (x * 3); + + if (testPixelStart < stride) + { + return false; + } + bool result = true; // test the left edge for dark pixels int i = 0; @@ -200,15 +205,36 @@ namespace DesertPaintLab int otherPixelStart = testPixelStart + (stride * i); result &= IsDarkPixel(pixBytes[otherPixelStart], pixBytes[otherPixelStart+1], pixBytes[otherPixelStart+2]); } + if (!result) + { + // No dark border on the left side + // WriteLog("Failed to find left border for swatch at {0}, {1}", x, y); + return false; + } // test the dark top border and for papyrus above and below the swatch + bool borderError = false; int papyErrorCount = 0; for (i = 0; result && (i < swatchWidth); ++i) { int otherPixelStart = testPixelStart + (3 * i); - result &= IsDarkPixel(pixBytes[otherPixelStart], pixBytes[otherPixelStart+1], pixBytes[otherPixelStart+2]); - otherPixelStart = otherPixelStart - stride; - papyErrorCount += (IsPapyTexture(pixBytes[otherPixelStart], pixBytes[otherPixelStart+1], pixBytes[otherPixelStart+2]) ? 0 : 1); + bool isBorder = IsDarkPixel(pixBytes[otherPixelStart], pixBytes[otherPixelStart+1], pixBytes[otherPixelStart+2]); + result &= isBorder; + if (!isBorder) + { + borderError = true; + } + if (otherPixelStart >= stride) + { + otherPixelStart = otherPixelStart - stride; + papyErrorCount += (IsPapyTexture(pixBytes[otherPixelStart], pixBytes[otherPixelStart + 1], pixBytes[otherPixelStart + 2]) ? 0 : 1); + } + else + { + papyErrorCount++; + } + + // Checking along the bottom of the swatch - otherPixelStart = testPixelStart + (stride * swatchHeight) + (3 * i); papyErrorCount += (IsPapyTexture(pixBytes[otherPixelStart], pixBytes[otherPixelStart+1], pixBytes[otherPixelStart+2]) ? 0 : 1); } @@ -216,7 +242,10 @@ namespace DesertPaintLab result &= (papyErrorCount < (swatchWidth / 20)); // allow up to 5% error rate checking for papy texture, because this seems to be inconsistent if (!result && ((i > (swatchWidth*0.8)) || (papyErrorCount >= (swatchWidth/20)))) { - WriteLog("Found a potential swatch candidate of width {0} at {1},{2} that had {3} failures matching papyrus texture", i, x, y, papyErrorCount); + if (!borderError && (papyErrorCount < swatchWidth)) + { + WriteLog("Found a potential swatch candidate of width {0} at {1},{2} that had {3} failures matching papyrus texture", i, x, y, papyErrorCount); + } } return result;