async def test_render_into(self): m = CustomMockFrame(Size(1, 1), RGB24, {'type': 'm', 'a': 0}) a = CustomMockFrame(Size(1, 2), GRAY8, {'type': 'a', 'b': 1}) async with AlphaFrame(m, a) as f: self.assertEqual(await f.render_into(bytearray(), 0, RGBA32, 0), 0) self.assertEqual(m._last_format, RGB24) self.assertEqual(m._last_plane, 0) self.assertIsNone(a._last_format) self.assertIsNone(a._last_plane) self.assertEqual(await f.render_into(bytearray(), 1, RGBA32, 0), 1) self.assertIsNone(a._last_format) self.assertIsNone(a._last_plane) self.assertEqual(m._last_format, RGB24) self.assertEqual(m._last_plane, 1) self.assertEqual(await f.render_into(bytearray(), 2, RGBA32, 0), 2) self.assertIsNone(a._last_format) self.assertIsNone(a._last_plane) self.assertEqual(m._last_format, RGB24) self.assertEqual(m._last_plane, 2) m._last_plane = None m._last_format = None self.assertEqual(await f.render_into(bytearray(), 3, RGBA32, 0), 0) self.assertEqual(a._last_format, GRAY8) self.assertEqual(a._last_plane, 0) self.assertIsNone(m._last_format) self.assertIsNone(m._last_plane)
async def test_can_render(self): m = CustomMockFrame(Size(1, 1), RGB24, {'type': 'm', 'a': 0}) a = CustomMockFrame(Size(1, 2), GRAY8, {'type': 'a', 'b': 1}) async with AlphaFrame(m, a) as f: self.assertTrue(await f.can_render(RGBA32)) self.assertTrue(await f.can_render(RGB24)) self.assertFalse(await f.can_render(GRAY8))
async def test_attributes(self): m = CustomMockFrame(Size(1, 1), RGB24, {'type': 'm', 'a': 0}) a = CustomMockFrame(Size(1, 2), GRAY8, {'type': 'a', 'b': 1}) async with m, a: async with AlphaFrame(m, a) as f: self.assertEqual(f.size, Size(1, 1)) self.assertEqual(f.native_format, RGB24._replace(num_fields=4))
async def test_attributes_packed(self): mf = RGB24._replace(planar=False) m = CustomMockFrame(Size(1, 1), mf, {'type': 'm', 'a': 0}) a = CustomMockFrame(Size(1, 2), GRAY8, {'type': 'a', 'b': 1}) async with m, a: async with AlphaFrame(m, a) as f: self.assertEqual(f.size, Size(1, 1)) self.assertEqual(f.native_format, mf)
async def test_resources_owned(self): m = CustomMockFrame(Size(1, 1), RGB24, {'type': 'm', 'a': 0}) a = CustomMockFrame(Size(1, 2), GRAY8, {'type': 'a', 'b': 1}) f = AlphaFrame(m, a) await f.acquire() self.assertTrue(m.acquired) self.assertTrue(a.acquired) await f.release() self.assertFalse(m.acquired) self.assertFalse(m.acquired)
def size(self) -> Size: """ Returns the size of the frame with no subsampling applied. :return: A size-object that returns the size of the frame. """ return Size(0, 0)
async def _acquire(self) -> NoReturn: await self.remote_clip.acquire() await self.client.acquire() register(self.remote_clip, self) register(self.client, self) msg_sz, msg_format = await gather(self.client.size(frame=self.frame), self.client.format(frame=self.frame)) self._size = Size(*msg_sz.values) self._native_format = RawFormat.from_json(msg_format.values)
def size(self) -> Size: if not self.acquired: return Size(0, 0) return Size(self._raw_frame.width, self._raw_frame.height)
async def test_metadata(self): m = CustomMockFrame(Size(1, 1), RGB24, {'type': 'm', 'a': 0}) a = CustomMockFrame(Size(1, 2), GRAY8, {'type': 'a', 'b': 1}) async with AlphaFrame(m, a) as f: self.assertDictEqual(await f.get_metadata(), {'type': 'm', 'a': 0, 'b': 1})
def size(self) -> Size: return Size(0, 0)