diff --git a/ReactionRecorder.cs b/ReactionRecorder.cs --- a/ReactionRecorder.cs +++ b/ReactionRecorder.cs @@ -35,6 +35,11 @@ namespace DesertPaintLab const InterfaceSize DEFAULT_INTERFACE_SIZE = InterfaceSize.Small; + // Swatch is 301x20 solid color, 1px darker left/top, 1px black outer left/top, 1px light right/bottom, 1px bright right/bottom + // top-right and bottom-left are bright instead of black + + // Color bars are 4x302 solid color, 2px border on all sides (darker left/top, lighter bottom/right + public static readonly int[] SWATCH_HEIGHT = { 24, // tiny @@ -194,10 +199,14 @@ namespace DesertPaintLab private static bool IsPapyTexture(byte r, byte g, byte b) { // red between 208 and 244 + // 240 and 255 // green between 192 and 237 + // 223 and 248 // blue between 145 and 205 - return ((r > 0xD0) && (g >= 0xC0) && (b >= 0x91)) && - ((r < 0xF4) && (g <= 0xED) && (b <= 0xCD)); + // 178 and 228 + //return ((r > 0xD0) && (g >= 0xC0) && (b >= 0x91)) && + // ((r < 0xF4) && (g <= 0xED) && (b <= 0xCD)); + return ((r >= 0xF0) && (r <= 0xFF) && (g >= 0xDF) && (g <= 0xF8) && (b >= 0xB2) && (b <= 0xE4)); } public void SetPixelMultiplier(int pixelMultiplier) @@ -303,6 +312,40 @@ namespace DesertPaintLab } bool result = true; + + int solidUpperLeft = testPixelStart + (2 * y * stride) + (2 * x * 3); + int solidLowerLeft = testPixelStart + ((swatchHeight - 4) * stride); + int solidUpperRight = testPixelStart + ((swatchWidth - 4) * 3); + int solidLowerRight = solidLowerLeft + ((swatchWidth - 4) * 3); + byte swatch_r = pixBytes[solidUpperLeft]; + byte swatch_g = pixBytes[solidUpperLeft + 1]; + byte swatch_b = pixBytes[solidUpperLeft + 2]; + + // Check the other 3 corners of the swatch size for color match + result &= IsColorMatch(swatch_r, swatch_r, swatch_r, pixBytes[solidUpperRight], pixBytes[solidUpperRight + 1], pixBytes[solidUpperRight + 2]); + result &= IsColorMatch(swatch_r, swatch_r, swatch_r, pixBytes[solidLowerLeft], pixBytes[solidLowerLeft + 1], pixBytes[solidLowerLeft + 2]); + result &= IsColorMatch(swatch_r, swatch_r, swatch_r, pixBytes[solidLowerRight], pixBytes[solidLowerRight + 1], pixBytes[solidLowerRight + 2]); + + if (!result) + { + return false; + } + + // scan down the right and left sides + for (int yOff = 1; yOff < (swatchHeight - 5); ++yOff) + { + int testPixel = solidUpperLeft + (yOff * stride); + result &= IsColorMatch(swatch_r, swatch_r, swatch_r, pixBytes[testPixel], pixBytes[testPixel + 1], pixBytes[testPixel + 2]); + testPixel += ((swatchWidth - 1) * (x + 3)); + result &= IsColorMatch(swatch_r, swatch_r, swatch_r, pixBytes[testPixel], pixBytes[testPixel + 1], pixBytes[testPixel + 2]); + } + + if (!result) + { + WriteLog("Failed to find left edge for potential swatch of color {2}, {3}, {4} at {0}, {1}", x, y, swatch_r, swatch_g, swatch_b); + return false; + } + // test the left edge for dark pixels int i = 0; for (i = 0; result && (i < swatchHeight-pixelMultiplier); ++i) @@ -313,7 +356,7 @@ namespace DesertPaintLab if (!result) { // No dark border on the left side - // WriteLog("Failed to find left border for swatch at {0}, {1}", x, y); + WriteLog("Failed to find left border for potential swatch of color {2}, {3}, {4} at {0}, {1}", x, y, swatch_r, swatch_g, swatch_b); return false; } @@ -368,6 +411,7 @@ namespace DesertPaintLab pixel_g = pixBytes[pixelStart + 1]; pixel_b = pixBytes[pixelStart + 2]; + // Check 4 corners of solid area and left/right solid bar areas bool foundSwatch = IsPossibleSwatchUpperLeft(pixBytes, x, y, stride); // ((pixel_r < 0x46) && (pixel_g < 0x46) && (pixel_b < 0x46)); if (foundSwatch) {