public static int[] calcMixedBitDepths(int[] utdepth, int ttype, int[] tdepth)
{
if (utdepth.Length < 3 && ttype != NONE)
{
throw new System.ArgumentException();
}
if (tdepth == null)
{
tdepth = new int[utdepth.Length];
}
switch (ttype)
{
case NONE:
Array.Copy(utdepth, 0, tdepth, 0, utdepth.Length);
break;
case INV_RCT:
if (utdepth.Length > 3)
{
Array.Copy(utdepth, 3, tdepth, 3, utdepth.Length - 3);
}
// The formulas are:
// tdepth[0] = ceil(log2(2^(utdepth[0])+2^utdepth[1]+
// 2^(utdepth[2])))-2+1
// tdepth[1] = ceil(log2(2^(utdepth[0])+2^(utdepth[1])-1))+1
// tdepth[2] = ceil(log2(2^(utdepth[1])+2^(utdepth[2])-1))+1
// The MathUtil.log2(x) function calculates floor(log2(x)), so we
// use 'MathUtil.log2(2*x-1)+1', which calculates ceil(log2(x))
// for any x>=1, x integer.
tdepth[0] = MathUtil.log2((1 << utdepth[0]) + (2 << utdepth[1]) + (1 << utdepth[2]) - 1) - 2 + 1;
tdepth[1] = MathUtil.log2((1 << utdepth[2]) + (1 << utdepth[1]) - 1) + 1;
tdepth[2] = MathUtil.log2((1 << utdepth[0]) + (1 << utdepth[1]) - 1) + 1;
break;
case INV_ICT:
if (utdepth.Length > 3)
{
Array.Copy(utdepth, 3, tdepth, 3, utdepth.Length - 3);
}
// The MathUtil.log2(x) function calculates floor(log2(x)), so we
// use 'MathUtil.log2(2*x-1)+1', which calculates ceil(log2(x))
// for any x>=1, x integer.
//UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
tdepth[0] =
MathUtil.log2(
(int)
System.Math.Floor(
(1 << utdepth[0]) * 0.299072 + (1 << utdepth[1]) * 0.586914
+ (1 << utdepth[2]) * 0.114014) - 1) + 1;
//UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
tdepth[1] =
MathUtil.log2(
(int)
System.Math.Floor(
(1 << utdepth[0]) * 0.168701 + (1 << utdepth[1]) * 0.331299 + (1 << utdepth[2]) * 0.5)
- 1) + 1;
//UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
tdepth[2] =
MathUtil.log2(
(int)
System.Math.Floor(
(1 << utdepth[0]) * 0.5 + (1 << utdepth[1]) * 0.418701 + (1 << utdepth[2]) * 0.081299)
- 1) + 1;
break;
}
return tdepth;
}