Exemplo n.º 1
0
        public void TestBasicPaintOperation()
        {
            Bitmap target = new Bitmap(64, 64);

            FastBitmap.ClearBitmap(target, Color.Transparent);

            PencilPaintOperation operation = new PencilPaintOperation(target)
            {
                Color = Color.Black
            };

            operation.StartOpertaion();

            operation.MoveTo(5, 5);
            operation.DrawTo(10, 10);
            operation.DrawTo(15, 17);
            operation.DrawTo(20, 25);
            operation.DrawTo(25, 37);

            operation.FinishOperation();

            // Hash of the .png image that represents the target result of the paint operation. Generated through the 'RegisterResultBitmap' method
            byte[] goodHash    = { 0xC5, 0x6B, 0x5C, 0x6B, 0xB0, 0x12, 0xBD, 0x28, 0xC4, 0x13, 0x8D, 0xAA, 0x5, 0xA1, 0x71, 0x5D, 0x1B, 0xAF, 0x9B, 0x4, 0xE7, 0x85, 0x98, 0x1E, 0xFD, 0xD4, 0x14, 0xC0, 0xB6, 0x36, 0x32, 0xA1 };
            byte[] currentHash = GetHashForBitmap(target);

            RegisterResultBitmap(target, "PencilOperation_BasicPaint");

            Assert.IsTrue(goodHash.SequenceEqual(currentHash), "The hash for the paint operation does not match the good hash stored. Verify the output image for an analysis of what went wrong");
        }
Exemplo n.º 2
0
        public void TestUndoOperationSized()
        {
            // Create the objects
            Bitmap target = new Bitmap(64, 64);

            FastBitmap.ClearBitmap(target, Color.Transparent);
            byte[] originalHash = GetHashForBitmap(target);

            // Create the test subjects
            PlottingPaintUndoGenerator generator = new PlottingPaintUndoGenerator(target, "Pencil");
            PencilPaintOperation       operation = new PencilPaintOperation(target)
            {
                Color = Color.Black, Notifier = generator, Size = 5
            };

            operation.StartOpertaion();

            operation.MoveTo(5, 5);
            operation.DrawTo(10, 10);
            operation.DrawTo(15, 17);
            operation.DrawTo(20, 25);
            operation.DrawTo(25, 37);
            operation.DrawTo(5, 5);

            operation.FinishOperation();

            // Undo the task
            generator.UndoTask.Undo();

            byte[] afterUndoHash = GetHashForBitmap(target);

            RegisterResultBitmap(target, "PencilOperation_AfterUndoSized");

            Assert.IsTrue(originalHash.SequenceEqual(afterUndoHash), "After undoing a paint operation's task, its pixels must return to their original state before the operation was applied");
        }
Exemplo n.º 3
0
        public void TestPaintOperationProperties()
        {
            Bitmap target  = new Bitmap(64, 64);
            Bitmap target2 = new Bitmap(64, 64);

            FastBitmap.ClearBitmap(target, Color.Transparent);

            PencilPaintOperation operation = new PencilPaintOperation(target)
            {
                Color = Color.Black
            };

            // Check TargetBitmap property
            Assert.AreEqual(operation.TargetBitmap, target, "The TargetBitmap property for the paint operation must point to the bitmap that was passed on its constructor");

            // Modify target bitmap
            operation.TargetBitmap = target2;

            // Check OperationStarted property
            operation.StartOpertaion();
            Assert.IsTrue(operation.OperationStarted, "After a call to StartOperation(), an operation's OperationStarted property should return true");

            operation.FinishOperation();
            Assert.IsFalse(operation.OperationStarted, "After a call to FinishOperation(), an operation's OperationStarted property should return false");
        }
Exemplo n.º 4
0
        public void TestSourceOverSizedPaintOperation()
        {
            Bitmap target = new Bitmap(64, 64);

            FastBitmap.ClearBitmap(target, Color.Transparent);

            PencilPaintOperation operation = new PencilPaintOperation(target)
            {
                Color = Color.FromArgb(127, 0, 0, 0), Size = 5, CompositingMode = CompositingMode.SourceOver
            };

            operation.StartOpertaion();

            Assert.IsTrue(operation.OperationStarted, "After a call to StartOperation(), an operation's OperationStarted property should return true");

            operation.MoveTo(5, 5);
            operation.DrawTo(10, 10);
            operation.DrawTo(15, 17);
            operation.DrawTo(20, 25);
            operation.DrawTo(25, 37);

            operation.FinishOperation();

            Assert.IsFalse(operation.OperationStarted, "After a call to FinishOperation(), an operation's OperationStarted property should return false");

            // Hash of the .png image that represents the target result of the paint operation. Generated through the 'RegisterResultBitmap' method
            byte[] goodHash    = { 0x95, 0x68, 0xB9, 0xC4, 0x9, 0xB6, 0xC, 0x3C, 0xC5, 0xDE, 0xFB, 0xEB, 0x97, 0x39, 0x21, 0x1F, 0x98, 0x16, 0x24, 0x9B, 0xD4, 0xDB, 0xB, 0xC5, 0xCD, 0x4B, 0xD0, 0xFE, 0xF2, 0xE0, 0x98, 0x7C };
            byte[] currentHash = GetHashForBitmap(target);

            RegisterResultBitmap(target, "PencilOperation_SourceOverSizedPaintBrush");

            Assert.IsTrue(goodHash.SequenceEqual(currentHash), "The hash for the paint operation does not match the good hash stored. Verify the output image for an analysis of what went wrong");
        }
Exemplo n.º 5
0
        public void TestOutOfBoundsPaintOperation()
        {
            Bitmap target = new Bitmap(64, 64);

            FastBitmap.ClearBitmap(target, Color.Transparent);

            PencilPaintOperation operation = new PencilPaintOperation(target)
            {
                Color = Color.Black
            };

            operation.StartOpertaion();

            operation.MoveTo(-20, 40);
            operation.DrawTo(40, -20);

            operation.FinishOperation();

            // Hash of the .png image that represents the target result of the paint operation. Generated through the 'RegisterResultBitmap' method
            byte[] goodHash    = { 0x35, 0xC8, 0x80, 0x21, 0xE7, 0xC1, 0x48, 0x28, 0xA5, 0xA9, 0xDC, 0xF5, 0x2D, 0x1F, 0xBB, 0x8B, 0xE3, 0xBC, 0x3C, 0x80, 0x2B, 0xCC, 0x95, 0x2C, 0xD3, 0xC8, 0xD, 0x52, 0xC2, 0xE5, 0xC2, 0x62 };
            byte[] currentHash = GetHashForBitmap(target);

            RegisterResultBitmap(target, "PencilOperation_OutOfBoundsPaint");

            Assert.IsTrue(goodHash.SequenceEqual(currentHash), "The hash for the paint operation does not match the good hash stored. Verify the output image for an analysis of what went wrong");
        }
Exemplo n.º 6
0
        public void TestSinglePixelPaintOperation()
        {
            Bitmap target = new Bitmap(64, 64);

            FastBitmap.ClearBitmap(target, Color.Transparent);

            PencilPaintOperation operation = new PencilPaintOperation(target, true)
            {
                Color           = Color.FromArgb(127, 0, 0, 0),
                CompositingMode = CompositingMode.SourceOver
            };

            operation.StartOpertaion();

            operation.MoveTo(5, 5);
            operation.DrawTo(5, 5);

            operation.FinishOperation();

            // Hash of the .png image that represents the target result of the paint operation. Generated through the 'RegisterResultBitmap' method
            byte[] goodHash    = { 0x9, 0xD8, 0xAD, 0x5, 0x84, 0x5E, 0x98, 0x81, 0x5D, 0x6B, 0xCD, 0x63, 0x74, 0x3A, 0xF8, 0x2A, 0x32, 0x48, 0x90, 0x35, 0x90, 0x21, 0xC7, 0xBA, 0xBF, 0x63, 0xC, 0xD5, 0x1, 0x1F, 0x90, 0x62 };
            byte[] currentHash = GetHashForBitmap(target);

            RegisterResultBitmap(target, "PencilOperation_SinglePlotPaint");

            Assert.IsTrue(goodHash.SequenceEqual(currentHash), "The hash for the paint operation does not match the good hash stored. Verify the output image for an analysis of what went wrong");
        }
Exemplo n.º 7
0
        public void TestBasicSizedPaintOperation()
        {
            Bitmap target = new Bitmap(64, 64);

            FastBitmap.ClearBitmap(target, Color.Transparent);

            PencilPaintOperation operation = new PencilPaintOperation(target)
            {
                Color = Color.Black, Size = 5
            };

            operation.StartOpertaion();

            Assert.IsTrue(operation.OperationStarted, "After a call to StartOperation(), an operation's OperationStarted property should return true");

            operation.MoveTo(5, 5);
            operation.DrawTo(10, 10);
            operation.DrawTo(15, 17);
            operation.DrawTo(20, 25);
            operation.DrawTo(25, 37);

            operation.FinishOperation();

            Assert.IsFalse(operation.OperationStarted, "After a call to FinishOperation(), an operation's OperationStarted property should return false");

            // Hash of the .png image that represents the target result of the paint operation. Generated through the 'RegisterResultBitmap' method
            byte[] goodHash    = { 0x1B, 0xB1, 0x7D, 0x42, 0x41, 0x93, 0xE5, 0x88, 0xCD, 0xF5, 0xE4, 0x4C, 0x9D, 0xE7, 0x33, 0x15, 0x2C, 0x9C, 0xFD, 0x3B, 0x9D, 0x33, 0x16, 0x25, 0xB0, 0x1A, 0x1B, 0xAF, 0xB1, 0xE3, 0xEA, 0x35 };
            byte[] currentHash = GetHashForBitmap(target);

            RegisterResultBitmap(target, "PencilOperation_BasicSizedPaintBrush");

            Assert.IsTrue(goodHash.SequenceEqual(currentHash), "The hash for the paint operation does not match the good hash stored. Verify the output image for an analysis of what went wrong");
        }
Exemplo n.º 8
0
        public void TestClearBitmap()
        {
            Bitmap bitmap = GenerateRandomBitmap(63, 63); // Non-dibisible by 8 bitmap, used to test loop unrolling

            FastBitmap.ClearBitmap(bitmap, Color.Red);

            // Loop through the image checking the pixels now
            for (int y = 0; y < bitmap.Height; y++)
            {
                for (int x = 0; x < bitmap.Width; x++)
                {
                    if (bitmap.GetPixel(x, y).ToArgb() != Color.Red.ToArgb())
                    {
                        Assert.Fail(
                            "Immediately after a call to FastBitmap.Clear(), all of the bitmap's pixels must be of the provided color");
                    }
                }
            }

            // Test an arbitratry color now
            FastBitmap.ClearBitmap(bitmap, Color.FromArgb(25, 12, 0, 42));

            // Loop through the image checking the pixels now
            for (int y = 0; y < bitmap.Height; y++)
            {
                for (int x = 0; x < bitmap.Width; x++)
                {
                    if (bitmap.GetPixel(x, y).ToArgb() != Color.FromArgb(25, 12, 0, 42).ToArgb())
                    {
                        Assert.Fail(
                            "Immediately after a call to FastBitmap.Clear(), all of the bitmap's pixels must be of the provided color");
                    }
                }
            }

            // Test instance call
            FastBitmap fastBitmap = new FastBitmap(bitmap);

            fastBitmap.Clear(Color.FromArgb(25, 12, 0, 42));

            Assert.IsFalse(fastBitmap.Locked, "After a successfull call to .Clear() on a fast bitmap previously unlocked, the .Locked property must be false");

            // Loop through the image checking the pixels now
            for (int y = 0; y < bitmap.Height; y++)
            {
                for (int x = 0; x < bitmap.Width; x++)
                {
                    if (bitmap.GetPixel(x, y).ToArgb() != Color.FromArgb(25, 12, 0, 42).ToArgb())
                    {
                        Assert.Fail(
                            "Immediately after a call to FastBitmap.Clear(), all of the bitmap's pixels must be of the provided color");
                    }
                }
            }
        }
Exemplo n.º 9
0
        //
        // Decorate Main Image method
        //
        public override void DecorateMainBitmap(Bitmap bitmap)
        {
            base.DecorateMainBitmap(bitmap);

            if (!_layerStatuses[_layerController.ActiveLayerIndex].Visible)
            {
                FastBitmap.ClearBitmap(bitmap, Color.Transparent);
            }
            // Transparent layer
            else if (_layerStatuses[_layerController.ActiveLayerIndex].Transparency < 1)
            {
                TransparencyFilter filter = new TransparencyFilter
                {
                    Transparency = _layerStatuses[_layerController.ActiveLayerIndex].Transparency
                };

                filter.ApplyToBitmap(bitmap);
            }
        }
Exemplo n.º 10
0
        public void TestOperationNotification()
        {
            // Setup the test by performing a few pencil strokes
            Bitmap target = new Bitmap(64, 64);

            FastBitmap.ClearBitmap(target, Color.Transparent);

            // Stub a notifier
            IPlottingOperationNotifier stubNotifier = MockRepository.GenerateStub <IPlottingOperationNotifier>(null);

            // Create the operation and perform it
            PencilPaintOperation operation = new PencilPaintOperation(target)
            {
                Color    = Color.Black,
                Notifier = stubNotifier
            };

            // Perform the operation
            operation.StartOpertaion();

            operation.MoveTo(5, 5);
            operation.DrawTo(10, 10);
            operation.DrawTo(5, 5);

            operation.FinishOperation();

            // Test the results
            // Test line from 5x5 -> 10x10
            for (int i = 5; i <= 10; i++)
            {
                var i1 = i;
                stubNotifier.AssertWasCalled(x => x.PlottedPixel(new Point(i1, i1), Color.Transparent.ToArgb(), Color.Black.ToArgb()));
            }
            // Test line that goes back from 9x9 -> 5x5, in which the black pixels due to the previous DrawTo() are ignored
            for (int i = 5; i < 10; i++)
            {
                var i1 = i;
                stubNotifier.AssertWasNotCalled(x => x.PlottedPixel(new Point(i1, i1), Color.Black.ToArgb(), Color.Black.ToArgb()));
            }
        }
Exemplo n.º 11
0
 public void FillScreenFg()
 {
     FastBitmap.ClearBitmap(_shadowImage, ForegroundColor);
 }
Exemplo n.º 12
0
 public void FillScreenBg()
 {
     FastBitmap.ClearBitmap(_shadowImage, BackgroundColor);
 }
Exemplo n.º 13
0
        /// <summary>
        /// Shows the onion skin
        /// </summary>
        public void ShowOnionSkin()
        {
            Settings.OnionSkinEnabled = true;

            if (frameView.FrameLoaded == null)
            {
                return;
            }

            if (onionSkin != null && (onionSkin.Width != frameView.FrameLoaded.Width || onionSkin.Height != frameView.FrameLoaded.Height))
            {
                onionSkin.Dispose();
                onionSkin = null;
            }
            else if (onionSkin != null)
            {
                FastBitmap.ClearBitmap(onionSkin, 0);
            }

            if (onionSkin == null)
            {
                // Create the new onion skin
                onionSkin = new Bitmap(frameView.FrameLoaded.Width, frameView.FrameLoaded.Height, PixelFormat.Format32bppArgb);
            }

            Graphics og = Graphics.FromImage(onionSkin);

            og.CompositingMode = CompositingMode.SourceOver;

            Rectangle bounds = new Rectangle(0, 0, frameView.FrameLoaded.Width, frameView.FrameLoaded.Height);

            // Create image attributes
            ImageAttributes attributes = new ImageAttributes();

            // Create a color matrix object
            ColorMatrix matrix = new ColorMatrix();

            //float multDecay = 0.3f + (0.7f / OnionSkinDepth);
            float multDecay = 0.5f + (Settings.OnionSkinDepth / 50.0f);

            // Draw the previous frames
            if (Settings.OnionSkinMode == OnionSkinMode.PreviousFrames || Settings.OnionSkinMode == OnionSkinMode.PreviousAndNextFrames)
            {
                int   fi   = frameView.FrameLoaded.Index;
                float mult = 1;
                for (int i = fi - 1; i > fi - Settings.OnionSkinDepth - 1 && i >= 0; i--)
                {
                    matrix.Matrix33 = Settings.OnionSkinTransparency * mult;
                    mult           *= multDecay;
                    attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

                    using (var bitmap = frameView.FrameLoaded.Animation[i].GetComposedBitmap())
                    {
                        og.DrawImage(bitmap, bounds, 0, 0, bounds.Width, bounds.Height, GraphicsUnit.Pixel, attributes);
                    }
                }
            }
            // Draw the next frames
            if (Settings.OnionSkinMode == OnionSkinMode.NextFrames || Settings.OnionSkinMode == OnionSkinMode.PreviousAndNextFrames)
            {
                int   fi   = frameView.FrameLoaded.Index;
                float mult = 1;
                for (int i = fi + 1; i < fi + Settings.OnionSkinDepth + 1 && i < frameView.FrameLoaded.Animation.FrameCount; i++)
                {
                    matrix.Matrix33 = Settings.OnionSkinTransparency * mult;
                    mult           *= multDecay;
                    attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

                    using (var bitmap = frameView.FrameLoaded.Animation[i].GetComposedBitmap())
                    {
                        og.DrawImage(bitmap, bounds, 0, 0, bounds.Width, bounds.Height, GraphicsUnit.Pixel, attributes);
                    }
                }
            }

            og.Flush();
            og.Dispose();

            pictureBox.DisplayImage = Settings.OnionSkinShowCurrentFrame;
            pictureBox.Invalidate();
        }