Personal tools

Views

AIF Toolkit:Tutorial

From Adobe Labs

This tutorial assumes that the user has already installed the AIF Toolkit. Additionally, the tutorial assumes a rudimentary knowledge of image processing.

Table of contents

Step One: Become Familiar with the AIF Toolkit

Open the Adobe Image Foundation (AIF) Toolkit.

There are three basic areas to the toolkit:

Image:AIF_Toolkit_Arrangement.jpg

Area 1: The Image view section

This area shows the filter results on the loaded images. If a filter hasn't been loaded, it will display the image file loaded in the "Load Image 1..." file menu.

Area 2: The Hydra Source Editor

This area is where the hydra source code is edited. It provides basic code development capabilities including syntax highlighting and code completion.

Area 3: The Filter parameter UI

If you expose a user specified parameter, the toolkit will automatically create UI to control that parameter. This area is where that UI is drawn.

In addition to these three areas, there is a menu which will let you control some of the settings of the Toolkit.

Step Two: Load a Sample Image

Open up the File menu and click on "Load Image 1." A file dialog will open up. Navigate to a sample image of your choosing. The Toolkit supports the JPEG, PNG, and OpenEXR file formats.

Step Three: Create a New Hydra Program

Click on the File menu and select "New Hydra Filter." The basic structure of a Hydra filter will display in the Hydra Source Editor. By default the new filter will have the code necessary to perform a basic identity on the image, ie. no edits to the image.

Step Four: Edit and Run the Hydra Program

We're going to perform a basic filter operation that reduces all of the channels in the input image by one half. Edit the following line of code in the Hydra Source Editor and click on the Run button at the bottom right of the window:

From:

dst = sampleNearest(src,outCoord());

To:

dst = 0.5 * sampleNearest(src, outCoord());

Running this filter will reduce all of the channels (including the opacity) by one half. This has the effect of darkening the image.

Step Five: Split Up the Image Channels

In this step, we're going to split up the one line of hydra code to apply the math differently to the different channels of the image. We're going to change the code to darken only the color channels and leave the alpha channel - opacity - alone.

Change the following code in the Hydra Editor window:

From:

dst = 0.5 * sampleNearest(src, outCoord());

To:

float4 inputColor = sampleNearest(src, outCoord());
    
dst.rgb = 0.5 * inputColor.rgb;
dst.a = inputColor.a;

The above code saves the input color in a temporary variable of type float4. The float4 will that the red, green, and blue channels in the first three elements and the alpha channel in the last element. These channels are accessible by using the first letter of their name after the dot operator, which is what we're doing in the next two lines.

Step Six: Change the Filter Operation to Exposure

In this step, we're going to change the algorithm from a simple scale to a simple exposure change similar to the Exposure setting in LightRoom. To do this, we're going to use the pow() built-in function (please consult the Hydra documentation for a list of other built-in functions) to do a simple exponential calculation on the color channels.

Change the following code in the Hydra Editor window:

From:

dst.rgb = 0.5 * inputColor.rgb;

To:

dst.rgb = pow(inputColor.rgb, float3(0.5));

There are a couple of things to note here. We are passing in the three channels to the same function. We can do this because the built-in function pow() can support the float, float2, float3, and float4 types. We have to add the float3() constructor around the constant value because the types of the two inputs to pow have to match.

Step Seven: Export the Exposure Value as a Parameter

In this step, we're going to export the exposure value we're using as a user controlled parameter.

Add the following line of code just before the evaluatePixels() function and click run:

parameter float exposure;

and change the following line: From:

dst.rgb = pow(inputColor.rgb, float3(0.5));       

To:

dst.rgb = pow(inputColor.rgb, float3(1.0 - exposure));

In the parameter UI portion of the toolkit, you should now see a slider for the exposure parameter. You can now slide the exposure slider to adjust the image. The 1.0 is used to switch around the exposure so a positive value of the exposure brightens the image.

Step Eight: Limit the parameter

If you've played with the slider enough, you've noticed that the image only lightens because the value is only available from 0 to 1. We're going to add constraints around the parameter, so that the UI results in more intuitive results.

Change the parameter specification to the following:

parameter float exposure
< 
    minValue:float(-0.5);
    maxValue:float(0.5);
    defaultValue:float(0.0);
>;

And click Run. We've made use of the parameter metadata to specify the limits and default values of the parameters. We now have a more intuitive limit around our slider, and we've enabled darkening as well.


Final Source:

<languageVersion : 1.0;>

kernel NewFilter
< namespace : "your namespace";
  vendor : "your vendor";
  version : 1;
  description : "your description";
>
{
    input image4 src;
    output pixel4 dst;

    parameter float exposure
    < minValue:float(-0.5);
      maxValue:float(0.5);
      defaultValue:float(0.0);
    >;

    void
    evaluatePixel()
    {
        float4 inputColor = sampleNearest(src, outCoord());
        dst.rgb = pow(inputColor.rgb, float3(1.0 - exposure));;
        dst.a = inputColor.a;
    }
}
Retrieved from "http://labs.adobe.com/wiki/index.php/AIF_Toolkit:Tutorial"