LEADTOOLS Color Conversion C DLL Help > Tutorials > Visual Basic Tutorials > Generic YUV conversion (Visual Basic) |
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:
1. |
No sub-sampling of Y is supported |
2. |
The number of Y elements must be a multiple of both U, and V. |
3. |
With non-planar formats, vertical sub-sampling of Y, U, and V is not supported. |
4. |
No alignment supported in planar format; line width must not contain additional bytes. |
5. |
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:
1. |
Converting Y41P to RGB using Generic YUV Conversion: |
Function GenericY41PToRGB(YUVData() As Byte, RGBData() As Byte, nWidth As Integer, nHeight As Integer) As Integer
Dim ret As Integer
Dim ClrHandle As Long
Dim cnvParam As CONVERSION_PARAMS
Dim pOff(12) As Long
pOff(0) = 1
pOff(1) = 3
pOff(2) = 5
pOff(3) = 7
pOff(4) = 8
pOff(5) = 9
pOff(6) = 10
pOff(7) = 11
pOff(8) = 0
pOff(9) = 4
pOff(10) = 2
pOff(11) = 6
'(1,3,5,7,8,9,10,11,0,4,2,6)
Dim YUVParamas As LPYUV_PARAMS
With YUVParamas
.uStructSize = Len(YUVParamas)
.nMask = 0
.nUh = 4
.nUv = 1
.nVh = 4
.nVv = 1
.pOffsets = VarPtr(pOff(0))
.nMacroPixel = 8
.nRange = YUVRANGE_FULL
.bPlanar = 0
End With
cnvParam.uStructSize = Len(cnvParam)
cnvParam.nQuantization = 0
cnvParam.nMethod = USE_BUILTIN
cnvParam.nActiveMethod = USE_BUILTIN
cnvParam.pCmykParams = 0
cnvParam.pLabParams = 0
cnvParam.pYuvParams = VarPtr(YUVParamas)
cnvParam.sInputProfile(0) = 0
cnvParam.sOutputProfile(0) = 0
ret = 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 = ret
End Function
2. |
Converting YVU9 (Planar) to RGB using Generic YUV Conversion: |
Function GenericYVU9ToRGB(YUVData() As Byte, RGBData() As Byte, nWidth As Integer, nHeight As Integer) As Integer
Dim ret As Integer
Dim ClrHandle As Long
Dim cnvParam As CONVERSION_PARAMS
Dim pOff(0) As Long
pOff(0) = PLANAR_YVU
Dim YUVParamas As LPYUV_PARAMS
With YUVParamas
.uStructSize = Len(YUVParamas)
.nMask = 0
.nUh = 4
.nUv = 1
.nVh = 4
.nVv = 1
.pOffsets = VarPtr(pOff(0))
.nMacroPixel = 8
.nRange = YUVRANGE_FULL
.bPlanar = 1
End With
cnvParam.uStructSize = Len(cnvParam)
cnvParam.nQuantization = 0
cnvParam.nMethod = USE_BUILTIN
cnvParam.nActiveMethod = USE_BUILTIN
cnvParam.pCmykParams = 0
cnvParam.pLabParams = 0
cnvParam.pYuvParams = VarPtr(YUVParamas)
cnvParam.sInputProfile(0) = 0
cnvParam.sOutputProfile(0) = 0
ret = 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 = ret
End Function
See Also:
Programming with Color Conversion
Color Conversion C DLL Function Groups