public void GenerateRandomPixels_ShouldGeneratePixles_ListOfPixelsWithCertainLength() { //Arrange PixelHandler pixelHandler = new PixelHandler(); int heightOfImage = pixelHandler.HeightOfImage; int widthOfImage = pixelHandler.WidthOfImage; int totalLength = heightOfImage * widthOfImage; List <Color> listOfRandomPixels = new List <Color>(); //Act listOfRandomPixels = pixelHandler.GenerateRandomPixels(); //Assert Assert.AreEqual(totalLength, listOfRandomPixels.Count); }
public void PerPixelInArea(Rectangle area, PixelHandler pixelHandler) { if (area.X + area.Width > PixelWidth) { throw new ArgumentException($"Requested Rectangle {area} does not fit into the bounds of the bitmap width {PixelWidth}"); } if (area.Y + area.Height > PixelHeight) { throw new ArgumentException($"Requested Rectangle {area} does not fit into the bounds of the bitmap height {PixelHeight}"); } var pixelExtractor = PixelColorExtractor.Create(PixelFormat); int pixelWidth = area.X; int pixelHeight = area.Y; int pixelFinalWidth = (area.X + area.Width); int byteIndex = PixelXYToByteIndex(area.X, area.Y); int byteFinalIndex = PixelXYToByteIndex(0, area.Y + area.Height); int A = 255; int R = 255; int G = 255; int B = 255; while (byteIndex < byteFinalIndex) { pixelExtractor.ExtractPixelBytesToColor(RawPixelBytes, byteIndex, ref A, ref R, ref G, ref B); pixelHandler?.Invoke(pixelWidth - area.X, pixelHeight - area.Y, A, R, G, B); pixelWidth++; if (pixelWidth >= pixelFinalWidth) { pixelWidth = area.X; pixelHeight++; } byteIndex = PixelXYToByteIndex(pixelWidth, pixelHeight); A = 255; R = 255; G = 255; B = 255; } }
public void SortPixelsByHue_SortPixelsInAscendingOrder_SortedPixels() { //Arrange List <Color> listOfPixelsToBeSorted = new List <Color>(); List <Color> listOfPixelsExpected = new List <Color>(); List <Color> listOfPixelsActual = new List <Color>(); listOfPixelsToBeSorted.Add(Color.FromArgb(100, 0, 255, 255)); listOfPixelsToBeSorted.Add(Color.FromArgb(100, 0, 255, 0)); listOfPixelsToBeSorted.Add(Color.FromArgb(100, 0, 0, 255)); listOfPixelsToBeSorted.Add(Color.FromArgb(100, 255, 191, 0)); listOfPixelsToBeSorted.Add(Color.FromArgb(100, 255, 64, 0)); listOfPixelsToBeSorted.Add(Color.FromArgb(100, 64, 0, 255)); listOfPixelsToBeSorted.Add(Color.FromArgb(100, 0, 255, 64)); listOfPixelsToBeSorted.Add(Color.FromArgb(100, 0, 255, 128)); listOfPixelsToBeSorted.Add(Color.FromArgb(100, 0, 128, 255)); listOfPixelsToBeSorted.Add(Color.FromArgb(100, 191, 255, 0)); listOfPixelsExpected.Add(Color.FromArgb(100, 255, 64, 0)); listOfPixelsExpected.Add(Color.FromArgb(100, 255, 191, 0)); listOfPixelsExpected.Add(Color.FromArgb(100, 191, 255, 0)); listOfPixelsExpected.Add(Color.FromArgb(100, 0, 255, 0)); listOfPixelsExpected.Add(Color.FromArgb(100, 0, 255, 64)); listOfPixelsExpected.Add(Color.FromArgb(100, 0, 255, 128)); listOfPixelsExpected.Add(Color.FromArgb(100, 0, 255, 255)); listOfPixelsExpected.Add(Color.FromArgb(100, 0, 128, 255)); listOfPixelsExpected.Add(Color.FromArgb(100, 0, 0, 255)); listOfPixelsExpected.Add(Color.FromArgb(100, 64, 0, 255)); PixelHandler pixelHandler = new PixelHandler(); //Act listOfPixelsActual = pixelHandler.SortPixelsByHue(listOfPixelsToBeSorted); //Assert CollectionAssert.AreEqual(listOfPixelsExpected, listOfPixelsActual); }
public void PerPixel(PixelHandler pixelHandler) { PerPixelInArea(new Rectangle(0, 0, PixelWidth, PixelHeight), pixelHandler); }