Table of Contents
| OFX is an open API for writing visual effects plug-ins for a wide variety of applications, such as video editing systems and compositing systems. It seems to have two interchangable names, "OpenFX" and "OFX". I prefer OFX for some reason. This book is actually very broad in scope, as it has to not only define the API, it will need to go into some depth describing concepts behind imaging applications that use it. UNFINISHED Intended AudienceDo you write visual effects or image processing software? Do you have an application which deals with moving images and hosts plug-ins or would like to host plug-ins? Then OFX is for you. This book assumes you can program in the "C" language and are familiar with the concepts involved in writing visual effects software. You need to understand concepts like pixels, clips, pixel aspect ratios and more. If you don't, I suggest you read further or attempt to soldier on bravely and see how far you go before you get lost. What is OFXOFX is actually several things. At the lowest level OFX is a generic 'C' based plug-in architecture that can be used to define any kind of plug-in API. You could use this low level architecture to implement any API, however it was originally designed to host our visual effects image processing API. The basic architecture could be re-used to create other higher level APIs such as a sound effects API, a 3D API and more. This book describes the basic OFX plug-in architecture and the visual effects plug-in API built on top of it. The visual effects API is very broad and intended to allow visual effects plug-ins to work on a wide range of host applications, including compositing hosts, rotoscopers, encoding applications, colour grading hosts, editing hosts and more I haven't thought of yet. While all these type of applications process images, they often have very different work flows and present effects to a user in incompatible ways. OFX is an attempt to deal with all of these in a clear and consistent manner. Chapter 1. OFX OverviewThis chapter provides a brief overview of the basic plug-in architecture and some of the reasoning behind it. It will touch lightly . LanguageThe OFX API is specified using the 'C' programming language. The traditional languages used to implement visual effects applications and plug-ins have been C and C++, so we stuck with that school. By making the API C, rather than C++, you remove the whole set of problems around C++ symbol mangling between the host an application. API DefinitionThe APIs defined by OFX are defined purely by a set of C header files and the associated documentation. There are no binary libraries to link against. Symbolic DependanciesThe host relies on two symbols within a plug-in, all other communication is boot strapped from those two symbols. The plug-in has no symbolic dependancies from the host. This minimal symbolic dependancy allows for run-time determination of what features to provide over the API, making implementation much more flexible and less prone to backwards compatibility problems. Host to Plugin CommunicationA host communicates with a plug-in via a Host to Plugin CommunicationA host communicates with a plug-in via a Chapter 2. Introduction To OFX, A Simple Plug-inThis chapter will describe in detail a fully functioning, but simple OFX image effect plug-in that inverts 8 bit RGBA images. It gives a flavour for how the API operates and some of the components in it. The source will be broken down into sections and each one explained as we go along. The code is actually C++, but it uses the raw OFX API. The code is not meant to be perfectly optimised example of how to write an image processing effect, but rather as an illustrative example of the API. Headers#include This section of code shows the headers used by the invert plug-in. It includes three OFX header files (you can tell because they start with "ofx") which are...
The system include file The Plug-in Struct and The Two Exported Functions// forward declaration of two functions needed by the plug-in struct The first thing to note in this section are the two functions
In order the members of
The Host Struct// pointer to the host structure passed to us by the host application This section has the structure that holds information about the host application and allows us to fetch suites from the host. The The Main Entry Function// forward declarations static OfxStatus render(OfxImageEffectHandle instance, OfxPropertySetHandle inArgs, OfxPropertySetHandle outArgs); static OfxStatus describe(OfxImageEffectHandle effect); static OfxStatus onLoad(void); static OfxStatus describeInContext( OfxImageEffectHandle effect, OfxPropertySetHandle inArgs) The The function also takes a "handle" argument. This handle is the thing the action must be performed on. In this case, as we are an image effect, the handle must be cast to an OfxImageEffectHandle, which is simply a blind pointer to some host data representing an image effect. The last two parameters Our main entry only traps four of the many possible actions. The actual actions will be described below. The Load ActionOfxImageEffectSuiteV1 *gEffectSuite = 0; OfxPropertySuiteV1 *gPropertySuite = 0; //////////////////////////////////////////////////////////////////////////////// // Called at load static OfxStatus onLoad(void) { The load action is always the first action called after the initial boot-strap phase has happened. By this time the plug-in's What this action does is first to check that the host application has in fact set the We are only fetching two suites from the host, the OfxImageEffectSuiteV1 to give us access to images and more, and the OfxPropertySuiteV1 which allows us to access values in property sets. The Describe Action// the plug-in's description routine The purpose of the describe action is to tell the host the overall behaviour of the plug-in. The OfxImageEffectHandle passed to the describe action is a descriptor as opposed to an instance. A descriptor is a handle that is used to tell the host how a plug-in should look, whilst an instance is an actual running copy of a plug-in. Descriptors are passed to only two actions, the describe action, and the describe in context action. Most other actions that are passed an instance handle. The first thing this function does is to fetch the handle holding the properties used to describe the plug-in. Note how it uses the The next thing the plug-in does is set the integer property Note how the property setting functions take four arguments. The first is the set of properties to be modified, the second is the name (again a string) of the property in that set they wish to change, the third is the index of the property (as properties can be multi-dimensional) and the last is the value they wish to set. The plug-in goes on to set properties that describe it as supporting only images of 8 bits per component, the user visible name of the effect, the grouping the effect should be placed in on any user interface and finally the context it can be used under. An image effect context describes the semantics of how a plug-in should be used. In this case we are saying the plug-in is a filter, which means it has to have one input clip called "Source" and one output clip called "Output". Other contexts include transitions, where an image effect has two inputs and a single output and is require to go from one to the other, a general context for tree based compositing systems and several more. A plug-in can say that it works in more than one context, which brings us on to the next function. The Describe In Context Action// describe the plug-in in context static OfxStatus describeInContext( OfxImageEffectHandle effect, OfxPropertySetHandle inArgs) { OfxPropertySetHandle props; // define the single output clip in both contexts gEffectSuite->clipDefine(effect, "Output", &props); The describe in context action is called once for each context that a plug-in says it can work in. Here the plug-in must define the clips it will use and any parameters it may need for that context. The set of clips and parameters need not be the same for each context, though typically a core of parameters and some clips will be the same. Note that, as with the describe action, the describe in context action is passed a descriptor rather than an instance. The first thing our function does is to define the clip called "Output" which is mandatory for the filter context. This function returns a property set which is used to describe how the effect wants to deal with that clip. In this case the effect says that it will only accept RGBA images on the output. Next it does the same for the mandated "Source" clip. Having defined the two clips needed for this context it returns. The Render Action// look up a pixel in the image, does bounds checking to see if it is in the image rectangle The render action is where a plug-in turns its input images into output images. The first thing to note is that the effect is no longer a descriptor by an. For our simple example, this makes not much difference, however if the plug-in is maintaining private data, it is very important. The first thing the render function does is to extract two properties from the Next the function fetches the output clip. A clip is a handle that is accessible by name and represents a sequences of images. The returned handle is valid for the lifetime of the instance, and so does not need releasing or deleting. Next an image is extracted from the clip. An image, unlike a clip, does need to be released when the plug-in is done with it. Images are encapsulated as a property set, and so the ordinary property mechanism is used to fetch out information from the image. In this case three properties are needed, the The source image is fetched in a similar way as the destination image. Next the void * data pointers are cast to OfxRGBAColourB pointers, and we start iterating over the render window filling in output pixels. The render window must always be equal to or less than the bounds on the destination image. The inline function Note the Finally, once we are done, the images are released and we return. In SummaryOur small working example shows the core mechanisms behind the OFX Image Effect API, but leaves out much of the messy detail. The important things to note are the use of suites to call functions on the host, the use of properties to get and set values in objects and the use of actions to call things on the plug-in. There are many more suites which have not been used, as well as actions that have not been trapped, as well as gory bits to do with pixel aspect ratios, interlacing and more. These extra suites and actions add a rich functionality to OFX that give it a great flexibility as well as dealing with the evil little details such as video standards. Chapter 3. The Generic OFX Plug-in ArchitectureOverviewAs explained in the introduction, OFX is actually several things,
This chapter concentrates on defining the underlying architecture, including how plug-ins should be identified, defined, versioned, installed and the initial bootstrapping of communication occurs. The two OFX include files relevant for this section are
OFX APIs are all implemented via prototyped "C" header files. There are no OFX specific libraries to link against as the APIs consists solely of sets of header files and their supporting documentation. The API is also designed to minimise symbolic dependencies between the host and the plug-in. Certain concepts are at the core of the OFX plug-in architecture, these are APIs, actions, suites, properties and handles. No matter what kind of API is being built on top of the core architecture, it will use these objects.
Plug-in Binaries and Required SymbolsOFX plug-ins are distributed as dynamically loadable shared libraries, the exact format is dependant upon the host operating system and is defined below. Each such binary can contain one or more OFX plug-ins .The whole set of OFX APIs bootstrap from two symbols inside a plug-in, these are OfxGetNumberOfPluginsint OfxGetNumberOfPlugins(void)This function returns the number of plug-ins inside the given binary. This will be the first function called by a host after initially loading the binary. OfxGetPluginOfxPlugin * OfxGetPlugin(int nth)This function returns an OfxPlugin struct which defines the nth plug-in to the host. The data structure returned should point to a static chunk of memory in the plug-in, as the host will make no attempt to free the returned data structure when the plug-in is unloaded. Typically this will be the called multiple times by the host, once for each plug-in that the plug-in says it contains. Identifying, Versioning and Defining an OFX Plug-inA plug-in's description is bootstrapped by using the required The OfxPlugin StructThis structure is returned by a plugin to identify itself to the host. typedef struct OfxPlugin { const char *pluginApi; int apiVersion; const char *pluginIdentifier; unsigned int pluginVersionMajor; unsigned int pluginVersionMinor; void (*setHost)(OfxHost *host); OfxPluginEntryPoint *mainEntry; } OfxPlugin;
Interpreting the OfxPlugin StructWhen a host gets a pointer back from OfxGetPlugin, it examines the string Knowing the type of plug-in, the host then knows what suites and host handles are required for that plug-in and what functions the plug-in itself will have. The host passes a OfxHost structure appropriate to that plug-in via it's OFX explicitly versions plug-in APIs. By examining the If a host does not support the given plug-in type, or it does not support the given version it should simply ignore that plug-in. A plug-in needs to uniquely identify itself to a host. This is the job of A plug-in (as opposed to the API it implements) is versioned with two separate integers in the OfxPlugin struct. They serve two separate functions and are,
If a host encounters multiple versions of the same plug-in it should,
A more concrete example of versioning, the plug-in identified by "org.wibble:Fred" is initially released as 1.0, however a few months later, wibble.org figured out how to make it faster and release it as 1.1. A year later, Fred can now do automatically what a user once needed to set five parameters up to do, thus making it much simpler to use. However this breaks backwards compatibility as the effect can no longer produce the same output as before, so wibble.org then release this as v2.0. A user's host might now have three versions of the Fred plug-in on it, v1.0, v1.1 and v2.0. When creating a new instance of the plug-in, the host should always use v2.0. When loading an old project which has a setup from a v1.x plug-in, it should always use the latest, in this case being v1.1 Note that plug-ins can change the set of parameters between minor version releases. If a plug-in does so, it should do so in a backwards compatible manner, such that the default value of any new parameter would yield the same results as previously. See the chapter below about parameters. Suites, Hosts and APIsFunction SuitesA function suite is simply a struct filled with function pointers. Below is some code from the memory allocation suite found in #define kOfxMemorySuite "OfxMemorySuite" typedef struct OfxMemorySuiteV1 { OfxStatus (*memoryAlloc)(void *handle, size_t nBytes, void **allocatedData); OfxStatus (*memoryFree)(void *allocatedData); } OfxMemorySuiteV1; The use is fairly obvious, you call functions through the pointers in the struct. This has the effect of avoiding any symbolic dependencies from the plug-in to the host. Note two other things about this code listing.
The explicit naming and versioning of suites is how a plug-in fetches one, by calling the The OfxHost StructThe OfxHost struct is how a host provides plug-ins with access to the various suites that make up the API they implement, as well as a host property set handle which a plug-in can ask questions of. The typedef struct OfxHost { OfxPropertySetHandle host; void *(*fetchSuite)(OfxPropertySetHandle host, const char *suiteName, int suiteVersion); } OfxHost; The OfxHost contains two elements,
The The Sequences of Operations Required to Load a Plug-inThe following sequences of operations needs to be performed by a host before it can start telling a plug-in what to do via its
Errors, Status Codes and ExceptionsOFX has a standard set of unsigned integer status codes used to indicate errors and general status. These are returned by most functions in the host suites and by the plug ins' entry points. The error codes returned by functions and actions are documented along side them. It is an error to throw a C++ exception across the API, all exceptions should be trapped on either side of the API and an appropriate error code passed instead. Packaging OFX Plug-insWhere a host application chooses to search for OFX plug ins, what binary format they are in and any directory hierarchy is entirely up to it. However, it is strongly recommended that the following scheme be followed. Binary TypesPlug-ins should be distributed in the following formats, depending on the host operating system....
Installation Directory HierarchyEach plug-in binary is distributed as a Mac OS X package style directory hierarchy. Note that the there are two distinct meanings of 'bundle', one referring to a binary file format, the other to a directory hierarchy used to distribute software. We are distributing binaries in a bundle package, and in the case of OSX, the binary is a binary bundle. All the binaries must end with The directory hierarchy is as follows.....
Where...
Note that not all the above architectures need be supported, only at least one. This structure is necessary on OS X, but it also gives a nice skeleton to hang all other operating systems from in a single install, as well as a clean place to put resources. The
Installation LocationPlug ins are searched for in a variety of locations, both default and user specified. All such directories are examined for plug-in bundles and sub directories are also recursively examined. A list of directories is supplied in the "OFX_PLUGIN_PATH" environment variable, these are examined, first to last, for plug ins, then the default location is examined. On Microsoft Windows machines, the plug ins are searched for in,
On Apple OSX machines, the plug ins are searched for in,
On UNIX, Linux and other UNIX like operating systems,
Any bundle or sub-directory name starting with the character '@' is to be ignored. Such directories or bundles must be skipped. Different versions of the same plug-in may be encountered in multiple locations, in which case, only the greatest minor version of each major version should be taken note of. For example: 3.2, 1.4 and 2.3 would be noted, but not 3.1, 1.3 or 2.0. If two copies of a plug-in with the same major and minor version are encountered, it can be assumed they are duplicates and all but the first one ignored. plug-in IconsSome hosts may wish to display an icon associated with a plug-in on their interfaces. Any such icon must be in the Portable Network Graphics format (see http://www.libpng.org/) and must contain 32 bits of colour, including an alpha channel. Ideally it should be at least 128x128 pixels. Host applications should dynamically resize the icon to fit their preferred icon size. The icon should not have it's aspect changed, rather the host should fill with some appropriate colour any blank areas due to aspect mis matches. Ideally plug-in developers should not render the plug-in's name into the icon, as this may be changed by the resource file, especially for internationalisation purposes. Hosts should thus present the plug-in's name next to the icon in some way. The icon file must be named as the corresponding Externally Specified ResourcesSome plug-ins may supply an externally specified resource file. Typically this is for tasks such as internationalising interfaces, tweaking user interfaces for specific hosts and so on. These are XML files and have DTD associated with the specific API, for example OFX Image Effect DTD is found in The xml resource file is installed in the Chapter 4. Visual Effects ArchitecturesAll applications that perform visual effects have certain basic similarities, unfortunately they also have many differences, and OFX needs to cope with them all. This chapter gives an overview of architectures and the concepts behind them. Feel free to skip it if you have experience of programming for a range of visual effects applications. The concepts are expressed in OFX terminology and may be somewhat different to how other systems express them ClipsA clip simply a sequences of still images, played back at some frame rate to give the illusion of motion. Thank you Lumiere brothers. All applications that process moving images use clips in one form or another. A clip is typically a single set of images that are logically associated, for example they consist of a single shot from a motion picture. bit depth components PARImagesAn image is a 2D array of pixels. A set of input images are processed by an effect to produce an output image. bit depth components pixel aspect ratio bounds data ParametersTimeEffectsContextsCo-ordinate SystemsRegions of Definition and Regions of InterestChapter 5. OFX Image Effect Plug-insAn OFX image effect plug-in is one that uses the OFX Image Effect API to implement a visual effect. To do that it needs Chapter 6. Parameters |