update docstring and style fix

This commit is contained in:
Kayla Man 2023-02-22 21:47:32 +08:00
parent 7d1744dd93
commit 709d663870
3 changed files with 43 additions and 26 deletions

View file

@ -16,7 +16,15 @@ from six import string_types
from maya import cmds, mel
import maya.api.OpenMaya as om
from arnold import * # noqa
from arnold import (
AiTextureGetBitDepth,
AiTextureGetFormat,
AiTextureInvalidate,
# types
AI_TYPE_BYTE,
AI_TYPE_INT,
AI_TYPE_UINT
)
from openpype.client import (
get_project,
@ -3465,19 +3473,23 @@ def write_xgen_file(data, filepath):
f.writelines(lines)
def imageInfo(filepath):
"""Take reference from makeTx.py in Arnold
ImageInfo(filename): Get Image Information for colorspace
AiTextureGetFormat(filename): Get Texture Format
AiTextureGetBitDepth(filename): Get Texture Bit Depth
def image_info(file_path):
# type: (str) -> dict
"""Based on tha texture path, get its bit depth and format information.
Take reference from makeTx.py in Arnold:
ImageInfo(filename): Get Image Information for colorspace
AiTextureGetFormat(filename): Get Texture Format
AiTextureGetBitDepth(filename): Get Texture bit depth
Args:
file_path (str): Path to the texture file.
Returns:
dict: Dictionary with the information about the texture file.
"""
# Get Texture Information
img_info = {}
img_info['filename'] = filepath
if os.path.isfile(filepath):
img_info['bit_depth'] = AiTextureGetBitDepth(filepath) # noqa
img_info['format'] = AiTextureGetFormat(filepath) # noqa
img_info = {'filename': file_path}
if os.path.isfile(file_path):
img_info['bit_depth'] = AiTextureGetBitDepth(file_path) # noqa
img_info['format'] = AiTextureGetFormat(file_path) # noqa
else:
img_info['bit_depth'] = 8
img_info['format'] = "unknown"
@ -3485,21 +3497,25 @@ 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)
'''
# type: (dict) -> str
"""Guess the colorspace of the input image filename.
Note:
Reference from makeTx.py
Args:
img_info (dict): Image info generated by :func:`image_info`
Returns:
str: color space name use in the `--colorconvert`
option of maketx.
"""
try:
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']) # noqa
except ValueError:
print('[maketx] Error: Could not guess'
'colorspace for "%s"' % img_info['filename'])
return 'linear'
print(("[maketx] Error: Could not guess"
"colorspace for {}").format(img_info["filename"]))
return "linear"

View file

@ -16,7 +16,7 @@ import pyblish.api
from openpype.lib import source_hash, run_subprocess
from openpype.pipeline import legacy_io, publish
from openpype.hosts.maya.api import lib
from openpype.hosts.maya.api.lib import imageInfo, guess_colorspace
from openpype.hosts.maya.api.lib import image_info, guess_colorspace
# Modes for transfer
COPY = 1
@ -369,7 +369,7 @@ class ExtractLook(publish.Extractor):
linearize = False
# if OCIO color management enabled
# it wont take the condition of the files_metadata
# it won't take the condition of the files_metadata
ocio_maya = cmds.colorManagementPrefs(q=True,
cmConfigFileEnabled=True,
@ -542,14 +542,14 @@ class ExtractLook(publish.Extractor):
color_space = cmds.getAttr(color_space_attr)
except ValueError:
# node doesn't have color space attribute
img_info = imageInfo(filepath)
img_info = image_info(filepath)
color_space = guess_colorspace(img_info)
self.log.info("tx: converting {0} -> {1}".format(color_space, render_colorspace)) # noqa
additional_args.extend(["--colorconvert",
color_space,
render_colorspace])
else:
img_info = imageInfo(filepath)
img_info = image_info(filepath)
color_space = guess_colorspace(img_info)
if color_space == "sRGB":
self.log.info("tx: converting sRGB -> linear")

View file

@ -2,6 +2,7 @@ from maya import cmds
import pyblish.api
from openpype.pipeline.publish import ValidateContentsOrder
from openpype.pipeline import PublishValidationError
class ValidateMayaColorSpace(pyblish.api.InstancePlugin):
@ -22,4 +23,4 @@ class ValidateMayaColorSpace(pyblish.api.InstancePlugin):
maketx = instance.data["maketx"]
if ocio_maya and maketx:
raise RuntimeError("Maya is color managed and maketx option is on. OpenPype doesn't support this combination yet.") # noqa
raise PublishValidationError("Maya is color managed and maketx option is on. OpenPype doesn't support this combination yet.") # noqa