添加信号格式修改
This commit is contained in:
@@ -14,7 +14,7 @@ class UCDController:
|
||||
self.role = None
|
||||
self.timing_manager = None
|
||||
self.config = None
|
||||
self.color_mode = None
|
||||
self.color_info = None
|
||||
self.status = False
|
||||
self.current_interface = "HDMI"
|
||||
|
||||
@@ -51,7 +51,7 @@ class UCDController:
|
||||
|
||||
pg, _ = self.get_tx_modules()
|
||||
self.timing_manager = pg.timing_manager
|
||||
self.color_mode = UniTAP.ColorInfo()
|
||||
self.color_info = UniTAP.ColorInfo()
|
||||
self.status = True
|
||||
|
||||
return True
|
||||
@@ -60,23 +60,26 @@ class UCDController:
|
||||
self._force_cleanup()
|
||||
return False
|
||||
|
||||
def _reset_state(self):
|
||||
"""重置所有运行时状态(不关闭设备句柄)"""
|
||||
self.dev = None
|
||||
self.role = None
|
||||
self.status = False
|
||||
self.timing_manager = None
|
||||
self.current_timing = None
|
||||
self.current_pattern = None
|
||||
self.current_pattern_param = None
|
||||
self.current_pattern_params = None
|
||||
self.current_pattern_index = 0
|
||||
self.current_interface = "HDMI"
|
||||
|
||||
def close(self):
|
||||
"""关闭设备"""
|
||||
try:
|
||||
if self.dev:
|
||||
self._close_device_object(self.dev)
|
||||
|
||||
self.dev = None
|
||||
self.role = None
|
||||
self.status = False
|
||||
self.timing_manager = None
|
||||
self.current_timing = None
|
||||
self.current_pattern = None
|
||||
self.current_pattern_param = None
|
||||
self.current_pattern_params = None
|
||||
self.current_pattern_index = 0
|
||||
self.current_interface = "HDMI"
|
||||
|
||||
self._reset_state()
|
||||
self.lUniTAP = None
|
||||
|
||||
for i in range(3):
|
||||
@@ -89,16 +92,7 @@ class UCDController:
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
self.dev = None
|
||||
self.role = None
|
||||
self.status = False
|
||||
self.timing_manager = None
|
||||
self.current_timing = None
|
||||
self.current_pattern = None
|
||||
self.current_pattern_param = None
|
||||
self.current_pattern_params = None
|
||||
self.current_pattern_index = 0
|
||||
self.current_interface = "HDMI"
|
||||
self._reset_state()
|
||||
|
||||
try:
|
||||
self.lUniTAP = None
|
||||
@@ -135,16 +129,7 @@ class UCDController:
|
||||
if self.dev:
|
||||
self._close_device_object(self.dev)
|
||||
|
||||
self.dev = None
|
||||
self.role = None
|
||||
self.status = False
|
||||
self.timing_manager = None
|
||||
self.current_timing = None
|
||||
self.current_pattern = None
|
||||
self.current_pattern_param = None
|
||||
self.current_pattern_params = None
|
||||
self.current_pattern_index = 0
|
||||
self.current_interface = "HDMI"
|
||||
self._reset_state()
|
||||
|
||||
except Exception as e:
|
||||
pass
|
||||
@@ -210,22 +195,12 @@ class UCDController:
|
||||
pg, _ = self.get_tx_modules()
|
||||
self.timing_manager = pg.timing_manager
|
||||
|
||||
if test_type == "hdr_movie":
|
||||
color_format_str = self.config.current_test_types[test_type]["color_format"]
|
||||
color_format = UCDEnum.ColorInfo.get_color_format(color_format_str)
|
||||
color_format = self.config.current_test_types[test_type]["color_format"]
|
||||
bpc = self.config.current_test_types[test_type]["bpc"]
|
||||
colorimetry = self.config.current_test_types[test_type]["colorimetry"]
|
||||
|
||||
if color_format:
|
||||
self.color_mode.color_format = color_format
|
||||
else:
|
||||
return False
|
||||
|
||||
else:
|
||||
color_format = self.config.current_test_types[test_type]["color_format"]
|
||||
bpc = self.config.current_test_types[test_type]["bpc"]
|
||||
colorimetry = self.config.current_test_types[test_type]["colorimetry"]
|
||||
|
||||
if not self.set_color_mode(color_format, bpc, colorimetry):
|
||||
return False
|
||||
if not self.set_color_mode(color_format, bpc, colorimetry):
|
||||
return False
|
||||
|
||||
timing_str = self.config.current_test_types[test_type]["timing"]
|
||||
self.set_timing_from_string(timing_str)
|
||||
@@ -251,7 +226,7 @@ class UCDController:
|
||||
return True
|
||||
|
||||
def send_image_pattern(self, image_path):
|
||||
"""发送图片 Pattern(依赖当前 timing/color_mode 状态)。"""
|
||||
"""发送图片 Pattern(依赖当前 timing/color_info 状态)。"""
|
||||
if not self.status or not self.role:
|
||||
return False
|
||||
|
||||
@@ -265,7 +240,7 @@ class UCDController:
|
||||
return False
|
||||
|
||||
def send_solid_rgb_pattern(self, rgb):
|
||||
"""发送纯色 RGB Pattern(依赖当前 timing/color_mode 状态)。"""
|
||||
"""发送纯色 RGB Pattern(依赖当前 timing/color_info 状态)。"""
|
||||
if not self.status or not self.role:
|
||||
return False
|
||||
|
||||
@@ -300,14 +275,7 @@ class UCDController:
|
||||
|
||||
def set_color_mode(self, cf, bpc, cm):
|
||||
"""设置颜色模式"""
|
||||
current_dynamic_range = None
|
||||
current_transfer_characteristic = None
|
||||
|
||||
if hasattr(self.color_mode, "dynamic_range"):
|
||||
current_dynamic_range = self.color_mode.dynamic_range
|
||||
|
||||
if hasattr(self.color_mode, "transfer_characteristic"):
|
||||
current_transfer_characteristic = self.color_mode.transfer_characteristic
|
||||
current_dynamic_range = self.color_info.dynamic_range
|
||||
|
||||
color_format = UCDEnum.ColorInfo.get_color_format(cf)
|
||||
if color_format is None:
|
||||
@@ -320,20 +288,15 @@ class UCDController:
|
||||
if colorimetry is None:
|
||||
return False
|
||||
|
||||
self.color_mode.color_format = color_format
|
||||
self.color_mode.bpc = bpc
|
||||
self.color_mode.colorimetry = colorimetry
|
||||
|
||||
if current_dynamic_range is not None:
|
||||
self.color_mode.dynamic_range = current_dynamic_range
|
||||
|
||||
if current_transfer_characteristic is not None:
|
||||
self.color_mode.transfer_characteristic = current_transfer_characteristic
|
||||
self.color_info.color_format = color_format
|
||||
self.color_info.bpc = bpc
|
||||
self.color_info.colorimetry = colorimetry
|
||||
self.color_info.dynamic_range = current_dynamic_range
|
||||
|
||||
return True
|
||||
|
||||
def apply_video_mode(self):
|
||||
"""应用当前colormode和timing"""
|
||||
"""应用当前 color_info 和 timing"""
|
||||
if self.current_timing:
|
||||
self.set_video_mode()
|
||||
return True
|
||||
@@ -341,25 +304,34 @@ class UCDController:
|
||||
|
||||
def set_video_mode(self):
|
||||
"""设置视频模式"""
|
||||
# 对比上次发出的配置,判断是否会触发电视重新锁定信号
|
||||
current_config = (
|
||||
self.current_timing,
|
||||
self.color_info.color_format,
|
||||
self.color_info.colorimetry,
|
||||
self.color_info.dynamic_range,
|
||||
self.color_info.bpc,
|
||||
)
|
||||
self.format_changed = (current_config != getattr(self, "_last_sent_config", None))
|
||||
video_mode = UniTAP.VideoMode(
|
||||
timing=self.current_timing, color_info=self.color_mode
|
||||
timing=self.current_timing, color_info=self.color_info
|
||||
)
|
||||
pg, _ = self.get_tx_modules()
|
||||
pg.set_vm(vm=video_mode)
|
||||
self._last_sent_config = current_config
|
||||
return True
|
||||
|
||||
def set_pattern(self, pattern, pattern_params=None):
|
||||
"""设置pattern"""
|
||||
if self.current_timing:
|
||||
if (
|
||||
pattern == UCDEnum.VideoPatternInfo.VideoPatternParams.SolidColor
|
||||
or pattern == UCDEnum.VideoPatternInfo.VideoPatternParams.WhiteVStrips
|
||||
or pattern
|
||||
== UCDEnum.VideoPatternInfo.VideoPatternParams.GradientRGBStripes
|
||||
or pattern == UCDEnum.VideoPatternInfo.VideoPatternParams.MotionPattern
|
||||
or pattern == UCDEnum.VideoPatternInfo.VideoPatternParams.SquareWindow
|
||||
and pattern_params
|
||||
):
|
||||
needs_params = {
|
||||
UCDEnum.VideoPatternInfo.VideoPatternParams.SolidColor,
|
||||
UCDEnum.VideoPatternInfo.VideoPatternParams.WhiteVStrips,
|
||||
UCDEnum.VideoPatternInfo.VideoPatternParams.GradientRGBStripes,
|
||||
UCDEnum.VideoPatternInfo.VideoPatternParams.MotionPattern,
|
||||
UCDEnum.VideoPatternInfo.VideoPatternParams.SquareWindow,
|
||||
}
|
||||
if pattern in needs_params and pattern_params:
|
||||
self.set_pattern_params(pattern, pattern_params)
|
||||
return True
|
||||
return False
|
||||
@@ -552,138 +524,62 @@ class UCDController:
|
||||
else:
|
||||
return False
|
||||
|
||||
def set_sdr_format(
|
||||
self, color_space=None, gamma=None, data_range=None, bit_depth=None
|
||||
def apply_signal_format(
|
||||
self, color_space=None, data_range=None, bit_depth=None, color_format=None, **_
|
||||
):
|
||||
"""设置SDR信号格式"""
|
||||
|
||||
def _get_colorimetry_from_color_space(color_space_name):
|
||||
"""将色彩空间名称转换为UniTAP colorimetry枚举值"""
|
||||
try:
|
||||
colorimetry_map = {
|
||||
"BT.709": UniTAP.ColorInfo.Colorimetry.CM_ITUR_BT709,
|
||||
"BT.601": UniTAP.ColorInfo.Colorimetry.CM_ITUR_BT601,
|
||||
"BT.2020": UniTAP.ColorInfo.Colorimetry.CM_ITUR_BT2020_RGB,
|
||||
}
|
||||
result = colorimetry_map.get(color_space_name)
|
||||
return result if result else UniTAP.ColorInfo.Colorimetry.CM_ITUR_BT709
|
||||
except Exception as e:
|
||||
return UniTAP.ColorInfo.Colorimetry.CM_ITUR_BT709
|
||||
|
||||
def _set_gamma_transfer_characteristic(gamma_value_str):
|
||||
"""设置Gamma传输特性"""
|
||||
try:
|
||||
gamma_value = float(gamma_value_str)
|
||||
|
||||
if abs(gamma_value - 2.2) < 0.1:
|
||||
self.color_mode.transfer_characteristic = (
|
||||
UniTAP.ColorInfo.TransferCharacteristic.TRANSFER_BT709
|
||||
)
|
||||
return True
|
||||
|
||||
elif abs(gamma_value - 2.4) < 0.1:
|
||||
if hasattr(
|
||||
UniTAP.ColorInfo.TransferCharacteristic, "TRANSFER_GAMMA24"
|
||||
):
|
||||
self.color_mode.transfer_characteristic = (
|
||||
UniTAP.ColorInfo.TransferCharacteristic.TRANSFER_GAMMA24
|
||||
)
|
||||
return True
|
||||
else:
|
||||
self.color_mode.transfer_characteristic = (
|
||||
UniTAP.ColorInfo.TransferCharacteristic.TRANSFER_BT709
|
||||
)
|
||||
return False
|
||||
|
||||
elif abs(gamma_value - 2.6) < 0.1:
|
||||
if hasattr(
|
||||
UniTAP.ColorInfo.TransferCharacteristic, "TRANSFER_GAMMA26"
|
||||
):
|
||||
self.color_mode.transfer_characteristic = (
|
||||
UniTAP.ColorInfo.TransferCharacteristic.TRANSFER_GAMMA26
|
||||
)
|
||||
return True
|
||||
else:
|
||||
self.color_mode.transfer_characteristic = (
|
||||
UniTAP.ColorInfo.TransferCharacteristic.TRANSFER_BT709
|
||||
)
|
||||
return False
|
||||
else:
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
return False
|
||||
|
||||
"""统一设置信号格式(color_format / colorimetry / dynamic_range / bpc)。
|
||||
注:Gamma/EOTF 传输特性在 ColorInfo API 中不存在;
|
||||
max_cll / max_fall 暂无对应 SDK 接口,通过 **_ 接收后忽略。
|
||||
"""
|
||||
try:
|
||||
if color_space:
|
||||
colorimetry = _get_colorimetry_from_color_space(color_space)
|
||||
if colorimetry:
|
||||
self.color_mode.colorimetry = colorimetry
|
||||
if color_format:
|
||||
fmt_key = UCDEnum.SignalFormat.OutputFormat.get_format_key(color_format)
|
||||
cf = UCDEnum.ColorInfo.get_color_format(fmt_key)
|
||||
if cf is not None:
|
||||
self.color_info.color_format = cf
|
||||
|
||||
if gamma:
|
||||
_set_gamma_transfer_characteristic(gamma)
|
||||
if color_space:
|
||||
colorimetry = self._get_colorimetry_from_color_space(color_space, color_format)
|
||||
if colorimetry:
|
||||
self.color_info.colorimetry = colorimetry
|
||||
|
||||
if data_range:
|
||||
if data_range == "Full":
|
||||
self.color_mode.dynamic_range = (
|
||||
UniTAP.ColorInfo.DynamicRange.DR_VESA
|
||||
)
|
||||
self.color_info.dynamic_range = UniTAP.ColorInfo.DynamicRange.DR_VESA
|
||||
elif data_range == "Limited":
|
||||
self.color_mode.dynamic_range = UniTAP.ColorInfo.DynamicRange.DR_CTA
|
||||
self.color_info.dynamic_range = UniTAP.ColorInfo.DynamicRange.DR_CTA
|
||||
|
||||
if bit_depth:
|
||||
bpc = UCDEnum.SignalFormat.BitDepth.get_bit_value(bit_depth)
|
||||
self.color_mode.bpc = bpc
|
||||
self.color_info.bpc = bpc
|
||||
|
||||
if self.current_timing:
|
||||
self.set_video_mode()
|
||||
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
def set_hdr_format(
|
||||
self,
|
||||
color_space=None,
|
||||
data_range=None,
|
||||
bit_depth=None,
|
||||
max_cll=None,
|
||||
max_fall=None,
|
||||
):
|
||||
"""设置HDR信号格式"""
|
||||
try:
|
||||
if color_space:
|
||||
colorimetry = self._get_colorimetry_from_color_space(color_space)
|
||||
if colorimetry:
|
||||
self.color_mode.colorimetry = colorimetry
|
||||
# 向后兼容别名
|
||||
set_sdr_format = apply_signal_format
|
||||
set_hdr_format = apply_signal_format
|
||||
|
||||
if data_range:
|
||||
if data_range == "Full":
|
||||
self.color_mode.dynamic_range = (
|
||||
UniTAP.ColorInfo.DynamicRange.DR_VESA
|
||||
)
|
||||
elif data_range == "Limited":
|
||||
self.color_mode.dynamic_range = UniTAP.ColorInfo.DynamicRange.DR_CTA
|
||||
|
||||
if bit_depth:
|
||||
bpc = UCDEnum.SignalFormat.BitDepth.get_bit_value(bit_depth)
|
||||
self.color_mode.bpc = bpc
|
||||
|
||||
if self.current_timing:
|
||||
self.set_video_mode()
|
||||
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
return False
|
||||
|
||||
def _get_colorimetry_from_color_space(self, color_space):
|
||||
"""将色彩空间字符串转换为UniTAP.ColorInfo.Colorimetry"""
|
||||
def _get_colorimetry_from_color_space(self, color_space, color_format=None):
|
||||
"""将色彩空间字符串转换为UniTAP.ColorInfo.Colorimetry。
|
||||
BT.2020 在 YCbCr 输出时使用 CM_ITUR_BT2020_YCbCr,RGB 输出时使用 CM_ITUR_BT2020_RGB。
|
||||
"""
|
||||
is_ycbcr = UCDEnum.SignalFormat.OutputFormat.is_ycbcr(color_format)
|
||||
bt2020_cm = (
|
||||
UniTAP.ColorInfo.Colorimetry.CM_ITUR_BT2020_YCbCr
|
||||
if is_ycbcr
|
||||
else UniTAP.ColorInfo.Colorimetry.CM_ITUR_BT2020_RGB
|
||||
)
|
||||
colorimetry_map = {
|
||||
"sRGB": UniTAP.ColorInfo.Colorimetry.CM_sRGB,
|
||||
"BT.709": UniTAP.ColorInfo.Colorimetry.CM_ITUR_BT709,
|
||||
"BT.601": UniTAP.ColorInfo.Colorimetry.CM_ITUR_BT601,
|
||||
"BT.2020": UniTAP.ColorInfo.Colorimetry.CM_ITUR_BT2020_RGB,
|
||||
"BT.2020": bt2020_cm,
|
||||
"DCI-P3": UniTAP.ColorInfo.Colorimetry.CM_DCI_P3,
|
||||
}
|
||||
return colorimetry_map.get(color_space)
|
||||
|
||||
Reference in New Issue
Block a user