示例#1
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);
                    }
                }
            }
        }
示例#2
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);
        }
示例#3
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);
        }
示例#4
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));
        }
示例#5
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));
        }
示例#6
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));
        }
示例#7
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));
            }
        }
示例#8
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);
         }
     }
 }
示例#9
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;
         }
     }
 }
示例#10
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;
            }
        }
示例#11
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);
            }
        }
示例#12
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);
        }
示例#13
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);
         }
     }
 }
示例#14
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);
        }
示例#15
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);
        }
示例#16
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);
        }