- colorspace = image.colorspace_settings.name
- if usage=='GRAY' and colorspace=='sRGB':
- raise Exception("Grayscale textures with sRGB colorspace are not supported")
-
- from .util import basename
- fn = basename(image.filepath)
- if not self.inline_data and fn:
- srgb = "_srgb" if colorspace=='sRGB' else ""
+ from .texture import Texture
+ texture = Texture(tex_node, channels)
+
+ invert_mask = sum(1<<i for i, c in enumerate(channels) if c[0]=='~')
+
+ fn = bpy.path.basename(image.filepath)
+ native_channels = None
+ if fn:
+ abs_path = bpy.path.abspath(image.filepath)
+ if os.path.exists(abs_path):
+ import imbuf
+ native_bpp = imbuf.load(bpy.path.abspath(image.filepath)).planes
+ if native_bpp==32:
+ native_channels = ['R', 'G', 'B', 'A']
+ elif native_bpp==24:
+ native_channels = ['R', 'G', 'B']
+ elif native_bpp==8:
+ native_channels = ['Y']
+
+ if not invert_mask and channels==native_channels:
+ if not tex_node.use_mipmap:
+ tex_res.statements.append(Statement("mipmap_levels", 1))
+ srgb = "_srgb" if texture.srgb else ""