Changeset - 334157513064
[Not reviewed]
default
0 1 0
Jason Maltzen - 5 years ago 2019-11-08 21:35:30
jason@hiddenachievement.com
Change IsRed / IsGreen / IsBlue tests to be a little more tolerant of brighter pixels - was not detecting green clipped high correctly with the new brighter background texture.
1 file changed with 3 insertions and 3 deletions:
0 comments (0 inline, 0 general)
ReactionRecorder.cs
Show inline comments
...
 
@@ -139,137 +139,137 @@ namespace DesertPaintLab
 
            {
 
                return pixelMultiplier;
 
            }
 
            set
 
            {
 
                pixelMultiplier = value;
 
                UpdateSwatchSizes();
 
            }
 
        }
 
        private InterfaceSize interfaceSize;
 
        public InterfaceSize InterfaceSize
 
        {
 
            get
 
            {
 
                return interfaceSize;
 
            }
 
            set
 
            {
 
                interfaceSize = value;
 
                UpdateSwatchSizes();
 
            }
 
        }
 

	
 
        bool firstRun = true;
 
        int lastSwatchX = -1;
 
        int lastSwatchY = -1;
 
        public int SwatchX { get { return lastSwatchX; } }
 
        public int SwatchY { get { return lastSwatchY; } }
 

	
 
        private LogVerbosity logVerbosity = LogVerbosity.Normal;
 

	
 
        private class PixelColor
 
        {
 
            public byte r;
 
            public byte g;
 
            public byte b;
 

	
 
            public bool IsMatch(PixelColor other)
 
            {
 
                return ((Math.Abs(r - other.r) <= COLOR_TOLERANCE) &&
 
                    (Math.Abs(g - other.g) <= COLOR_TOLERANCE) &&
 
                    (Math.Abs(b - other.b) <= COLOR_TOLERANCE));
 
            }
 

	
 
            public static bool IsDark(PixelColor color)
 
            {
 
                return (color.r < 0x47) && (color.g < 0x47) && (color.b < 0x47);
 
            }
 

	
 
            public static bool IsPapyrus(PixelColor color)
 
            {
 
                // red between 208 and 244
 
                // 240 and 255
 
                // green between 192 and 237
 
                // 223 and 250
 
                // blue between 145 and 205
 
                // 178 and 232
 
                //return ((r > 0xD0) && (g >= 0xC0) && (b >= 0x91)) &&
 
                //       ((r < 0xF4) && (g <= 0xED) && (b <= 0xCD));
 
                return ((color.r >= 0xF0) && (color.r <= 0xFF) && (color.g >= 0xDF) && (color.g <= 0xFA) && (color.b >= 0xB2) && (color.b <= 0xE8));
 
            }
 

	
 
            public static bool IsRed(PixelColor color)
 
            {
 
                return (color.r > 0x9F) && (color.g < 0x62) && (color.b < 0x62);
 
                return (color.r > 0x9F) && (color.g < 0x70) && (color.b < 0x70);
 
            }
 
            public static bool IsGreen(PixelColor color)
 
            {
 
                return (color.r < 0x62) && (color.g > 0x9F) && (color.b < 0x62);
 
                return (color.r < 0x70) && (color.g > 0x9F) && (color.b < 0x70);
 
            }
 
            public static bool IsBlue(PixelColor color)
 
            {
 
                return (color.r < 0x62) && (color.g < 0x62) && (color.b > 0x9F);
 
                return (color.r < 0x70) && (color.g < 0x70) && (color.b > 0x9F);
 
            }
 
        }
 

	
 
        unsafe private class Pixels
 
        {
 
            public byte* pixBytes;
 
            public int width;
 
            public int height;
 
            public int stride;
 
            public int pixelMultiplier;
 
            public int numChannels;
 

	
 
            private PixelColor _tempColor = new PixelColor();
 
            private PixelColor _tempColor2 = new PixelColor();
 

	
 
            public int ComputeOffset(int x, int y)
 
            {
 
                return (y * pixelMultiplier * stride) + (x * pixelMultiplier * numChannels);
 
            }
 

	
 
            public int UpdateOffset(int offset, int xChange, int yChange)
 
            {
 
                return offset + (yChange * pixelMultiplier * stride) + (xChange * pixelMultiplier * numChannels);
 
            }
 

	
 
            unsafe public void ColorAt(int offset, ref PixelColor pixel)
 
            {
 
                pixel.r = pixBytes[offset];
 
                pixel.g = pixBytes[offset + 1];
 
                pixel.b = pixBytes[offset + 2];
 
            }
 

	
 
            unsafe public void ColorAt(int x, int y, ref PixelColor pixel)
 
            {
 
                int offset = ComputeOffset(x, y);
 
                ColorAt(offset, ref pixel);
 
            }
 

	
 
            unsafe public bool DoesPixelMatch(int x, int y, Func<PixelColor, bool> matchFunc)
 
            {
 
                int offset = ComputeOffset(x, y);
 
                ColorAt(offset, ref _tempColor);
 
                return matchFunc(_tempColor);
 
            }
 

	
 
            unsafe public bool DoesPixelMatch(int offset, Func<PixelColor, bool> matchFunc)
 
            {
 
                ColorAt(offset, ref _tempColor);
 
                return matchFunc(_tempColor);
 
            }
 

	
 
            // Compute length of horizontal bar starting at x,y using matching function
 
            unsafe public int LengthOfColorAt(int x, int y, Func<PixelColor, bool> matchesColor)
 
            {
 
                int count = 0;
 
                for (int xVal = x; xVal < width; ++xVal)
 
                {
 
                    int offset = ComputeOffset(xVal, y);
 
                    if (!DoesPixelMatch(xVal, y, matchesColor)) break;
 
                    ++count;
 
                }
 
                return count;
 
            }
 

	
0 comments (0 inline, 0 general)