code: def _save(im, fp, filename):
      if im.mode not in ("RGB", "RGBA", "L", "LA"):
          msg = f"cannot write mode {im.mode} as DDS"
          raise OSError(msg)
  
      rawmode = im.mode
      masks = [0xFF0000, 0xFF00, 0xFF]
      if im.mode in ("L", "LA"):
          pixel_flags = DDPF_LUMINANCE
      else:
          pixel_flags = DDPF_RGB
          rawmode = rawmode[::-1]
      if im.mode in ("LA", "RGBA"):
          pixel_flags |= DDPF_ALPHAPIXELS
          masks.append(0xFF000000)
  
      bitcount = len(masks) * 8
      while len(masks) < 4:
          masks.append(0)
  
      fp.write(
          o32(DDS_MAGIC)
          + o32(124)  # header size
          + o32(
              DDSD_CAPS
              | DDSD_HEIGHT
              | DDSD_WIDTH
              | DDSD_PITCH
              | DDSD_PIXELFORMAT
          )  # flags
          + o32(im.height)
          + o32(im.width)
          + o32((im.width * bitcount + 7) // 8)  # pitch
          + o32(0)  # depth
          + o32(0)  # mipmaps
          + o32(0) * 11  # reserved
          + o32(32)  # pfsize
          + o32(pixel_flags)  # pfflags
          + o32(0)  # fourcc
          + o32(bitcount)  # bitcount
          + b"".join(o32(mask) for mask in masks)  # rgbabitmask
          + o32(DDSCAPS_TEXTURE)  # dwCaps
          + o32(0)  # dwCaps2
          + o32(0)  # dwCaps3
          + o32(0)  # dwCaps4
          + o32(0)  # dwReserved2
      )
      if im.mode == "RGBA":
          r, g, b, a = im.split()
          im = Image.merge("RGBA", (a, r, g, b))
      ImageFile._save(
          im, fp, [("raw", (0, 0) + im.size, 0, (rawmode, 0, 1))]
      )
  
file_path: catboost/contrib/python/Pillow/py3/PIL/DdsImagePlugin.py
imports: import struct
  from io import BytesIO
  from .None import Image, ImageFile, ImagePalette
  from ._binary import o32le
label_desc: Use image node_id 1 for calling a global function with example usage: _save(im, fp, filename) without return types