|
7 | 7 |
|
8 | 8 | import av |
9 | 9 | from av import VideoFrame |
| 10 | +from av.video.reformatter import ColorRange, Colorspace, Interpolation |
10 | 11 |
|
11 | 12 | from .common import ( |
12 | 13 | TestCase, |
@@ -145,6 +146,24 @@ def test_roundtrip(self) -> None: |
145 | 146 | img.save(self.sandboxed("roundtrip-high.jpg")) |
146 | 147 | assertImagesAlmostEqual(image, img) |
147 | 148 |
|
| 149 | + def test_interpolation(self) -> None: |
| 150 | + import PIL.Image as Image |
| 151 | + |
| 152 | + image = Image.open(fate_png()) |
| 153 | + frame = VideoFrame.from_image(image) |
| 154 | + assert frame.width == 330 and frame.height == 330 |
| 155 | + |
| 156 | + img = frame.to_image(width=200, height=100, interpolation=Interpolation.BICUBIC) |
| 157 | + assert img.width == 200 and img.height == 100 |
| 158 | + |
| 159 | + img = frame.to_image(width=200, height=100, interpolation="BICUBIC") |
| 160 | + assert img.width == 200 and img.height == 100 |
| 161 | + |
| 162 | + img = frame.to_image( |
| 163 | + width=200, height=100, interpolation=int(Interpolation.BICUBIC) |
| 164 | + ) |
| 165 | + assert img.width == 200 and img.height == 100 |
| 166 | + |
148 | 167 | def test_to_image_rgb24(self) -> None: |
149 | 168 | sizes = [(318, 238), (320, 240), (500, 500)] |
150 | 169 | for width, height in sizes: |
@@ -838,14 +857,20 @@ def test_reformat_identity() -> None: |
838 | 857 |
|
839 | 858 |
|
840 | 859 | def test_reformat_colorspace() -> None: |
841 | | - # This is allowed. |
842 | 860 | frame = VideoFrame(640, 480, "rgb24") |
843 | 861 | frame.reformat(src_colorspace=None, dst_colorspace="smpte240m") |
844 | 862 |
|
845 | | - # I thought this was not allowed, but it seems to be. |
| 863 | + frame = VideoFrame(640, 480, "rgb24") |
| 864 | + frame.reformat(src_colorspace=None, dst_colorspace=Colorspace.smpte240m) |
| 865 | + |
846 | 866 | frame = VideoFrame(640, 480, "yuv420p") |
847 | 867 | frame.reformat(src_colorspace=None, dst_colorspace="smpte240m") |
848 | 868 |
|
| 869 | + frame = VideoFrame(640, 480, "rgb24") |
| 870 | + frame.colorspace = Colorspace.smpte240m |
| 871 | + assert frame.colorspace == int(Colorspace.smpte240m) |
| 872 | + assert frame.colorspace == Colorspace.smpte240m |
| 873 | + |
849 | 874 |
|
850 | 875 | def test_reformat_pixel_format_align() -> None: |
851 | 876 | height = 480 |
|
0 commit comments