Chapter 15. VL Blending

This chapter explains how to combine video frame information and computer-generated graphics, if your equipment supports such operations.

Use the VL to perform three types of blending:

This chapter explains how the VL performs blending. Topics in this chapter include:

The chapter concludes with example application programs.

The VL Key Generator

Blending in the VL is based on values that the key generator assigns to each pixel in the sources to be blended. The key generator generates a key for each pixel in the two source nodes (foreground and background):

  • If luma keying is set, the key generator assesses the brightness of each pixel.

  • If chroma keying is set, the key generator assesses the color of each pixel.

  • If spatial, or transition, keying (fade, tile, wipe) is set, the key generator assesses the (x,y) coordinates for each pixel.

In addition, the key generator determines the alpha value (opacity) of a pixel and sets a value for it ranging from 0 (completely transparent) to 1 (completely opaque). This alpha value can be used downstream for further layering operations.

Key generation is usually for one alpha source only. The other alpha source can be constant or can come from a matte signal or from graphics on systems that support alpha rendering.

The VL Blend Node

Blending takes place in the VL's internal blend node, which is created with the vlGetNode() function.


Note: Not all connections are possible on all video options.

The code fragment in Example 15-1 sets up source, drain and blend nodes.

Example 15-1. Setting Up Source, Drain, and Blend Nodes

/* variable definitions */
{
 VLServer svr;
 VLPath path;
 VLNode src, drn; 
 VLControlValue val;
 int x, y, c;
 uint w, h, bw{

/* Open a video device */ 
svr = vlOpenVideo(“”)

/* Set up drain nodes on the screen and video */
drn_scr = vlGetNode(vlSvr, VL_DRN, VL_SCREEN, VL_ANY);
drn_vid = vlGetNode(vlSvr, VL_DRN, VL_VIDEO, VL_ANY);

/* Set up source nodes on the screen and video */
src_scr = vlGetNode(vlSvr, VL_SRC, VL_SCREEN, VL_ANY);
src_vid = vlGetNode(vlSvr, VL_SRC, VL_VIDEO, vin);

/* Set up internal blending node */
blend_node = vlGetNode(vlSvr, VL_INTERNAL, VL_BLENDER,
                       VL_ANY);

Figure 15-1 diagrams the blender setup.

Figure 15-1. Setting Up the Blend Node


The blend node mixes the foreground and background video signals by applying a blend function to the foreground and background pixels.

Figure 15-2 diagrams the Galileo Video alpha blender.

Figure 15-2. Galileo Video Alpha Blender


The blend node then sends the data to the drain node. For example, blending analog video with part of a graphics screen and sending it to video out can be diagrammed as shown in Figure 15-3.

Figure 15-3. Blending Analog Video with Part of a Graphics Screen


Blending analog video with static frame data and sending it to video out can be diagrammed as shown in Figure 15-4.

Figure 15-4. Blending Analog Video with Static Frame Data


Adding another drain, such as a screen location at which to preview the output, can be diagrammed as shown in Figure 15-5.

Figure 15-5. Adding Another Drain to Preview the Blend


In Figure 15-5, the source called Screen in and the drain called Screen out are shaded to indicate that although they are separate and distinct nodes, they overlap physically; that is, they are set for the same screen location.

VL Blending Controls

The VL uses blending controls to set blending options.

All blending controls—that is, all the controls discussed in this chapter—apply only to blend nodes, except for VL_EV1_ALPHA_NOT_PIXEL, which applies to drain nodes. The order of blending and zooming depends on the node type: for a source, zooming takes place before blending; for a drain, blending takes place before zooming.

All controls are available for all platforms unless otherwise noted. See the Sirius Video Owner's and Programming Guide for Sirius Video blending controls.


Note: The reference “Galileo Video” includes Indigo2 Video and Indy Video, unless otherwise noted.

Table 15-1 summarizes the VL controls for blending.

Table 15-1. VL Blend Controls

Control

Values

Selects

VL_BLEND_A_FCN
type intVal

VL_BLDFCN_ZERO
VL_BLDFCN_ONE
VL_BLDFCN_B_ALPHA
(background alpha)/255
VL_BLDFCN_MINUS_B_ALPHA:
1 - ((background alpha) / 255)

Blend function that controls mixing of foreground signals

VL_BLEND_B_FCN
type intVal

VL_BLDFCN_ZERO
VL_BLDFCN_ONE
VL_BLDFCN_A_ALPHA
(foreground alpha)/255
VL_BLDFCN_MINUS_A_ALPHA
1 - ((foreground alpha) / 255)

Blend function that controls mixing of background signals

VL_BLEND_A
type intVal

VLNode type, derived from vlGetNode(); must be one of the two source nodes

Input source for foreground image

VL_BLEND_B
type intVal

VLNode type, derived from vlGetNode(); must be one of the two source nodes

Input source for background image

VL_BLEND_A_ALPHA
type intVal

VLNode type, derived from vlGetNode(); must be one of the two source nodes

Input source for foreground alpha; cannot be used on Galileo Video, Indigo

2 Video, or Indy Video

 

VL_BLEND_B_ALPHA
type intVal

VLNode type, derived from vlGetNode(); must be one of the two source nodes

Input source for background alpha

VL_BLEND_A_NORMALIZE
type boolVal

(0,1)
0 = off, 1 = on

Follows Porter-Duff model (background pixels premultiplied by their corresponding alphas before blending)

VL_BLEND_B_NORMALIZE
type boolVal

(0,1)
0 = off, 1 = on

Follows Porter-Duff model

VL_BLEND_OUT_NORMALIZ E
type boolVal

(0,1)
0 = off, 1 = on

Follows Porter-Duff model


VL Keying

For each kind of keying—luma keying, chroma keying, and transitions—further VL controls enable you to specify the properties of the blend.


Note: Keying parameters are implemented as device-dependent VL controls; this section explains Galileo Video (including Indigo2 Video and Indy Video) keying controls.

The values for the Galileo Video “master” keyer control VL_EV1_KEYER_MODE determine the type of keying performed:

  • luma keying: VL_EV1_KEYERMODE_LUMA

  • chroma keying: VL_EV1_KEYERMODE_CHROMA

  • transitions, that is, fades, tiles, or wipes: VL_EV1_KEYERMODE_SPATIAL

For example, the following fragment specifies that chroma keying is to be performed:

vlSetControl(vlSvr, vlPath, blend_node, VL_EV1_KEYER_MODE
             VL_EV1_KEYERMODE_CHROMA); 

Keying controls fall into three groups:

  • luma keying

  • chroma keying

  • fades, tiles, and wipes

Each type is explained separately in this section.

Galileo Video Luma Keying

Luma keying is typically used to overlay a fixed image on video, such as the name and title of an individual being interviewed, a cable channel's logo, or a symbol that denotes an ongoing news story during a newscast. Figure 15-6 diagrams an application.

Figure 15-6. Luma Keying Application: Titling


The four Galileo Video luma keying controls are summarized in Table 15-2; each is of type intVal.

Table 15-2. Galileo Video Luma Keying Controls

Control

Range

Sets

VL_EV1_KEYER_VALUE_LUMA

(0,255)

Central luma value. This control sets the luma value at which the background shows through the foreground.

VL_EV1_KEYER_RANGE_LUM A

(0,255)

One-sided range of the center value. This control determines the range of luma values where the background shows through the foreground.

VL_EV1_KEYER_FG_OPACITY

(0,255)

Opacity of the foreground, thus limiting the value of foreground alpha at any point.

VL_EV1_KEYER_DETAIL

(-8,7)

Sharpness of transition between foreground and background allowing blurring of edges. The value -8 yields the most gradual transition, +7 the sharpest.

Figure 15-7 diagrams the relationships between these controls.

Figure 15-7. Relationships Between Galileo Video Luma Keying Controls


Galileo Video Chroma Keying

Chroma keying overlays one image on another based on the color value. Figure 15-8 diagrams a common application.

Figure 15-8. Chroma Keying Application: TV Weather Map


Table 15-3 summarizes the controls for Galileo Video chroma keying and gives their ranges. These controls are all of type intVal.

Table 15-3. Galileo Video Chroma Keying Controls

Control

Range

Sets

VL_EV1_KEYER_VALUE_CHROMA_U

(-226,226)

Central U value at which the background shows through the foreground.

VL_EV1_KEYER_RANGE_CHROMA_U

(0,452)

One-sided range of U where the background shows through the foreground.

VL_EV1_KEYER_VALUE_CHROMA_V

(-179,179)

Central V value at which the background shows through the foreground.

VL_EV1_KEYER_RANGE_CHROMA_V

(0,358)

One-sided range of V where the background shows through the foreground.

VL_EV1_KEYER_DETAIL

(-8,7)

Sharpness of transition between foreground and background



Note: VL_EV1_KEYER_FG_OPACITY has no effect on Galileo Video in chroma key mode.

Figure 15-9 diagrams the relationships between these controls.

Figure 15-9. Relationships Between Galileo Video Chroma Keying Controls


Galileo Video Fades, Tiles, and Wipes

The values used with the control VL_EV1_WIPE_TYPE determine the type of blending performed:

  • from all-foreground to all-background: VL_EV1_WIPETYPE_FADE

  • from all-foreground to all-background by randomly tiling screen with rectangles of a specified size: VL_EV1_WIPETYPE_TILE

  • wipe to cross the screen as a vertical, diagonal, or horizontal “front,” with a specified angle: VL_EV1_WIPETYPE_SINGLE

  • wipe in two orthogonal directions simultaneously (two single wipes at the same time): VL_EV1_WIPETYPE_DOUBLE

  • wipe in two orthogonal directions, with the perpendicular position locked to the normal, or in-line position: VL_EV1_WIPETYPE_CORNER

For example, the following fragment specifies that a fade is to be performed:

VLControlType val;
val.intVal = VL_EV1_WIPETYPE_FADE;
vlSetControl(vlSvr, vlPath, blend_node, VL_EV1_WIPE_TYPE,
             val); 

Fades, tiles, and wipes go from all-foreground (VL_EV1_WIPE_POSN=0) to all-background (VL_EV1_WIPE_POSN=1000), unless VL_EV1_WIPE_INVERT control is set, in which case they go from all-background (VL_EV1_WIPE_POSN = 0) to all-foreground (VL_EV1_WIPE_POSN = 1000).

Table 15-4 summarizes controls common to all wipe types.

Table 15-4. Controls for Fades, Tiles, and Wipes

Control

Values

Sets

VL_EV1_WIPE_POSN
type fractVal

numerator (0,1000)
denominator (1000)

Amount of progress of wipe, from none (numerator = 0) to full (numerator = 1000).

VL_EV1_WIPE_REPT
type intVal

(0,15)

Number of repetitions of pattern in direction of wipe, usually louvers on single, corner, or double wipe, and length of one side of rectangles for a tile wipe.
Note: This control does not apply to fades.

VL_EV1_WIPE_INVERT
type intVal

(0,1)
0 = off, 1 = on

Reversal of foreground and background regions of a wipe. When set to 0, wipes proceed from foreground (position = minimum) to background (position = maximum). When set to 1, wipes proceed from background (position = minimum) to foreground (position = maximum).

This value is buffered (does not go into effect) until another blending control is set.

Table 15-5 summarizes the controls specific to wipes or that work differently for wipes. Some of these controls work in conjunction with each other.

Table 15-5. Galileo Video Controls Specific to Wipes

Control

Values

Sets

VL_EV1_WIPE_ANGLE
type intVal

VL_EV1_WIPEANGLE_E
VL_EV1_WIPEANGLE_NE
VL_EV1_WIPEANGLE_N
VL_EV1_WIPEANGLE_N W
VL_EV1_WIPEANGLE_W
VL_EV1_WIPEANGLE_SW
VL_EV1_WIPEANGLE_S
VL_EV1_WIPEANGLE_SE

Wipe vector direction, that is, the direction the wipe appears to be proceeding in as its position increases.

Note: VL_EV1_WIPEANGLE_N and VL_EV1_WIPEANGLE_S do not work for the wipe types VL_EV1_WIPETYPE_DOUBLE and VL_EV1_WIPETYPE_CORNER on Galileo Video.

VL_EV1_WIPE_FUZZ
type intVal

(-8,7)

Sharpness of wipe transition band. As for VL_EV1_KEYER_DETAIL, -8 is most gradual, +7 is sharpest.

VL_EV1_WIPE_SYMMETRY
type intVal

(0,1)
0 = off, 1 = on

Wipe symmetry (on or off) so that wipe proceeds in both directions at once from the center line. Effect depends on type of wipe: no effect for fades or tiling; enables VL_EV1_WIPE_CENT for single, double, and corner wipes; enables VL_EV1_WIPE_CENT_PERP control for double and corner wipes.

VL_EV1_WIPE_POSN_PER P
type fractVal

numerator (0,1000)
denominator (1000)

Amount of progress of wipe, from none (numerator = 0) to full (numerator = 1000), along a direction perpendicular to normal wipe position VL_EV1_WIPE_POSN.

VL_EV1_WIPE_CENT
type fractVal

numerator (0,1000)
denominator (1000)

Offset that is center of a symmetrical wipe along wipe position. 0 means center is where VL_EV1_WIPE_POSN is 0, and 1000 means center is where VL_EV1_WIPE_POSN is 1000. For this control to work for single, double, and corner wipes, VL_EV1_WIPE_SYMMETRY must be on.

VL_EV1_WIPE_CENT_PER P
type fractVal

numerator (0,1000)
denominator (1000)

Offset that is center of a symmetrical wipe along a perpendicular wipe position. 0 means center is where VL_WIPE_POSN_PERP is 0, and 1000 means center is where VL_WIPE_POSN_PERP is 1000. VL_WIPE_SYMMETRY must be on for this control to work for double and corner wipes.

VL_EV1_WIPE_REPT_PERP
type intVal

(0,15)

Number of repetitions perpendicular to wipe direction for single, double, and corner wipes, and length of other side of rectangles for tile wipe.

Figure 15-10 shows relationships between the Galileo Video keying controls.

Figure 15-10. Galileo Video Keying Controls


VL Blending Examples

This section explains two example programs from /usr/people/4Dgifts/examples/dmedia/video/vl:

  • simpleblend.c

  • simplewipe.c

Because the programs are lengthy, they are not duplicated here. Look at the source code in a separate window, or print them out to look at while you read their descriptions.


Caution: To simplify the code, these examples do not check returns. The programmer should, however, always check returns.


Blending Video and Graphics

simpleblend.c , which blends video with graphics and outputs it to both a graphics window and video out. The program:

  • constrains the window's aspect ratio

  • checks that the device the user requested is in the device list

  • sets up a path between the source (screen) and the drain (video)

  • adds video source and a screen drain nodes to create the blend

  • sets the keyer mode, keyer source, and blend controls

  • displays the drain window and sets the video to appear in it

  • specifies appropriate event handling

  • starts data transfer

  • specifies that video is updated if the user changes the size of the window

Creating a Simple Wipe Effect

Like simpleblend.c, simplewipe.c blends video with graphics and outputs it to a graphics window and video out. When the user presses the w key, it executes a wipe.

Specifically, in addition to doing everything that simpleblend.c does, simplewipe.c:

  • sets up blend parameters (VL_WIPE_TYPE, VL_WIPE_ANGLE, VL_WIPE_CENT, VL_WIPE_REPT)

  • calls a loop that sets the keyer mode to spatial and sets the position in the loop; doswitchloop() and dowipe() execute the loop

  • checks for the w key and calls dowipe(), which in turn calls doswitchloop()