public void TestPixelCount() { // Create the tracker PixelHistoryTracker tracker = new PixelHistoryTracker(false, 12); // Add the pixels tracker.RegisterPixel(5, 5, 0xFF, 0x1F); tracker.RegisterPixel(6, 5, 0xEF, 0x2F); tracker.RegisterPixel(7, 5, 0xCF, 0x3F); Assert.AreEqual(3, tracker.PixelCount, "After consecutive calls to RegisterPixel, the pixel count must match the number of unique pixels provided"); }
public void TestDuplicatedPixelRegisteringReplaceOriginal() { // Create the tracker PixelHistoryTracker tracker = new PixelHistoryTracker(false, 12); // Add the pixels tracker.RegisterPixel(5, 5, 0xFF, 0x1F, false); tracker.RegisterPixel(5, 5, 0xEF, 0x2F, false); tracker.RegisterPixel(5, 5, 0xCF, 0x3F, false); var undo = tracker.PixelUndoForPixel(5, 5); Assert.IsTrue(undo != null && undo.Value.OldColor == 0xCF, "The returned PixelUndo does not contains the undo color that was expected. The pixel color must match the color of the last pixel registered RegisterPixel"); }
public void TestClearing() { // Create the tracker PixelHistoryTracker tracker = new PixelHistoryTracker(false, 12); // Add the pixels tracker.RegisterPixel(5, 5, 0xFF, 0x1F); tracker.RegisterPixel(6, 5, 0xEF, 0x2F); tracker.RegisterPixel(7, 5, 0xCF, 0x3F); tracker.Clear(); var undo = tracker.PixelUndoForPixel(5, 5); Assert.IsNull(undo, "After a call to .Clear(), all pixels that were previously stored must be cleared off the PixelHistoryTracker"); }
public void TestPixelRegistering() { // Create the tracker PixelHistoryTracker tracker = new PixelHistoryTracker(true, 12); // Add the pixels tracker.RegisterPixel(5, 5, 0xFF, 0x1F); var undo = tracker.PixelUndoForPixel(5, 5); Assert.IsTrue(undo != null && undo.Value.OldColor == 0xFF, "The returned PixelUndo does not contains the undo color that was expected"); }
/// <summary> /// Plots a pencil point at the specified point coordinates /// </summary> /// <param name="pointX">The X position to plot at</param> /// <param name="pointY">The Y position to plot at</param> public virtual void PlotPixel(int pointX, int pointY) { // Test boundaries if (!WithinBounds(pointX, pointY)) { return; } if (!AccumulateAlpha && pixelsDrawn.ContainsPixel(pointX, pointY)) { return; } Color oldColor = (useFastBitmap ? fastBitmap.GetPixel(pointX, pointY) : targetBitmap.GetPixel(pointX, pointY)); Color newColor = GetBlendedColor(oldColor); uint oldColorArgb = unchecked ((uint)oldColor.ToArgb()); uint newColorArgb = unchecked ((uint)newColor.ToArgb()); // If the colors are virtually the same, quit early if (oldColorArgb == newColorArgb) { return; } if (useFastBitmap) { fastBitmap.SetPixel(pointX, pointY, newColorArgb); } else { targetBitmap.SetPixel(pointX, pointY, newColor); } if (!AccumulateAlpha) { pixelsDrawn.RegisterPixel(pointX, pointY, oldColorArgb, newColorArgb); } Notifier?.PlottedPixel(new Point(pointX, pointY), (int)oldColorArgb, (int)newColorArgb); }