Example #1
0
        private static Color getOppositeVerticalHalfPixelColor(int i, int j, Color hiddenPixelColor,
                                                               Picture sourcePicture, Picture hiddenPicture)
        {
            if (i <= sourcePicture.VerticalCenter)
            {
                var swappedYValue = (int)(i + sourcePicture.VerticalCenter);
                if (swappedYValue < hiddenPicture.Height && j < hiddenPicture.Width)
                {
                    hiddenPixelColor = PixelUtilities.GetPixelBgra8(hiddenPicture.Pixels, swappedYValue, j,
                                                                    hiddenPicture.Width, hiddenPicture.Height);
                }
            }

            else
            {
                var swappedYValue = (int)(i - sourcePicture.VerticalCenter);
                if (swappedYValue < hiddenPicture.Height && j < hiddenPicture.Width)
                {
                    hiddenPixelColor = PixelUtilities.GetPixelBgra8(hiddenPicture.Pixels, swappedYValue, j,
                                                                    hiddenPicture.Width, hiddenPicture.Height);
                }
            }

            return(hiddenPixelColor);
        }
Example #2
0
        /// <summary>
        ///     Encrypts the image embedding.
        /// </summary>
        /// <param name="pixels">The pixels.</param>
        /// <param name="sourcePicture">The source picture.</param>
        /// <param name="hiddenPicture">The hidden picture.</param>
        public static void EncryptImage(byte[] pixels, Picture sourcePicture, Picture hiddenPicture)
        {
            for (var i = 0; i < sourcePicture.Height; i++)
            {
                for (var j = 0; j < sourcePicture.Width; j++)
                {
                    j = HeaderManager.SkipHeaderLocation(i, j);
                    var sourcePixelColor =
                        PixelUtilities.GetPixelBgra8(pixels, i, j, sourcePicture.Width, sourcePicture.Height);
                    var hiddenPixelColor = Colors.White;
                    hiddenPixelColor =
                        getOppositeVerticalHalfPixelColor(i, j, hiddenPixelColor, sourcePicture, hiddenPicture);

                    if (PixelUtilities.IsColorBlack(hiddenPixelColor))
                    {
                        embedBlackPixel(pixels, sourcePixelColor, i, j, sourcePicture);
                    }

                    else
                    {
                        embedWhitePixel(pixels, sourcePixelColor, i, j, sourcePicture);
                    }
                }
            }
        }
Example #3
0
        private void setSecondPixel(Color pixelColor, byte[] imageWithHeader)
        {
            if (this.EncryptionType == EncryptionType.Encrypted)
            {
                pixelColor.R |= 1;
            }
            else
            {
                pixelColor.R &= 0xfe;
            }

            if (this.FileType == FileType.Text)
            {
                pixelColor.B |= 1;
            }
            else
            {
                pixelColor.B &= 0xfe;
            }

            pixelColor.G = (byte)this.Bpcc;
            PixelUtilities.SetPixelBgra8(imageWithHeader, ImageConstants.FirstX, ImageConstants.SecondX,
                                         pixelColor, this.sourcePicture.Width,
                                         this.sourcePicture.Height);
        }
Example #4
0
        private void checkBpccValue()
        {
            var sourcePixelColor = PixelUtilities.GetPixelBgra8(this.sourcePicture.Pixels, ImageConstants.FirstX,
                                                                ImageConstants.SecondX, this.sourcePicture.Width,
                                                                this.sourcePicture.Height);

            this.bpcc = HeaderManager.CheckBpccValue(sourcePixelColor);
        }
Example #5
0
        private void setPixelWhite(int j, int i)
        {
            var sourcePixelColor =
                Color.FromArgb(this.maxRgbValue, this.maxRgbValue, this.maxRgbValue, this.maxRgbValue);

            PixelUtilities.SetPixelBgra8(this.sourcePicture.Pixels, j, i, sourcePixelColor,
                                         this.sourcePicture.Width, this.sourcePicture.Height);
        }
Example #6
0
        /// <summary>
        ///     Checks for encryption.
        /// </summary>
        /// <param name="pixelColor">Color of the pixel.</param>
        /// <returns>
        ///     Encrypted if LSB == 0, Unencrypted otherwise
        /// </returns>
        public static EncryptionType CheckForEncryption(Color pixelColor)
        {
            if (PixelUtilities.GetLeastSignificantBit(pixelColor.R) != ImageConstants.MinRgbValue)
            {
                return(EncryptionType.Encrypted);
            }

            return(EncryptionType.Unencrypted);
        }
Example #7
0
        /// <summary>
        ///     Determines whether this instance is encrypted.
        /// </summary>
        /// <returns>
        ///     <c>Encrypted</c> if this instance is encrypted; otherwise, <c>Unencrypted</c>.
        /// </returns>
        public EncryptionType IsEncrypted()
        {
            var sourcePixelColor = PixelUtilities.GetPixelBgra8(this.sourcePicture.Pixels, ImageConstants.FirstX,
                                                                ImageConstants.SecondX,
                                                                this.sourcePicture.Width,
                                                                this.sourcePicture.Height);

            return(HeaderManager.CheckForEncryption(sourcePixelColor));
        }
Example #8
0
        /// <summary>
        ///     Determines whether [contains hidden message].
        /// </summary>
        /// <returns>
        ///     <c>true</c> if [contains hidden message]; otherwise, <c>false</c>.
        /// </returns>
        public bool ContainsHiddenMessage()
        {
            var sourcePixelColor = PixelUtilities.GetPixelBgra8(this.sourcePicture.Pixels, ImageConstants.FirstX,
                                                                ImageConstants.FirstX,
                                                                this.sourcePicture.Width,
                                                                this.sourcePicture.Height);

            return(HeaderManager.ContainsHiddenMessage(sourcePixelColor));
        }
Example #9
0
        private void setPixelBlack(byte[] pixels, int i, int j)
        {
            var sourcePixelColor =
                Color.FromArgb(this.maxRgbValue, this.minRgbValue, this.minRgbValue, this.minRgbValue);

            PixelUtilities.SetPixelBgra8(pixels, i, j, sourcePixelColor,
                                         this.sourcePicture.Width,
                                         this.sourcePicture.Height);
        }
Example #10
0
        /// <summary>
        ///     Determines whether this instance is text.
        /// </summary>
        /// <returns>
        ///     <c>true</c> if this instance is text; otherwise, <c>false</c>.
        /// </returns>
        public bool IsText()
        {
            var sourcePixelColor = PixelUtilities.GetPixelBgra8(this.sourcePicture.Pixels, ImageConstants.FirstX,
                                                                ImageConstants.SecondX,
                                                                this.sourcePicture.Width,
                                                                this.sourcePicture.Height);

            return(HeaderManager.CheckFileType(sourcePixelColor));
        }
Example #11
0
 private void setFirstPixel(Color pixelColor, byte[] imageWithHeader)
 {
     pixelColor.R = (byte)ImageConstants.HiddenMessageValue;
     pixelColor.G = (byte)ImageConstants.HiddenMessageValue;
     pixelColor.B = (byte)ImageConstants.HiddenMessageValue;
     PixelUtilities.SetPixelBgra8(imageWithHeader, ImageConstants.FirstX, ImageConstants.FirstX,
                                  pixelColor, this.sourcePicture.Width,
                                  this.sourcePicture.Height);
 }
Example #12
0
        private void addWhitePoint(Picture sourcePicture, int i, int j, List <Point> points)
        {
            var pixelColor = PixelUtilities.GetPixelBgra8(sourcePicture.Pixels, i, j, sourcePicture.Width,
                                                          sourcePicture.Height);

            if (PixelUtilities.IsColorWhite(pixelColor))
            {
                points.Add(new Point(j, i));
            }
        }
Example #13
0
 private void setPixelToMonochromeColor(byte[] pixels, Color hiddenPixelColor, int i, int j)
 {
     if (PixelUtilities.GetLeastSignificantBit(hiddenPixelColor.B) == ImageConstants.MinRgbValue)
     {
         this.setPixelBlack(pixels, i, j);
     }
     else
     {
         this.setPixelWhite(pixels, i, j);
     }
 }
Example #14
0
        private void CreateTransformedImage()
        {
            Bitmap bitmap;

            ArgbColor[]     originalData;
            Size            size;
            IErrorDiffusion dither;

            this.CleanUpTransformed();

            if (_image == null)
            {
                return;
            }

            bitmap = _image;
            size   = bitmap.Size;

            int levels = (int)GrayscaleLevel.Value;
            int matrix = (int)ditherMatrix.Value;

            originalData = bitmap.GetPixelsFrom32BitArgbImage();

            dither = errorDiffusion.GetDitheringInstance();

            for (int row = 0; row < size.Height; row++)
            {
                for (int col = 0; col < size.Width; col++)
                {
                    int       index;
                    ArgbColor current;
                    ArgbColor transformed;

                    index = row * size.Width + col;

                    current = originalData[index];

                    // transform the pixel - normally this would be some form of color
                    // reduction. For this sample it's simple threshold based
                    // monochrome conversion
                    transformed         = PixelUtilities.TransformPixel(current, form1);
                    originalData[index] = transformed;

                    // apply a dither algorithm to this pixel
                    if (dither != null)
                    {
                        dither.Diffuse(originalData, current, transformed, col, row, size.Width, size.Height, levels, matrix);
                    }
                }
            }

            _transformed        = originalData.ToBitmap(size);
            WorkedPicture.Image = _transformed;
        }
Example #15
0
        private bool checkNewCircleCollision(int x, int y, Circle circle, ref bool valid)
        {
            var d = PixelUtilities.CalculateDistanceBetweenPixels(x, y, circle.X, circle.Y);

            if (d < circle.Radius + this.currentNewCircleRadius + 2)
            {
                valid = false;
                return(true);
            }

            return(false);
        }
Example #16
0
        private static bool checkCircleGrowthCollision(Circle circle, Circle other)
        {
            var d = PixelUtilities.CalculateDistanceBetweenPixels(circle.X, circle.Y, other.X,
                                                                  other.Y);
            var distance = circle.Radius + other.Radius;

            if (d - 2 < distance)
            {
                circle.Growing = false;
                return(true);
            }

            return(false);
        }
Example #17
0
 /// <summary>
 ///     Extracts the image.
 /// </summary>
 /// <param name="pixels">The pixels.</param>
 public void ExtractImage(byte[] pixels)
 {
     for (var i = 0; i < this.sourcePicture.Height; i++)
     {
         for (var j = 0; j < this.sourcePicture.Width; j++)
         {
             j = HeaderManager.SkipHeaderLocation(i, j);
             var hiddenPixelColor = PixelUtilities.GetPixelBgra8(pixels, i, j,
                                                                 this.sourcePicture.Width,
                                                                 this.sourcePicture.Height);
             this.setPixelToMonochromeColor(pixels, hiddenPixelColor, i, j);
         }
     }
 }
Example #18
0
        private void checkForEncryption()
        {
            var sourcePixelColor = PixelUtilities.GetPixelBgra8(this.sourcePicture.Pixels, ImageConstants.FirstX,
                                                                ImageConstants.SecondX, this.sourcePicture.Width,
                                                                this.sourcePicture.Height);

            if (HeaderManager.CheckForEncryption(sourcePixelColor) == EncryptionType.Encrypted)
            {
                this.isEncrypted = true;
            }
            else
            {
                this.isEncrypted = false;
            }
        }
Example #19
0
 private void loadAllPixelColorData(int[,] allPixR, int[,] allPixG, int[,] allPixB)
 {
     for (var i = 0; i < this.sourcePicture.Width - 1; i++)
     {
         for (var j = 0; j < this.sourcePicture.Height - 1; j++)
         {
             var sourcePixelColor = PixelUtilities.GetPixelBgra8(this.sourcePicture.Pixels, j, i,
                                                                 this.sourcePicture.Width,
                                                                 this.sourcePicture.Height);
             allPixR[i, j] = sourcePixelColor.R;
             allPixG[i, j] = sourcePixelColor.G;
             allPixB[i, j] = sourcePixelColor.B;
         }
     }
 }
Example #20
0
        private void embedPixel(byte[] pixels, int i, int j)
        {
            var sourcePixelColor = PixelUtilities.GetPixelBgra8(pixels, i, j, this.sourcePicture.Width,
                                                                this.sourcePicture.Height);
            var hiddenPixelColor = PixelUtilities.GetPixelBgra8(this.hiddenPicture.Pixels, i, j,
                                                                this.hiddenPicture.Width, this.hiddenPicture.Height);

            if (PixelUtilities.IsColorBlack(hiddenPixelColor))
            {
                this.embedBlackPixel(pixels, sourcePixelColor, i, j);
            }
            else
            {
                this.embedWhitePixel(pixels, sourcePixelColor, i, j);
            }
        }
        private void colorPolygon(Polygon polygon)
        {
            if (polygon.Points != null)
            {
                var maxX         = polygon.Points.Max(point => point.X);
                var maxY         = polygon.Points.Max(point => point.Y);
                var minX         = polygon.Points.Min(point => point.X);
                var minY         = polygon.Points.Min(point => point.Y);
                var firstPoint   = new Point(minX, minY);
                var secondPoint  = new Point(maxX, maxY);
                var averageColor = PixelUtilities.GetAverageColor(this.SourcePicture, firstPoint, secondPoint);

                Brush brush = new SolidColorBrush(averageColor);
                polygon.Fill            = brush;
                polygon.Stroke          = brush;
                polygon.StrokeThickness = 1.0;
            }
        }
Example #22
0
        private int updatePixel(IReadOnlyList <byte> bytes, int i, int j, int index)
        {
            var sourcePixelColor = PixelUtilities.GetPixelBgra8(this.sourcePicture.Pixels, i, j,
                                                                this.sourcePicture.Width, this.sourcePicture.Height);

            sourcePixelColor.R = bytes[index];
            index++;

            sourcePixelColor.G = bytes[index];
            index++;

            sourcePixelColor.B = bytes[index];
            index++;

            PixelUtilities.SetPixelBgra8(this.sourcePicture.Pixels, i, j, sourcePixelColor,
                                         this.sourcePicture.Width, this.sourcePicture.Height);
            return(index);
        }
Example #23
0
 private void setPixelToClosestQuantizedColor(List <QuantizedColor> colors, Color sourcePixelColor,
                                              double distance, int j, int i)
 {
     foreach (var quantizedColor in colors)
     {
         var color   = quantizedColor.Color;
         var curDist = Math.Pow(color.R - sourcePixelColor.R, 2) +
                       Math.Pow(color.G - sourcePixelColor.G, 2) +
                       Math.Pow(color.B - sourcePixelColor.B, 2);
         if (curDist < distance)
         {
             distance = curDist;
             var newPixelColor = Color.FromArgb(255, color.R, color.G, color.B);
             PixelUtilities.SetPixelBgra8(this.sourcePicture.Pixels, j, i, newPixelColor,
                                          this.sourcePicture.Width,
                                          this.sourcePicture.Height);
         }
     }
 }
Example #24
0
 /// <summary>
 ///     Decrypts the picture.
 /// </summary>
 /// <param name="extractedImage">The extracted image.</param>
 public static void DecryptPicture(Picture extractedImage)
 {
     for (var i = 0; i < extractedImage.Height / 2; i++)
     {
         for (var j = 0; j < extractedImage.Width; j++)
         {
             var currentIndex       = i;
             var oppositeYValue     = (int)(currentIndex + extractedImage.VerticalCenter);
             var oppositePixelColor = PixelUtilities.GetPixelBgra8(extractedImage.Pixels, oppositeYValue, j,
                                                                   extractedImage.Width, extractedImage.Height);
             var pixelColor = PixelUtilities.GetPixelBgra8(extractedImage.Pixels, i, j, extractedImage.Width,
                                                           extractedImage.Height);
             PixelUtilities.SetPixelBgra8(extractedImage.Pixels, i, j, oppositePixelColor, extractedImage.Width,
                                          extractedImage.Height);
             PixelUtilities.SetPixelBgra8(extractedImage.Pixels, oppositeYValue, j, pixelColor,
                                          extractedImage.Width, extractedImage.Height);
         }
     }
 }
Example #25
0
        /// <summary>
        ///     Sets the header for hidden message.
        /// </summary>
        /// <returns>
        ///     source pixels
        /// </returns>
        public byte[] SetHeaderForHiddenMessage()
        {
            var imageWithHeader = this.sourcePicture.Pixels;

            for (var i = 0; i <= ImageConstants.SecondX; i++)
            {
                var pixelColor = PixelUtilities.GetPixelBgra8(imageWithHeader, ImageConstants.FirstX, i,
                                                              this.sourcePicture.Width,
                                                              this.sourcePicture.Height);
                if (i == ImageConstants.FirstX)
                {
                    this.setFirstPixel(pixelColor, imageWithHeader);
                }
                else
                {
                    this.setSecondPixel(pixelColor, imageWithHeader);
                }
            }

            return(imageWithHeader);
        }
Example #26
0
        /// <summary>
        ///     Applies the grayscale filter.
        /// </summary>
        public void applyGrayscaleFilter()
        {
            for (var i = 0; i < this.sourcePicture.Width - 1; i++)
            {
                for (var j = 0; j < this.sourcePicture.Height - 1; j++)
                {
                    var sourcePixelColor = PixelUtilities.GetPixelBgra8(this.sourcePicture.Pixels, j, i,
                                                                        this.sourcePicture.Width,
                                                                        this.sourcePicture.Height);
                    var averageColor = (sourcePixelColor.R + sourcePixelColor.G + sourcePixelColor.B) /
                                       ImageConstants.ColorChannelCount;
                    var averageColorByte = Convert.ToByte(averageColor);
                    var newPixelColor    = Color.FromArgb(this.maxRgbValue, averageColorByte, averageColorByte,
                                                          averageColorByte);
                    PixelUtilities.SetPixelBgra8(this.sourcePicture.Pixels, j, i, newPixelColor,
                                                 this.sourcePicture.Width,
                                                 this.sourcePicture.Height);
                }
            }

            this.sourcePicture.ModifiedImage =
                new WriteableBitmap((int)this.sourcePicture.Width, (int)this.sourcePicture.Height);
        }
Example #27
0
        /// <summary>
        ///     Applies image segmentation on an image to get the amount of specified colors from the image.
        /// </summary>
        /// <param name="colorCount">The color count.</param>
        /// <param name="quality">The quality.</param>
        public async Task ApplyImageSegmentation(int colorCount, int quality)
        {
            var colorThief = new ColorThief();
            var fileStream = await this.sourcePicture.File.OpenAsync(FileAccessMode.Read);

            var decoder = await BitmapDecoder.CreateAsync(fileStream);

            var colors = await colorThief.GetPalette(decoder, colorCount, quality, false);

            for (var i = 0; i < this.sourcePicture.Width - 1; i++)
            {
                for (var j = 0; j < this.sourcePicture.Height - 1; j++)
                {
                    var sourcePixelColor = PixelUtilities.GetPixelBgra8(this.sourcePicture.Pixels, j, i,
                                                                        this.sourcePicture.Width,
                                                                        this.sourcePicture.Height);
                    this.setPixelToClosestQuantizedColor(colors, sourcePixelColor, MaxDistance, j, i);
                }
            }

            this.sourcePicture.ModifiedImage =
                new WriteableBitmap((int)this.sourcePicture.Width, (int)this.sourcePicture.Height);
        }
Example #28
0
 /// <summary>
 ///     Determines whether this instance is text.
 /// </summary>
 /// <param name="pixelColor">Color of the pixel.</param>
 /// <returns>
 ///     <c>true</c> if this instance is text; otherwise, <c>false</c>.
 /// </returns>
 public static bool CheckFileType(Color pixelColor)
 {
     return(PixelUtilities.GetLeastSignificantBit(pixelColor.B) != ImageConstants.MinRgbValue);
 }
Example #29
0
 private static void embedBlackPixel(byte[] pixels, Color sourcePixelColor, int i, int j, Picture sourcePicture)
 {
     sourcePixelColor.B = (byte)(sourcePixelColor.B & ~1);
     PixelUtilities.SetPixelBgra8(pixels, i, j, sourcePixelColor,
                                  sourcePicture.Width, sourcePicture.Height);
 }
Example #30
0
 private static void embedWhitePixel(byte[] pixels, Color sourcePixelColor, int i, int j, Picture sourcePicture)
 {
     sourcePixelColor.B |= 1;
     PixelUtilities.SetPixelBgra8(pixels, i, j, sourcePixelColor, sourcePicture.Width, sourcePicture.Height);
 }