Пример #1
0
        public void Opacity(MyImage myImage2, float opacity, TransitionModes transitionMode = TransitionModes.NoTransition, float previousPercentage = 0f, float percentage = 1f)
        {
            if (IsBlendingCalculated)
            {
                return;
            }

            percentage         = Calculations.ClampToNormal(percentage);
            previousPercentage = Calculations.ClampToNormal(previousPercentage);

            InitBoundaries(previousPercentage, percentage,
                           out float previousLinearBoundaryX, out float linearBoundaryX, out float previousReversedLinearBoundaryX, out float reversedLinearBoundaryX,
                           out float previousLinearBoundaryY, out float linearBoundaryY, out float previousReversedLinearBoundaryY, out float reversedLinearBoundaryY,
                           out float previousRightHalfLinearBoundaryX, out float rightHalfLinearBoundaryX, out float previousLeftHalfLinearBoundaryX, out float leftHalfLinearBoundaryX,
                           out float previousLowerHalfLinearBoundaryY, out float lowerHalfLinearBoundaryY, out float previousHigherHalfLinearBoundaryY, out float higherHalfLinearBoundaryY,
                           out float previusRadiusBoundary, out float radiusBoundary);

            int[] nums = Enumerable.Range(0, ByteArray.PrimitiveArray.Length / Channels).Select(i => i * Channels).ToArray();
            Parallel.ForEach(nums, i =>
            {
                Point coordinates = ByteArray.GetCoordinates(i);

                bool isValid = ValidateBoundaries(coordinates, transitionMode,
                                                  previousLinearBoundaryX, linearBoundaryX, previousReversedLinearBoundaryX, reversedLinearBoundaryX,
                                                  previousLinearBoundaryY, linearBoundaryY, previousReversedLinearBoundaryY, reversedLinearBoundaryY,
                                                  previousLeftHalfLinearBoundaryX, leftHalfLinearBoundaryX, previousRightHalfLinearBoundaryX, rightHalfLinearBoundaryX,
                                                  previousHigherHalfLinearBoundaryY, higherHalfLinearBoundaryY, previousLowerHalfLinearBoundaryY, lowerHalfLinearBoundaryY,
                                                  previusRadiusBoundary, radiusBoundary);

                if (!isValid)
                {
                    return;
                }

                for (int channel = 0; channel < Channels; channel++)
                {
                    ByteArray.PrimitiveArray[i + channel] = Calculations.ClampToByte(Blending.Opacity(ByteArray.PrimitiveArray[i + channel], myImage2.ByteArray.PrimitiveArray[i + channel], opacity));
                }
            });

            WriteableBitmap writeableBitmap = new WriteableBitmap(BitmapSource.Create(Width, Height, 96, 96, PixelFormats.Bgr32, null, ByteArray.PrimitiveArray, ByteArray.Stride));

            WriteableBitmap = writeableBitmap;
        }
Пример #2
0
        public WriteableBitmap Fade(MyImage myImage1, float percentage = 1f)
        {
            percentage = Calculations.ClampToNormal(percentage);

            ByteArray tempByteArray = ByteArray.Clone();

            int[] nums = Enumerable.Range(0, ByteArray.PrimitiveArray.Length / Channels).Select(i => i * Channels).ToArray();
            Parallel.ForEach(nums, i =>
            {
                for (int channel = 0; channel < Channels; channel++)
                {
                    tempByteArray.PrimitiveArray[i + channel] = Blending.Opacity(
                        tempByteArray.PrimitiveArray[i + channel],
                        myImage1.ByteArray.PrimitiveArray[i + channel],
                        percentage);
                }
            });

            WriteableBitmap writeableBitmap = new WriteableBitmap(BitmapSource.Create(Width, Height, 96, 96, PixelFormats.Bgr32, null, tempByteArray.PrimitiveArray, tempByteArray.Stride));

            writeableBitmap.Freeze();
            return(writeableBitmap);
        }