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"); }
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"); }
public void TestSourceOverAlphaAccumulationOffTransparentOperation() { Bitmap target = FrameGenerator.GenerateRandomBitmap(64, 64, 10); PencilPaintOperation operation = new PencilPaintOperation(target) { Color = Color.FromArgb(127, 0, 0, 0), CompositingMode = CompositingMode.SourceOver }; operation.StartOpertaion(false); 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(); // Hash of the .png image that represents the target result of the paint operation. Generated through the 'RegisterResultBitmap' method byte[] goodHash = { 0x7E, 0xCD, 0xAB, 0x2D, 0xB, 0x48, 0x83, 0x2B, 0x1E, 0xCA, 0xA, 0x98, 0x68, 0x58, 0x86, 0x66, 0x67, 0x15, 0x62, 0xDA, 0xC4, 0xB5, 0xE2, 0x8, 0x12, 0xBD, 0x3C, 0x7A, 0xF2, 0x92, 0x80, 0x9 }; byte[] currentHash = GetHashForBitmap(target); RegisterResultBitmap(target, "PencilOperation_SourceOverTransparentPaint_AccumulateAlphaOff"); Assert.IsTrue(goodHash.SequenceEqual(currentHash), "The hash for the paint operation must match the good hash stored"); }
public void TestUnstartedOperationException() { Bitmap bitmap = new Bitmap(64, 64); PencilPaintOperation paintOperation = new PencilPaintOperation(bitmap); paintOperation.DrawTo(5, 5); }
public void TestSourceCopyTransparentOperation() { Bitmap target = FrameGenerator.GenerateRandomBitmap(64, 64, 10); PencilPaintOperation operation = new PencilPaintOperation(target, true) { Color = Color.FromArgb(127, 0, 0, 0), CompositingMode = CompositingMode.SourceCopy }; 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 = { 0x7C, 0xB0, 0xE9, 0x83, 0x12, 0xC3, 0x13, 0x74, 0x20, 0xCA, 0x40, 0x8E, 0x27, 0x11, 0x8B, 0xF5, 0xE9, 0x5F, 0x33, 0x41, 0xCE, 0x7D, 0x8D, 0x74, 0x76, 0x5C, 0xA6, 0xD1, 0xAB, 0x90, 0x1C, 0x34 }; byte[] currentHash = GetHashForBitmap(target); RegisterResultBitmap(target, "PencilOperation_SourceCopyTransparentPaint"); 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"); }
public void TestSourceOverTransparentOperation() { Bitmap target = FrameGenerator.GenerateRandomBitmap(64, 64, 10); PencilPaintOperation operation = new PencilPaintOperation(target) { Color = Color.FromArgb(127, 0, 0, 0), CompositingMode = CompositingMode.SourceOver }; 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(); // Hash of the .png image that represents the target result of the paint operation. Generated through the 'RegisterResultBitmap' method byte[] goodHash = { 0x7D, 0xBB, 0x8A, 0xAE, 0x0, 0x75, 0x55, 0x54, 0x67, 0xE1, 0x35, 0x90, 0xE2, 0x77, 0xD3, 0xF1, 0xE4, 0xAD, 0xE2, 0xD6, 0xB, 0xDA, 0xCA, 0xB9, 0xDD, 0x64, 0x99, 0x70, 0xFF, 0x69, 0x6D, 0x52 }; byte[] currentHash = GetHashForBitmap(target); RegisterResultBitmap(target, "PencilOperation_SourceOverTransparentPaint"); Assert.IsTrue(goodHash.SequenceEqual(currentHash), "The hash for the paint operation must match the good hash stored"); }
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"); }
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"); }
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"); }
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"); }
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"); }
public void TestChangeBitmapUnderOperationException() { Bitmap bitmap = new Bitmap(64, 64); PencilPaintOperation paintOperation = new PencilPaintOperation(bitmap); paintOperation.StartOpertaion(); paintOperation.DrawTo(5, 5); paintOperation.TargetBitmap = new Bitmap(64, 64); }
/// <summary> /// Initializes this Paint Tool /// </summary> /// <param name="targetPictureBox">The picture box to initialize the paint tool on</param> public override void Initialize(ImageEditPanel.InternalPictureBox targetPictureBox) { base.Initialize(targetPictureBox); pictureBox = targetPictureBox; lastMousePosition = new Point(); pencilOperation = new PencilPaintOperation(targetPictureBox.Bitmap); UpdatePen(); ChangeBitmap(targetPictureBox.Bitmap); currentTraceBitmap = new Bitmap(targetPictureBox.Bitmap.Width, targetPictureBox.Bitmap.Height); CompositingMode = targetPictureBox.OwningPanel.DefaultCompositingMode; visible = true; Loaded = true; }
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())); } }
public void TestRedoOperation_SizedSourceOverAlpha() { // Create the objects Bitmap target = FrameGenerator.GenerateRandomBitmap(64, 64, 10); // Create the test subjects PlottingPaintUndoGenerator generator = new PlottingPaintUndoGenerator(target, "Pencil"); PencilPaintOperation operation = new PencilPaintOperation(target) { Color = Color.FromArgb(127, 0, 0, 0), CompositingMode = CompositingMode.SourceOver, Size = 5, Notifier = generator }; 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(); byte[] originalHash = GetHashForBitmap(target); // Undo and redo the task back generator.UndoTask.Undo(); generator.UndoTask.Redo(); byte[] afterRedoHash = GetHashForBitmap(target); RegisterResultBitmap(target, "PencilOperation_AfterRedo_SizedSourceOverAlpha"); Assert.IsTrue(originalHash.SequenceEqual(afterRedoHash), "After redoing a paint operation's task, its pixels must return to their original state after the operation was applied"); }
/// <summary> /// Performs the Line paint operation with the given parameters /// </summary> /// <param name="color">The color to use when drawing the line</param> /// <param name="firstPoint">The first point of the line to draw</param> /// <param name="secondPoint">The second point of the line to draw</param> /// <param name="bitmap">The Bitmap to draw the line on</param> /// <param name="compositingMode">The CompositingMode to use when drawing the line</param> /// <param name="size">The size of the line to draw</param> /// <param name="recordUndo">Whether to generate an undo operation for this line operation</param> /// <returns>An undo task for the line operation, or null, if recordUndo is false</returns> public static PerPixelUndoTask PerformLineOperation(Color color, Point firstPoint, Point secondPoint, Bitmap bitmap, CompositingMode compositingMode, int size, bool recordUndo) { PlottingPaintUndoGenerator generator = null; if (recordUndo) { generator = new PlottingPaintUndoGenerator(bitmap, "Line"); } PencilPaintOperation operation = new PencilPaintOperation(bitmap, true, firstPoint) { Color = color, CompositingMode = compositingMode, Notifier = generator, Size = size }; operation.StartOpertaion(false); operation.DrawTo(secondPoint.X, secondPoint.Y); operation.FinishOperation(); return(recordUndo ? generator.UndoTask : null); }
public void TestUndoOperation_SourceOverAlphaFailing() { // Create the objects Bitmap target = FrameGenerator.GenerateRandomBitmap(64, 64, 10); byte[] originalHash = GetHashForBitmap(target); // Create the test subjects PlottingPaintUndoGenerator generator = new PlottingPaintUndoGenerator(target, "Pencil", keepReplacedUndos: false); PencilPaintOperation operation = new PencilPaintOperation(target) { Color = Color.FromArgb(127, 0, 0, 0), CompositingMode = CompositingMode.SourceOver, Notifier = generator }; 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_AfterUndo_SourceOverAlpha_Failed"); Assert.IsFalse(originalHash.SequenceEqual(afterUndoHash), "Plotting the same pixel repeatedly with an undo generator that has keepReplacedOriginals should fail, since the redrawn pixels have their undo color replaced"); }