Tutorial step 2: creating the FilterDefinition record

Every VirtualDub filter holds the information about its definition in a record of type TFilterDefinition:

TFilterDefinition = packed record
    next:            PFilterDefinition;
    prev:            PFilterDefinition;
    module:          PFilterModule;
    name:            PChar;
    desc:            PChar;
    maker:           PChar;
    private_data:    Pointer;
    inst_data_size:  Integer;
    initProc:        FilterInitProc;
    deinitProc:      FilterDeinitProc;
    runProc:         FilterRunProc;
    paramProc:       FilterParamProc;
    configProc:      FilterConfigProc;
    stringProc:      FilterStringProc;
    startProc:       FilterStartProc;
    endProc:         FilterEndProc;
    script_obj:      PCScriptObject;
    fssProc:         FilterScriptStrProc;
  end;

This record tells VirtualDub how to present the filter to the user and how to invoke it. These are the necessary fields:

  • name: The name of the filter, as it shows up in the filter dialogs.
  • desc: A description of the filter that shows in when filters are added. This may be extended up to three lines using \n, but may not exceed 255 characters.
  • maker: A short name for whoever or whatever wrote the filter.
  • inst_data_size: The size, in bytes, of instance data needed for each instance of the filter.
  • *Proc: Pointers to various filter functions. Functions not supported, except for runProc, are specified as NIL.

The next, prev, module, and private_data fields are for VirtualDub's internal use, and should be initialized to NIL.

Creating the FilterDefinition for our filter

We only support one function, and need no instance data, so our record is fairly simple:

Const
  filterDef_tutorial: TFilterDefinition = (
   next:           nil;
   prev:           nil;
   module:         nil;
   name:           'tutorial';
   desc:           'Emphasizes green and de-emphasizes blue in the image.';
   maker:          'anyone';
   private_data:   nil;
   inst_data_size: 0;
   initProc:       nil;
   deinitProc:     nil;
   runProc:        tutorialRunProc;
   paramProc:      nil;
   configProc:     nil;
   stringProc:     nil;
   startProc:      nil;
   endProc:        nil;
   script_obj:     nil;
   fssProc:        nil);

We're done. Later on, we'll fill in other fields as we need them, but for a simple pixel-level filter, this is all we need.