Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

HSL support

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    HSL support

    Forms supported HSL -- Color had useful conversion methods. There is no support for HSL in WPF.

    One can look up how to do the conversion and then test your work. That takes some time. Since converting back and forth between RGBA and HSLA is a generic functionality, not specific to anyone's indicators, I would suggest that NinjaTrader should provide it.

    Note that this is a product suggestion, not a personal request. I have already implemented and tested it for myself. I just think that it is a common core thing that other users should not have to go through.

    --EV

    #2
    Originally posted by ETFVoyageur View Post
    Forms supported HSL -- Color had useful conversion methods. There is no support for HSL in WPF.

    One can look up how to do the conversion and then test your work. That takes some time. Since converting back and forth between RGBA and HSLA is a generic functionality, not specific to anyone's indicators, I would suggest that NinjaTrader should provide it.

    Note that this is a product suggestion, not a personal request. I have already implemented and tested it for myself. I just think that it is a common core thing that other users should not have to go through.

    --EV
    Maybe not. This .NET thing is extensive. Whew!

    I just realized, from the deep recesses of my memory, that there is already a class for converting to and fro between HSL and RGB color spaces.

    It is in the Microsoft.VisualStudio.Modeling.Diagrams namespace. Bring it into scope and use it.

    ref: https://msdn.microsoft.com/en-us/lib...v=vs.120).aspx
    Last edited by koganam; 08-19-2015, 12:08 PM. Reason: Corrected punctuation.

    Comment


      #3
      Originally posted by koganam View Post
      Maybe not. This .NET thing is extensive. Whew!

      I just realized, from the deep recesses of my memory, that there is already a class for converting to and fro between HSL and RGB color spaces.

      It is in the Microsoft.VisualStudio.Modeling.Diagrams namespace. Bring it into scope and use it.

      ref: https://msdn.microsoft.com/en-us/lib...v=vs.120).aspx
      Thanks for your suggestion. I agree -- .NET is extensive, especially when you consider Forms as well as WPF.

      The HSL class is a Forms item, not a WPF item. It works with System.Drawing.Color. That has a couple of problems.
      • Purity -- I have tried to avoid pulling any Forms code into this WPF application. If I were to do that, I could just continue to use Color for my HSL conversions. In fact, when you Google the Internet, that is what most people's solutions do.
      • Functionality -- the Forms code lacks support for alpha, while the WPF code does support alpha. In particular, the WPF version of Color (System.Media.Color) does include alpha. That means using the HSL class to do Color -> HSL -> Color would not in general give back the original Color (alpha would get lost).

      I Googled pretty thoroughly and, as far as I could find, there is no WPF support for HSL -- an unpleasant surprise to more than one person. I may have missed something, but if so it does not seem to be very common knowledge. Unless someone can turn up some WPF library support for HSL it would sure be nice of NinjaTrader to provide an alpha-preserving HSL conversion capability that works with System.Media.Color.

      FWIW: mine works with Color, SolidColorBrush, and to a limited degree Stroke (with a SolidColorBrush).
      • SolidColorBrush -- because you cannot get Color from other Brush types
      • Cannot go HSL -> Stroke, because that would require non-Color information

      Some sample code to show its ease of use (I am still looking at the best way to darken a color -- the code below is more like dimming the color than darkening it; HSLBrush is my conversion code)
      Code:
      private SolidColorBrush DarkerColor(SolidColorBrush baseBrush, double percent, bool freeze)
              {
                  HSLBrush tmp = baseBrush;
                  tmp.Luminosity = tmp.Luminosity + (1.0 - tmp.Luminosity) * percent;
                  SolidColorBrush retVal = tmp;
                  if (freeze) retVal.Freeze();
                  return retVal;
              }
      --EV
      Last edited by ETFVoyageur; 08-19-2015, 12:57 PM.

      Comment


        #4
        Originally posted by ETFVoyageur View Post
        Thanks for your suggestion. I agree -- .NET is extensive, especially when you consider Forms as well as WPF.

        The HSL class is a Forms item, not a WPF item. It works with System.Drawing.Color. That has a couple of problems.
        • Purity -- I have tried to avoid pulling any Forms code into this WPF application. If I were to do that, I could just continue to use Color for my HSL conversions. In fact, when you Google the Internet, that is what most people's solutions do.
        • Functionality -- the Forms code lacks support for alpha, while the WPF code does support alpha. In particular, the WPF version of Color (System.Media.Color) does include alpha. That means using the HSL class to do Color -> HSL -> Color would not in general give back the original Color (alpha would get lost).

        I Googled pretty thoroughly and, as far as I could find, there is no WPF support for HSL -- an unpleasant surprise to more than one person. I may have missed something, but if so it does not seem to be very common knowledge. Unless someone can turn up some WPF library support for HSL it would sure be nice of NinjaTrader to provide an alpha-preserving HSL conversion capability that works with System.Media.Color.
        Well, again, not quite. the HslColor class is neither WinForms, nor WPF: it is pure C# if you will. It is in the Microsoft.VisualStudio.Modeling.Diagrams namespace, sourced directly in fact in the VS SDK, and contained in the assembly called Microsoft.VisualStudio.Modeling.Sdk.12.0 (in Microsoft.VisualStudio.Modeling.Sdk.12.0.dll)
        FWIW: mine works with Color, SolidColorBrush, and to a limited degree Stroke (with a SolidColorBrush).
        • SolidColorBrush -- because you cannot get Color from other Brush types
        • Cannot go HSL -> Stroke, because that would require non-Color information

        Some sample code to show its ease of use (I am still looking at the best way to darken a color -- the code below is more like dimming the color than darkening it; HSLBrush is my conversion code)
        Code:
        private SolidColorBrush DarkerColor(SolidColorBrush baseBrush, double percent, bool freeze)
                {
                    HSLBrush tmp = baseBrush;
                    tmp.Luminosity = tmp.Luminosity + (1.0 - tmp.Luminosity) * percent;
                    SolidColorBrush retVal = tmp;
                    if (freeze) retVal.Freeze();
                    return retVal;
                }
        --EV
        You have merely adjusted the luminosity. That can easily be done, either in situ, or by writing an overarching method to do it, which is more or less what you have done here. Similarly, it is simple to add alpha to RGB color.

        Comment


          #5
          I referred to it as Forms because of its use of Forms' Color class and its lack of support for alpha.

          I understand that perpetuating alpha is conceptually easy -- it does not get caught up in RGB <--> HSL transformations. However, if you ever use the HSL class in isolation you need the class carrying the alpha information or else you cannot create an RGBA (with the correct alpha) from it.

          The example I gave only adjusts luminosity, but I have others that adjust more than that.

          --EV

          Comment


            #6
            Originally posted by ETFVoyageur View Post
            I referred to it as Forms because of its use of Forms' Color class and its lack of support for alpha.

            I understand that perpetuating alpha is conceptually easy -- it does not get caught up in RGB <--> HSL transformations. However, if you ever use the HSL class in isolation you need the class carrying the alpha information or else you cannot create an RGBA (with the correct alpha) from it.

            The example I gave only adjusts luminosity, but I have others that adjust more than that.

            --EV
            Not sure that I quite understand. The alpha is an invariant in the conversion.

            Comment


              #7
              Originally posted by koganam View Post
              Not sure that I quite understand. The alpha is an invariant in the conversion.
              There is no problem for simple local cases -- the code can just copy the original alpha into the new Color. One more thing to overlook; one more source of bugs. The real problem arises when the HSL object is passed to code that lacks access to the original Color or its alpha -- then that code has no idea what alpha to put into a new Color object.

              As with most things, one could code around the issues. SMOP. But why not have proper conversion facilities to begin with? Code should be able to convert a System.Media.Color to something that provides HSL values and which can also be directly converted back to a complete Color object.

              And don't forget that the HSL object in question works with Forms' Color object, which we do not want to do.

              --EV
              Last edited by ETFVoyageur; 08-19-2015, 04:18 PM.

              Comment


                #8
                Hello ETFVoyageur,

                Thank you for your suggestion.

                I will forward this to our development team.

                Comment


                  #9
                  This feature request is being tracked with the id of SFT-675.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by CortexZenUSA, Today, 12:53 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post CortexZenUSA  
                  Started by CortexZenUSA, Today, 12:46 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post CortexZenUSA  
                  Started by usazencortex, Today, 12:43 AM
                  0 responses
                  5 views
                  0 likes
                  Last Post usazencortex  
                  Started by sidlercom80, 10-28-2023, 08:49 AM
                  168 responses
                  2,265 views
                  0 likes
                  Last Post sidlercom80  
                  Started by Barry Milan, Yesterday, 10:35 PM
                  3 responses
                  11 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Working...
                  X