code: def _save(im, fp, filename):
      if im.mode != "P":
          msg = "Unsupported BLP image mode"
          raise ValueError(msg)
  
      magic = (
          b"BLP1"
          if im.encoderinfo.get("blp_version") == "BLP1"
          else b"BLP2"
      )
      fp.write(magic)
  
      fp.write(
          struct.pack("<i", 1)
      )  # Uncompressed or DirectX compression
      fp.write(struct.pack("<b", Encoding.UNCOMPRESSED))
      fp.write(struct.pack("<b", 1 if im.palette.mode == "RGBA" else 0))
      fp.write(struct.pack("<b", 0))  # alpha encoding
      fp.write(struct.pack("<b", 0))  # mips
      fp.write(struct.pack("<II", *im.size))
      if magic == b"BLP1":
          fp.write(struct.pack("<i", 5))
          fp.write(struct.pack("<i", 0))
  
      ImageFile._save(im, fp, [("BLP", (0, 0) + im.size, 0, im.mode)])
  
imports: from __future__ import annotations
  import os
  import struct
  from enum import IntEnum
  from io import BytesIO
  from .None import Image, ImageFile
label_desc: Use image node_id 6 for calling a global function with example usage: _save(im, fp, filename) without return types