Release NaraMotion v0.26.0: Structure of Arrays (SoA), Path Arena Allocator, Uniform Grid Indexing, Dual-Buffer Rendering & Centroid Spring Pop-in
b516e00 verified Download tests/test_numpy_pil.py from ArifiIslam/NaraMotion: direct link, hf CLI and curl.
- Browser
- Download file 1.26 kB
-
https://huggingface.co/ArifiIslam/NaraMotion/resolve/main/tests/test_numpy_pil.py
- Command line
-
hf download hf://ArifiIslam/NaraMotion/tests/test_numpy_pil.py
-
curl -L -o test_numpy_pil.py https://huggingface.co/ArifiIslam/NaraMotion/resolve/main/tests/test_numpy_pil.py
1.26 kB
| import numpy as np | |
| from PIL import Image as PILImage | |
| import pytest | |
| from naramotion import Image, Context, Format | |
| def test_numpy_zero_copy_view(): | |
| img = Image(100, 100, Format.PRGB32) | |
| with Context(img) as ctx: | |
| ctx.fill_all("black") | |
| arr = img.to_numpy(copy=False) | |
| assert arr.shape == (100, 100, 4) | |
| assert arr.dtype == np.uint8 | |
| # Modify pixel via NumPy directly | |
| arr[50, 50] = [255, 0, 0, 255] # Blue in BGRA | |
| # Verify that image buffer updated in-place without copy | |
| arr2 = img.to_numpy(copy=False) | |
| assert list(arr2[50, 50]) == [255, 0, 0, 255] | |
| def test_image_from_numpy(): | |
| raw = np.zeros((80, 120, 4), dtype=np.uint8) | |
| raw[:, :] = [0, 255, 0, 255] # Green in BGRA | |
| img = Image.from_numpy(raw, Format.PRGB32) | |
| assert img.width == 120 | |
| assert img.height == 80 | |
| arr = img.to_numpy() | |
| assert np.array_equal(arr, raw) | |
| def test_pil_conversion(): | |
| pil_src = PILImage.new("RGBA", (150, 100), color=(255, 128, 0, 255)) | |
| img = Image.from_pil(pil_src) | |
| assert img.width == 150 | |
| assert img.height == 100 | |
| pil_out = img.to_pil() | |
| assert pil_out.size == (150, 100) | |
| assert pil_out.getpixel((50, 50)) == (255, 128, 0, 255) | |