AmaroK86.ImageFormat.ImageMipMapHandler.ShrinkImage C# (CSharp) Метод

ShrinkImage() приватный Метод

private ShrinkImage ( byte imageData, ImageSize imgsize, float BytesPerPixel ) : byte[]
imageData byte
imgsize ImageSize
BytesPerPixel float
Результат byte[]
        private byte[] ShrinkImage(byte[] imageData, ImageSize imgsize, float BytesPerPixel)
        {
            //Console.WriteLine("image length: {0}, image size: {1}, BPP: {2}", imageData.Length, imgsize, BytesPerPixel);
            byte[] final = new byte[imageData.Length / 4];
            int BPP = (int)BytesPerPixel;

            for (int i = 0; i < imgsize.height; i += 2)
            {
                for (int j = 0; j < imgsize.width; j += 2)
                {
                    for (int k = 0; k < BPP; k++)
                    {
                        final[(i * (imgsize.width * BPP) / 4) + j * BPP / 2 + k] = (byte)
                          ((imageData[i * (imgsize.width * BPP) + j * BPP + k] +
                            imageData[i * (imgsize.width * BPP) + j * BPP + BPP + k] +
                            imageData[(i + 1) * (imgsize.width * BPP) + j * BPP + k] +
                            imageData[(i + 1) * (imgsize.width * BPP) + j * BPP + BPP + k]) / 4);
                    }
                }
            }

            return final;
        }