uGIF.Image.ResizeBilinear C# (CSharp) Method

ResizeBilinear() public method

public ResizeBilinear ( int newWidth, int newHeight ) : void
newWidth int
newHeight int
return void
        public void ResizeBilinear(int newWidth, int newHeight)
        {
            if (newWidth == width && newHeight == height)
                return;
            var texColors = pixels;
            var newColors = new Color32[newWidth * newHeight];
            var ratioX = 1.0f / ((float)newWidth / (width - 1));
            var ratioY = 1.0f / ((float)newHeight / (height - 1));
            var w = width;
            var w2 = newWidth;

            for (var y = 0; y < newHeight; y++) {
                var yFloor = Mathf.FloorToInt (y * ratioY);
                var y1 = yFloor * w;
                var y2 = (yFloor + 1) * w;
                var yw = y * w2;

                for (var x = 0; x < w2; x++) {
                    int xFloor = (int)Mathf.Floor (x * ratioX);
                    var xLerp = x * ratioX - xFloor;
                    newColors [yw + x] = ColorLerpUnclamped (ColorLerpUnclamped (texColors [y1 + xFloor], texColors [y1 + xFloor + 1], xLerp), ColorLerpUnclamped (texColors [y2 + xFloor], texColors [y2 + xFloor + 1], xLerp), y * ratioY - yFloor);
                }
            }
            pixels = newColors;
            height = newHeight;
            width = newWidth;
        }