private static unsafe void GrayToRgb(ZsImage grayImage)
        {
            if (grayImage == null)
            {
                throw new ArgumentNullException();
            }

            grayImage.InsertComponents(new[] { 0.0, 0.0 }, 1);

            const int NotDividableMinAmountElements = 80;

            double[] pixelsData = grayImage.PixelsData;

            int pointsAmount = grayImage.Width * grayImage.Height;

            // Decide on how many partitions we should divade the processing
            // of the elements.
            var partsCount = pointsAmount > NotDividableMinAmountElements
                ? Environment.ProcessorCount
                : 1;

            var partSize = (int)(pointsAmount / partsCount);

            Parallel.For(0, partsCount, partIndex =>
            {
                var firstPointIndex = partIndex * partSize;
                var lastPointIndex  = firstPointIndex + partSize - 1;
                if (partIndex == partsCount - 1)
                {
                    lastPointIndex = pointsAmount - 1;
                }
                if (lastPointIndex > pointsAmount)
                {
                    lastPointIndex = pointsAmount - 1;
                }

                fixed(double *pixelsDataP = pixelsData)
                {
                    for (int pointIndex = lastPointIndex; pointIndex >= firstPointIndex; pointIndex--)
                    {
                        // Step 1. Inverse Companding
                        int i = pointIndex * 3;

                        // components should be in the range [0.0 , 1.0]
                        double gray = *(pixelsDataP + i + 0);

                        //*(pixelsDataP + i + 0) = gray;
                        *(pixelsDataP + i + 1) = gray;
                        *(pixelsDataP + i + 2) = gray;
                    }
                }
            });
        }
 public static ZsImage FromRgbToArgb(this ZsImage rgbImage, Area2D opaqueArea)
 {
     return(rgbImage.InsertComponents(new[] { 0.0 }, 0)
            .SetComponentsValues(opaqueArea, new[] { 1.0 }, 0));
 }