コード例 #1
0
ファイル: Processor.cs プロジェクト: Khrystyna-Pelekh/ITA
        public byte[] GetWaterMarkedBytes(string waterMark)
        {
            InseredWaterMarkIndexes.Clear();

            var waterMarkedBytes = new byte[originalBytes.Length];

            originalBytes.CopyTo(waterMarkedBytes, 0);

            var waterMarkBits = WaterMark.FromString(waterMark);

            OriginalWaterMarkBits = waterMarkBits;
            var waterMarkBitIndex = 0;

            if (mode == Mode.Direct)
            {
                for (var index = HeaderSize + 4; index + Shift < waterMarkedBytes.Length; index += Shift)
                {
                    var startIndex = index;
                    var endIndex   = index + Shift;

                    var maxAmplitudeIndex = FindMaxAmplitudeIndex(waterMarkedBytes, startIndex, endIndex);

                    InseredWaterMarkIndexes.Add(maxAmplitudeIndex);
                    SetMark(waterMarkedBytes, waterMarkBits[waterMarkBitIndex], maxAmplitudeIndex);

                    waterMarkBitIndex = waterMarkBitIndex < waterMarkBits.Length - 1
                                ? waterMarkBitIndex + 1
                                : 0;
                }
            }
            else if (mode == Mode.Quasi)
            {
                var quasi        = new QuasiStationary(waterMarkedBytes.Skip(HeaderSize).Take(waterMarkedBytes.Length - HeaderSize).ToArray(), Shift, QuasiEpsilon);
                var quasiIndexes = quasi.Split();

                for (var i = 0; i < quasiIndexes.Count; i++)
                {
                    var startIndex = quasiIndexes[i] * Shift;
                    var endIndex   = (i + 1) < quasiIndexes.Count
                           ? quasiIndexes[i + 1] * Shift - 1 // Start index of next quasi area * segment length - 1
                           : waterMarkedBytes.Length - 1;    // End of signal

                    var maxAmplitudeIndex = FindMaxAmplitudeIndex(waterMarkedBytes, startIndex, endIndex);

                    InseredWaterMarkIndexes.Add(maxAmplitudeIndex);
                    SetMark(waterMarkedBytes, waterMarkBits[waterMarkBitIndex], maxAmplitudeIndex);

                    waterMarkBitIndex = waterMarkBitIndex < waterMarkBits.Length - 1
                                ? waterMarkBitIndex + 1
                                : 0;
                }
            }
            else
            {
                throw new NotImplementedException();
            }

            return(waterMarkedBytes);
        }
コード例 #2
0
ファイル: Processor.cs プロジェクト: Khrystyna-Pelekh/ITA
        public byte[] ExtractWaterMark(byte[] waterMarkedBytes)
        {
            ExtractedWaterMarkIndexes.Clear();

            var unwaterMarkedBytes = new byte[waterMarkedBytes.Length];

            waterMarkedBytes.CopyTo(unwaterMarkedBytes, 0);

            var waterMarkBits = new List <byte>();

            if (mode == Mode.Direct)
            {
                for (var index = HeaderSize + 4; index + Shift < unwaterMarkedBytes.Length; index += Shift)
                {
                    var startIndex = index;
                    var endIndex   = index + Shift;

                    var maxAmplitudeIndex = FindMaxAmplitudeIndex(unwaterMarkedBytes, startIndex, endIndex);

                    ExtractedWaterMarkIndexes.Add(maxAmplitudeIndex);
                    waterMarkBits.Add(GetMark(unwaterMarkedBytes, maxAmplitudeIndex));
                }
            }
            else if (mode == Mode.Quasi)
            {
                var quasi        = new QuasiStationary(waterMarkedBytes.Skip(HeaderSize).Take(waterMarkedBytes.Length - HeaderSize).ToArray(), Shift, QuasiEpsilon);
                var quasiIndexes = quasi.Split();

                for (var i = 0; i < quasiIndexes.Count; i++)
                {
                    var startIndex = quasiIndexes[i] * Shift;
                    var endIndex   = (i + 1) < quasiIndexes.Count
                           ? quasiIndexes[i + 1] * Shift - 1 // Start index of next quasi area * segment length - 1
                           : waterMarkedBytes.Length - 1;    // End of signal

                    var maxAmplitudeIndex = FindMaxAmplitudeIndex(waterMarkedBytes, startIndex, endIndex);

                    ExtractedWaterMarkIndexes.Add(maxAmplitudeIndex);
                    waterMarkBits.Add(GetMark(unwaterMarkedBytes, maxAmplitudeIndex));
                }
            }
            else
            {
                throw new NotImplementedException();
            }

            ExtractedWaterMarkBits = waterMarkBits.ToArray();

            return(unwaterMarkedBytes);
        }