def _produce_jbig2_images(jbig2_groups, root, log, options):
    """Produce JBIG2 images from their groups"""

    def jbig2_group_futures(executor, root, groups):
        for group, xref_exts in groups.items():
            prefix = f'group{group:08d}'
            future = executor.submit(
                jbig2enc.convert_group,
                cwd=fspath(root),
                infiles=(img_name(root, xref, ext) for xref, ext in xref_exts),
                out_prefix=prefix,
            )
            yield future

    def jbig2_single_futures(executor, root, groups):
        for group, xref_exts in groups.items():
            prefix = f'group{group:08d}'
            # Second loop is to ensure multiple images per page are unpacked
            for n, xref_ext in enumerate(xref_exts):
                xref, ext = xref_ext
                future = executor.submit(
                    jbig2enc.convert_single,
                    cwd=fspath(root),
                    infile=img_name(root, xref, ext),
                    outfile=root / f'{prefix}.{n:04d}',
                )
                yield future

    if options.jbig2_page_group_size > 1:
        jbig2_futures = jbig2_group_futures
    else:
        jbig2_futures = jbig2_single_futures

    with concurrent.futures.ThreadPoolExecutor(max_workers=options.jobs) as executor:
        futures = jbig2_futures(executor, root, jbig2_groups)
        for future in concurrent.futures.as_completed(futures):
            proc = future.result()
            log.debug(proc.stderr.decode())
def _produce_jbig2_images ( jbig2_groups , root , log , options ) : def jbig2_group_futures ( executor , root , groups ) : for group , xref_exts in groups . items ( ) : prefix = f'group{group:08d}' future = executor . submit ( jbig2enc . convert_group , cwd = fspath ( root ) , infiles = ( img_name ( root , xref , ext ) for xref , ext in xref_exts ) , out_prefix = prefix , ) yield future def jbig2_single_futures ( executor , root , groups ) : for group , xref_exts in groups . items ( ) : prefix = f'group{group:08d}' for n , xref_ext in enumerate ( xref_exts ) : xref , ext = xref_ext future = executor . submit ( jbig2enc . convert_single , cwd = fspath ( root ) , infile = img_name ( root , xref , ext ) , outfile = root / f'{prefix}.{n:04d}' , ) yield future if options . jbig2_page_group_size > 1 : jbig2_futures = jbig2_group_futures else : jbig2_futures = jbig2_single_futures with concurrent . futures . ThreadPoolExecutor ( max_workers = options . jobs ) as executor : futures = jbig2_futures ( executor , root , jbig2_groups ) for future in concurrent . futures . as_completed ( futures ) : proc = future . result ( ) log . debug ( proc . stderr . decode ( ) )
Produce JBIG2 images from their groups