Example #1
0
        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);
            }
        }