TextureScale.BilinearScale C# (CSharp) Method

BilinearScale() public static method

public static BilinearScale ( System obj ) : void
obj System
return void
    public static void BilinearScale(System.Object obj)
    {
        ThreadData threadData = (ThreadData)obj;
        for (var y = threadData.start; y < threadData.end; y++)
        {
            int yFloor = (int)Mathf.Floor(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);
            }
        }

        mutex.WaitOne();
        finishCount++;
        mutex.ReleaseMutex();
    }

Usage Example

Exemplo n.º 1
0
 public static void Scale(Texture2D tex, int newWidth, int newHeight)
 {
     TextureScale.texColors = tex.GetPixels();
     TextureScale.newColors = new Color[newWidth * newHeight];
     TextureScale.ratioX    = 1f / ((float)newWidth / (float)(tex.width - 1));
     TextureScale.ratioY    = 1f / ((float)newHeight / (float)(tex.height - 1));
     TextureScale.w         = tex.width;
     TextureScale.w2        = newWidth;
     TextureScale.BilinearScale(0, newHeight);
     tex.Resize(newWidth, newHeight);
     tex.SetPixels(TextureScale.newColors);
     tex.Apply();
 }
All Usage Examples Of TextureScale::BilinearScale