Changeset - cca1f914411a
[Not reviewed]
T9_V6 default
0 4 0
Jason Maltzen - 5 years ago 2019-11-04 19:08:16
jason@hiddenachievement.com
More fixes for finding the pigment lab interface. Add a function for loading a saved screenshot and scanning it instead of a screen capture.
4 files changed with 212 insertions and 69 deletions:
0 comments (0 inline, 0 general)
PaintColor.cs
Show inline comments
...
 
@@ -115,9 +115,9 @@ namespace DesertPaintLab
 
        }
 
		
 
		public override string ToString()
 
		{
 
			return "[" + name + ", " + red + ", " + green + ", " + blue + "]";
 
			return "[" + name + ": " + red + ", " + green + ", " + blue + "]";
 
		}
 
		
 
	}
 
}
ReactionRecorder.cs
Show inline comments
...
 
@@ -53,17 +53,17 @@ namespace DesertPaintLab
 
            306, // tiny
 
            306, // small
 
            306, // medium
 
            320, // large
 
            320 // huge
 
            350 // huge
 
        };
 
        public static readonly int[] COLOR_BAR_WIDTH =
 
        {
 
            306, // tiny
 
            306, // small -- includes left and right borders
 
            306, // medium
 
            320, // large
 
            320 // huge
 
            350 // huge
 
        };
 
        public static readonly int[] RED_BAR_SPACING =
 
        {
 
            32, // tiny
...
 
@@ -124,9 +124,33 @@ namespace DesertPaintLab
 
        public int RedBarX { get; private set; }
 
        public int RedBarY { get; private set; }
 

	
 
        int pixelMultiplier = 1;
 
        InterfaceSize interfaceSize;
 
        public int PixelMultiplier
 
        {
 
            get
 
            {
 
                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;
...
 
@@ -155,14 +179,14 @@ namespace DesertPaintLab
 
            {
 
                // red between 208 and 244
 
                // 240 and 255
 
                // green between 192 and 237
 
                // 223 and 248
 
                // 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 <= 0xF8) && (color.b >= 0xB2) && (color.b <= 0xE8));
 
                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)
 
            {
...
 
@@ -184,20 +208,21 @@ namespace DesertPaintLab
 
            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 * 3);
 
                return (y * pixelMultiplier * stride) + (x * pixelMultiplier * numChannels);
 
            }
 

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

	
 
            unsafe public void ColorAt(int offset, ref PixelColor pixel)
 
            {
...
 
@@ -241,8 +266,9 @@ namespace DesertPaintLab
 
            unsafe public bool IsSolidPatchAt(int x, int y, int patchWidth, int patchHeight)
 
            {
 
                if ((x + patchWidth >= width) || (y + patchHeight >= height)) return false;
 
                ColorAt(x, y, ref _tempColor2);
 
                Console.WriteLine("color at {0},{1} = {2},{3},{4}", x, y, _tempColor2.r, _tempColor2.g, _tempColor2.b);
 
                bool ok = true;
 
                ok &= DoesPixelMatch(x + patchWidth - 1, y, _tempColor2.IsMatch);
 
                ok &= DoesPixelMatch(x, y + patchHeight - 1, _tempColor2.IsMatch);
 
                ok &= DoesPixelMatch(x + patchWidth - 1, y + patchHeight - 1, _tempColor2.IsMatch);
...
 
@@ -294,60 +320,44 @@ namespace DesertPaintLab
 
        public ReactionRecorder()
 
        {
 
            pixelMultiplier = 1;
 
            interfaceSize = DEFAULT_INTERFACE_SIZE;
 
            swatchHeight = SWATCH_HEIGHT[(int)interfaceSize] * pixelMultiplier;
 
            swatchWidth = SWATCH_WIDTH[(int)interfaceSize] * pixelMultiplier;
 
            colorBarWidth = COLOR_BAR_WIDTH[(int)interfaceSize] * pixelMultiplier;
 
            redBarSpacing = RED_BAR_SPACING[(int)interfaceSize] * pixelMultiplier;
 
            greenBarSpacing = GREEN_BAR_SPACING[(int)interfaceSize] * pixelMultiplier;
 
            blueBarSpacing = BLUE_BAR_SPACING[(int)interfaceSize] * pixelMultiplier;
 
            swatchTestWidth = SWATCH_TEST_WIDTH[(int)interfaceSize] * pixelMultiplier;
 

	
 
            UpdateSwatchSizes();
 
        }
 

	
 
        public ReactionRecorder(int pixelMultiplier)
 
        {
 
            this.pixelMultiplier = pixelMultiplier;
 
            this.interfaceSize = DEFAULT_INTERFACE_SIZE;
 
            swatchHeight = SWATCH_HEIGHT[(int)interfaceSize] * pixelMultiplier;
 
            swatchWidth = SWATCH_WIDTH[(int)interfaceSize] * pixelMultiplier;
 
            colorBarWidth = COLOR_BAR_WIDTH[(int)interfaceSize] * pixelMultiplier;
 
            redBarSpacing = RED_BAR_SPACING[(int)interfaceSize] * pixelMultiplier;
 
            greenBarSpacing = GREEN_BAR_SPACING[(int)interfaceSize] * pixelMultiplier;
 
            blueBarSpacing = BLUE_BAR_SPACING[(int)interfaceSize] * pixelMultiplier;
 
            swatchTestWidth = SWATCH_TEST_WIDTH[(int)interfaceSize] * pixelMultiplier;
 

	
 
            UpdateSwatchSizes();
 
        }
 

	
 
        public ReactionRecorder(int pixelMultiplier, InterfaceSize interfaceSize)
 
        {
 
            this.pixelMultiplier = pixelMultiplier;
 
            this.interfaceSize = interfaceSize;
 
            swatchHeight = SWATCH_HEIGHT[(int)interfaceSize] * pixelMultiplier;
 
            swatchWidth = SWATCH_WIDTH[(int)interfaceSize] * pixelMultiplier;
 
            colorBarWidth = COLOR_BAR_WIDTH[(int)interfaceSize] * pixelMultiplier;
 
            redBarSpacing = RED_BAR_SPACING[(int)interfaceSize] * pixelMultiplier;
 
            greenBarSpacing = GREEN_BAR_SPACING[(int)interfaceSize] * pixelMultiplier;
 
            blueBarSpacing = BLUE_BAR_SPACING[(int)interfaceSize] * pixelMultiplier;
 
            swatchTestWidth = SWATCH_TEST_WIDTH[(int)interfaceSize] * pixelMultiplier;
 

	
 
            UpdateSwatchSizes();
 
        }
 

	
 
        public void SetPixelMultiplier(int pixelMultiplier)
 
        {
 
            this.pixelMultiplier = pixelMultiplier;
 

	
 
            swatchHeight = SWATCH_HEIGHT[(int)interfaceSize] * pixelMultiplier;
 
            swatchWidth      = SWATCH_WIDTH[(int)interfaceSize] * pixelMultiplier;
 
            colorBarWidth    = COLOR_BAR_WIDTH[(int)interfaceSize] * pixelMultiplier;
 
            redBarSpacing    = RED_BAR_SPACING[(int)interfaceSize] * pixelMultiplier;
 
            greenBarSpacing  = GREEN_BAR_SPACING[(int)interfaceSize] * pixelMultiplier;
 
            blueBarSpacing   = BLUE_BAR_SPACING[(int)interfaceSize] * pixelMultiplier;
 
            swatchTestWidth  = SWATCH_TEST_WIDTH[(int)interfaceSize] * pixelMultiplier;
 
            UpdateSwatchSizes();
 
        }
 

	
 
        public void SetInterfaceSize(InterfaceSize interfaceSize)
 
        {
 
            this.interfaceSize = interfaceSize;
 

	
 
            UpdateSwatchSizes();
 
        }
 

	
 
        private void UpdateSwatchSizes()
 
        {
 
            swatchHeight = SWATCH_HEIGHT[(int)interfaceSize] * pixelMultiplier;
 
            swatchWidth = SWATCH_WIDTH[(int)interfaceSize] * pixelMultiplier;
 
            colorBarWidth = COLOR_BAR_WIDTH[(int)interfaceSize] * pixelMultiplier;
 
            redBarSpacing = RED_BAR_SPACING[(int)interfaceSize] * pixelMultiplier;
...
 
@@ -404,8 +414,9 @@ namespace DesertPaintLab
 
            int testPixelStart = pixels.ComputeOffset(x, y);
 

	
 
            if (testPixelStart < pixels.stride)
 
            {
 
                WriteLog("Can't test {0},{1} - is not at least 1 row in", x, y);
 
                return false;
 
            }
 

	
 
            bool result = true;
...
 
@@ -421,12 +432,30 @@ namespace DesertPaintLab
 
            pixels.ColorAt(swatchSolidLeftX, swatchSolidTopY, ref swatchColor);
 

	
 
            // Check the other 3 corners of the swatch size for color match
 
            PixelColor testColor = new PixelColor();
 
            result &= pixels.DoesPixelMatch(swatchSolidRightX, swatchSolidTopY, swatchColor.IsMatch);
 
            result &= pixels.DoesPixelMatch(swatchSolidLeftX, swatchSolidBottomY, swatchColor.IsMatch);
 
            result &= pixels.DoesPixelMatch(swatchSolidRightX, swatchSolidBottomY, swatchColor.IsMatch);
 
            bool upperRightResult = pixels.DoesPixelMatch(swatchSolidRightX, swatchSolidTopY, swatchColor.IsMatch);
 
            //if (!upperRightResult)
 
            //{
 
            //    pixels.ColorAt(swatchSolidRightX, swatchSolidTopY, ref testColor);
 
            //    WriteLog("Upper-right mismatch for {8}, {9} - found {0},{1},{2} at {3}, {4} expected {5},{6},{7}", testColor.r, testColor.g, testColor.b, swatchSolidRightX, swatchSolidTopY, swatchColor.r, swatchColor.g, swatchColor.b, x, y);
 
            //}
 
            bool lowerLeftResult = pixels.DoesPixelMatch(swatchSolidLeftX, swatchSolidBottomY, swatchColor.IsMatch);
 
            //if (!lowerLeftResult)
 
            //{
 
            //    pixels.ColorAt(swatchSolidLeftX, swatchSolidBottomY, ref testColor);
 
            //    WriteLog("Lower-left mismatch for {8}, {9} - found {0},{1},{2} at {3}, {4} expected {5},{6},{7}", testColor.r, testColor.g, testColor.b, swatchSolidLeftX, swatchSolidBottomY, swatchColor.r, swatchColor.g, swatchColor.b, x, y);
 
            //}
 
            bool lowerRightResult = pixels.DoesPixelMatch(swatchSolidRightX, swatchSolidBottomY, swatchColor.IsMatch);
 
            //if (!lowerRightResult)
 
            //{
 
            //    pixels.ColorAt(swatchSolidRightX, swatchSolidBottomY, ref testColor);
 
            //    WriteLog("Lower-right mismatch for {8}, {9} - found {0},{1},{2} at {3}, {4} expected {5},{6},{7}", testColor.r, testColor.g, testColor.b, swatchSolidRightX, swatchSolidBottomY, swatchColor.r, swatchColor.g, swatchColor.b, x, y);
 
            //}
 

	
 
            result &= upperRightResult;
 
            result &= lowerLeftResult;
 
            result &= lowerRightResult;
 
            if (!result)
 
            {
 
                // Box corners test failed
 
                // 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);
...
 
@@ -490,14 +519,15 @@ namespace DesertPaintLab
 

	
 
            // 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)
 
            for (i = 0; result && (i < swatchWidth - 1); ++i)
 
            {
 
                bool isBorder = pixels.DoesPixelMatch(x + i, y, PixelColor.IsDark);
 
                result &= isBorder;
 
                if (!isBorder)
 
                {
 
                    WriteLog("Probably swatch at {0},{1} failed upper border test at {2},{3}", x, y, x + i, y);
 
                    borderError = true;
 
                }
 

	
 
                // Checking along the top of the swatch for papyrus
...
 
@@ -544,13 +574,24 @@ namespace DesertPaintLab
 
            // Check 4 corners of solid area and left/right solid bar areas
 
            bool foundSwatch = IsPossibleSwatchUpperLeft(pixels, x, y); // ((pixel_r < 0x46) && (pixel_g < 0x46) && (pixel_b < 0x46));
 
            if (foundSwatch)
 
            {
 
                WriteLog("Found probable swatch at {0},{1} - checking border slices", x, y);
 
                int borderXOffset = 0;
 
                for (borderXOffset = 2; foundSwatch && (borderXOffset < swatchTestWidth); ++borderXOffset)
 
                {
 
                    foundSwatch &= IsPossibleSwatchSlice(pixels, x + borderXOffset, y);
 
                    if (!foundSwatch)
 
                    {
 
                        WriteLog("Failed slice test at {0},{1}", x + borderXOffset, y);
 
                        break;
 
                    }
 
                    foundSwatch &= IsPossibleSwatchSlice(pixels, x + swatchWidth - borderXOffset, y);
 
                    if (!foundSwatch)
 
                    {
 
                        WriteLog("Failed slice test at {0},{1}", x + swatchWidth - borderXOffset, y);
 
                        break;
 
                    }
 
                }
 
            }
 

	
 
            if (foundSwatch)
...
 
@@ -570,9 +611,9 @@ namespace DesertPaintLab
 
            }
 
            return false;
 
        }
 

	
 
        unsafe public bool CaptureReaction(byte* pixBytes, int screenshotWidth, int screenshotHeight, int stride)
 
        unsafe public bool CaptureReaction(byte* pixBytes, int screenshotWidth, int screenshotHeight, int stride, int numChannels, int bitsPerSample)
 
        {
 
            PaintColor reactedColor = new PaintColor();
 
            int redPixelStart = 0;
 
            ScreenWidth = screenshotWidth;
...
 
@@ -585,8 +626,9 @@ namespace DesertPaintLab
 
                pixBytes = pixBytes,
 
                width = screenshotWidth,
 
                height = screenshotHeight,
 
                stride = stride,
 
                numChannels = numChannels,
 
                pixelMultiplier = pixelMultiplier
 
            };
 
            IsCaptured = false;
 
            if (!firstRun)
...
 
@@ -594,9 +636,9 @@ namespace DesertPaintLab
 
                // If this is not the first run, let's check the last location, to see if the UI is still there.
 
                if (TestPosition(lastSwatchX, lastSwatchY, pixels, ref reactedColor, ref redPixelStart))
 
                {
 
                    IsCaptured = true;
 
                    RedBarX = (redPixelStart % stride) / 3;
 
                    RedBarX = (redPixelStart % stride) / numChannels;
 
                    RedBarY = redPixelStart / stride;
 
                    RecordedColor = reactedColor;
 
                    return true;
 
                }
...
 
@@ -615,25 +657,33 @@ namespace DesertPaintLab
 
            DesertPaintLab.AppSettings.Get("ScanLimitX", out endX);
 
            DesertPaintLab.AppSettings.Get("ScanLimitY", out endY);
 
            if (endX == 0) endX = screenshotWidth;
 
            if (endY == 0) endY = screenshotHeight;
 
            if (endX > screenshotWidth) endX = screenshotWidth;
 
            if (endY > screenshotHeight) endY = screenshotHeight;
 
            if (startX < 2) startX = 2;
 
            if (startY < 2) startY = 2;
 
            if (startX > screenshotWidth) startX = 2;
 
            if (startY > screenshotHeight) startY = 2;
 

	
 
            int patchTestSize = (swatchHeight / 2) - 1;
 
            int patchTestSize = ((swatchHeight - 5) / 2) - 1;
 
            PixelColor patchColor = new PixelColor();
 
            for (int roughX = startX; roughX < endX - colorBarWidth - patchTestSize; roughX += patchTestSize)
 
            for (int roughX = startX; roughX < endX - colorBarWidth + patchTestSize; roughX += patchTestSize)
 
            {
 
                for (int roughY = startY; roughY < (endY - (blueBarSpacing + 10) - patchTestSize  /*53*/); roughY += patchTestSize)
 
                for (int roughY = startY; roughY < (endY - (blueBarSpacing + 10) + patchTestSize  /*53*/); roughY += patchTestSize)
 
                {
 
                    OnCaptureProgress?.Invoke(roughX, roughY);
 
                    if (!pixels.IsSolidPatchAt(roughX, roughY, patchTestSize, patchTestSize)) continue;
 
                    pixels.ColorAt(roughX, roughY, ref patchColor);
 
                    for (X = roughX - patchTestSize; X < roughX; ++X)
 
                    //Console.WriteLine("Found a solid patch of {2},{3},{4} at {0}, {1}", roughX, roughY, patchColor.r, patchColor.g, patchColor.b);
 
                    for (X = Math.Max(0, roughX - patchTestSize); X < roughX; ++X)
 
                    {
 
                        for (Y = roughY - patchTestSize; Y < roughY; ++Y)
 
                        for (Y = Math.Max(0, roughY - patchTestSize); Y < roughY; ++Y)
 
                        {
 
                            //WriteLog("Checking for potential swatch at {0},{1} after found square at {2},{3}", X, Y, roughX, roughY);
 
                            if (TestPosition(X, Y, pixels, ref reactedColor, ref redPixelStart))
 
                            {
 
                                RedBarX = (redPixelStart % stride) / 3;
 
                                RedBarX = (redPixelStart % stride) / numChannels;
 
                                RedBarY = redPixelStart / stride;
 
                                RecordedColor = reactedColor;
 
                                lastSwatchX = X;
 
                                lastSwatchY = Y;
UI/CaptureView.cs
Show inline comments
...
 
@@ -23,9 +23,9 @@ namespace DesertPaintLab
 

	
 
        bool recordEnabled = true;
 
        bool isCaptured = false;
 

	
 
        public CaptureView(PlayerProfile profile, Gdk.Pixbuf screenBuffer) : base()
 
        public CaptureView(PlayerProfile profile, Gdk.Pixbuf screenBuffer)
 
        {
 
            this.profile = profile;
 
            this.screenBuffer = screenBuffer;
 

	
...
 
@@ -59,8 +59,13 @@ namespace DesertPaintLab
 
                screenBuffer = value;
 
            }
 
        }
 

	
 
        public Gdk.Pixbuf RecordBuffer
 
        {
 
            get; set;
 
        }
 

	
 
        public PlayerProfile Profile
 
        {
 
            set {
 
                profile = value;
...
 
@@ -297,12 +302,12 @@ namespace DesertPaintLab
 
        }
 

	
 
        unsafe private void CaptureReactionThread()
 
        {
 
            byte* pixBytes = (byte*)screenBuffer.Pixels;
 
            byte* pixBytes = (byte*)RecordBuffer.Pixels;
 

	
 
            ReactionRecorder.Instance.OnCaptureProgress += OnCaptureProgress;
 
            ReactionRecorder.Instance.CaptureReaction(pixBytes, screenBuffer.Width, screenBuffer.Height, screenBuffer.Rowstride);
 
            ReactionRecorder.Instance.CaptureReaction(pixBytes, RecordBuffer.Width, RecordBuffer.Height, RecordBuffer.Rowstride, RecordBuffer.NChannels, RecordBuffer.BitsPerSample);
 
            ReactionRecorder.Instance.OnCaptureProgress -= OnCaptureProgress;
 

	
 
            notifyCaptureComplete.WakeupMain();
 
        }
...
 
@@ -316,16 +321,23 @@ namespace DesertPaintLab
 
        {
 
            // TODO: progress bar
 
            //ReactionRecorder.Instance.X;
 
            //ReactionRecorder.Instance.Y;
 
            progressBar.Fraction = ((double)(ReactionRecorder.Instance.X) / (double)(ReactionRecorder.Instance.ScreenWidth - ReactionRecorder.Instance.ColorBarWidth));
 
            double denom = (double)(ReactionRecorder.Instance.ScreenWidth - ReactionRecorder.Instance.ColorBarWidth);
 
            double numer = (double)(ReactionRecorder.Instance.X);
 
            double fraction = (denom > 0 && numer > 0) ? (numer / denom) : 0;
 
            if (numer > denom)
 
            {
 
                fraction = 1;
 
            }
 
            progressBar.Fraction = fraction;
 
        }
 

	
 
        void OnCaptureComplete(bool isCaptured, PaintColor reactedColor, int swatchX, int swatchY)
 
        {
 
            int screenWidth = screenBuffer.Width;
 
            int screenHeight = screenBuffer.Height;
 
            int stride = screenBuffer.Rowstride;
 
            int screenHeight = RecordBuffer.Height;
 
            int stride = RecordBuffer.Rowstride;
 

	
 
            StreamWriter log = ReactionRecorder.Instance.Log;
 
            if (log != null)
 
            {
...
 
@@ -345,9 +357,9 @@ namespace DesertPaintLab
 
                {
 
                    // write out the whole screenshot on a failure to capture
 
                    string screenshotDir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
 
                    string filename = FileUtils.FindNumberedFile("DesertPaintLab_Colormatch", "png", screenshotDir);
 
                    screenBuffer.Save(filename, "png");
 
                    RecordBuffer.Save(filename, "png");
 
                }
 
                else
 
                {
 
                    // record the swatch that was captured
...
 
@@ -360,17 +372,17 @@ namespace DesertPaintLab
 
                    int y = swatchY - 16;
 
                    int captureAreaHeight = ReactionRecorder.Instance.BlueBarSpacing + 42;
 
                    captureAreaHeight = Math.Min(screenHeight - y, captureAreaHeight);
 

	
 
                    Gdk.Pixbuf outPixBuf = new Gdk.Pixbuf(screenBuffer, Math.Max(0, x), Math.Max(0, y), 
 
                    Gdk.Pixbuf outPixBuf = new Gdk.Pixbuf(RecordBuffer, Math.Max(0, x), Math.Max(0, y), 
 
                        captureAreaWidth, captureAreaHeight);
 
                    //Gdk.Pixbuf outPixBuf = new Gdk.Pixbuf(screenBuffer, Math.Max(0, redPixelStartX), Math.Max(0, redPixelStartY),
 
                    //Gdk.Pixbuf outPixBuf = new Gdk.Pixbuf(RecordBuffer, Math.Max(0, redPixelStartX), Math.Max(0, redPixelStartY),
 
                    //    ReactionRecorder.Instance.ColorBarWidth, ReactionRecorder.Instance.GreenBarSpacing - ReactionRecorder.Instance.RedBarSpacing);
 
                    //screenBuffer.Save(filename, "png");
 
                    //RecordBuffer.Save(filename, "png");
 
                    outPixBuf.Save(filename, "png");
 
                }
 
            }
 
            //screenBuffer.Save("screenshot.png", "png");
 
            //RecordBuffer.Save("screenshot.png", "png");
 

	
 
            if (isCaptured)
 
            {
 
                string warning = "";
...
 
@@ -438,8 +450,11 @@ namespace DesertPaintLab
 

	
 
            progressBar.Hide();
 
            recordButton.Show();
 

	
 
            // release
 
            RecordBuffer = null;
 

	
 
            ingredient1ComboBox.Sensitive = true;
 
            ingredient2ComboBox.Sensitive = true;
 
            ingredient3ComboBox.Sensitive = (GetSelectedReagentName(1) != null) && (GetSelectedReagentName(2) != null);
 
        }
...
 
@@ -460,20 +475,83 @@ namespace DesertPaintLab
 
            Gdk.Window rootWindow = Gdk.Global.DefaultRootWindow;
 
            DesertPaintLab.AppSettings.Get("ScreenWidth", out screenWidth);
 
            DesertPaintLab.AppSettings.Get("ScreenHeight", out screenHeight);
 
            Gdk.Image rootImage = rootWindow.GetImage(0, 0, screenWidth, screenHeight);
 
            screenBuffer.GetFromImage(rootImage, rootImage.Colormap, 0, 0, 0, 0, screenWidth, screenHeight);
 
            RecordBuffer = screenBuffer;
 
            RecordBuffer.GetFromImage(rootImage, rootImage.Colormap, 0, 0, 0, 0, screenWidth, screenHeight);
 
            rootImage.Unref();
 
            System.GC.Collect(); // really, clean up now
 

	
 
            int pixelMultiplier;
 
            AppSettings.Get("PixelMultiplier", out pixelMultiplier);
 
            if (pixelMultiplier == 0) pixelMultiplier = 1;
 
            int interfaceSizeIndex = 1;
 
            AppSettings.Get("InterfaceSize", out interfaceSizeIndex);
 
            InterfaceSize interfaceSize = (InterfaceSize)interfaceSizeIndex;
 
            ReactionRecorder.Instance.PixelMultiplier = pixelMultiplier;
 
            ReactionRecorder.Instance.InterfaceSize = interfaceSize;
 

	
 
            BeginCapture();
 
        }
 

	
 
        unsafe void CaptureReactionColorFromLoadedImage(string filePath)
 
        {
 
            // read the screenshot from a file
 
            string screenshotDir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
 
            FileStream pixStream = new FileStream(filePath, FileMode.Open);
 
            RecordBuffer = new Gdk.Pixbuf(pixStream);
 
            ReactionRecorder.Instance.SetPixelMultiplier(1);
 
            // TODO: allow for other size
 
            InterfaceSize interfaceSize = InterfaceSize.Small;
 
            if (filePath.Contains("Large"))
 
            {
 
                interfaceSize = InterfaceSize.Large;
 
            }
 
            else if (filePath.Contains("Huge"))
 
            {
 
                interfaceSize = InterfaceSize.Huge;
 
            }
 
            ReactionRecorder.Instance.InterfaceSize = interfaceSize;
 

	
 
            System.Console.WriteLine("Loaded {0} size {1} x {2} stride {3} bits {4} colorspace {5} channels {6} hasAlpha {7}", filePath, RecordBuffer.Width, RecordBuffer.Height, RecordBuffer.Rowstride, RecordBuffer.BitsPerSample, RecordBuffer.Colorspace, RecordBuffer.NChannels, RecordBuffer.HasAlpha);
 

	
 
            System.GC.Collect(); // really, clean up now
 

	
 
            BeginCapture();
 
        }
 

	
 
        protected virtual void OnCapture(object sender, System.EventArgs e)
 
        {
 
            CaptureReactionColor();
 
        }
 
        
 

	
 
        protected void OnCaptureFromFile(object sender, EventArgs e)
 
        {
 
            Gtk.FileChooserDialog fileDialog =
 
                new Gtk.FileChooserDialog("Select screenshot file.",
 
                        (Gtk.Window)Toplevel, Gtk.FileChooserAction.Open,
 
                        Gtk.Stock.Cancel, Gtk.ResponseType.Cancel,
 
                        Gtk.Stock.Open, Gtk.ResponseType.Accept);
 
            Gtk.FileFilter filter = new Gtk.FileFilter();
 
            filter.AddPattern("*.png");
 
            fileDialog.AddFilter(filter);
 
            Gtk.ResponseType resp = (Gtk.ResponseType)fileDialog.Run();
 
            if (resp == Gtk.ResponseType.Accept)
 
            {
 
                string fileName = fileDialog.Filename;
 
                string directory = fileDialog.CurrentFolder;
 
                if (directory != null)
 
                {
 
                    CaptureReactionColorFromLoadedImage(System.IO.Path.Combine(directory, fileName));
 
                }
 
                else
 
                {
 
                    CaptureReactionColorFromLoadedImage(fileName);
 
                }
 
            }
 
            fileDialog.Destroy();
 
        }
 

	
 
        protected virtual void OnRecord(object sender, System.EventArgs e)
 
        {
 
            if (ReactionRecorder.Instance.RecordReaction(profile, expectedColor, reactedColor, reagents))
 
            {
gtk-gui/DesertPaintLab.CaptureView.cs
Show inline comments
...
 
@@ -42,10 +42,12 @@ namespace DesertPaintLab
 
		
 
		private global::DesertPaintLab.PaintSwatch unmodifiedSwatch;
 
		
 
		private global::Gtk.Button captureButton;
 
		
 
		private global::Gtk.Label unmodifiedLabel;
 

	
 
        private global::Gtk.Button captureFromFileButton;
 

	
 
        private global::Gtk.Label unmodifiedLabel;
 
		
 
		private global::Gtk.Frame reactedColorFrame;
 
		
 
		private global::Gtk.Alignment GtkAlignment2;
...
 
@@ -210,13 +212,25 @@ namespace DesertPaintLab
 
			this.captureButton.Name = "captureButton";
 
			this.captureButton.UseUnderline = true;
 
			this.captureButton.Label = "Capture";
 
			this.vbox3.Add (this.captureButton);
 
			global::Gtk.Box.BoxChild w15 = ((global::Gtk.Box.BoxChild)(this.vbox3 [this.captureButton]));
 
			w15.Position = 1;
 
			w15.Expand = false;
 
			w15.Fill = false;
 
			this.GtkAlignment1.Add (this.vbox3);
 
            // Container child vbox3.Gtk.Box+BoxChild
 
            global::Gtk.Box.BoxChild w15 = ((global::Gtk.Box.BoxChild)(this.vbox3[this.captureButton]));
 
            w15.Position = 1;
 
            w15.Expand = false;
 
            w15.Fill = false;
 
            this.captureFromFileButton = new global::Gtk.Button();
 
            this.captureFromFileButton.CanFocus = true;
 
            this.captureFromFileButton.Name = "captureButton";
 
            this.captureFromFileButton.UseUnderline = true;
 
            this.captureFromFileButton.Label = "Capture from File";
 
            this.vbox3.Add(this.captureFromFileButton);
 
            // Container child vbox3.Gtk.Box+BoxChild
 
            global::Gtk.Box.BoxChild w16 = ((global::Gtk.Box.BoxChild)(this.vbox3[this.captureFromFileButton]));
 
            w16.Position = 2;
 
            w16.Expand = false;
 
            w16.Fill = false;
 
            this.GtkAlignment1.Add (this.vbox3);
 
			this.unmodifiedColorFrame.Add (this.GtkAlignment1);
 
			this.unmodifiedLabel = new global::Gtk.Label ();
 
			this.unmodifiedLabel.Name = "unmodifiedLabel";
 
			this.unmodifiedLabel.LabelProp = "<b>Unmodified</b>";
...
 
@@ -298,8 +312,9 @@ namespace DesertPaintLab
 
			this.ingredient2ComboBox.Changed += new global::System.EventHandler (this.OnChangedIngredient2);
 
			this.ingredient3ComboBox.Changed += new global::System.EventHandler (this.OnChangedIngredient3);
 
			this.clearReactionButton.Clicked += new global::System.EventHandler (this.OnClearReaction);
 
			this.captureButton.Clicked += new global::System.EventHandler (this.OnCapture);
 
			this.recordButton.Clicked += new global::System.EventHandler (this.OnRecord);
 
            this.captureFromFileButton.Clicked += new global::System.EventHandler(this.OnCaptureFromFile);
 
            this.recordButton.Clicked += new global::System.EventHandler (this.OnRecord);
 
		}
 
	}
 
}
0 comments (0 inline, 0 general)