Helper to save image based on tile list :param im: Image object. :param fp: File object. :param tile: Tile list. :param bufsize: Optional buffer size
(im: Image.Image, fp: IO[bytes], tile: list[_Tile], bufsize: int = 0)
| 642 | |
| 643 | |
| 644 | def _save(im: Image.Image, fp: IO[bytes], tile: list[_Tile], bufsize: int = 0) -> None: |
| 645 | """Helper to save image based on tile list |
| 646 | |
| 647 | :param im: Image object. |
| 648 | :param fp: File object. |
| 649 | :param tile: Tile list. |
| 650 | :param bufsize: Optional buffer size |
| 651 | """ |
| 652 | |
| 653 | im.load() |
| 654 | if not hasattr(im, "encoderconfig"): |
| 655 | im.encoderconfig = () |
| 656 | tile.sort(key=_tilesort) |
| 657 | # FIXME: make MAXBLOCK a configuration parameter |
| 658 | # It would be great if we could have the encoder specify what it needs |
| 659 | # But, it would need at least the image size in most cases. RawEncode is |
| 660 | # a tricky case. |
| 661 | bufsize = max(MAXBLOCK, bufsize, im.size[0] * 4) # see RawEncode.c |
| 662 | try: |
| 663 | fh = fp.fileno() |
| 664 | fp.flush() |
| 665 | _encode_tile(im, fp, tile, bufsize, fh) |
| 666 | except (AttributeError, io.UnsupportedOperation) as exc: |
| 667 | _encode_tile(im, fp, tile, bufsize, None, exc) |
| 668 | if hasattr(fp, "flush"): |
| 669 | fp.flush() |
| 670 | |
| 671 | |
| 672 | def _encode_tile( |
nothing calls this directly
no test coverage detected
searching dependent graphs…