code: def deflate_jpegs(
      pdf: Pdf, root: Path, options, executor: Executor
  ) -> None:
      """Apply FlateDecode to JPEGs.
  
      This is a lossless compression method that is supported by all PDF viewers,
      and generally results in a smaller file size compared to straight DCTDecode
      images.
      """
      jpegs = []
      for _pageno, xref_ext in extract_images(
          pdf, root, options, _find_deflatable_jpeg
      ):
          xref = xref_ext.xref
          log.debug(f"xref {xref}: marking this JPEG as deflatable")
          jpegs.append(xref)
  
      complevel = 9 if options.optimize == 3 else 6
  
      # Our calls to xobj.write() in finish() need coordination
      lock = threading.Lock()
  
      def deflate_args() -> Iterator:
          for xref in jpegs:
              yield pdf, lock, xref, complevel
  
      def finish(result: tuple[Xref, bytes], pbar: ProgressBar):
          xref, compdata = result
          if len(compdata) > 0:
              with lock:
                  xobj = pdf.get_object(xref, 0)
                  xobj.write(
                      compdata,
                      filter=[Name.FlateDecode, Name.DCTDecode],
                  )
          pbar.update()
  
      executor(
          use_threads=True,  # We're sharing the pdf directly, must use threads
          max_workers=options.jobs,
          progress_kwargs=dict(
              desc="Deflating JPEGs",
              total=len(jpegs),
              unit="image",
              disable=not options.progress_bar,
          ),
          task=_deflate_jpeg,
          task_arguments=deflate_args(),
          task_finished=finish,
      )
  
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 18 for calling a global function with example usage: deflate_jpegs(pdf, root, options, executor) without return types