- 
                Notifications
    
You must be signed in to change notification settings  - Fork 20
 
Description
Describe the bug
When I want to compress a large resolution image, I want to cut the large resolution image into multiple sub-images of small resolution, such as 512*512, pillow_heif supports the compression of multiple sub-images, but the performance will be greatly reduced compared with the direct compression of large-resolution images. I noticed that multi-graph compression in the code seems to be serial for encode one by one,
pillow_heif/pillow_heif/heif.py
Line 604 in 55a3d39
| for i, img in enumerate(images_to_save): | 
Steps/Code to Reproduce
rgb_img = Image.open("1-input.jpeg")
heif_file = HeifFile()
tile_size = 512
for i in range(0, rgb_img.height, tile_size):
    h_start = i
    h_end = i + tile_size
    for j in range(0, rgb_img.width, tile_size):
        w_start = j
        w_end = j + tile_size
        patch = rgb_img.crop((w_start, h_start, w_end, h_end))
        heif_file.add_from_pillow(patch)
heif_file.save(output_heif_path, quality=50)
and here is my test image
1-input.zip
Expected Results
The performance of multiple sub-images encode should be no lower than that of a single full-resolution graph directly encode
Actual Results
The performance of multi-subimage encode is more than 4 times lower than that of direct encode for a single full-resolution image
multi-subimage encode cost: 1.2968940734863281s
single full-resolution encode cost: 5.515080690383911s
Versions
3.10.15 | packaged by conda-forge | (main, Oct 16 2024, 01:24:24) [GCC 13.3.0]
Linux-6.8.0-49-generic-x86_64-with-glibc2.35
0.20.0
{'libheif': '1.18.2', 'HEIF': 'x265 HEVC encoder (3.5+1-f0c1022b6)', 'AVIF': 'AOMedia Project AV1 Encoder v3.6.1', 'encoders': {'x265': 'x265 HEVC encoder (3.5+1-f0c1022b6)', 'aom': 'AOMedia Project AV1 Encoder v3.6.1', 'mask': 'mask'}, 'decoders': {'libde265': 'libde265 HEVC decoder, version 1.0.15', 'aom': 'AOMedia Project AV1 Decoder v3.6.1'}}