Пример #1
0
        /// <summary>
        /// Combines two black/white masks in a new bitmap
        /// </summary>
        /// <param name="mask1">The first mask for the merge</param>
        /// <param name="mask2">The second mask for the merge</param>
        /// <param name="logic">How to merge the masks</param>
        /// <returns>The merged masks</returns>
        private Bitmap MergeMasks(Bitmap mask1, Bitmap mask2, WindowMaskLogic logic)
        {
            Bitmap[]  windowLogicMasks = new Bitmap[4];
            Rectangle maskRec          = new Rectangle(new Point(0, 0), mask2.Size);

            //needs to run if there is any OR, XOR, XNOR => baiscally if there is any that is not And
            if (logic != WindowMaskLogic.And)
            {
                Bitmap          mask = new Bitmap(mask1);
                ImageAttributes attr = new ImageAttributes();
                attr.SetColorKey(Color.White, Color.White);

                using (Graphics g = Graphics.FromImage(mask))
                {
                    g.DrawImage(mask2, maskRec, maskRec.X, maskRec.Y,
                                maskRec.Width, maskRec.Height, GraphicsUnit.Pixel, attr);
                }
                windowLogicMasks[(int)WindowMaskLogic.Or] = mask;
            }
            //needs to run if there is any AND, XOR, XNOR => baiscally if there is any that is not Or
            if (logic != WindowMaskLogic.Or)
            {
                Bitmap          mask = new Bitmap(mask1);
                ImageAttributes attr = new ImageAttributes();
                attr.SetColorKey(Color.Black, Color.Black);

                using (Graphics g = Graphics.FromImage(mask))
                {
                    g.DrawImage(mask2, maskRec, maskRec.X, maskRec.Y,
                                maskRec.Width, maskRec.Height, GraphicsUnit.Pixel, attr);
                }
                windowLogicMasks[(int)WindowMaskLogic.And] = mask;
            }
            if (logic == WindowMaskLogic.Xor || logic == WindowMaskLogic.XNor)
            {
                Bitmap          mask = new Bitmap(windowLogicMasks[(int)WindowMaskLogic.Or]);
                ImageAttributes attr = new ImageAttributes();
                attr.SetColorKey(Color.Black, Color.Black);

                using (Graphics g = Graphics.FromImage(mask))
                {
                    g.DrawImage(BitmapEffects.Invert(windowLogicMasks[(int)WindowMaskLogic.And]),
                                maskRec, maskRec.X, maskRec.Y, maskRec.Width, maskRec.Height, GraphicsUnit.Pixel, attr);
                }

                mask.Save("XOR.png");
                windowLogicMasks[(int)WindowMaskLogic.Xor]  = mask;
                windowLogicMasks[(int)WindowMaskLogic.XNor] = BitmapEffects.Invert(mask);
            }

            return(windowLogicMasks[(int)logic]);
        }
Пример #2
0
        /// <summary>
        /// Gets the screen as it would be displayed by the SNES.
        /// </summary>
        /// <returns></returns>
        public Bitmap GetScreen()
        {
            if (BG1 == null || BG2 == null || BG3 == null || BG4 == null)
            {
                throw new ArgumentNullException("BGs need to be initialized");
            }
            if (FixedColor == null)
            {
                throw new ArgumentNullException("FixedColor need to be initialized");
            }
            if (Backdrop == null)
            {
                throw new ArgumentNullException("Backdrop need to be initialized");
            }


            Bitmap main, sub;
            Bitmap statusBar  = new Bitmap(LayerSizes.Width, LayerSizes.Height);
            Bitmap bg3_remain = new Bitmap(LayerSizes.Width, LayerSizes.Height);

            //cut layer 3 into status bar end rest.
            using (Graphics g = Graphics.FromImage(statusBar))
                g.DrawImageUnscaledAndClipped(BG3, new Rectangle(0, 0, statusBar.Width, StatusBarHeight));
            using (Graphics g = Graphics.FromImage(bg3_remain))
            {
                Rectangle rec = new Rectangle(0, StatusBarHeight, bg3_remain.Width, bg3_remain.Height - StatusBarHeight);
                g.DrawImageUnscaledAndClipped(BG3.Clone(rec, BG3.PixelFormat), rec);
            }


            Func <bool, bool, bool, bool, WindowMaskLogic, Bitmap, Bitmap> doWindowing = (enable1, enable2, invert1, invert2, logic, bg) =>
            {
                Bitmap mask1 = invert1 ? BitmapEffects.Invert(WindowingMask1) : WindowingMask1;
                Bitmap mask2 = invert2 ? BitmapEffects.Invert(WindowingMask2) : WindowingMask2;

                if (enable1 && enable2)
                {
                    return(BitmapEffects.ApplyMask(bg, MergeMasks(mask1, mask2, logic), 0.5f));
                }
                else if (enable1)
                {
                    return(BitmapEffects.ApplyMask(bg, mask1, 0.5f));
                }
                else if (enable2)
                {
                    return(BitmapEffects.ApplyMask(bg, mask2, 0.5f));
                }
                else
                {
                    return(bg);
                }
            };

            Bitmap bg1Windowed = doWindowing(Window1Enabled.HasFlag(WindowingLayers.BG1), Window2Enabled.HasFlag(WindowingLayers.BG1),
                                             Window1Inverted.HasFlag(WindowingLayers.BG1), Window2Inverted.HasFlag(WindowingLayers.BG1), Bg1MaskLogic, BG1);

            Bitmap bg2Windowed = doWindowing(Window1Enabled.HasFlag(WindowingLayers.BG2), Window2Enabled.HasFlag(WindowingLayers.BG2),
                                             Window1Inverted.HasFlag(WindowingLayers.BG2), Window2Inverted.HasFlag(WindowingLayers.BG2), Bg2MaskLogic, BG2);

            Bitmap statusBarWindowed = doWindowing(Window1Enabled.HasFlag(WindowingLayers.BG3), Window2Enabled.HasFlag(WindowingLayers.BG3),
                                                   Window1Inverted.HasFlag(WindowingLayers.BG3), Window2Inverted.HasFlag(WindowingLayers.BG3), Bg3MaskLogic, statusBar);

            Bitmap bg3RemainWindowed = doWindowing(Window1Enabled.HasFlag(WindowingLayers.BG3), Window2Enabled.HasFlag(WindowingLayers.BG3),
                                                   Window1Inverted.HasFlag(WindowingLayers.BG3), Window2Inverted.HasFlag(WindowingLayers.BG3), Bg3MaskLogic, bg3_remain);

            Bitmap bg4Windowed = doWindowing(Window1Enabled.HasFlag(WindowingLayers.BG4), Window2Enabled.HasFlag(WindowingLayers.BG4),
                                             Window1Inverted.HasFlag(WindowingLayers.BG4), Window2Inverted.HasFlag(WindowingLayers.BG4), Bg4MaskLogic, BG4);

            Bitmap objWindowed = doWindowing(Window1Enabled.HasFlag(WindowingLayers.OBJ), Window2Enabled.HasFlag(WindowingLayers.OBJ),
                                             Window1Inverted.HasFlag(WindowingLayers.OBJ), Window2Inverted.HasFlag(WindowingLayers.OBJ), ObjMaskLogic, OBJ);

            Bitmap colorWindowed      = BitmapEffects.FromColor(Color.Black, LayerSizes);
            Bitmap colorWindowedHoles = doWindowing(Window1Enabled.HasFlag(WindowingLayers.Color), Window2Enabled.HasFlag(WindowingLayers.Color),
                                                    Window1Inverted.HasFlag(WindowingLayers.Color), Window2Inverted.HasFlag(WindowingLayers.Color), ColorMaskLogic,
                                                    BitmapEffects.FromColor(Color.White, LayerSizes));

            //colorWindowsedHoles is white with holes where the black should be
            using (Graphics g = Graphics.FromImage(colorWindowed))
                g.DrawImage(colorWindowedHoles, 0, 0);

            #region Sub Screen
            List <Bitmap> BGs = new List <Bitmap>();
            if (SubScreenDesignation.HasFlag(ScreenDesignation.OBJ) && !Hide.HasFlag(ScreenDesignation.OBJ))
            {
                BGs.Add(SubScreenWindowMaskDesignation.HasFlag(ScreenDesignation.OBJ) ? objWindowed : OBJ);
            }

            if (SubScreenDesignation.HasFlag(ScreenDesignation.BG1) && !Hide.HasFlag(ScreenDesignation.BG1))
            {
                BGs.Add(SubScreenWindowMaskDesignation.HasFlag(ScreenDesignation.BG1) ? bg1Windowed : BG1);
            }

            if (SubScreenDesignation.HasFlag(ScreenDesignation.BG2) && !Hide.HasFlag(ScreenDesignation.BG2))
            {
                BGs.Add(SubScreenWindowMaskDesignation.HasFlag(ScreenDesignation.BG2) ? bg2Windowed : BG2);
            }

            //layer 3 special (status bar split) onyl lower part
            if (SubScreenDesignation.HasFlag(ScreenDesignation.BG3) && !Hide.HasFlag(ScreenDesignation.BG3))
            {
                BGs.Add(SubScreenWindowMaskDesignation.HasFlag(ScreenDesignation.BG3) ? bg3RemainWindowed : bg3_remain);
            }

            if (SubScreenDesignation.HasFlag(ScreenDesignation.BG4) && !Hide.HasFlag(ScreenDesignation.BG4))
            {
                BGs.Add(SubScreenWindowMaskDesignation.HasFlag(ScreenDesignation.BG4) ? bg4Windowed : BG4);
            }

            BGs.Add(FixedColor);
            sub = BitmapEffects.OverlapImages(BGs.ToArray());
            #endregion

            #region Main Screen

            BGs.Clear();
            if (MainScreenDesignation.HasFlag(ScreenDesignation.OBJ) && !Hide.HasFlag(ScreenDesignation.OBJ))
            {
                Bitmap objUse = MainScreenWindowMaskDesignation.HasFlag(ScreenDesignation.OBJ) ? objWindowed : OBJ;
                if (ColorMathDesignation.HasFlag(ColorMathMode.OBJ))
                {
                    BGs.Add(ApplyColorMath(objUse, AddColor ? FixedColor : sub, ColorMathDesignation, colorWindowed, ClipToBlack, PreventColorMath));
                }
                else
                {
                    BGs.Add(objUse);
                }
            }
            if (MainScreenDesignation.HasFlag(ScreenDesignation.BG1) && !Hide.HasFlag(ScreenDesignation.BG1))
            {
                Bitmap bg1Use = MainScreenWindowMaskDesignation.HasFlag(ScreenDesignation.BG1) ? bg1Windowed : BG1;
                if (ColorMathDesignation.HasFlag(ColorMathMode.BG1))
                {
                    BGs.Add(ApplyColorMath(bg1Use, AddColor ? FixedColor : sub, ColorMathDesignation, colorWindowed, ClipToBlack, PreventColorMath));
                }
                else
                {
                    BGs.Add(bg1Use);
                }
            }
            if (MainScreenDesignation.HasFlag(ScreenDesignation.BG2) && !Hide.HasFlag(ScreenDesignation.BG2))
            {
                Bitmap bg2Use = MainScreenWindowMaskDesignation.HasFlag(ScreenDesignation.BG2) ? bg2Windowed : BG2;
                if (ColorMathDesignation.HasFlag(ColorMathMode.BG2))
                {
                    BGs.Add(ApplyColorMath(bg2Use, AddColor ? FixedColor : sub, ColorMathDesignation, colorWindowed, ClipToBlack, PreventColorMath));
                }
                else
                {
                    BGs.Add(bg2Use);
                }
            }
            if (MainScreenDesignation.HasFlag(ScreenDesignation.BG3) && !Hide.HasFlag(ScreenDesignation.BG3))
            {
                //layer 3 special (status bar split) onyl lower half
                Bitmap bg3Use = MainScreenWindowMaskDesignation.HasFlag(ScreenDesignation.BG3) ? bg3RemainWindowed : bg3_remain;
                if (ColorMathDesignation.HasFlag(ColorMathMode.BG3))
                {
                    BGs.Add(ApplyColorMath(bg3Use, AddColor ? FixedColor : sub, ColorMathDesignation, colorWindowed, ClipToBlack, PreventColorMath));
                }
                else
                {
                    BGs.Add(bg3Use);
                }
            }
            if (MainScreenDesignation.HasFlag(ScreenDesignation.BG4) && !Hide.HasFlag(ScreenDesignation.BG4))
            {
                Bitmap bg4Use = MainScreenWindowMaskDesignation.HasFlag(ScreenDesignation.BG3) ? bg4Windowed : BG4;
                if (ColorMathDesignation.HasFlag(ColorMathMode.BG4))
                {
                    BGs.Add(ApplyColorMath(bg4Use, AddColor ? FixedColor : sub, ColorMathDesignation, colorWindowed, ClipToBlack, PreventColorMath));
                }
                else
                {
                    BGs.Add(bg4Use);
                }
            }

            //handle the backdrop too
            if (ColorMathDesignation.HasFlag(ColorMathMode.Backdrop))
            {
                BGs.Add(ApplyColorMath(Backdrop, AddColor ? FixedColor : sub, ColorMathDesignation, colorWindowed, ClipToBlack, PreventColorMath));
            }
            else
            {
                BGs.Add(Backdrop);
            }

            main = BitmapEffects.OverlapImages(BGs.ToArray());
            #endregion

            BGs.Clear();

            //check windowing for status bar
            if (MainScreenDesignation.HasFlag(ScreenDesignation.BG3) && !Hide.HasFlag(ScreenDesignation.BG3))
            {
                BGs.Add(MainScreenWindowMaskDesignation.HasFlag(ScreenDesignation.BG3) ? statusBarWindowed : statusBar);
            }
            //if not main, check subscreen. (still put it before main for display purpose)
            else if (SubScreenDesignation.HasFlag(ScreenDesignation.BG3) && !Hide.HasFlag(ScreenDesignation.BG3))
            {
                BGs.Add(SubScreenWindowMaskDesignation.HasFlag(ScreenDesignation.BG3) ? statusBarWindowed : statusBar);
            }

            BGs.Add(main);
            BGs.Add(sub);

            return(BitmapEffects.OverlapImages(BGs.ToArray()));
        }