// public static Vector2Int GetResultSize(ITextureProcessor tp) { if (tp.SourceTexture == null) { return(Vector2Int.zero); } if ((tp.Width > 0 && tp.Width != tp.SourceTexture.width) || (tp.Height > 0 && tp.Height != tp.SourceTexture.height)) { var w = tp.Width > 0 ? tp.Width : tp.SourceTexture.width; var h = tp.Height > 0 ? tp.Height : tp.SourceTexture.height; return(new Vector2Int(w, h)); } return(new Vector2Int(tp.SourceTexture.width, tp.SourceTexture.height)); }
protected void _initialize(string profile) { _player = new GstMultipleNetworkPlayer(); if (profile == "Ovrvision") { var p = new OvrvisionTextureProcessor(); ProcessedTextures = p.GetTextures(); _processor = p; } if (_processor != null && _config != null) { _processor.SetConfigurations(_config.CamerConfigurationsStr); } _IsDone = false; }
public override void Destroy() { if (_processingThread != null) { _IsDone = true; _processingThread.Join(); _processingThread = null; } base.Destroy(); _player = null; Debug.Log("Destroying Network Texture"); if (_processor != null) { _processor.Close(); _processor = null; } }
// public static void Generate(ITextureProcessor tp, Texture2D result) { Color32[] pixels; var size = GetResultSize(tp); if (size.x != tp.SourceTexture.width || size.y != tp.SourceTexture.height) { pixels = (tp.ResizeMethod == TextureProcessor.ResizeMethodType.Point) ? Scale.Point(tp.SourceTexture, size) : Scale.Bilinear(tp.SourceTexture, size); } else { pixels = tp.SourceTexture.GetPixels32(); } // BRIGHTNESS https://www.dfstudios.co.uk/articles/programming/image-programming-algorithms/image-processing-algorithms-part-4-brightness-adjustment/ var brightness = tp.Brightness * 255.0; // CONTRAST https://www.dfstudios.co.uk/articles/programming/image-programming-algorithms/image-processing-algorithms-part-5-contrast-adjustment/ var contrast = tp.Contrast * 255.0; var contrastFactor = (259.0 * (contrast + 255.0)) / (255.0 * (259.0 - contrast)); // GAMMA https://www.dfstudios.co.uk/articles/programming/image-programming-algorithms/image-processing-algorithms-part-6-gamma-correction/ var gammaCorrection = 1.0 / (double)tp.Gamma; // SATURATION https://www.dfstudios.co.uk/articles/programming/image-programming-algorithms/image-processing-algorithms-part-3-greyscale-conversion/ var saturation = (double)tp.Saturation; // COLOR var red = (double)tp.Red; var green = (double)tp.Green; var blue = (double)tp.Blue; double Remap(double value, double oldMin, double oldMax, double newMin, double newMax) { return(((newMax - newMin) * (value - oldMin) / (oldMax - oldMin)) + newMin); } for (int i = 0; i < pixels.Length; ++i) { var pr = (double)pixels[i].r; var pg = (double)pixels[i].g; var pb = (double)pixels[i].b; if (brightness != 0.0) { pr = pr + brightness; pg = pg + brightness; pb = pb + brightness; } if (contrast != 0.0) { pr = contrastFactor * (pr - 128.0) + 128.0; pg = contrastFactor * (pg - 128.0) + 128.0; pb = contrastFactor * (pb - 128.0) + 128.0; } if (gammaCorrection != 1.0) { pr = (255.0 * System.Math.Pow(pr / 255.0, gammaCorrection)); pg = (255.0 * System.Math.Pow(pg / 255.0, gammaCorrection)); pb = (255.0 * System.Math.Pow(pb / 255.0, gammaCorrection)); } var gray = 0.299 * pr + 0.587 * pg + 0.144 * pb; if (saturation != 0.0) { pr = Remap(saturation, -1f, 0f, gray, pr); pg = Remap(saturation, -1f, 0f, gray, pg); pb = Remap(saturation, -1f, 0f, gray, pb); } if (tp.Red != 0.0 || green != 0.0 || blue != 0.0) { pr = Remap(tp.Red, 0f, -1f, Remap(green, 0f, -1f, Remap(blue, 0f, -1f, pr, gray), gray), 1.0); pg = Remap(green, 0f, -1f, Remap(tp.Red, 0f, -1f, Remap(blue, 0f, -1f, pg, gray), gray), 1.0); pb = Remap(blue, 0f, -1f, Remap(tp.Red, 0f, -1f, Remap(green, 0f, -1f, pb, gray), gray), 1.0); } pixels[i] = new Color32((byte)(pr > 255.0 ? 255.0 : pr < 0.0 ? 0.0 : pr), (byte)(pg > 255.0 ? 255.0 : pg < 0.0 ? 0.0 : pg), (byte)(pb > 255.0 ? 255.0 : pb < 0.0 ? 0.0 : pb), pixels[i].a); } result.SetPixels32(pixels, 0); result.Apply(true, false); }