Filter Coding Guidelines

The filter code is written in Javascript. The code should be such that for every pixel (x,y) on the original image, it should return a corresponding pixel in the final image. The general structure of a filter block looks like this

Constants declarations
 
getNewPoint(x,y) :

Filter Code
 
First you declare any constants that you want you use. 'getNewPoint(x,y) :' marks the beginning of the filter code (from the next line). Write the filter code n javascript as a function with parameters x, y and any other constants that you might have declared. It should finally return an Color object (look at the existing filters for more insight)

API

Constants

Two types of constants are allowed.
Integer : Any number within a given range.
      Format:
      var <var-name> = Param(<Display Name without quotes>, <min>, <max>, <default value>);
      
      Ex declaration:
      var c = Param(Coverage, 30, 100, 50);
    
Point : Any point location on the image
      Format:
      var (<var-x>,<var-y>) = Point(<Display Name>, <default x / width>, <default y / height>);
      
      Ex declaration:
      var (cx, cy) = Point(Eye Location, 0.5, 0.5);
    
Apart from this you also have Width and Height predefined as width and height of the image respectively.

Color Object

You can get color object using the function getPoint(x, y) which returns the color of the point (x, y). The object has properties { r, g, b, a } corresponding to red, blue, green and alpha channel correspondingly. All these four values should be in range {0, 255}. Following are the operations available on the color object:
factor(num) Multiplies the red, blue and green channels with a factor of num
factorA(num) Multiplies the red, blue, green and alpha channels with a factor of num
add(num) Adds num the red, blue and green channels
addA(num) Adds num the red, blue, green and alpha channels
addC(point) Adds the red, blue and green channels of point to the corresponding channels
addCA(point) Adds the red, blue, green and alpha channels of point to the corresponding channels
norm() Brings the various channels in the range {0,255}
For more information look at the various available filters