public static int GetMemorySize(int width, int height, int depth, PixelFormat format)
        {
            if (Compressed(format))
            {
                switch (format)
                {
                // DXT formats work by dividing the image into 4x4 blocks, then encoding each
                // 4x4 block with a certain number of bytes. DXT can only be used on 2D images.
                case PixelFormat.DXT1:
                    Debug.Assert(depth == 1);
                    return(((width + 3) / 4) * ((height + 3) / 4) * 8);

                case PixelFormat.DXT2:
                case PixelFormat.DXT3:
                case PixelFormat.DXT4:
                case PixelFormat.DXT5:
                    Debug.Assert(depth == 1);
                    return(((width + 3) / 4) * ((height + 3) / 4) * 16);

                default:
                    throw new Exception("Invalid compressed pixel format, in PixelBox.GetMemorySize");
                }
            }
            else
            {
                return(width * height * depth * PixelConverter.GetNumElemBytes(format));
            }
        }