code: def calculate_downsample(
      image: Image.Image,
      *,
      max_size: tuple[int, int] | None = None,
      max_pixels: int | None = None,
      max_bytes: int | None = None,
  ) -> tuple[int, int]:
      """Calculate image size required to downsample an image to fit limits.
  
      If no limit is exceeded, the input image's size is returned.
  
      Args:
          image: The image to downsample.
          max_size: The maximum width and height of the image.
          max_pixels: The maximum number of pixels in the image. Some image consumers
              limit the total number of pixels as some value other than width*height.
          max_bytes: The maximum number of bytes in the image. RGB is counted as 4
              bytes; all other modes are counted as 1 byte.
      """
      return _calculate_downsample(
          image.size,
          bytes_per_pixel(image.mode),
          max_size=max_size,
          max_pixels=max_pixels,
          max_bytes=max_bytes,
      )
  
imports: from __future__ import annotations
  import logging
  from math import floor, sqrt
  from PIL import Image
label_desc: Use image node_id 3 for calling a global function with example usage: calculate_downsample(image) and returns: _calculate_downsample