示例#1
0
        /// Simplified to be single-threaded and blocking
        private unsafe static void Bilinear(
            Color32[] texColors, int texWidth, int texHeight,
            Color32[] newColors, int newWidth, int newHeight)
        {
            // A single pass of bilinear filtering blends 4 pixels together,
            // so don't try to reduce by more than a factor of 2 per iteration
            Debug.Assert(newWidth * newHeight == newColors.Length);

            fixed(Color32 *pTex = texColors)
            {
                ColorBuffer cur = new ColorBuffer(texColors, pTex, texWidth, texHeight);

                while (true)
                {
                    int tmpWidth  = moveTowardsLog(cur.width, newWidth);
                    int tmpHeight = moveTowardsLog(cur.height, newHeight);
                    if (newColors.Length == tmpWidth * tmpHeight)
                    {
                        fixed(Color32 *pNew = newColors)
                        {
                            SinglePassBilinear(cur.array, cur.length, cur.width, cur.height,
                                               pNew, newColors.Length, newWidth, newHeight);
                        }

                        return;
                    }

                    ColorBuffer tmp = new ColorBuffer(tmpWidth, tmpHeight);
                    SinglePassBilinear(cur.array, cur.length, cur.width, cur.height,
                                       tmp.array, tmp.length, tmp.width, tmp.height);
                    cur.Deallocate();
                    cur = tmp;
                }
            }
        }