1.1.0版本
This commit is contained in:
BIN
UniTAP/libs/lib_uicl/UICL.dll
Normal file
BIN
UniTAP/libs/lib_uicl/UICL.dll
Normal file
Binary file not shown.
0
UniTAP/libs/lib_uicl/__init__.py
Normal file
0
UniTAP/libs/lib_uicl/__init__.py
Normal file
73
UniTAP/libs/lib_uicl/uicl.py
Normal file
73
UniTAP/libs/lib_uicl/uicl.py
Normal file
@@ -0,0 +1,73 @@
|
||||
from .uicl_types import *
|
||||
from ..lib_helper import OS_Requirements, lib_method_wrapper
|
||||
|
||||
|
||||
UICL_CURRENT_VERSION = 1
|
||||
UICL = OS_Requirements("UICL").get_lib()
|
||||
|
||||
|
||||
class UICLError(Exception):
|
||||
def __init__(self, message, errors=None):
|
||||
super().__init__(message)
|
||||
self.errors = errors
|
||||
|
||||
|
||||
def UICL_GetRequiredBufferSize(dest_image: UICL_Image):
|
||||
_UICL_GetRequiredBufferSize = lib_method_wrapper(UICL.UICL_GetRequiredBufferSize, [POINTER(UICL_Image)], c_int64)
|
||||
|
||||
return _UICL_GetRequiredBufferSize(byref(dest_image))
|
||||
|
||||
|
||||
def UICL_Convert(src_image: UICL_Image, dest_image: UICL_Image):
|
||||
_UICL_Convert = lib_method_wrapper(UICL.UICL_Convert, [POINTER(UICL_Image), POINTER(UICL_Image)], UICL_RESULT)
|
||||
|
||||
return _UICL_Convert(byref(src_image), byref(dest_image))
|
||||
|
||||
|
||||
def UICL_SaveToFile(src_image: UICL_Image, file_name, image_file_format):
|
||||
_UICL_SaveToFile = lib_method_wrapper(UICL.UICL_SaveToFile, [c_char_p, POINTER(UICL_Image), c_int], UICL_RESULT)
|
||||
|
||||
return _UICL_SaveToFile(c_char_p(file_name.encode('utf-8')), byref(src_image), image_file_format)
|
||||
|
||||
|
||||
def UICL_CalculateCRC16(src_image: UICL_Image, crc: UICL_CRC16):
|
||||
_UICL_CalculateCRC16 = lib_method_wrapper(UICL.UICL_CalculateCRC16, [POINTER(UICL_Image), POINTER(UICL_CRC16)],
|
||||
UICL_RESULT)
|
||||
|
||||
return _UICL_CalculateCRC16(byref(src_image), byref(crc))
|
||||
|
||||
|
||||
def UICL_GeneratePattern(src_image: UICL_Image, pattern_type: int):
|
||||
_UICL_GeneratePattern = lib_method_wrapper(UICL.UICL_GeneratePattern, [POINTER(UICL_Image), c_int],
|
||||
UICL_RESULT)
|
||||
|
||||
return _UICL_GeneratePattern(byref(src_image), pattern_type)
|
||||
|
||||
|
||||
def UICL_GeneratePattern_3Tap(src_image: UICL_Image, pattern_type: int):
|
||||
_UICL_GeneratePattern_3Tap = lib_method_wrapper(UICL.UICL_GeneratePattern_3Tap, [POINTER(UICL_Image), c_int],
|
||||
UICL_RESULT)
|
||||
|
||||
return _UICL_GeneratePattern_3Tap(byref(src_image), pattern_type)
|
||||
|
||||
|
||||
def UICL_FreeImage(src_image: UICL_Image):
|
||||
_UICL_DeleteImage = lib_method_wrapper(UICL.UICL_FreeImage, [ POINTER(UICL_Image) ],
|
||||
UICL_RESULT)
|
||||
|
||||
return _UICL_DeleteImage(byref(src_image))
|
||||
|
||||
|
||||
def UICL_AllocImage(image_params: UICL_ImageParameters) -> UICL_Image:
|
||||
_UICL_AllocateImage = lib_method_wrapper(UICL.UICL_AllocImage,
|
||||
[POINTER(UICL_ImageParameters), POINTER(UICL_Image)],
|
||||
UICL_RESULT)
|
||||
|
||||
image = UICL_Image()
|
||||
|
||||
result = _UICL_AllocateImage(byref(image_params), byref(image))
|
||||
|
||||
if result < UICL_SUCCESS:
|
||||
raise UICLError(f"Cannot allocate image. Error code: {result}")
|
||||
|
||||
return image
|
||||
169
UniTAP/libs/lib_uicl/uicl_types.py
Normal file
169
UniTAP/libs/lib_uicl/uicl_types.py
Normal file
@@ -0,0 +1,169 @@
|
||||
from ctypes import *
|
||||
from enum import IntEnum
|
||||
|
||||
UICL_RESULT = c_int32
|
||||
|
||||
UICL_SUCCESS = 0
|
||||
UICL_ERROR_UNKNOWN = -1
|
||||
UICL_ERROR_NULL_IMAGE = -2
|
||||
UICL_ERROR_INVALID_COLORSPACE = -3
|
||||
UICL_ERROR_CONVERSION_NOT_SUPPORTED = -4
|
||||
|
||||
|
||||
class CtypesEnum(IntEnum):
|
||||
@classmethod
|
||||
def from_param(cls, obj):
|
||||
return int(obj)
|
||||
|
||||
|
||||
class UICL_ImageFileFormat(CtypesEnum):
|
||||
FILE_FORMAT_BMP = 0,
|
||||
FILE_FORMAT_BIN = 1,
|
||||
FILE_FORMAT_PPM = 2,
|
||||
|
||||
|
||||
class UICL_Colorspace(CtypesEnum):
|
||||
Colorspace_Unknown = 0,
|
||||
Colorspace_RGB = 1,
|
||||
Colorspace_YCbCr = 2,
|
||||
Colorspace_Raw = 3,
|
||||
Colorspace_Y = 4,
|
||||
Colorspace_MaxValue = 5
|
||||
|
||||
|
||||
class UICL_Sampling(CtypesEnum):
|
||||
Sampling_Unknown = 0,
|
||||
Sampling_444 = 1,
|
||||
Sampling_422 = 2,
|
||||
Sampling_420 = 3,
|
||||
Sampling_MaxValue = 4
|
||||
|
||||
|
||||
class UICL_Colorimetry(CtypesEnum):
|
||||
Colorimetry_Unknown = 0,
|
||||
Colorimetry_ITU_R_BT601 = 1,
|
||||
Colorimetry_ITU_R_BT709 = 2,
|
||||
Colorimetry_ITU_R_BT2020 = 3,
|
||||
Colorimetry_MaxValue = 4
|
||||
|
||||
|
||||
class UICL_Packing(CtypesEnum):
|
||||
Packing_Unknown = 0,
|
||||
Packing_Planar = 1,
|
||||
Packing_Packed = 2,
|
||||
Packing_DP_1_lane = 3
|
||||
Packing_DP_2_lane = 4
|
||||
Packing_DP_4_lane = 5
|
||||
Packing_MaxValue = 6
|
||||
|
||||
|
||||
class UICL_ComponentOrder(CtypesEnum):
|
||||
Order_Unknown = 0,
|
||||
Order_UCDTX_HI = 1,
|
||||
Order_UCDTX_LO = 2,
|
||||
Order_UCDRX = 3,
|
||||
Order_RGB = 4,
|
||||
Order_RGBA = 5,
|
||||
Order_BGR = 6,
|
||||
Order_BGRA = 7,
|
||||
Order_YCbCr = 8,
|
||||
Order_CbYCr = 9,
|
||||
Order_CbY0CrY1 = 10,
|
||||
Order_PlainRaw = 11,
|
||||
Order_Y = 12,
|
||||
Order_CirdanRaw = 13,
|
||||
Order_MaxValue = 14
|
||||
|
||||
|
||||
class UICL_Alignment(CtypesEnum):
|
||||
Alignment_Unknown = 0,
|
||||
Alignment_MSB = 1,
|
||||
Alignment_LSB = 2,
|
||||
Alignment_MaxValue = 3
|
||||
|
||||
|
||||
class UICL_ImageParameters(Structure):
|
||||
_fields_ = [
|
||||
('Width', c_uint32),
|
||||
('Height', c_uint32),
|
||||
('BitsPerColor', c_uint8),
|
||||
('Colorspace', c_int),
|
||||
('Colorimetry', c_int),
|
||||
('Sampling', c_int),
|
||||
('Packing', c_int),
|
||||
('ComponentOrder', c_int),
|
||||
('Alignment', c_int),
|
||||
('IsFullRange', c_bool),
|
||||
]
|
||||
|
||||
|
||||
class ImageFileFormat(CtypesEnum):
|
||||
FILE_FORMAT_BMP = 0,
|
||||
FILE_FORMAT_BIN = 1
|
||||
FILE_FORMAT_PPM = 2
|
||||
|
||||
|
||||
class UICL_Image(Structure):
|
||||
_fields_ = [
|
||||
('Parameters', UICL_ImageParameters),
|
||||
('DataPtr', POINTER(c_uint8)),
|
||||
('DataSize', c_uint64)
|
||||
]
|
||||
|
||||
|
||||
class UICL_CRC16(Structure):
|
||||
_fields_ = [
|
||||
('R', c_uint16),
|
||||
('G', c_uint16),
|
||||
('B', c_uint16)
|
||||
]
|
||||
|
||||
|
||||
parse_attributes_bpc = [6, 8, 10, 12, 16, 7, 14, 0]
|
||||
|
||||
parse_attributes_packing = [UICL_Packing.Packing_Packed,
|
||||
UICL_Packing.Packing_Packed,
|
||||
UICL_Packing.Packing_Unknown,
|
||||
UICL_Packing.Packing_Unknown]
|
||||
|
||||
parse_attributes_sampling = [UICL_Sampling.Sampling_444,
|
||||
UICL_Sampling.Sampling_422,
|
||||
UICL_Sampling.Sampling_444,
|
||||
UICL_Sampling.Sampling_420,
|
||||
UICL_Sampling.Sampling_444,
|
||||
UICL_Sampling.Sampling_Unknown,
|
||||
UICL_Sampling.Sampling_Unknown,
|
||||
UICL_Sampling.Sampling_Unknown]
|
||||
|
||||
parse_attributes_colorspace = [UICL_Colorspace.Colorspace_RGB,
|
||||
UICL_Colorspace.Colorspace_YCbCr,
|
||||
UICL_Colorspace.Colorspace_YCbCr,
|
||||
UICL_Colorspace.Colorspace_YCbCr,
|
||||
UICL_Colorspace.Colorspace_Y,
|
||||
UICL_Colorspace.Colorspace_Raw,
|
||||
UICL_Colorspace.Colorspace_Unknown,
|
||||
UICL_Colorspace.Colorspace_Unknown]
|
||||
|
||||
parse_attributes_colorimetry = [UICL_Colorimetry.Colorimetry_Unknown,
|
||||
UICL_Colorimetry.Colorimetry_ITU_R_BT601,
|
||||
UICL_Colorimetry.Colorimetry_ITU_R_BT709,
|
||||
UICL_Colorimetry.Colorimetry_Unknown]
|
||||
|
||||
parse_attributes_ecolorimetry = [UICL_Colorimetry.Colorimetry_Unknown,
|
||||
UICL_Colorimetry.Colorimetry_Unknown,
|
||||
UICL_Colorimetry.Colorimetry_Unknown,
|
||||
UICL_Colorimetry.Colorimetry_Unknown,
|
||||
UICL_Colorimetry.Colorimetry_Unknown,
|
||||
UICL_Colorimetry.Colorimetry_ITU_R_BT2020,
|
||||
UICL_Colorimetry.Colorimetry_ITU_R_BT2020,
|
||||
UICL_Colorimetry.Colorimetry_ITU_R_BT601]
|
||||
|
||||
dict_colorspace = {0: "Unknown", 1: "RGB", 2: "YCbCr", 3: "Raw", 4: "MaxValue"}
|
||||
dict_sampling = {0: "Unknown", 1: "4:4:4", 2: "4:2:2", 3: "4:2:0"}
|
||||
dict_colorimetry = {0: "Unknown", 1: "RGB", 2: "ITU_R_BT601", 3: "ITU_R_BT709", 4: "ITU_R_BT2020"}
|
||||
dict_packing = {0: "Unknown", 1: "Planar", 2: "SemiPlanar", 3: "Packed", 4: "32bit", 5: "48bit"}
|
||||
dict_component_oreder = {0: "Unknown", 1: "UCDTX_HI", 2: "UCDTX_LO", 3: "UCDRX", 4: "RGB", 5: "RGBA", 6: "BGR",
|
||||
7: "BGRA", 8: "YCbCr", 9: "CbYCr", 10: "CrYCb", 11: "CbY0CrY1", 12: "PlainRaw"}
|
||||
dict_alignment = {0: "Unknown", 1: "MSB", 2: "LSB"}
|
||||
uicl_errors = {-1: "Error unknown", -2: "Error null image", -3: "Invalid colorspace", -4: "Conversion not supported",
|
||||
-5: "Error in conversion", -6: "Unsupported format", -7: "Invalid parameters"}
|
||||
331
UniTAP/libs/lib_uicl/uicl_utils.py
Normal file
331
UniTAP/libs/lib_uicl/uicl_utils.py
Normal file
@@ -0,0 +1,331 @@
|
||||
from UniTAP.common import VideoMode, VideoFrame, ColorInfo, Timing, ImageFileFormat, DataInfo
|
||||
from .uicl_types import UICL_Image, UICL_ImageParameters, UICL_Colorimetry, UICL_Sampling,\
|
||||
UICL_Colorspace, UICL_Packing, UICL_Alignment, UICL_ComponentOrder, UICL_SUCCESS,\
|
||||
UICL_ImageFileFormat
|
||||
from .uicl import UICL_Convert, UICL_GetRequiredBufferSize, UICL_SaveToFile, UICL_CRC16, UICL_CalculateCRC16
|
||||
|
||||
from typing import Tuple
|
||||
from ctypes import c_uint8
|
||||
|
||||
|
||||
def uicl_cf_from_vm(color_format: ColorInfo.ColorFormat) -> UICL_Colorspace:
|
||||
if color_format == ColorInfo.ColorFormat.CF_RGB:
|
||||
return UICL_Colorspace.Colorspace_RGB
|
||||
elif color_format in [ColorInfo.ColorFormat.CF_YCbCr_444, ColorInfo.ColorFormat.CF_YCbCr_422,
|
||||
ColorInfo.ColorFormat.CF_YCbCr_420]:
|
||||
return UICL_Colorspace.Colorspace_YCbCr
|
||||
else:
|
||||
return UICL_Colorspace.Colorspace_Unknown
|
||||
|
||||
|
||||
def uicl_sampling_from_vm(color_format: ColorInfo.ColorFormat) -> UICL_Sampling:
|
||||
if color_format in [ColorInfo.ColorFormat.CF_RGB, ColorInfo.ColorFormat.CF_YCbCr_444]:
|
||||
return UICL_Sampling.Sampling_444
|
||||
elif color_format == ColorInfo.ColorFormat.CF_YCbCr_422:
|
||||
return UICL_Sampling.Sampling_422
|
||||
elif color_format == ColorInfo.ColorFormat.CF_YCbCr_420:
|
||||
return UICL_Sampling.Sampling_420
|
||||
else:
|
||||
return UICL_Sampling.Sampling_Unknown
|
||||
|
||||
|
||||
def uicl_colorimetry_from_ci_colorimetry(colorimetry: ColorInfo.Colorimetry) -> UICL_Colorimetry:
|
||||
if colorimetry == ColorInfo.Colorimetry.CM_ITUR_BT601:
|
||||
return UICL_Colorimetry.Colorimetry_ITU_R_BT601
|
||||
elif colorimetry == ColorInfo.Colorimetry.CM_ITUR_BT709:
|
||||
return UICL_Colorimetry.Colorimetry_ITU_R_BT709
|
||||
elif colorimetry == ColorInfo.Colorimetry.CM_ITUR_BT2020_YCbCr:
|
||||
return UICL_Colorimetry.Colorimetry_ITU_R_BT2020
|
||||
else:
|
||||
return UICL_Colorimetry.Colorimetry_Unknown
|
||||
|
||||
|
||||
def uicl_colorimetry_to_ci_colorimetry(colorimetry: UICL_Colorimetry) -> ColorInfo.Colorimetry:
|
||||
if colorimetry == UICL_Colorimetry.Colorimetry_ITU_R_BT601:
|
||||
return ColorInfo.Colorimetry.CM_ITUR_BT601
|
||||
elif colorimetry == UICL_Colorimetry.Colorimetry_ITU_R_BT709:
|
||||
return ColorInfo.Colorimetry.CM_ITUR_BT709
|
||||
elif colorimetry == UICL_Colorimetry.Colorimetry_ITU_R_BT2020:
|
||||
return ColorInfo.Colorimetry.CM_ITUR_BT2020_YCbCr
|
||||
else:
|
||||
return ColorInfo.Colorimetry.CM_NONE
|
||||
|
||||
|
||||
def uicl_parameters_from_vm(vm: VideoMode) -> UICL_ImageParameters:
|
||||
parameters = UICL_ImageParameters()
|
||||
|
||||
parameters.Width = vm.timing.hactive
|
||||
parameters.Height = vm.timing.vactive
|
||||
parameters.BitsPerColor = vm.color_info.bpc
|
||||
parameters.Colorimetry = uicl_colorimetry_from_ci_colorimetry(vm.color_info.colorimetry)
|
||||
|
||||
if vm.color_info.color_format == ColorInfo.ColorFormat.CF_RGB:
|
||||
parameters.Colorspace = UICL_Colorspace.Colorspace_RGB
|
||||
parameters.ComponentOrder = UICL_ComponentOrder.Order_RGB
|
||||
parameters.Sampling = UICL_Sampling.Sampling_444
|
||||
parameters.Packing = UICL_Packing.Packing_Packed
|
||||
parameters.Alignment = UICL_Alignment.Alignment_LSB
|
||||
parameters.IsFullRange = vm.color_info.DynamicRange == ColorInfo.DynamicRange.DR_VESA
|
||||
|
||||
elif vm.color_info.color_format == ColorInfo.ColorFormat.CF_YCbCr_444:
|
||||
parameters.Colorspace = UICL_Colorspace.Colorspace_YCbCr
|
||||
parameters.ComponentOrder = UICL_ComponentOrder.Order_YCbCr
|
||||
parameters.Sampling = UICL_Sampling.Sampling_444
|
||||
parameters.Packing = UICL_Packing.Packing_Packed
|
||||
parameters.Alignment = UICL_Alignment.Alignment_LSB
|
||||
parameters.IsFullRange = False
|
||||
|
||||
elif vm.color_info.color_format == ColorInfo.ColorFormat.CF_YCbCr_422:
|
||||
parameters.Colorspace = UICL_Colorspace.Colorspace_YCbCr
|
||||
parameters.ComponentOrder = UICL_ComponentOrder.Order_CbY0CrY1
|
||||
parameters.Sampling = UICL_Sampling.Sampling_422
|
||||
parameters.Packing = UICL_Packing.Packing_Packed
|
||||
parameters.Alignment = UICL_Alignment.Alignment_LSB
|
||||
parameters.IsFullRange = False
|
||||
|
||||
elif vm.color_info.color_format == ColorInfo.ColorFormat.CF_YCbCr_420:
|
||||
parameters.Colorspace = UICL_Colorspace.Colorspace_YCbCr
|
||||
parameters.ComponentOrder = UICL_ComponentOrder.Order_YCbCr
|
||||
parameters.Sampling = UICL_Sampling.Sampling_420
|
||||
parameters.Packing = UICL_Packing.Packing_Planar
|
||||
parameters.Alignment = UICL_Alignment.Alignment_LSB
|
||||
parameters.IsFullRange = False
|
||||
|
||||
return parameters
|
||||
|
||||
|
||||
def uicl_image_from_vm_and_data(video_mode: VideoMode, data: bytearray) -> UICL_Image:
|
||||
image = UICL_Image()
|
||||
|
||||
image.DataPtr = (c_uint8 * len(data))(*data)
|
||||
image.DataSize = len(data)
|
||||
image.Parameters = uicl_parameters_from_vm(video_mode)
|
||||
|
||||
return image
|
||||
|
||||
|
||||
def uicl_image_convert_to_vm(src_image: UICL_Image, video_mode: VideoMode) -> bytearray:
|
||||
dest_image = UICL_Image()
|
||||
|
||||
dest_image.Parameters = uicl_parameters_from_vm(video_mode)
|
||||
result = UICL_GetRequiredBufferSize(dest_image)
|
||||
|
||||
assert result >= UICL_SUCCESS, f"Calculation required buffer size failed with error {result}"
|
||||
|
||||
dest_image.DataPtr = (c_uint8 * result)()
|
||||
dest_image.DataSize = result
|
||||
|
||||
result = UICL_Convert(src_image, dest_image)
|
||||
|
||||
assert result == UICL_SUCCESS, f"Image conversion failed with error {result}"
|
||||
|
||||
return bytearray(dest_image.DataPtr[:dest_image.DataSize])
|
||||
|
||||
|
||||
def image_from_vf(video_frame: VideoFrame) -> UICL_Image:
|
||||
image = UICL_Image()
|
||||
|
||||
image.Parameters = image_params_from_size_and_ci(video_frame.width, video_frame.height, video_frame.color_info,
|
||||
video_frame.data_info)
|
||||
image.DataSize = len(video_frame.data)
|
||||
image.DataPtr = (c_uint8 * len(video_frame.data)).from_buffer(video_frame.data)
|
||||
|
||||
return image
|
||||
|
||||
|
||||
def image_to_vf(image: UICL_Image) -> VideoFrame:
|
||||
video_frame = VideoFrame()
|
||||
|
||||
video_frame.width, video_frame.height, video_frame.color_info, video_frame.data_info = image_params_to_size_and_ci(image.Parameters)
|
||||
video_frame.data = bytearray(image.DataPtr[:image.DataSize])
|
||||
|
||||
return video_frame
|
||||
|
||||
|
||||
def uicl_image_calculate_crc(src_vf: VideoFrame) -> tuple:
|
||||
crc = UICL_CRC16()
|
||||
|
||||
src_image = image_from_vf(src_vf)
|
||||
|
||||
result = UICL_CalculateCRC16(src_image, crc)
|
||||
|
||||
assert result >= UICL_SUCCESS, f"Calculation CRC failed with error {result}"
|
||||
|
||||
return crc.R, crc.G, crc.B
|
||||
|
||||
|
||||
def image_params_to_vm(image_params: UICL_ImageParameters) -> VideoMode:
|
||||
pass
|
||||
|
||||
|
||||
def image_params_to_size_and_ci(image_params: UICL_ImageParameters) -> Tuple[int, int, ColorInfo, DataInfo]:
|
||||
width = image_params.Width
|
||||
height = image_params.Height
|
||||
color_info = ColorInfo()
|
||||
|
||||
color_info.bpc = image_params.BitsPerColor
|
||||
color_info.colorimetry = uicl_colorimetry_to_ci_colorimetry(image_params.Colorimetry)
|
||||
color_info.dynamic_range = ColorInfo.DynamicRange.DR_VESA if image_params.IsFullRange else ColorInfo.DynamicRange.DR_CTA
|
||||
|
||||
if image_params.Colorspace == UICL_Colorspace.Colorspace_RGB:
|
||||
color_info.color_format = ColorInfo.ColorFormat.CF_RGB
|
||||
elif image_params.Colorspace == UICL_Colorspace.Colorspace_YCbCr:
|
||||
if image_params.Sampling == UICL_Sampling.Sampling_444:
|
||||
color_info.color_format = ColorInfo.ColorFormat.CF_YCbCr_444
|
||||
elif image_params.Sampling == UICL_Sampling.Sampling_422:
|
||||
color_info.color_format = ColorInfo.ColorFormat.CF_YCbCr_422
|
||||
elif image_params.Sampling == UICL_Sampling.Sampling_420:
|
||||
color_info.color_format = ColorInfo.ColorFormat.CF_YCbCr_420
|
||||
else:
|
||||
color_info.color_format = ColorInfo.ColorFormat.CF_UNKNOWN
|
||||
elif image_params.Colorspace == UICL_Colorspace.Colorspace_Y:
|
||||
color_info.color_format = ColorInfo.ColorFormat.CF_Y_ONLY
|
||||
elif image_params.Colorspace == UICL_Colorspace.Colorspace_Raw:
|
||||
color_info.color_format = ColorInfo.ColorFormat.CF_RAW
|
||||
|
||||
data_info = DataInfo()
|
||||
data_info.alignment = uicl_alignment_to_vf_alignment(image_params.Alignment)
|
||||
data_info.component_order = uicl_com_order_to_vf_com_order(image_params.ComponentOrder)
|
||||
data_info.packing = uicl_packing_to_vf_packing(image_params.Packing)
|
||||
|
||||
return width, height, color_info, data_info
|
||||
|
||||
|
||||
def vf_com_order_to_uicl_com_order(component_order: DataInfo.ComponentOrder) -> UICL_ComponentOrder:
|
||||
if component_order == DataInfo.ComponentOrder.CO_UCDRX:
|
||||
return UICL_ComponentOrder.Order_UCDRX
|
||||
elif component_order == DataInfo.ComponentOrder.CO_RGB:
|
||||
return UICL_ComponentOrder.Order_RGB
|
||||
elif component_order == DataInfo.ComponentOrder.CO_RGBA:
|
||||
return UICL_ComponentOrder.Order_RGBA
|
||||
elif component_order == DataInfo.ComponentOrder.CO_BGR:
|
||||
return UICL_ComponentOrder.Order_BGR
|
||||
elif component_order == DataInfo.ComponentOrder.CO_BGRA:
|
||||
return UICL_ComponentOrder.Order_BGRA
|
||||
elif component_order == DataInfo.ComponentOrder.CO_YCbCr:
|
||||
return UICL_ComponentOrder.Order_YCbCr
|
||||
elif component_order == DataInfo.ComponentOrder.CO_CbY0CrY1:
|
||||
return UICL_ComponentOrder.Order_CbY0CrY1
|
||||
else:
|
||||
return UICL_ComponentOrder.Order_Unknown
|
||||
|
||||
|
||||
def uicl_com_order_to_vf_com_order(component_order: UICL_ComponentOrder) -> DataInfo.ComponentOrder:
|
||||
if component_order == UICL_ComponentOrder.Order_UCDRX:
|
||||
return DataInfo.ComponentOrder.CO_UCDRX
|
||||
elif component_order == UICL_ComponentOrder.Order_RGB:
|
||||
return DataInfo.ComponentOrder.CO_RGB
|
||||
elif component_order == UICL_ComponentOrder.Order_RGBA:
|
||||
return DataInfo.ComponentOrder.CO_RGBA
|
||||
elif component_order == UICL_ComponentOrder.Order_BGR:
|
||||
return DataInfo.ComponentOrder.CO_BGR
|
||||
elif component_order == UICL_ComponentOrder.Order_BGRA:
|
||||
return DataInfo.ComponentOrder.CO_BGRA
|
||||
elif component_order == UICL_ComponentOrder.Order_YCbCr:
|
||||
return DataInfo.ComponentOrder.CO_YCbCr
|
||||
elif component_order == UICL_ComponentOrder.Order_CbY0CrY1:
|
||||
return DataInfo.ComponentOrder.CO_CbY0CrY1
|
||||
else:
|
||||
return DataInfo.ComponentOrder.CO_UNKNOWN
|
||||
|
||||
|
||||
def vf_packing_to_uicl_packing(packing: DataInfo.Packing) -> UICL_Packing:
|
||||
if packing == DataInfo.Packing.P_PLANAR:
|
||||
return UICL_Packing.Packing_Planar
|
||||
elif packing == DataInfo.Packing.P_PACKED:
|
||||
return UICL_Packing.Packing_Packed
|
||||
else:
|
||||
return UICL_Packing.Packing_Unknown
|
||||
|
||||
|
||||
def uicl_packing_to_vf_packing(packing: UICL_Packing) -> DataInfo.Packing:
|
||||
if packing == UICL_Packing.Packing_Planar:
|
||||
return DataInfo.Packing.P_PLANAR
|
||||
elif packing == UICL_Packing.Packing_Packed:
|
||||
return DataInfo.Packing.P_PACKED
|
||||
else:
|
||||
return DataInfo.Packing.P_UNKNOWN
|
||||
|
||||
|
||||
def vf_alignment_to_uicl_alignment(alignment: DataInfo.Alignment) -> UICL_Alignment:
|
||||
if alignment == DataInfo.Alignment.A_LSB:
|
||||
return UICL_Alignment.Alignment_LSB
|
||||
elif alignment == DataInfo.Alignment.A_MSB:
|
||||
return UICL_Alignment.Alignment_MSB
|
||||
else:
|
||||
return UICL_Alignment.Alignment_Unknown
|
||||
|
||||
|
||||
def uicl_alignment_to_vf_alignment(alignment: UICL_Alignment) -> DataInfo.Alignment:
|
||||
if alignment == UICL_Alignment.Alignment_LSB:
|
||||
return DataInfo.Alignment.A_LSB
|
||||
elif alignment == UICL_Alignment.Alignment_MSB:
|
||||
return DataInfo.Alignment.A_MSB
|
||||
else:
|
||||
return DataInfo.Alignment.A_UNKNOWN
|
||||
|
||||
|
||||
def image_params_from_vm(video_mode: VideoMode) -> UICL_ImageParameters:
|
||||
pass
|
||||
|
||||
|
||||
def image_params_from_size_and_ci(width: int, height: int, color_info: ColorInfo,
|
||||
data_info: DataInfo) -> UICL_ImageParameters:
|
||||
parameters = UICL_ImageParameters()
|
||||
|
||||
parameters.Width = width
|
||||
parameters.Height = height
|
||||
parameters.BitsPerColor = color_info.bpc
|
||||
parameters.Colorimetry = uicl_colorimetry_from_ci_colorimetry(color_info.colorimetry)
|
||||
parameters.ComponentOrder = vf_com_order_to_uicl_com_order(data_info.component_order)
|
||||
parameters.Packing = vf_packing_to_uicl_packing(data_info.packing)
|
||||
parameters.Alignment = vf_alignment_to_uicl_alignment(data_info.alignment)
|
||||
|
||||
if color_info.color_format == ColorInfo.ColorFormat.CF_RGB:
|
||||
parameters.Colorspace = UICL_Colorspace.Colorspace_RGB
|
||||
parameters.Sampling = UICL_Sampling.Sampling_444
|
||||
parameters.IsFullRange = color_info.DynamicRange == ColorInfo.DynamicRange.DR_VESA
|
||||
|
||||
elif color_info.color_format == ColorInfo.ColorFormat.CF_YCbCr_444:
|
||||
parameters.Colorspace = UICL_Colorspace.Colorspace_YCbCr
|
||||
parameters.Sampling = UICL_Sampling.Sampling_444
|
||||
parameters.IsFullRange = True if data_info.component_order == DataInfo.ComponentOrder.CO_UCDRX else False
|
||||
|
||||
elif color_info.color_format == ColorInfo.ColorFormat.CF_YCbCr_422:
|
||||
parameters.Colorspace = UICL_Colorspace.Colorspace_YCbCr
|
||||
parameters.Sampling = UICL_Sampling.Sampling_422
|
||||
parameters.IsFullRange = True if data_info.component_order == DataInfo.ComponentOrder.CO_UCDRX else False
|
||||
|
||||
elif color_info.color_format == ColorInfo.ColorFormat.CF_YCbCr_420:
|
||||
parameters.Colorspace = UICL_Colorspace.Colorspace_YCbCr
|
||||
parameters.Sampling = UICL_Sampling.Sampling_420
|
||||
parameters.IsFullRange = True if data_info.component_order == DataInfo.ComponentOrder.CO_UCDRX else False
|
||||
|
||||
else:
|
||||
parameters.Colorspace = UICL_Colorspace.Colorspace_Unknown
|
||||
parameters.Sampling = UICL_Sampling.Sampling_Unknown
|
||||
parameters.IsFullRange = True if data_info.component_order == DataInfo.ComponentOrder.CO_UCDRX else False
|
||||
|
||||
return parameters
|
||||
|
||||
|
||||
def image_convert_to_parameters(src_image: UICL_Image, parameters: UICL_ImageParameters) -> UICL_Image:
|
||||
dst_image = UICL_Image()
|
||||
|
||||
dst_image.Parameters = parameters
|
||||
result = UICL_GetRequiredBufferSize(dst_image)
|
||||
|
||||
assert result >= UICL_SUCCESS, f"Calculation required buffer size failed with error {result}"
|
||||
|
||||
dst_image.DataSize = result
|
||||
dst_image.DataPtr = (c_uint8 * result)()
|
||||
|
||||
result = UICL_Convert(src_image, dst_image)
|
||||
|
||||
assert result >= UICL_SUCCESS, f"Image conversion failed with error {result}"
|
||||
|
||||
return dst_image
|
||||
|
||||
|
||||
def image_save_to_file(image: UICL_Image, path: str, image_format: UICL_ImageFileFormat) -> bool:
|
||||
return UICL_SaveToFile(image, path, image_format)
|
||||
Reference in New Issue
Block a user