internal int GetBitsCount(PixelRGBValue selectedPixel)
        {
            switch (selectedPixel)
            {
            case PixelRGBValue.R:
                return(R);

            case PixelRGBValue.G:
                return(G);

            case PixelRGBValue.B:
                return(B);

            default:
                throw new ArgumentException("Wrong selected Pixel value", "selectedPixel");
            }
        }
        protected static PixelRGBValue IncreasePixelRGBValue(PixelRGBValue selectedPixel, ref bool shouldIncreaseRowAndColumn)
        {
            switch (selectedPixel)
            {
            case PixelRGBValue.R:
                return(PixelRGBValue.G);

            case PixelRGBValue.G:
                return(PixelRGBValue.B);

            case PixelRGBValue.B:
                shouldIncreaseRowAndColumn = true;
                return(PixelRGBValue.R);

            default:
                throw new ArgumentException("Wrong PixelRGBValue value", "selectedPixel");
            }
        }
        public Stream EncodeDataFromImage(Bitmap bitmap, BitmapCodeDataConfig config)
        {
            var           streamWriter = new MemoryStream();
            int           row = 0, column = 0;
            PixelRGBValue selectedPixel            = PixelRGBValue.R;
            int           readedBitsInPixelSegment = 0;
            byte          encodedByte              = 0;

            do
            {
                encodedByte = EncodeByteFromBitmap(bitmap, config, ref row, ref column, ref selectedPixel, ref readedBitsInPixelSegment);
                if (encodedByte != 0)
                {
                    streamWriter.WriteByte(encodedByte);
                }
            } while (encodedByte != 0 && RowAndColumnIsValid(bitmap, row, column));
            streamWriter.Position = 0;
            return(streamWriter);
        }
Exemple #4
0
        private static Color SetColorValue(Color pixelColor, BitmapCodeDataConfig config, PixelRGBValue selectedPixel, int savedBitsInByte, int readedData, ref int savedBits)
        {
            int r = pixelColor.R;
            int g = pixelColor.G;
            int b = pixelColor.B;

            switch (selectedPixel)
            {
            case PixelRGBValue.R:
                r = CalculateNewColorPropertyValue(pixelColor.R, config.R, readedData, savedBitsInByte, ref savedBits);
                break;

            case PixelRGBValue.G:
                g = CalculateNewColorPropertyValue(pixelColor.G, config.G, readedData, savedBitsInByte, ref savedBits);
                break;

            case PixelRGBValue.B:
                b = CalculateNewColorPropertyValue(pixelColor.B, config.B, readedData, savedBitsInByte, ref savedBits);
                break;

            default:
                throw new ArgumentException("Wrong PixelRGBValue value", "selectedPixel");
            }
            return(Color.FromArgb(r, g, b));
        }
Exemple #5
0
 private static Color CodeBitDataToPixelColor(Color pixelColor, BitmapCodeDataConfig config, int savedBitsInByte, int readedData, ref PixelRGBValue selectedPixel, ref int savedBits, ref bool shouldIncreaseRowAndColumn)
 {
     pixelColor = SetColorValue(pixelColor, config, selectedPixel, savedBitsInByte, readedData, ref savedBits);
     if (config.GetBitsCount(selectedPixel) == savedBits)
     {
         selectedPixel = IncreasePixelRGBValue(selectedPixel, ref shouldIncreaseRowAndColumn);
         savedBits     = 0;
     }
     return(pixelColor);
 }
Exemple #6
0
        private static Bitmap WriteDataToBitmap(Bitmap result, int readedData, BitmapCodeDataConfig config, ref int column, ref int row, ref PixelRGBValue selectedPixel, ref int savedBits)
        {
            for (int savedBitsInByte = 0; savedBitsInByte < 8; savedBitsInByte++)
            {
                bool shouldIncreaseRowAndColumn = false;
                var  pixelColor    = result.GetPixel(row, column);
                var  newPixelColor = CodeBitDataToPixelColor(pixelColor, config, savedBitsInByte, readedData, ref selectedPixel, ref savedBits, ref shouldIncreaseRowAndColumn);
                result.SetPixel(row, column, newPixelColor);

                if (shouldIncreaseRowAndColumn)
                {
                    IncreaseRowAndColumn(result, ref row, ref column);
                }
            }
            return(result);
        }
        private byte AddBitToResultFromColor(Color pixelColor, BitmapCodeDataConfig config, PixelRGBValue selectedPixel, byte result, ref int readedBitsInPixelSegment)
        {
            switch (selectedPixel)
            {
            case PixelRGBValue.R:
                result = AddBitToResult(pixelColor.R, config.R, result, ref readedBitsInPixelSegment);
                break;

            case PixelRGBValue.G:
                result = AddBitToResult(pixelColor.G, config.G, result, ref readedBitsInPixelSegment);
                break;

            case PixelRGBValue.B:
                result = AddBitToResult(pixelColor.B, config.B, result, ref readedBitsInPixelSegment);
                break;

            default:
                throw new ArgumentException("Wrong PixelRGBValue value", "selectedPixel");
            }
            return(result);
        }
 private byte EncodeBitDataFromPixelColor(Color pixelColor, BitmapCodeDataConfig config, byte result, ref PixelRGBValue selectedPixel, ref int readedBitsInPixelSegment, ref bool shouldIncreaseRowAndColumn)
 {
     result = AddBitToResultFromColor(pixelColor, config, selectedPixel, result, ref readedBitsInPixelSegment);
     if (config.GetBitsCount(selectedPixel) == readedBitsInPixelSegment)
     {
         selectedPixel            = IncreasePixelRGBValue(selectedPixel, ref shouldIncreaseRowAndColumn);
         readedBitsInPixelSegment = 0;
     }
     return(result);
 }
        private byte EncodeByteFromBitmap(Bitmap bitmap, BitmapCodeDataConfig config, ref int row, ref int column, ref PixelRGBValue selectedPixel, ref int readedBitsInPixelSegment)
        {
            byte result = 0;

            for (int encodedBitsInByte = 0; encodedBitsInByte < 8 && RowAndColumnIsValid(bitmap, row, column); encodedBitsInByte++)
            {
                bool shouldIncreaseRowAndColumn = false;
                var  pixelColor = bitmap.GetPixel(row, column);
                result = EncodeBitDataFromPixelColor(pixelColor, config, result, ref selectedPixel, ref readedBitsInPixelSegment, ref shouldIncreaseRowAndColumn);
                if (shouldIncreaseRowAndColumn)
                {
                    IncreaseRowAndColumn(bitmap, ref row, ref column);
                }
            }
            return(result);
        }