private void FindProperValues(float threshold, ref SerializedProperty top, ref SerializedProperty bottom, ref SerializedProperty left, ref SerializedProperty right) { int width = InputSequence.width; int height = InputSequence.height; int minX = width; int maxX = 0; int minY = height; int maxY = 0; Color[] colors; RenderTexture tempRT = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear); for (int i = 0; i < InputSequence.frames.Count; i++) { ProcessingFrame f = InputSequence.frames[i]; VFXToolboxGUIUtility.DisplayProgressBar("Crop processor", "Evaluating closest bound (Frame #" + i + " on " + InputSequence.frames.Count + "...)", (float)i / InputSequence.frames.Count); if (InputSequence.processor != null) { f.Process(); colors = VFXToolboxUtility.ReadBack(f.texture as RenderTexture); } else { Graphics.Blit(f.texture, tempRT); colors = VFXToolboxUtility.ReadBack(tempRT); } // Check frame for (int j = 0; j < colors.Length; j++) { int x = j % width; int y = j / width; if (colors[j].a >= threshold) { minX = Mathf.Min(minX, x); maxX = Mathf.Max(maxX, x); minY = Mathf.Min(minY, y); maxY = Mathf.Max(maxY, y); } } } VFXToolboxGUIUtility.ClearProgressBar(); bottom.intValue = minY; top.intValue = height - maxY - 1; left.intValue = minX; right.intValue = width - maxX - 1; RenderTexture.ReleaseTemporary(tempRT); }
private SpriteMetaData[] GetSpriteMetaData(ProcessingFrame frame, int numU, int numV) { SpriteMetaData[] result = new SpriteMetaData[numU * numV]; float width = (float)frame.texture.width / numU; float height = (float)frame.texture.height / numV; for (int i = 0; i < numU; i++) { for (int j = 0; j < numV; j++) { SpriteMetaData data = new SpriteMetaData(); data.name = "Frame_" + (i + (j * numU)); data.rect = new Rect(i * width, (numV - j - 1) * height, width, height); result[i + (j * numU)] = data; } } return(result); }
public bool Process(ProcessingFrame frame) { return(Process(OutputSequence.frames.IndexOf(frame))); }