Random.C
This demonstrates setting an input region to be an image that comes from a
different point in time, and then requesting it.
/*
* RandFrame
* Plugin which will return random frames from the sequence
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <memory.h>
#include "cpi.h"
CPIDSOEXPORT void upiCreateParameters( void )
{
cpiAddTab( "Random" );
cpiAddInteger( "Seed", 1, 0, 100, P_ANIMATE );
return;
}
CPIDSOEXPORT int upiResultInput( CPI_ImageContext *result )
{
return RESULT_SEPARATE;
}
CPIDSOEXPORT void upiRegionsNeeded( CPI_ImageContext *result )
{
int seed;
if( cpiGetInteger( "Seed", result->time, &seed ) != 0 )
{
cpiError( "Could not get seed" );
return;
}
srand( seed );
// get range of input frames
long start, end;
if( cpiInputFrameRange( 0, &start, &end ) != 0 )
{
cpiError( "Couldn't get input frame range" );
return;
}
// compute new frame number in that range
long frame = rand()%(end-start) + start;
result->input = 0;
result->time = cpiGetTime( frame );
// tell Chalice which image will be required
cpiNeedRegion( result );
}
CPIDSOEXPORT int upiProcessImage( CPI_Image *result )
{
CPI_Image input;
// get the image we need
if( cpiCookRegion( 0, &input ) != 0 )
return -1;
int pelsize;
if (result->info.pelType == P_INT8)
pelsize = 1;
else if (result->info.pelType == P_INT16)
pelsize = 2;
else if (result->info.pelType == P_FLOAT32)
pelsize = 4;
else
{
cpiError( "Unknown pixel type" );
return -1;
}
int memsize = result->info.sizeX * result->info.sizeY *
result->info.channels * pelsize;
memcpy( result->data, input.data, memsize );
return 0;
}
[ Table of Contents ]
[ Index]
Copyright © 1998 Silicon Grail Inc.
710 Seward Street, Hollywood, CA 90038