code: def convert_to_jbig2(
      pdf: Pdf,
      jbig2_groups: dict[int, list[XrefExt]],
      root: Path,
      options,
      executor: Executor,
  ) -> None:
      """Convert images to JBIG2 and insert into PDF.
  
      When the JBIG2 page group size is > 1 we do several JBIG2 images at once
      and build a symbol dictionary that will span several pages. Each JBIG2
      image must reference to its symbol dictionary. If too many pages shared the
      same dictionary JBIG2 encoding becomes more expensive and less efficient.
      The default value of 10 was determined through testing. Currently this
      must be lossy encoding since jbig2enc does not support refinement coding.
  
      When the JBIG2 symbolic coder is not used, each JBIG2 stands on its own
      and needs no dictionary. Currently this must be lossless JBIG2.
      """
      jbig2_globals_dict: Dictionary | None
  
      _produce_jbig2_images(jbig2_groups, root, options, executor)
  
      for group, xref_exts in jbig2_groups.items():
          prefix = f"group{group:08d}"
          jbig2_symfile = root / (prefix + ".sym")
          if jbig2_symfile.exists():
              jbig2_globals_data = jbig2_symfile.read_bytes()
              jbig2_globals = Stream(pdf, jbig2_globals_data)
              jbig2_globals_dict = Dictionary(
                  JBIG2Globals=jbig2_globals
              )
          elif options.jbig2_page_group_size == 1:
              jbig2_globals_dict = None
          else:
              raise FileNotFoundError(jbig2_symfile)
  
          for n, xref_ext in enumerate(xref_exts):
              xref, _ = xref_ext
              jbig2_im_file = root / (prefix + f".{n:04d}")
              jbig2_im_data = jbig2_im_file.read_bytes()
              im_obj = pdf.get_object(xref, 0)
              im_obj.write(
                  jbig2_im_data,
                  filter=Name.JBIG2Decode,
                  decode_parms=jbig2_globals_dict,
              )
  
imports: from __future__ import annotations
  import logging
  import sys
  import tempfile
  import threading
  from collections import defaultdict
  from collections.abc import Iterator, MutableSet, Sequence
  from os import fspath
  from pathlib import Path
  from typing import Any, Callable, NamedTuple, NewType
  from warnings import warn
  from zlib import compress
  import img2pdf
  from pikepdf import Dictionary, Name, Object, ObjectStreamMode, Pdf, PdfError, PdfImage, Stream, UnsupportedImageTypeError
  from PIL import Image
  from ocrmypdf._concurrent import Executor, SerialExecutor
  from ocrmypdf._exec import jbig2enc, pngquant
  from ocrmypdf._jobcontext import PdfContext
  from ocrmypdf._progressbar import ProgressBar
  from ocrmypdf.exceptions import OutputFileAccessError
  from ocrmypdf.helpers import IMG2PDF_KWARGS, safe_symlink
label_desc: Use image node_id 13 for calling a global function with example usage: convert_to_jbig2(pdf, jbig2_groups, root, options, executor) without return types