static void FindClosestUNORM(ref BC4_UNORM pBC, float[] theTexelsU) { UInt32 NUM_PIXELS_PER_BLOCK = 16; float[] rGradient = new float[8]; for (UInt32 i = 0; i < 8; ++i) { rGradient[i] = pBC.DecodeFromIndex(i); } for (UInt32 i = 0; i < NUM_PIXELS_PER_BLOCK; ++i) { UInt32 uBestIndex = 0; float fBestDelta = 100000; for (UInt32 uIndex = 0; uIndex < 8; uIndex++) { float fCurrentDelta = Math.Abs(rGradient[uIndex] - theTexelsU[i]); if (fCurrentDelta < fBestDelta) { uBestIndex = uIndex; fBestDelta = fCurrentDelta; } } pBC.SetIndex((int)i, (int)uBestIndex); } }
public static void D3DXEncodeBC4U(ref UInt64 resultantBlock, float[] refData, List <float> theTexelsU) { var pBC4 = new BC4_UNORM(); FindEndPointsBC4U(theTexelsU, theTexelsU.Count, ref pBC4.red_0, ref pBC4.red_1); FindClosestUNORM(ref pBC4, refData); resultantBlock = pBC4.data; }
public static void D3DXDecodeBC4U(ref float[] pColor, UInt64 pBC) { UInt32 NUM_PIXELS_PER_BLOCK = 16; var pBC4 = new BC4_UNORM(); pBC4.data = pBC; for (int i = 0; i < NUM_PIXELS_PER_BLOCK; ++i) { pColor[i] = pBC4.R(i); } }
public static void D3DXDecodeBC4U(ref float[] pColor, ulong pBC) { uint NUM_PIXELS_PER_BLOCK = 16; var pBC4 = new BC4_UNORM { Data = pBC }; for (var i = 0; i < NUM_PIXELS_PER_BLOCK; ++i) { pColor[i] = pBC4.R(i); } }