update the guess colorspace code reference from arnold

This commit is contained in:
Kayla Man 2023-02-02 12:00:49 +08:00
parent 90ef934f49
commit 1df0eb1fd8
2 changed files with 22 additions and 15 deletions

View file

@ -15,7 +15,7 @@ from six import string_types
from maya import cmds, mel
import maya.api.OpenMaya as om
from arnold import *
from arnold import * # noqa
from openpype.client import (
get_project,
@ -3390,12 +3390,13 @@ def imageInfo(filepath):
AiTextureGetFormat(filename): Get Texture Format
AiTextureGetBitDepth(filename): Get Texture Bit Depth
"""
# Get Texture Information
img_info = {}
img_info['filename'] = filepath
if os.path.isfile(filepath):
img_info['bit_depth'] = AiTextureGetBitDepth(filepath)
img_info['format'] = AiTextureGetFormat(filepath)
img_info['bit_depth'] = AiTextureGetBitDepth(filepath) # noqa
img_info['format'] = AiTextureGetFormat(filepath) # noqa
else:
img_info['bit_depth'] = 8
img_info['format'] = "unknown"
@ -3404,16 +3405,19 @@ def imageInfo(filepath):
def guess_colorspace(img_info):
''' Take reference from makeTx.py
Guess the colorspace of the input image filename.
@return: a string suitable for the --colorconvert option of maketx (linear, sRGB, Rec709)
@return: a string suitable for the --colorconvert
option of maketx (linear, sRGB, Rec709)
'''
try:
if img_info['bit_depth'] <= 16 and img_info['format'] in (AI_TYPE_BYTE, AI_TYPE_INT, AI_TYPE_UINT):
return 'sRGB'
else:
return 'linear'
if img_info['bit_depth'] <= 16:
if img_info['format'] in (AI_TYPE_BYTE, AI_TYPE_INT, AI_TYPE_UINT): # noqa
return 'sRGB'
else:
return 'linear'
# now discard the image file as AiTextureGetFormat has loaded it
AiTextureInvalidate(img_info['filename'])
except:
print('[maketx] Error: Could not guess colorspace for "%s"' % img_info['filename'])
AiTextureInvalidate(img_info['filename']) # noqa
except ValueError:
print('[maketx] Error: Could not guess'
'colorspace for "%s"' % img_info['filename'])
return 'linear'

View file

@ -553,12 +553,15 @@ class ExtractLook(publish.Extractor):
color_space = guess_colorspace(img_info)
if color_space == "sRGB":
self.log.info("tx: converting sRGB -> linear")
additional_args.extend(["--colorconvert", "sRGB", "Raw"])
additional_args.extend(["--colorconvert",
"sRGB",
"Raw"])
else:
self.log.info("tx: texture's colorspace is already linear")
self.log.info("tx: texture's colorspace "
"is already linear")
config_path = cmds.colorManagementPrefs(query=True, configFilePath=True)
config_path = cmds.colorManagementPrefs(query=True,
configFilePath=True)
if not os.path.exists(config_path):
raise RuntimeError("No OCIO config path found!")
additional_args.extend(["--colorconfig", config_path])