newBright.C
This demonstrates a simple plugin that mimics the function of the Chalice
Brightness node.
/*
plugin Tutorial
example 1 - newBright.C
brightness node as plugin
*/
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <memory.h>
#include "cpi.h"
CPIDSOEXPORT void upiCreateParameters( void )
{
// First let's add a "Tab":
cpiAddTab( "Parameters" );
// Now let's add the brightness parameter
cpiAddFloat( "Brightness", 1.0F, 0.0F, 10.0F, P_ANIMATE );
}
template <class TYPE>
void Brightness( TYPE *d, float brightness, float max, int numpix )
{
float val;
// Go through all pixels
while( numpix-- )
{
// Apply the brightness
val = (float)*d * brightness;
// Clip the result to make sure it's within range
if( val > max ) val = max;
if( val < 0 ) val = 0;
// We're done, go to the next pixel
*d = val;
d++;
}
}
CPIDSOEXPORT
int upiProcessImage( CPI_Image *result )
{
// First, we get the brightness parameter
float brightness;
if( cpiGetFloat( "Brightness", result->info.time, &brightness ) != 0 )
{
cpiError( "Could not get brightness parameter" );
return -1;
}
// We calculate how many pixels we have
int numpix = result->info.sizeX*result->info.sizeY*result->info.channels;
// Now we look at what type of image we have and call the right Brightness
switch( result->info.pelType )
{
case P_INT8:
Brightness( (unsigned char *)result->data, brightness,
(float)UCHAR_MAX, numpix );
break;
case P_INT16:
Brightness( (unsigned short *)result->data, brightness,
(float)USHRT_MAX, numpix );
break;
case P_FLOAT32:
Brightness( (float *)result->data, brightness,
1.0F, numpix );
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