Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Duroure <julien.duroure@gmail.com>2020-04-11 16:34:44 +0300
committerJulien Duroure <julien.duroure@gmail.com>2020-04-11 16:34:44 +0300
commit7a3fdf08f3fe4984bc81219a075a8bd3234c7d72 (patch)
treecab2cebb70396a96c51205b044526945a895f4f2 /io_scene_gltf2/blender/exp/gltf2_blender_image.py
parent43148f17496ce7d51f0377631b6d393756b22724 (diff)
glTF exporter: less naive file format detection for textures
Diffstat (limited to 'io_scene_gltf2/blender/exp/gltf2_blender_image.py')
-rw-r--r--io_scene_gltf2/blender/exp/gltf2_blender_image.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_image.py b/io_scene_gltf2/blender/exp/gltf2_blender_image.py
index 145e1ed9..e9db7e66 100644
--- a/io_scene_gltf2/blender/exp/gltf2_blender_image.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_image.py
@@ -272,15 +272,24 @@ class ExportImage:
def __encode_from_image(self, image: bpy.types.Image) -> bytes:
# See if there is an existing file we can use.
+ data = None
if image.source == 'FILE' and image.file_format == self.file_format and \
not image.is_dirty:
if image.packed_file is not None:
- return image.packed_file.data
+ data = image.packed_file.data
else:
src_path = bpy.path.abspath(image.filepath_raw)
if os.path.isfile(src_path):
with open(src_path, 'rb') as f:
- return f.read()
+ data = f.read()
+ # Check magic number is right
+ if data:
+ if self.file_format == 'PNG':
+ if data.startswith(b'\x89PNG'):
+ return data
+ elif self.file_format == 'JPEG':
+ if data.startswith(b'\xff\xd8\xff'):
+ return data
# Copy to a temp image and save.
tmp_image = None