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

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'release/scripts/modules/bpy_extras/image_utils.py')
-rw-r--r--release/scripts/modules/bpy_extras/image_utils.py29
1 files changed, 25 insertions, 4 deletions
diff --git a/release/scripts/modules/bpy_extras/image_utils.py b/release/scripts/modules/bpy_extras/image_utils.py
index ff6d23badb6..f772aab2b14 100644
--- a/release/scripts/modules/bpy_extras/image_utils.py
+++ b/release/scripts/modules/bpy_extras/image_utils.py
@@ -32,6 +32,8 @@ def load_image(imagepath,
convert_callback=None,
verbose=False,
relpath=None,
+ check_existing=False,
+ force_reload=False,
):
"""
Return an image from the file path with options to search multiple paths
@@ -60,6 +62,14 @@ def load_image(imagepath,
:type convert_callback: function
:arg relpath: If not None, make the file relative to this path.
:type relpath: None or string
+ :arg check_existing: If true,
+ returns already loaded image datablock if possible
+ (based on file path).
+ :type check_existing: bool
+ :arg force_reload: If true,
+ force reloading of image (only useful when `check_existing`
+ is also enabled).
+ :type force_reload: bool
:return: an image or None
:rtype: :class:`bpy.types.Image`
"""
@@ -70,9 +80,12 @@ def load_image(imagepath,
# Utility Functions
def _image_load_placeholder(path):
- name = bpy.path.basename(path)
- if type(name) == bytes:
- name = name.decode("utf-8", "replace")
+ name = path
+ if type(path) is str:
+ name = name.encode("utf-8", "replace")
+ name = name.decode("utf-8", "replace")
+ name = os.path.basename(name)
+
image = bpy.data.images.new(name, 128, 128)
# allow the path to be resolved later
image.filepath = path
@@ -85,8 +98,12 @@ def load_image(imagepath,
if convert_callback:
path = convert_callback(path)
+ # Ensure we're not relying on the 'CWD' to resolve the path.
+ if not os.path.isabs(path):
+ path = os.path.abspath(path)
+
try:
- image = bpy.data.images.load(path)
+ image = bpy.data.images.load(path, check_existing)
except RuntimeError:
image = None
@@ -102,6 +119,8 @@ def load_image(imagepath,
image = _image_load_placeholder(path)
if image:
+ if force_reload:
+ image.reload()
if relpath is not None:
# make relative
from bpy.path import relpath as relpath_fn
@@ -131,6 +150,8 @@ def load_image(imagepath,
# -------------------------------------------------------------------------
+ imagepath = bpy.path.native_pathsep(imagepath)
+
if verbose:
print("load_image('%s', '%s', ...)" % (imagepath, dirname))