Generic YUV conversion provides the ability to convert any YUV format to any supported color space, using the YUV_PARAMS structure and adhering to the restrictions listed below. After defining the YUV format, you can proceed with the conversion normally, just like any other conversion. Use L_ClrConvert to perform the conversion and call L_ClrFree to free the conversion handle. Currently the conversion from any color space to Generic YUV is not supported.
Generic YUV conversion currently has the following restrictions:
No sub-sampling of Y is supported
The number of Y elements must be a multiple of both U, and V.
With non-planar formats, vertical sub-sampling of Y, U, and V is not supported.
No alignment supported in planar format; line width must not contain additional bytes.
The horizontal subsampling periods of U, and V must be multiples of each other, and the vertical subsampling periods of U, and V must be multiples of each other.
Examples:
Converting Y41P to RGB using Generic YUV Conversion:
Function GenericY41PToRGB(YUVData() As Byte, RGBData() As Byte, nWidth As Integer, nHeight As Integer) As IntegerDim ret As IntegerDim ClrHandle As LongDim cnvParam As CONVERSION_PARAMSDim pOff(12) As LongpOff(0) = 1pOff(1) = 3pOff(2) = 5pOff(3) = 7pOff(4) = 8pOff(5) = 9pOff(6) = 10pOff(7) = 11pOff(8) = 0pOff(9) = 4pOff(10) = 2pOff(11) = 6'(1,3,5,7,8,9,10,11,0,4,2,6)Dim YUVParamas As LPYUV_PARAMSWith YUVParamas.uStructSize = Len(YUVParamas).nMask = 0.nUh = 4.nUv = 1.nVh = 4.nVv = 1.pOffsets = VarPtr(pOff(0)).nMacroPixel = 8.nRange = YUVRANGE_FULL.bPlanar = 0End WithcnvParam.uStructSize = Len(cnvParam)cnvParam.nQuantization = 0cnvParam.nMethod = USE_BUILTINcnvParam.nActiveMethod = USE_BUILTINcnvParam.pCmykParams = 0cnvParam.pLabParams = 0cnvParam.pYuvParams = VarPtr(YUVParamas)cnvParam.sInputProfile(0) = 0cnvParam.sOutputProfile(0) = 0ret = L_ClrInit (ClrHandle, CCS_YUV, CCS_RGB, cnvParam)ret = L_ClrConvert (ClrHandle, YUVData(0), RGBData(0), nWidth, nHeight, 0, 0)ret = L_ClrFree (ClrHandle)GenericY41PToRGB = retEnd Function
Converting YVU9 (Planar) to RGB using Generic YUV Conversion:
Function GenericYVU9ToRGB(YUVData() As Byte, RGBData() As Byte, nWidth As Integer, nHeight As Integer) As IntegerDim ret As IntegerDim ClrHandle As LongDim cnvParam As CONVERSION_PARAMSDim pOff(0) As LongpOff(0) = PLANAR_YVUDim YUVParamas As LPYUV_PARAMSWith YUVParamas.uStructSize = Len(YUVParamas).nMask = 0.nUh = 4.nUv = 1.nVh = 4.nVv = 1.pOffsets = VarPtr(pOff(0)).nMacroPixel = 8.nRange = YUVRANGE_FULL.bPlanar = 1End WithcnvParam.uStructSize = Len(cnvParam)cnvParam.nQuantization = 0cnvParam.nMethod = USE_BUILTINcnvParam.nActiveMethod = USE_BUILTINcnvParam.pCmykParams = 0cnvParam.pLabParams = 0cnvParam.pYuvParams = VarPtr(YUVParamas)cnvParam.sInputProfile(0) = 0cnvParam.sOutputProfile(0) = 0ret = L_ClrInit (ClrHandle, CCS_YUV, CCS_RGB, cnvParam)ret = L_ClrConvert (ClrHandle, YUVData(0), RGBData(0), nWidth, nHeight, 0, 0)ret = L_ClrFree (ClrHandle)GenericYVU9ToRGB = retEnd Function