manim/tests/module/mobject/test_image.py
Jérome Eertmans 0a24cad22a
Account for dtype in the pixel array so the maximum value stays correct in the invert function (#3493)
* fix(lib): fix

This fixes an issue where the `invert` argument would only work for `uint8` dtypes. Now the `max` value is updated according to the pixel array dtype.

Maybe we should add unit tests for that, but haven't found an obvious place to put unit tests.

* chore(ci): add basic test

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix(ci): wrong attr name

* Update tests/module/mobject/test_image.py

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Benjamin Hackl <devel@benjamin-hackl.at>
2023-12-12 13:31:28 +01:00

14 lines
438 B
Python

import numpy as np
import pytest
from manim import ImageMobject
@pytest.mark.parametrize("dtype", [np.uint8, np.uint16])
def test_invert_image(dtype):
array = (255 * np.random.rand(10, 10, 4)).astype(dtype)
image = ImageMobject(array, pixel_array_dtype=dtype, invert=True)
assert image.pixel_array.dtype == dtype
array[:, :, :3] = np.iinfo(dtype).max - array[:, :, :3]
assert np.allclose(array, image.pixel_array)