2 Replies Latest reply on Apr 19, 2011 10:21 AM by bobtiki

    Gamma level calculation formula going awry?

    bobtiki Level 1

      Hello,

       

      I'm teaching myself how to build a Pixel Bender (2.5) plug-in for AE CS5 by porting an FCP FXScript that I wrote recently.

       

      I do some [other stuff] to the image, and it works great, but after the other functions, I want to allow adjustment of the gamma correction of the red channel of the image, and so I have a parameter:

       

          parameter float redGamma

          <

              minValue: 0.01;

              maxValue: 5.0;

              defaultValue: 1.0;

              stepInterval: 0.01;

              displayName: "Red Channel Gamma";

          >;

       

      ...and then I apply the gamma change late in the script, with what I understand is the standard gamma correction formula:

       

          src.r = pow((src.r / 255.0), 1.0/redGamma) * 255.0;

       

      However, the range does not act similarly to the normal AE Levels effect, where it crushes to black around 0.0 gamma, and blows out to full red at around 5.0. In the formula that I have implemented, the levels crush to black around 0.5 gamma and to full red at about 1.66.

       

      Is there a scaling factor or other exponent that AE's built-in Levels effect uses that I am missing, or something else I've gotten wrong?

       

      Thanks!

      MB

        • 1. Re: Gamma level calculation formula going awry?
          AIF Bob Level 3

          I'm not an expert on gamma, or on the way AE applies it, but I am suspicious about your use of the constant 255.0. Once you're running inside a PB filter the color values are floats in the range 0.0 - 1.0. The formula you've quoted seems to be asuming that the color values are 0 - 255 and it's doing an unnecessary, and I suspect incorrect, conversion.

           

          If you take out the / 255.0 and the * 255.0 do the results match what you expect?

          • 2. Re: Gamma level calculation formula going awry?
            bobtiki Level 1

            Aha! Bad assumption on my part — I was assuming 8-bit color values of 0-255. Took that out and it works great now.

             

            Bit of a vestige of porting it from FCP's FXScript, which does use 8-bit values. Thanks for the clarification!