def verify_img(im:Image): """ verify image has pixel data """ if not im: return None if not im.has_data: try: im.update() except RuntimeError: pass return im if im is not None and im.pixels is not None and len(im.pixels) > 0 else None
def test_create_textures(self): image = Image() image.filepath = "//test/image/path.png" image.library = "//test/image/library" node = ShaderNodeTexImage() node.image = image material = Material() material.name = "material" material.diffuse_color = [1.0, 1.0, 1.0, 1.0] material.use_nodes = True material.node_tree = NodeTree() material.node_tree.nodes = [node] mesh = Mesh() mesh.materials = [material] obj = Object() obj.data = mesh bpy.path.abspath = Mock(return_value=image.filepath) bpy.path.display_name_from_filepath = Mock(return_value="texture") reader = Mock() reader.read = Mock(return_value=[12, 34, [[0x05, 0x06], [0x07, 0x08]]]) png.Reader = Mock(return_value=reader) exporter = Exporter() exporter.create_textures([obj]) bpy.path.abspath.assert_called_once_with( "//test/image/path.png", library="//test/image/library") bpy.path.display_name_from_filepath.assert_called_once_with( "//test/image/path.png") png.Reader.assert_called_once_with("//test/image/path.png") reader.read.assert_called_once() self.assertEqual(exporter.names[0].node_name, "texture.tex") self.assertEqual(exporter.tex_images[0].tex_img_data, [5, 6, 7, 8]) self.assertEqual(exporter.textures[0].tex_img_width, 12) self.assertEqual(exporter.textures[0].tex_img_height, 34)
def set_pixels(image:Image, pix:list): image.pixels = pix