Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let users pass max_threads as an argument to _avif.AvifDecoder #50

Merged
merged 1 commit into from
Jul 3, 2024

Conversation

yit-b
Copy link
Contributor

@yit-b yit-b commented May 9, 2024

Although the Image.open API doesn't yet let you pass arguments nicely to the underlying decoder, it would be really nice to be able to configure the decoder's max_threads option via this plugin when I know that the image I am reading is an AVIF. Example:

decode_threads.py

import pillow_avif
from pillow_avif import _avif
from PIL import Image

if __name__ == "__main__":

    from pillow_avif import _avif

    orig = Image.open("tests/images/flower.jpg")
    orig.save("flower.avif", quality=80)

    with open("flower.avif", "rb") as f:
        decoder = _avif.AvifDecoder(f.read(), "auto", "auto", 4) # 4 is max_threads
        width, height, n_frames, mode, icc, exif, xmp = decoder.get_info()
        data, timescale, tsp_in_ts, dur_in_ts = decoder.get_frame(0)

        img = Image.frombytes(mode=mode, size=(width, height), data=data)
        img.save("foobar.jpg")

The default behavior is unchanged, max_threads is still 0 when you open an avif via Image.open(). Only when you drop down a layer can you configure this.

As with #49, maybe we should consider a more reasonable default value for the decoder's max_threads for the same reasons.

Reproduce:

conda activate foobar # This is some new empty conda environment
conda install -c conda-forge pillow 'libavif>=1.0.2' aom 'python=3.10.*' pillow
cd pillow-avif-plugin
pip install --no-deps .
python decode_threads.py

@yit-b
Copy link
Contributor Author

yit-b commented Jun 28, 2024

@fdintino gentle bump

@fdintino fdintino merged commit 9d7e5b0 into fdintino:main Jul 3, 2024
50 of 58 checks passed
github-merge-queue bot referenced this pull request in BSStudio/bss-web-file-api Jul 9, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [pillow-avif-plugin](https://togithub.com/fdintino/pillow-avif-plugin)
| `1.4.3` -> `1.4.4` |
[![age](https://developer.mend.io/api/mc/badges/age/pypi/pillow-avif-plugin/1.4.4?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/pypi/pillow-avif-plugin/1.4.4?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/pypi/pillow-avif-plugin/1.4.3/1.4.4?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/pypi/pillow-avif-plugin/1.4.3/1.4.4?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>fdintino/pillow-avif-plugin (pillow-avif-plugin)</summary>

###
[`v1.4.4`](https://togithub.com/fdintino/pillow-avif-plugin/releases/tag/v1.4.4)

[Compare
Source](https://togithub.com/fdintino/pillow-avif-plugin/compare/v1.4.3...v1.4.4)

#### What's Changed

- chore(ci): bump libavif to
[`e10e6d9`](https://togithub.com/fdintino/pillow-avif-plugin/commit/e10e6d9)-2024-07-01;
fix CI build issues by [@&#8203;fdintino](https://togithub.com/fdintino)
in
[https://github.com/fdintino/pillow-avif-plugin/pull/53](https://togithub.com/fdintino/pillow-avif-plugin/pull/53).
See table below for new versions (all versions are upgrades from the
1.4.3 release).

    |             |            |
    |-------------|------------|
| **libavif** | <b>1.0.3
([e10e6d9](https://togithub.com/AOMediaCodec/libavif/commit/e10e6d98e6d1dbcdd409859a924d1b607a1e06dc))</b>
|
    | **libaom**  | **3.9.1**  |
    | **dav1d**   | **1.4.3**  |
    | **SVT-AV1** | **2.1.1**  |
    | **rav1e**   | **0.7.1**  |

- feat: Allow users to pass `max_threads` to the avif encoder via
`Image.save` by [@&#8203;yit-b](https://togithub.com/yit-b) in
[https://github.com/fdintino/pillow-avif-plugin/pull/54](https://togithub.com/fdintino/pillow-avif-plugin/pull/54),
originally in
[https://github.com/fdintino/pillow-avif-plugin/pull/49](https://togithub.com/fdintino/pillow-avif-plugin/pull/49)

- feat: Let users pass `max_threads` as an argument to
`_avif.AvifDecoder` by [@&#8203;yit-b](https://togithub.com/yit-b) in
[https://github.com/fdintino/pillow-avif-plugin/pull/50](https://togithub.com/fdintino/pillow-avif-plugin/pull/50)

- chore(ci): build SVT-AV1 for aarch64 or arm64 by
[@&#8203;RaphaelVRossi](https://togithub.com/RaphaelVRossi) in
[https://github.com/fdintino/pillow-avif-plugin/pull/38](https://togithub.com/fdintino/pillow-avif-plugin/pull/38)

- fix: keep alpha channel for images with mode P and custom transparency
by [@&#8203;fdintino](https://togithub.com/fdintino) in
[https://github.com/fdintino/pillow-avif-plugin/pull/56](https://togithub.com/fdintino/pillow-avif-plugin/pull/56);
fixes
[https://github.com/fdintino/pillow-avif-plugin/issues/48](https://togithub.com/fdintino/pillow-avif-plugin/issues/48)

- fix: disable decoder strictness for `clap` and `pixi` properties by
[@&#8203;fdintino](https://togithub.com/fdintino) in
[https://github.com/fdintino/pillow-avif-plugin/pull/57](https://togithub.com/fdintino/pillow-avif-plugin/pull/57).
fixes
[https://github.com/fdintino/pillow-avif-plugin/issues/13](https://togithub.com/fdintino/pillow-avif-plugin/issues/13),
fixes
[https://github.com/fdintino/pillow-avif-plugin/issues/28](https://togithub.com/fdintino/pillow-avif-plugin/issues/28)

- fix(ci): lint secrets permission error and macOS GHA runner homebrew
`PATH` bug by [@&#8203;fdintino](https://togithub.com/fdintino) in
[https://github.com/fdintino/pillow-avif-plugin/pull/55](https://togithub.com/fdintino/pillow-avif-plugin/pull/55)

#### New Contributors

- [@&#8203;RaphaelVRossi](https://togithub.com/RaphaelVRossi) made their
first contribution in
[https://github.com/fdintino/pillow-avif-plugin/pull/38](https://togithub.com/fdintino/pillow-avif-plugin/pull/38)

**Full Changelog**:
fdintino/pillow-avif-plugin@v1.4.3...v1.4.4

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/BSStudio/bss-web-file-api).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40MjUuMSIsInVwZGF0ZWRJblZlciI6IjM3LjQyNS4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants