Skip to content

Commit

Permalink
FEAT: Forward constructor kwargs to PyAV (#1061)
Browse files Browse the repository at this point in the history
  • Loading branch information
FirefoxMetzger committed Feb 10, 2024
1 parent 65d7914 commit 85fe311
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Expand Up @@ -32,7 +32,7 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: 3.x
- uses: psf/black@22.12.0
- uses: psf/black@24.1.1
with:
args: ". --check"
- name: Install Dependencies
Expand Down
9 changes: 2 additions & 7 deletions imageio/plugins/_tifffile.py
Expand Up @@ -460,9 +460,7 @@ def imread(files, **kwargs):
return imseq.asarray(**kwargs)


def imsave(
file, data=None, shape=None, dtype=None, bigsize=2**32 - 2**25, **kwargs
):
def imsave(file, data=None, shape=None, dtype=None, bigsize=2**32 - 2**25, **kwargs):
"""Write numpy array to TIFF file.
Refer to the TiffWriter class and member functions for documentation.
Expand Down Expand Up @@ -3765,10 +3763,7 @@ def asrgb(

if photometric == PHOTOMETRIC.PALETTE:
colormap = self.colormap
if (
colormap.shape[1] < 2**self.bitspersample
or self.dtype.char not in "BH"
):
if colormap.shape[1] < 2**self.bitspersample or self.dtype.char not in "BH":
raise ValueError("cannot apply colormap")
if uint8:
if colormap.max() > 255:
Expand Down
1 change: 0 additions & 1 deletion imageio/plugins/opencv.py
Expand Up @@ -30,7 +30,6 @@
"""


import warnings
from pathlib import Path
from typing import Any, Dict, List, Optional, Union
Expand Down
20 changes: 11 additions & 9 deletions imageio/plugins/pyav.py
Expand Up @@ -268,15 +268,15 @@ class PyAVPlugin(PluginV3):
standard interface to access various the various ImageResources and
serves them to the plugin as a file object (or file). Check the docs for
details.
container : str
Only used during `iio_mode="w"`! If not None, overwrite the default container
format chosen by pyav.
kwargs : Any
Additional kwargs are forwarded to PyAV's constructor.
"""

def __init__(
self,
request: Request,
*,
container: str = None,
) -> None:
def __init__(self, request: Request, *, container: str = None, **kwargs) -> None:
"""Initialize a new Plugin Instance.
See Plugin's docstring for detailed documentation.
Expand All @@ -303,9 +303,9 @@ def __init__(
# HTTP-based streams like DASH. Note that solving streams
# like this is temporary until the new request object gets
# implemented.
self._container = av.open(request.raw_uri)
self._container = av.open(request.raw_uri, **kwargs)
else:
self._container = av.open(request.get_file())
self._container = av.open(request.get_file(), **kwargs)
self._video_stream = self._container.streams.video[0]
self._decoder = self._container.decode(video=0)
except av.AVError:
Expand All @@ -330,7 +330,9 @@ def __init__(
pass # read-only, nothing we can do

try:
self._container = av.open(file_handle, mode="w", format=container)
self._container = av.open(
file_handle, mode="w", format=container, **kwargs
)
except ValueError:
raise InitializationError(
f"PyAV can not write to `{self.request.raw_uri}`"
Expand Down
1 change: 0 additions & 1 deletion tests/test_bsdf.py
@@ -1,7 +1,6 @@
""" Test BSDF plugin.
"""


import numpy as np

from pytest import raises
Expand Down
1 change: 1 addition & 0 deletions tests/test_fei_tiff.py
Expand Up @@ -2,6 +2,7 @@
FEI TIFFs contain metadata as ASCII plaintext at the end of the file.
"""

from __future__ import unicode_literals

import pytest
Expand Down
5 changes: 2 additions & 3 deletions tests/test_fits.py
@@ -1,5 +1,6 @@
""" Test fits plugin functionality.
"""

import pytest

import imageio.v2 as iio
Expand Down Expand Up @@ -87,9 +88,7 @@ def test_fits_get_reader(normal_plugin_order, tmp_path):

sigma = 10
xx, yy = np.meshgrid(np.arange(512), np.arange(512))
z = (1 / (2 * np.pi * (sigma**2))) * np.exp(
-((xx**2) + (yy**2)) / (2 * (sigma**2))
)
z = (1 / (2 * np.pi * (sigma**2))) * np.exp(-((xx**2) + (yy**2)) / (2 * (sigma**2)))
img = np.log(z, where=z != 0, out=np.zeros_like(z))
phdu = fits.PrimaryHDU()
ihdu = fits.ImageHDU(img)
Expand Down
1 change: 1 addition & 0 deletions tests/test_gdal.py
@@ -1,5 +1,6 @@
""" Test gdal plugin functionality.
"""

import pytest
import imageio

Expand Down
1 change: 1 addition & 0 deletions tests/test_lytro.py
@@ -1,5 +1,6 @@
""" Test npz plugin functionality.
"""

from __future__ import division
import numpy as np
import json
Expand Down
4 changes: 1 addition & 3 deletions tests/test_pyav.py
Expand Up @@ -517,9 +517,7 @@ def test_rotation_flag_metadata(test_images, tmp_path):
if AV_VERSION >= (10, 0, 0):
pytest.xfail("PyAV >= 10.0.0 doesn't extract the rotation flag.")
else:
meta = iio.immeta(tmp_path / "test.mp4", plugin="pyav")
assert meta["comment"] == "This video has a rotation flag."
assert meta["rotate"] == "90"
pytest.xfail("PyAV v10.0.0+ doesn't extract the rotation flag.")


def test_read_filter(test_images):
Expand Down

0 comments on commit 85fe311

Please sign in to comment.