code: def _save(im, fp, filename, bitmap_header=True):
      try:
          rawmode, bits, colors = SAVE[im.mode]
      except KeyError as e:
          raise OSError(f"cannot write mode {im.mode} as BMP") from e
  
      info = im.encoderinfo
  
      dpi = info.get("dpi", (96, 96))
  
      # 1 meter == 39.3701 inches
      ppm = tuple(map(lambda x: int(x * 39.3701 + 0.5), dpi))
  
      stride = ((im.size[0] * bits + 7) // 8 + 3) & (~3)
      header = 40  # or 64 for OS/2 version 2
      image = stride * im.size[1]
  
      # bitmap header
      if bitmap_header:
          offset = 14 + header + colors * 4
          file_size = offset + image
          if file_size > 2**32 - 1:
              raise ValueError(
                  "File size is too large for the BMP format"
              )
          fp.write(
              b"BM"  # file type (magic)
              + o32(file_size)  # file size
              + o32(0)  # reserved
              + o32(offset)  # image data offset
          )
  
      # bitmap info header
      fp.write(
          o32(header)  # info header size
          + o32(im.size[0])  # width
          + o32(im.size[1])  # height
          + o16(1)  # planes
          + o16(bits)  # depth
          + o32(0)  # compression (0=uncompressed)
          + o32(image)  # size of bitmap
          + o32(ppm[0])  # resolution
          + o32(ppm[1])  # resolution
          + o32(colors)  # colors used
          + o32(colors)  # colors important
      )
  
      fp.write(b"\0" * (header - 40))  # padding (for OS/2 format)
  
      if im.mode == "1":
          for i in (0, 255):
              fp.write(o8(i) * 4)
      elif im.mode == "L":
          for i in range(256):
              fp.write(o8(i) * 4)
      elif im.mode == "P":
          fp.write(im.im.getpalette("RGB", "BGRX"))
  
      ImageFile._save(
          im, fp, [("raw", (0, 0) + im.size, 0, (rawmode, stride, -1))]
      )
  
file_path: pillow-simd/src/PIL/BmpImagePlugin.py
imports: from .None import Image, ImageFile, ImagePalette
  from ._binary import i16le
  from ._binary import i32le
  from ._binary import o8
  from ._binary import o16le
  from ._binary import o32le
label_desc: Use image node_id 4 for calling a global function with example usage: _save(im, fp, filename, bitmap_header) without return types