Exemple #1
0
 public void DoGUI(Rect rect, bool log, HistogramMode mode)
 {
     if (m_RT != null)
     {
         GUI.DrawTexture(rect, m_RT);
     }
 }
Exemple #2
0
        private void ChangeBarStyling(HistogramMode histogramBarMode)
        {
            var brushConverter = new BrushConverter();
            var askBrush       = ((SolidColorBrush)brushConverter.ConvertFrom("#7052CC54"));
            var bidBrush       = ((SolidColorBrush)brushConverter.ConvertFrom("#D0E26565"));

            switch (histogramBarMode)
            {
            case HistogramMode.VolumeLadder:

                AskStroke = new SolidColorBrush(Colors.White)
                {
                    Opacity = 0.8
                };
                AskFill = askBrush;

                BidStroke = new SolidColorBrush(Colors.White)
                {
                    Opacity = 0.8
                };
                BidFill = bidBrush;

                break;

            case HistogramMode.CumulativeVolume:

                AskStroke = new SolidColorBrush(Colors.Crimson)
                {
                    Opacity = 0.8
                };
                AskFill = new SolidColorBrush(Colors.Crimson)
                {
                    Opacity = 0.6
                };

                BidStroke = new SolidColorBrush(Colors.LimeGreen)
                {
                    Opacity = 0.8
                };
                BidFill = new SolidColorBrush(Colors.LimeGreen)
                {
                    Opacity = 0.6
                };

                break;

            case HistogramMode.MarketProfile:

                AskStroke = askBrush;
                AskFill   = askBrush;

                BidStroke = bidBrush;
                BidFill   = bidBrush;

                break;
            }
        }
Exemple #3
0
 public void DoGUI(Rect rect, bool log, HistogramMode mode)
 {
     if (mode == HistogramMode.RGB)
     {
         DoGUIrgb(rect, log);
     }
     else
     {
         DoGUImono(rect, log, mode);
     }
 }
 public static void AllocateHistogramData(int histogramBucketCount, HistogramMode mode, out HistogramData data)
 {
     data                 = new HistogramData();
     data.bucketCount     = histogramBucketCount;
     data.mode            = mode;
     data.histogram       = new ComputeBuffer(histogramBucketCount, sizeof(uint) * 4, ComputeBufferType.Structured);
     data.histogramData   = new ComputeBuffer(1, sizeof(uint) * 2, ComputeBufferType.Structured);
     data.previewMaterial = new Material(Shader.Find("Hidden/HistogramPreview"))
     {
         hideFlags = HideFlags.HideAndDontSave
     };
     _dataCount++;
 }
Exemple #5
0
            public void Update(RenderTexture source, Rect rect, bool log, HistogramMode mode)
            {
                if (m_Material == null)
                {
                    m_Material           = new Material(m_Shader);
                    m_Material.hideFlags = HideFlags.HideAndDontSave;
                }

                if (m_Buffer == null)
                {
                    m_Buffer = new ComputeBuffer(256, sizeof(uint) << 2);
                }

                m_Buffer.SetData(new uint[256 << 2]);

                ComputeShader cs = m_ComputeShader;

                int kernel = cs.FindKernel("KHistogram");

                cs.SetBuffer(kernel, "_Histogram", m_Buffer);
                cs.SetTexture(kernel, "_Source", source);
                cs.SetInt("_IsLinear", (QualitySettings.activeColorSpace == ColorSpace.Linear) ? 1 : 0);
                cs.Dispatch(kernel, source.width >> 4, source.height >> 4, 1);

                kernel = cs.FindKernel(log ? "KScale_Log" : "KScale");
                cs.SetBuffer(kernel, "_Histogram", m_Buffer);
                cs.SetFloat("_Height", rect.height);
                cs.Dispatch(kernel, 1, 1, 1);

                if (m_RT == null || m_RT.height != rect.height || m_RT.width != rect.width)
                {
                    DestroyImmediate(m_RT);
                    m_RT           = new RenderTexture((int)rect.width, (int)rect.height, 0, RenderTextureFormat.ARGB32);
                    m_RT.hideFlags = HideFlags.HideAndDontSave;
                }

                m_Material.SetBuffer("_Histogram", m_Buffer);
                m_Material.SetVector("_Size", new Vector2(m_RT.width, m_RT.height));
                m_Material.SetColor("_ColorR", s_RedCurveColor);
                m_Material.SetColor("_ColorG", s_GreenCurveColor);
                m_Material.SetColor("_ColorB", s_BlueCurveColor);
                m_Material.SetColor("_ColorL", s_MasterCurveColor);
                m_Material.SetInt("_Channel", (int)mode);
                Graphics.Blit(m_RT, m_RT, m_Material, (mode == HistogramMode.RGB) ? 1 : 0);
            }
Exemple #6
0
        void UpdateHistogram(RenderTexture source, Rect rect, HistogramMode mode)
        {
            if (m_HistogramMaterial == null)
            {
                m_HistogramMaterial = ImageEffectHelper.CheckShaderAndCreateMaterial(concreteTarget.histogramShader);
            }

            if (m_HistogramBuffer == null)
            {
                m_HistogramBuffer = new ComputeBuffer(256, sizeof(uint) << 2);
            }

            m_HistogramBuffer.SetData(k_EmptyBuffer);

            ComputeShader cs = concreteTarget.histogramComputeShader;

            int kernel = cs.FindKernel("KHistogramGather");

            cs.SetBuffer(kernel, "_Histogram", m_HistogramBuffer);
            cs.SetTexture(kernel, "_Source", source);
            cs.SetVector("_SourceSize", new Vector2(source.width, source.height));
            cs.SetInt("_IsLinear", concreteTarget.isGammaColorSpace ? 0 : 1);
            cs.Dispatch(kernel, Mathf.CeilToInt(source.width / 32f), Mathf.CeilToInt(source.height / 32f), 1);

            kernel = cs.FindKernel("KHistogramScale");
            cs.SetBuffer(kernel, "_Histogram", m_HistogramBuffer);
            cs.SetFloat("_Height", rect.height);
            cs.Dispatch(kernel, 1, 1, 1);

            if (m_HistogramTexture == null || m_HistogramTexture.height != rect.height || m_HistogramTexture.width != rect.width)
            {
                DestroyImmediate(m_HistogramTexture);
                m_HistogramTexture           = new RenderTexture((int)rect.width, (int)rect.height, 0, RenderTextureFormat.ARGB32);
                m_HistogramTexture.hideFlags = HideFlags.HideAndDontSave;
            }

            m_HistogramMaterial.SetBuffer("_Histogram", m_HistogramBuffer);
            m_HistogramMaterial.SetVector("_Size", new Vector2(m_HistogramTexture.width, m_HistogramTexture.height));
            m_HistogramMaterial.SetColor("_ColorR", redCurveColor);
            m_HistogramMaterial.SetColor("_ColorG", greenCurveColor);
            m_HistogramMaterial.SetColor("_ColorB", blueCurveColor);
            m_HistogramMaterial.SetColor("_ColorL", masterCurveColor);
            m_HistogramMaterial.SetInt("_Channel", (int)mode);
            Graphics.Blit(m_HistogramTexture, m_HistogramTexture, m_HistogramMaterial, (mode == HistogramMode.RGB) ? 1 : 0);
        }
Exemple #7
0
        public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            serializedObject.Update();

            if (Event.current.type == EventType.Repaint)
            {
                // If m_HistogramRect isn't set the preview was just opened so refresh the render to get the histogram data
                if (m_HistogramRect.width == 0 && m_HistogramRect.height == 0)
                {
                    InternalEditorUtility.RepaintAllViews();
                }

                // Sizing
                float width  = Mathf.Min(512f, r.width);
                float height = Mathf.Min(128f, r.height);
                m_HistogramRect = new Rect(
                    Mathf.Floor(r.x + r.width / 2f - width / 2f),
                    Mathf.Floor(r.y + r.height / 2f - height / 2f),
                    width, height
                    );

                if (m_HistogramTexture != null)
                {
                    GUI.DrawTexture(m_HistogramRect, m_HistogramTexture);
                }
            }

            // Toolbar
            GUILayout.BeginHorizontal();
            EditorGUI.BeginChangeCheck();
            {
                concreteTarget.histogramRefreshOnPlay = GUILayout.Toggle(concreteTarget.histogramRefreshOnPlay, new GUIContent("Refresh on Play", "Keep refreshing the histogram in play mode; this may impact performances."), EditorStyles.miniButton);
                GUILayout.FlexibleSpace();
                m_HistogramMode = (HistogramMode)EditorGUILayout.EnumPopup(m_HistogramMode);
            }
            GUILayout.EndHorizontal();

            serializedObject.ApplyModifiedProperties();

            if (EditorGUI.EndChangeCheck())
            {
                InternalEditorUtility.RepaintAllViews();
            }
        }
Exemple #8
0
        public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            serializedObject.Update();

            if (Event.current.type == EventType.Repaint)
            {
                // If m_HistogramRect isn't set the preview was just opened so refresh the render to get the histogram data
                if (m_HistogramRect.width == 0 && m_HistogramRect.height == 0)
                {
                    InternalEditorUtility.RepaintAllViews();
                }

                // Sizing
                float width  = Mathf.Min(512f, r.width);
                float height = Mathf.Min(128f, r.height);
                m_HistogramRect = new Rect(
                    Mathf.Floor(r.x + r.width / 2f - width / 2f),
                    Mathf.Floor(r.y + r.height / 2f - height / 2f),
                    width, height
                    );

                histogram.DoGUI(m_HistogramRect, m_LogHistogram, m_HistogramMode);
            }

            // Toolbar
            GUILayout.BeginHorizontal();
            EditorGUI.BeginChangeCheck();
            {
                concreteTarget.debugClamp = GUILayout.Toggle(concreteTarget.debugClamp, new GUIContent("Clipping", "Turns all overexposed pixels pink in the game view"), EditorStyles.miniButtonLeft);
                m_LogHistogram            = GUILayout.Toggle(m_LogHistogram, new GUIContent("Log", "Logarithmic histogram"), EditorStyles.miniButtonMid);
                m_RefreshHistogramOnPlay  = GUILayout.Toggle(m_RefreshHistogramOnPlay, new GUIContent("Refresh on Play", "Keep refreshing the histogram in play mode; this will impact performances"), EditorStyles.miniButtonRight);
                GUILayout.FlexibleSpace();
                m_HistogramMode = (HistogramMode)EditorGUILayout.EnumPopup(m_HistogramMode);
            }
            GUILayout.EndHorizontal();

            serializedObject.ApplyModifiedProperties();

            if (EditorGUI.EndChangeCheck())
            {
                InternalEditorUtility.RepaintAllViews();
            }
        }
        public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            serializedObject.Update();

            if (Event.current.type == EventType.Repaint)
            {
                // If m_HistogramRect isn't set the preview was just opened so refresh the render to get the histogram data
                if (m_HistogramRect.width == 0 && m_HistogramRect.height == 0)
                    InternalEditorUtility.RepaintAllViews();

                // Sizing
                float width = Mathf.Min(512f, r.width);
                float height = Mathf.Min(128f, r.height);
                m_HistogramRect = new Rect(
                        Mathf.Floor(r.x + r.width / 2f - width / 2f),
                        Mathf.Floor(r.y + r.height / 2f - height / 2f),
                        width, height
                        );

                histogram.DoGUI(m_HistogramRect, m_LogHistogram, m_HistogramMode);
            }

            // Toolbar
            GUILayout.BeginHorizontal();
            EditorGUI.BeginChangeCheck();
            {
                concreteTarget.debugClamp = GUILayout.Toggle(concreteTarget.debugClamp, new GUIContent("Clipping", "Turns all overexposed pixels pink in the game view"), EditorStyles.miniButtonLeft);
                m_LogHistogram = GUILayout.Toggle(m_LogHistogram, new GUIContent("Log", "Logarithmic histogram"), EditorStyles.miniButtonMid);
                m_RefreshHistogramOnPlay = GUILayout.Toggle(m_RefreshHistogramOnPlay, new GUIContent("Refresh on Play", "Keep refreshing the histogram in play mode; this will impact performances"), EditorStyles.miniButtonRight);
                GUILayout.FlexibleSpace();
                m_HistogramMode = (HistogramMode)EditorGUILayout.EnumPopup(m_HistogramMode);
            }
            GUILayout.EndHorizontal();

            serializedObject.ApplyModifiedProperties();

            if (EditorGUI.EndChangeCheck())
                InternalEditorUtility.RepaintAllViews();
        }
            void DoGUImono(Rect rect, bool log, HistogramMode mode)
            {
                // Scale histogram values
                int[] scaledHistogram = new int[256];

                int max = 0;
                for (int i = 0; i < 256; i++)
                    max = (max < m_Histogram[i]) ? m_Histogram[i] : max;

                scaledHistogram = new int[256];

                if (log)
                {
                    float factor = rect.height / Mathf.Log10(max);

                    for (int i = 0; i < 256; i++)
                        scaledHistogram[i] = (m_Histogram[i] == 0) ? 0 : Mathf.Max(Mathf.RoundToInt(Mathf.Log10(m_Histogram[i]) * factor), 1);
                }
                else
                {
                    float factor = rect.height / max;

                    for (int i = 0; i < 256; i++)
                        scaledHistogram[i] = Mathf.Max(Mathf.RoundToInt(m_Histogram[i] * factor), 1);
                }

                // Color
                if (mode == HistogramMode.Red)
                    Handles.color = s_RedCurveColor;
                else if (mode == HistogramMode.Green)
                    Handles.color = s_GreenCurveColor;
                else if (mode == HistogramMode.Blue)
                    Handles.color = s_BlueCurveColor;
                else
                    Handles.color = s_MasterCurveColor;

                // Base line
                Vector2 p1 = new Vector2(rect.x - 1, rect.yMax);
                Vector2 p2 = new Vector2(rect.xMax - 1, rect.yMax);
                Handles.DrawLine(p1, p2);

                // Histogram
                for (int i = 0; i < (int)rect.width; i++)
                {
                    float remapI = (float)i / rect.width * 255f;
                    int index = Mathf.FloorToInt(remapI);
                    float fract = remapI - (float)index;
                    float v1 = scaledHistogram[index];
                    float v2 = scaledHistogram[Mathf.Min(index + 1, 255)];
                    float h = v1 * (1.0f - fract) + v2 * fract;
                    Handles.DrawLine(
                        new Vector2(rect.x + i, rect.yMax),
                        new Vector2(rect.x + i, rect.yMin + (rect.height - h))
                        );
                }
            }
        void UpdateHistogram(RenderTexture source, Rect rect, HistogramMode mode)
        {
            if (m_HistogramMaterial == null)
                m_HistogramMaterial = ImageEffectHelper.CheckShaderAndCreateMaterial(concreteTarget.histogramShader);

            if (m_HistogramBuffer == null)
                m_HistogramBuffer = new ComputeBuffer(256, sizeof(uint) << 2);

            m_HistogramBuffer.SetData(k_EmptyBuffer);

            ComputeShader cs = concreteTarget.histogramComputeShader;

            int kernel = cs.FindKernel("KHistogramGather");
            cs.SetBuffer(kernel, "_Histogram", m_HistogramBuffer);
            cs.SetTexture(kernel, "_Source", source);
            cs.SetVector("_SourceSize", new Vector2(source.width, source.height));
            cs.SetInt("_IsLinear", concreteTarget.isGammaColorSpace ? 0 : 1);
            cs.Dispatch(kernel, Mathf.CeilToInt(source.width / 16f), Mathf.CeilToInt(source.height / 16f), 1);

            kernel = cs.FindKernel("KHistogramScale");
            cs.SetBuffer(kernel, "_Histogram", m_HistogramBuffer);
            cs.SetFloat("_Height", rect.height);
            cs.Dispatch(kernel, 1, 1, 1);

            if (m_HistogramTexture == null || m_HistogramTexture.height != rect.height || m_HistogramTexture.width != rect.width)
            {
                DestroyImmediate(m_HistogramTexture);
                m_HistogramTexture = new RenderTexture((int)rect.width, (int)rect.height, 0, RenderTextureFormat.ARGB32);
                m_HistogramTexture.hideFlags = HideFlags.HideAndDontSave;
            }

            m_HistogramMaterial.SetBuffer("_Histogram", m_HistogramBuffer);
            m_HistogramMaterial.SetVector("_Size", new Vector2(m_HistogramTexture.width, m_HistogramTexture.height));
            m_HistogramMaterial.SetColor("_ColorR", redCurveColor);
            m_HistogramMaterial.SetColor("_ColorG", greenCurveColor);
            m_HistogramMaterial.SetColor("_ColorB", blueCurveColor);
            m_HistogramMaterial.SetColor("_ColorL", masterCurveColor);
            m_HistogramMaterial.SetInt("_Channel", (int)mode);
            Graphics.Blit(m_HistogramTexture, m_HistogramTexture, m_HistogramMaterial, (mode == HistogramMode.RGB) ? 1 : 0);
        }
        public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            serializedObject.Update();

            if (Event.current.type == EventType.Repaint)
            {
                // If m_HistogramRect isn't set the preview was just opened so refresh the render to get the histogram data
                if (m_HistogramRect.width == 0 && m_HistogramRect.height == 0)
                    InternalEditorUtility.RepaintAllViews();

                // Sizing
                float width = Mathf.Min(512f, r.width);
                float height = Mathf.Min(128f, r.height);
                m_HistogramRect = new Rect(
                        Mathf.Floor(r.x + r.width / 2f - width / 2f),
                        Mathf.Floor(r.y + r.height / 2f - height / 2f),
                        width, height
                        );

                if (m_HistogramTexture != null)
                    GUI.DrawTexture(m_HistogramRect, m_HistogramTexture);
            }

            // Toolbar
            GUILayout.BeginHorizontal();
            EditorGUI.BeginChangeCheck();
            {
                concreteTarget.histogramRefreshOnPlay = GUILayout.Toggle(concreteTarget.histogramRefreshOnPlay, new GUIContent("Refresh on Play", "Keep refreshing the histogram in play mode; this may impact performances."), EditorStyles.miniButton);
                GUILayout.FlexibleSpace();
                m_HistogramMode = (HistogramMode)EditorGUILayout.EnumPopup(m_HistogramMode);
            }
            GUILayout.EndHorizontal();

            serializedObject.ApplyModifiedProperties();

            if (EditorGUI.EndChangeCheck())
                InternalEditorUtility.RepaintAllViews();
        }
            public void Update(RenderTexture source, Rect rect, bool log, HistogramMode mode)
            {
                if (m_TempTexture == null || m_TempTexture.height != source.height || m_TempTexture.width != source.width)
                {
                    DestroyImmediate(m_TempTexture);
                    m_TempTexture = new Texture2D(source.width, source.height, TextureFormat.RGB24, false);
                    m_TempTexture.anisoLevel = 0;
                    m_TempTexture.wrapMode = TextureWrapMode.Clamp;
                    m_TempTexture.filterMode = FilterMode.Bilinear;
                    m_TempTexture.hideFlags = HideFlags.HideAndDontSave;
                }

                // Grab the screen content for the camera
                RenderTexture.active = source;
                m_TempTexture.ReadPixels(new Rect(0, 0, source.width, source.height), 0, 0, false);
                m_TempTexture.Apply();
                RenderTexture.active = null;

                // Raw histogram
                Color[] pixels = m_TempTexture.GetPixels();

                switch (mode)
                {
                    case HistogramMode.Luminance:
                        Array.Clear(m_Histogram, 0, 256);
                        for (int i = 0; i < pixels.Length; i++)
                        {
                            Color c = pixels[i];
                            m_Histogram[(int)((c.r * 0.2125f + c.g * 0.7154f + c.b * 0.0721f) * 255)]++;
                        }
                        break;
                    case HistogramMode.RGB:
                        Array.Clear(m_HistogramRGB, 0, 256 * 3);
                        for (int i = 0; i < pixels.Length; i++)
                        {
                            Color c = pixels[i];
                            m_HistogramRGB[(int)(c.r * 255)]++;
                            m_HistogramRGB[(int)(c.g * 255) + 256]++;
                            m_HistogramRGB[(int)(c.b * 255) + 512]++;
                        }
                        break;
                    case HistogramMode.Red:
                        Array.Clear(m_Histogram, 0, 256);
                        for (int i = 0; i < pixels.Length; i++)
                            m_Histogram[(int)(pixels[i].r * 255)]++;
                        break;
                    case HistogramMode.Green:
                        Array.Clear(m_Histogram, 0, 256);
                        for (int i = 0; i < pixels.Length; i++)
                            m_Histogram[(int)(pixels[i].g * 255)]++;
                        break;
                    case HistogramMode.Blue:
                        Array.Clear(m_Histogram, 0, 256);
                        for (int i = 0; i < pixels.Length; i++)
                            m_Histogram[(int)(pixels[i].b * 255)]++;
                        break;
                }
            }
Exemple #14
0
            public void Update(RenderTexture source, Rect rect, bool log, HistogramMode mode)
            {
                if (m_TempTexture == null || m_TempTexture.height != source.height || m_TempTexture.width != source.width)
                {
                    DestroyImmediate(m_TempTexture);
                    m_TempTexture            = new Texture2D(source.width, source.height, TextureFormat.RGB24, false);
                    m_TempTexture.anisoLevel = 0;
                    m_TempTexture.wrapMode   = TextureWrapMode.Clamp;
                    m_TempTexture.filterMode = FilterMode.Bilinear;
                    m_TempTexture.hideFlags  = HideFlags.HideAndDontSave;
                }

                // Grab the screen content for the camera
                RenderTexture.active = source;
                m_TempTexture.ReadPixels(new Rect(0, 0, source.width, source.height), 0, 0, false);
                m_TempTexture.Apply();
                RenderTexture.active = null;

                // Raw histogram
                Color[] pixels = m_TempTexture.GetPixels();

                switch (mode)
                {
                case HistogramMode.Luminance:
                    Array.Clear(m_Histogram, 0, 256);
                    for (int i = 0; i < pixels.Length; i++)
                    {
                        Color c = pixels[i];
                        m_Histogram[(int)((c.r * 0.2125f + c.g * 0.7154f + c.b * 0.0721f) * 255)]++;
                    }
                    break;

                case HistogramMode.RGB:
                    Array.Clear(m_HistogramRGB, 0, 256 * 3);
                    for (int i = 0; i < pixels.Length; i++)
                    {
                        Color c = pixels[i];
                        m_HistogramRGB[(int)(c.r * 255)]++;
                        m_HistogramRGB[(int)(c.g * 255) + 256]++;
                        m_HistogramRGB[(int)(c.b * 255) + 512]++;
                    }
                    break;

                case HistogramMode.Red:
                    Array.Clear(m_Histogram, 0, 256);
                    for (int i = 0; i < pixels.Length; i++)
                    {
                        m_Histogram[(int)(pixels[i].r * 255)]++;
                    }
                    break;

                case HistogramMode.Green:
                    Array.Clear(m_Histogram, 0, 256);
                    for (int i = 0; i < pixels.Length; i++)
                    {
                        m_Histogram[(int)(pixels[i].g * 255)]++;
                    }
                    break;

                case HistogramMode.Blue:
                    Array.Clear(m_Histogram, 0, 256);
                    for (int i = 0; i < pixels.Length; i++)
                    {
                        m_Histogram[(int)(pixels[i].b * 255)]++;
                    }
                    break;
                }
            }
Exemple #15
0
            void DoGUImono(Rect rect, bool log, HistogramMode mode)
            {
                // Scale histogram values
                int[] scaledHistogram = new int[256];

                int max = 0;

                for (int i = 0; i < 256; i++)
                {
                    max = (max < m_Histogram[i]) ? m_Histogram[i] : max;
                }

                scaledHistogram = new int[256];

                if (log)
                {
                    float factor = rect.height / Mathf.Log10(max);

                    for (int i = 0; i < 256; i++)
                    {
                        scaledHistogram[i] = (m_Histogram[i] == 0) ? 0 : Mathf.Max(Mathf.RoundToInt(Mathf.Log10(m_Histogram[i]) * factor), 1);
                    }
                }
                else
                {
                    float factor = rect.height / max;

                    for (int i = 0; i < 256; i++)
                    {
                        scaledHistogram[i] = Mathf.Max(Mathf.RoundToInt(m_Histogram[i] * factor), 1);
                    }
                }

                // Color
                if (mode == HistogramMode.Red)
                {
                    Handles.color = s_RedCurveColor;
                }
                else if (mode == HistogramMode.Green)
                {
                    Handles.color = s_GreenCurveColor;
                }
                else if (mode == HistogramMode.Blue)
                {
                    Handles.color = s_BlueCurveColor;
                }
                else
                {
                    Handles.color = s_MasterCurveColor;
                }

                // Base line
                Vector2 p1 = new Vector2(rect.x - 1, rect.yMax);
                Vector2 p2 = new Vector2(rect.xMax - 1, rect.yMax);

                Handles.DrawLine(p1, p2);

                // Histogram
                for (int i = 0; i < (int)rect.width; i++)
                {
                    float remapI = (float)i / rect.width * 255f;
                    int   index  = Mathf.FloorToInt(remapI);
                    float fract  = remapI - (float)index;
                    float v1     = scaledHistogram[index];
                    float v2     = scaledHistogram[Mathf.Min(index + 1, 255)];
                    float h      = v1 * (1.0f - fract) + v2 * fract;
                    Handles.DrawLine(
                        new Vector2(rect.x + i, rect.yMax),
                        new Vector2(rect.x + i, rect.yMin + (rect.height - h))
                        );
                }
            }
 public void DoGUI(Rect rect, bool log, HistogramMode mode)
 {
     if (mode == HistogramMode.RGB)
         DoGUIrgb(rect, log);
     else
         DoGUImono(rect, log, mode);
 }
        public Style OverrideBarStyle(IRenderableSeries rSeries, double value, BidOrAsk barType, HistogramMode histogramMode)
        {
            Style barStyle = null;

            if (histogramMode == HistogramMode.VolumeLadder)
            {
                if (value >= VolumeThreshold)
                {
                    barStyle = OverriddenBarStyle;
                }
            }

            return(barStyle);
        }
            public void Update(RenderTexture source, Rect rect, bool log, HistogramMode mode)
            {
                if (m_Material == null)
                {
                    m_Material = new Material(m_Shader);
                    m_Material.hideFlags = HideFlags.HideAndDontSave;
                }

                if (m_Buffer == null)
                    m_Buffer = new ComputeBuffer(256, sizeof(uint) << 2);

                m_Buffer.SetData(new uint[256 << 2]);

                ComputeShader cs = m_ComputeShader;

                int kernel = cs.FindKernel("KHistogram");
                cs.SetBuffer(kernel, "_Histogram", m_Buffer);
                cs.SetTexture(kernel, "_Source", source);
                cs.SetInt("_IsLinear", (QualitySettings.activeColorSpace == ColorSpace.Linear) ? 1 : 0);
                cs.Dispatch(kernel, source.width >> 4, source.height >> 4, 1);

                kernel = cs.FindKernel(log ? "KScale_Log" : "KScale");
                cs.SetBuffer(kernel, "_Histogram", m_Buffer);
                cs.SetFloat("_Height", rect.height);
                cs.Dispatch(kernel, 1, 1, 1);

                if (m_RT == null || m_RT.height != rect.height || m_RT.width != rect.width)
                {
                    DestroyImmediate(m_RT);
                    m_RT = new RenderTexture((int)rect.width, (int)rect.height, 0, RenderTextureFormat.ARGB32);
                    m_RT.hideFlags = HideFlags.HideAndDontSave;
                }

                m_Material.SetBuffer("_Histogram", m_Buffer);
                m_Material.SetVector("_Size", new Vector2(m_RT.width, m_RT.height));
                m_Material.SetColor("_ColorR", s_RedCurveColor);
                m_Material.SetColor("_ColorG", s_GreenCurveColor);
                m_Material.SetColor("_ColorB", s_BlueCurveColor);
                m_Material.SetColor("_ColorL", s_MasterCurveColor);
                m_Material.SetInt("_Channel", (int)mode);
                Graphics.Blit(m_RT, m_RT, m_Material, (mode == HistogramMode.RGB) ? 1 : 0);
            }
 public void DoGUI(Rect rect, bool log, HistogramMode mode)
 {
     if (m_RT != null)
         GUI.DrawTexture(rect, m_RT);
 }