00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <UT/UT_DSOVersion.h>
00029 #include <UT/UT_WorkBuffer.h>
00030 #include <CH/CH_Manager.h>
00031 #include <OP/OP_Context.h>
00032 #include <OP/OP_OperatorTable.h>
00033
00034 #include <PRM/PRM_Include.h>
00035 #include <PRM/PRM_Parm.h>
00036
00037 #include <RU/RU_PixelFunctions.h>
00038
00039 #include "COP2_PixelAdd.h"
00040
00041 using namespace HDK_Sample;
00042
00043 COP_PIXEL_OP_SWITCHER(1, "Sample Pixel Add");
00044
00045 static PRM_Name names[] =
00046 {
00047 PRM_Name("addend", "Add Value"),
00048 };
00049
00050
00051 static PRM_Range addRange(PRM_RANGE_UI, -1, PRM_RANGE_UI, 1);
00052 PRM_Template
00053 COP2_PixelAdd::myTemplateList[] =
00054 {
00055 PRM_Template(PRM_SWITCHER, 3, &PRMswitcherName, switcher),
00056
00057 PRM_Template(PRM_RGB_J, TOOL_PARM, 4, &names[0], PRMoneDefaults,0,
00058 &addRange),
00059
00060 PRM_Template(),
00061 };
00062
00063 OP_TemplatePair COP2_PixelAdd::myTemplatePair( COP2_PixelAdd::myTemplateList,
00064 &COP2_PixelOp::myTemplatePair );
00065
00066 OP_VariablePair COP2_PixelAdd::myVariablePair( 0, &COP2_MaskOp::myVariablePair);
00067
00068 const char * COP2_PixelAdd::myInputLabels[] =
00069 {
00070 "Image to Add to",
00071 "Mask Input",
00072 0
00073 };
00074
00075 OP_Node *
00076 COP2_PixelAdd::myConstructor(OP_Network *net,
00077 const char *name,
00078 OP_Operator *op)
00079 {
00080 return new COP2_PixelAdd(net, name, op);
00081 }
00082
00083 COP2_PixelAdd::COP2_PixelAdd(OP_Network *parent,
00084 const char *name,
00085 OP_Operator *entry)
00086 : COP2_PixelOp(parent, name, entry)
00087 {
00088 }
00089
00090 COP2_PixelAdd::~COP2_PixelAdd() { }
00091
00092
00093
00094
00095 namespace HDK_Sample {
00096 class cop2_AddFunc : public RU_PixelFunction
00097 {
00098 public:
00099 cop2_AddFunc(float r,float g, float b, float a)
00100 { myAddend[0] = r; myAddend[1] = g; myAddend[2] = b; myAddend[3] = a; }
00101 protected:
00102
00103
00104 virtual bool eachComponentDifferent() const { return true; }
00105
00106
00107 virtual bool needAllComponents() const { return false; }
00108
00109
00110
00111
00112 static float add(RU_PixelFunction *pf, float val, int comp)
00113 { return val +((cop2_AddFunc*)pf)->myAddend[comp]; }
00114
00115
00116 virtual RUPixelFunc getPixelFunction() const { return add; }
00117
00118
00119
00120
00121
00122
00123
00124
00125 static void addvec(RU_PixelFunction *f, float **vals,
00126 const bool *scope)
00127 {
00128 cop2_AddFunc *pf = (cop2_AddFunc *) f;
00129
00130 if(vals[0] && scope[0]) *vals[0] = *vals[0] + pf->myAddend[0];
00131 if(vals[1] && scope[1]) *vals[1] = *vals[1] + pf->myAddend[1];
00132 if(vals[2] && scope[2]) *vals[2] = *vals[2] + pf->myAddend[2];
00133 if(vals[3] && scope[3]) *vals[3] = *vals[3] + pf->myAddend[3];
00134 }
00135
00136
00137 virtual RUVectorFunc getVectorFunction() const { return addvec; }
00138
00139 private:
00140 float myAddend[4];
00141 };
00142 }
00143
00144
00145
00146
00147
00148
00149 RU_PixelFunction *
00150 COP2_PixelAdd::addPixelFunction(const TIL_Plane*plane,int,float t, int,int,int)
00151 {
00152
00153
00154 int index = mySequence.getImageIndex(t);
00155 float effect = getFrameScopeEffect(index);
00156 float r,g,b,a;
00157
00158
00159 if(plane->isAlphaPlane())
00160 {
00161
00162 r = g = b = a = ADD(3, t) * effect;
00163 }
00164 else
00165 {
00166
00167 r = ADD(0,t) * effect;
00168 g = ADD(1,t) * effect;
00169 b = ADD(2,t) * effect;
00170 a = ADD(3,t) * effect;
00171 }
00172
00173 return new cop2_AddFunc(r,g,b,a);
00174 }
00175
00176 const char *
00177 COP2_PixelAdd::getOperationInfo()
00178 {
00179
00180
00181 float t = CHgetEvalTime();
00182 int index = mySequence.getImageIndex(t);
00183 float effect = getFrameScopeEffect(index);
00184
00185 static UT_WorkBuffer info;
00186
00187 info.sprintf("Add (%g, %g, %g, %g)",
00188 ADD(0,t)*effect, ADD(1,t)*effect,
00189 ADD(2,t)*effect, ADD(3,t)*effect);
00190
00191 return info.buffer();
00192 }
00193
00194 void
00195 newCop2Operator(OP_OperatorTable *table)
00196 {
00197 table->addOperator(new OP_Operator("hdk_samplepixadd",
00198 "HDK Sample Pixel Add",
00199 &COP2_PixelAdd::myConstructor,
00200 &COP2_PixelAdd::myTemplatePair,
00201 1,
00202 2,
00203 &COP2_PixelAdd::myVariablePair));
00204 }
00205