DiffMatte.C

This demonstrates multiple inputs to a node. In this case, the only acceptable number of inputs is 2; however, you can choose to have a node with from 1 to N inputs (such as Mcomp) by setting the min and max values in upiNumberofInputs().

/*
 *  Subtract one image from another, and return the absolute value
 *  of the difference. One input should be the shot, and the second
 *  should be the same shot with no foreground action. The idea is
 *  to try and make a matte for the foreground action.
 */

#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <memory.h>
#include <math.h>
#include "cpi.h"

CPIDSOEXPORT void upiNumberOfInputs( int *min, int *max )
{
    *min = 2;
    *max = 2;
}

CPI_PluginType upiPluginType( void )
{
    return T_MATTE;
}

template <class T>
void diffmatt(T *fg, T *bg, int pixels)
{
    float        diff;

    while (pixels--)
    {
        diff = (float)(*fg) - (float)(*bg);
        *fg = (T) (fabs(diff));
        fg++;
        bg++;
    }
}

CPIDSOEXPORT int upiProcessImage( CPI_Image *result )
{
    CPI_Image     input;
    float        boost;
    int            pixels;

    // result has a copy of input 0 (by default)
    // get the other image by cooking region 0 (not 1)
    // see documentation for why
    if( cpiCookRegion( 0, &input ) != 0 )
        return -1;

    cpiGetFloat("Boost", result->info.time, &boost);

    pixels = result->info.sizeX * result->info.sizeY * 
               result->info.channels;

    switch( result->info.pelType )
    {
        case P_INT8:
            diffmatt((unsigned char *)result->data, 
                     (unsigned char *)input.data, pixels);
            break;
        case P_INT16:
            diffmatt((unsigned short *)result->data, 
                     (unsigned short *)input.data, pixels);
            break;
        case P_FLOAT32:
            diffmatt((float *)result->data, 
                     (float *)input.data, pixels);
            break;
        default:
            cpiError( "Unknown pixel type" );
            return 1;
    }

    return 0;
}
[ Table of Contents ] [ Index]

Copyright © 1998 Silicon Grail Inc.
710 Seward Street, Hollywood, CA 90038