/// <summary>
        /// Converts a <see cref="GenericImage{T}"/> to a <see cref="Texture2D"/> type.
        /// </summary>
        /// <param name="image">The image to be converted.</param>
        /// <returns>Returns a new <see cref="Texture2D"/> type.</returns>
        public static Texture2D ToTexture2D(this GenericImage <UnityEngine.Color> image)
        {
            var texture      = new Texture2D(image.Width, image.Height, TextureFormat.ARGB32, false);
            var flippedImage = image.Clone();

            flippedImage.FlipVertically();
            texture.SetPixels32(flippedImage.ToUnityColor32Array());
            texture.Apply();
            return(texture);
        }
        /// <summary>
        /// Flips a image vertically.
        /// </summary>
        /// <typeparam name="T">
        /// Specifies the type use for pixel data.
        /// </typeparam>
        /// <param name="image">
        /// A reference to the image to be flipped.
        /// </param>
        /// <exception cref="NullReferenceException">
        /// If the <see cref="image"/> parameter is null.
        /// </exception>
        public static void FlipVertically <T>(this GenericImage <T> image)
        {
            // TODO: Cloning is easy but memory intensive replace with proper code
            var pixels = image.Clone();

            for (var y = 0; y < image.Height; y++)
            {
                for (var x = 0; x < image.Width; x++)
                {
                    image[x, y] = pixels[x, pixels.Height - 1 - y];
                }
            }
        }
        /// <summary>
        /// Scales a image.
        /// </summary>
        /// <typeparam name="T">
        /// Specifies the type use for pixel data.
        /// </typeparam>
        /// <param name="image">
        /// The source image.
        /// </param>
        /// <param name="x">
        /// The horizontal scale.
        /// </param>
        /// <param name="y">
        /// The vertical scale.
        /// </param>
        /// <returns>
        /// Returns a new scaled image.
        /// </returns>
        /// <exception cref="ArgumentOutOfRangeException">
        /// x and y values must be greater then 0.
        /// </exception>
        public static GenericImage <T> Scale <T>(this GenericImage <T> image, float x, float y)
        {
            if (x <= 0)
            {
                throw new ArgumentOutOfRangeException("x");
            }

            if (y <= 0)
            {
                throw new ArgumentOutOfRangeException("y");
            }

            if (Math.Abs(x - 1.0f) < 0 && Math.Abs(y - 1.0f) < 0)
            {
                return(image.Clone());
            }

            var width  = (int)(image.Width * x);
            var height = (int)(image.Height * y);

            if (width < 1)
            {
                width = 1;
            }

            if (height < 1)
            {
                height = 1;
            }

            var scaled = new GenericImage <T>(width, height);

            for (var indexY = 0; indexY < scaled.Height; indexY++)
            {
                for (var indexX = 0; indexX < scaled.Width; indexX++)
                {
                    var u = scaled.Width == 1 ? 1 : indexX / (float)(scaled.Width - 1);
                    var v = scaled.Height == 1 ? 1 : indexY / (float)(scaled.Height - 1);
                    scaled[indexX, indexY] = image[(int)Math.Round(u * (image.Width - 1)), (int)Math.Round(v * (image.Height - 1))];
                }
            }

            return(scaled);
        }