Esempio n. 1
0
        public BitmapPixelChanges ChangeBrightness(Layer layer, Coordinates coordinates, int toolSize,
                                                   float correctionFactor)
        {
            DoubleCords centeredCoords = CoordinatesCalculator.CalculateThicknessCenter(coordinates, toolSize);

            Coordinates[] rectangleCoordinates = CoordinatesCalculator.RectangleToCoordinates(centeredCoords.Coords1.X,
                                                                                              centeredCoords.Coords1.Y,
                                                                                              centeredCoords.Coords2.X, centeredCoords.Coords2.Y);
            BitmapPixelChanges changes = new BitmapPixelChanges(new Dictionary <Coordinates, Color>());

            for (int i = 0; i < rectangleCoordinates.Length; i++)
            {
                if (Mode == BrightnessMode.Default)
                {
                    if (_pixelsVisited.Contains(rectangleCoordinates[i]))
                    {
                        continue;
                    }
                    _pixelsVisited.Add(rectangleCoordinates[i]);
                }

                Color pixel    = layer.GetPixelWithOffset(rectangleCoordinates[i].X, rectangleCoordinates[i].Y);
                Color newColor = ExColor.ChangeColorBrightness(Color.FromArgb(pixel.A, pixel.R, pixel.G, pixel.B),
                                                               correctionFactor);
                changes.ChangedPixels.Add(new Coordinates(rectangleCoordinates[i].X, rectangleCoordinates[i].Y),
                                          newColor);
            }

            return(changes);
        }
Esempio n. 2
0
        private BitmapPixelChanges ChangeBrightness(Layer layer, Coordinates coordinates, int toolSize, float correctionFactor)
        {
            PenTool pen      = new PenTool();
            Color   pixel    = layer.LayerBitmap.GetPixel(coordinates.X, coordinates.Y);
            Color   newColor = ExColor.ChangeColorBrightness(Color.FromArgb(pixel.A, pixel.R, pixel.G, pixel.B), correctionFactor);

            return(pen.Draw(coordinates, newColor, toolSize));
        }
Esempio n. 3
0
        /// <summary>
        /// Darkens pixel color.
        /// </summary>
        /// <param name="bitmap">Bitmap to work on.</param>
        /// <param name="coordinates">Pixel coordinates.</param>
        /// <returns></returns>
        private WriteableBitmap Darken(WriteableBitmap bitmap, Coordinates coordinates)
        {
            WriteableBitmap wb       = bitmap;
            Color           pixel    = wb.GetPixel(coordinates.X, coordinates.Y);
            Color           newColor = ExColor.ChangeColorBrightness(System.Drawing.Color.FromArgb(pixel.R, pixel.G, pixel.B), -0.06f);

            wb.SetPixel(coordinates.X, coordinates.Y, newColor);
            return(wb);
        }
        public void HslToRgbTest(int h, float s, float l, int r, int g, int b)
        {
            Color rgb            = ExColor.HslToRgb(h, s, l);
            int   marginOfErrorR = Math.Abs(rgb.R - r);
            int   marginOfErrorG = Math.Abs(rgb.G - g);
            int   marginOfErrorB = Math.Abs(rgb.B - b);

            Assert.True(marginOfErrorR <= AcceptableMaringOfError);
            Assert.True(marginOfErrorG <= AcceptableMaringOfError);
            Assert.True(marginOfErrorB <= AcceptableMaringOfError);
        }
        public void RgbToHslTest(int r, int g, int b, int h, float s, float l)
        {
            Tuple <int, float, float> hsl = ExColor.RgbToHsl(r, g, b);
            float marginOfErrorH          = Math.Abs(hsl.Item1 - h);
            float marginOfErrorS          = Math.Abs(hsl.Item2 - s);
            float marginOfErrorL          = Math.Abs(hsl.Item3 - l);

            Assert.True(marginOfErrorH <= AcceptableMaringOfError);
            Assert.True(marginOfErrorS <= AcceptableMaringOfError);
            Assert.True(marginOfErrorL <= AcceptableMaringOfError);
        }
Esempio n. 6
0
        public void ChangeColorBrightnessNewValueTest()
        {
            Color newColor = ExColor.ChangeColorBrightness(Colors.White, -1f);

            Assert.AreEqual(Colors.Black, newColor);
        }
Esempio n. 7
0
        public void ChangeColorBrightnessIsNotTheSameTest()
        {
            Color newColor = ExColor.ChangeColorBrightness(Colors.White, -0.1f);

            Assert.AreNotEqual(Colors.White, newColor);
        }
        public void ChangeColorBrightnessNewValueTest()
        {
            SKColor newColor = ExColor.ChangeColorBrightness(SKColors.White, -100);

            Assert.Equal(SKColors.Black, newColor);
        }
        public void ChangeColorBrightnessIsNotTheSameTest()
        {
            SKColor newColor = ExColor.ChangeColorBrightness(SKColors.White, -1);

            Assert.NotEqual(SKColors.White, newColor);
        }