def test_images_in_expr(self): img1_path = "hopper.ppm" img2_path = "pal1wb.bmp" with PIL.open(path_to_file_in_data_dir(img1_path)) as img1: with PIL.open(path_to_file_in_data_dir(img2_path)) as img2: res = self.kernel_session.evaluate( wl.Map(wl.ImageDimensions, {"img1": img1, "img2": img2}) ) self.assertEqual( res, { "img1": self.IMAGE_FILES_DIMS[img1_path], "img2": self.IMAGE_FILES_DIMS[img2_path], }, )
def test_png_mode_I(self): with PIL.open(path_to_file_in_data_dir('5x2.png')) as image: self.assertEqual( export(image, target_format='wl'), b'ImportByteArray[ByteArray["iVBORw0KGgoAAAANSUhEUgAAAAUAAAACEAAAAADlkZXCAAAAH0lEQVR4nGP0+P39rf6+ky9/R7Aoen2+9shDWSRCHwCO7ws73c3PRQAAAABJRU5ErkJggg=="], "PNG"]' )
def test_bool_img(self): a = numpy.array([[1, 0], [0, 1]], dtype='bool') img = PIL.fromarray(a) out = export(img, target_format='wl') self.assertTrue( out == b'Image[BinaryDeserialize[ByteArray["ODrCEAICAgEAAAA="]], "Bit", Rule[ColorSpace, Automatic], Rule[Interleaving, True]]' or out == b'Image[BinaryDeserialize[ByteArray["ODrCEAICAgEAAAA="]], "Bit", Rule[Interleaving, True], Rule[ColorSpace, Automatic]]' )
def test_mode_L(self): a = numpy.arange(10).reshape((2, 5)) img = PIL.fromarray(a, mode='L') out = export(img, target_format='wl') self.assertTrue( out == b'Image[BinaryDeserialize[ByteArray["ODrCEAICBQAAAAAAAAAAAQA="]], "Byte", Rule[ColorSpace, "Grayscale"], Rule[Interleaving, True]]' or out == b'Image[BinaryDeserialize[ByteArray["ODrCEAICBQAAAAAAAAAAAQA="]], "Byte", Rule[Interleaving, True], Rule[ColorSpace, "Grayscale"]]' )
def test_images_serialization(self): for path, dimensions in self.IMAGE_FILES_DIMS.items(): with PIL.open(path_to_file_in_data_dir(path)) as img: res = self.kernel_session.evaluate(wl.ImageDimensions(img)) self.assertEqual(res, dimensions)