// Add.C // Copyright (c) 2009 The Foundry Visionmongers Ltd. All Rights Reserved. static const char* const HELP = "Adds a constant to a set of channels"; #include "DDImage/PixelIop.h" \导入像素处理器头文件,该头文件用于对像素进行操作 #include "DDImage/Row.h" #include "DDImage/Knobs.h" using namespace DD::Image; class Add : public PixelIop { float value[4]; \定义一个包含四个浮点类型变量的列表 public: \定义公有函数 void in_channels(int input, ChannelSet& mask) const; \定义一个无返回值无类型的in_channels成员函数,该成员函数类型是const Add(Node* node) : PixelIop(node) \该Add类继承PixelIop类 { value[0] = value[1] = value[2] = value[3] = 0; \初始化value列表 } bool pass_transform() const { return true; } \定义公有成员函数 void pixel_engine(const Row &in, int y, int x, int r, ChannelMask, Row & out); \调用公有函数,该成员函数来自PixelIop类 virtual void knobs(Knob_Callback); \定义成员函数,该成员函数继承自PixelIop类 static const Iop::Description d; \定义一个静态函数d,该函数用于描述Add类的属性 const char* Class() const { return d.name; } \ const char* node_help() const { return HELP; } void _validate(bool); }; void Add::_validate(bool for_real) { copy_info(); for (unsigned i = 0; i < 4; i++) { if (value[i]) { set_out_channels(Mask_All); info_.black_outside(false); return; } } set_out_channels(Mask_None); } void Add::in_channels(int input, ChannelSet& mask) const { // mask is unchanged } void Add::pixel_engine(const Row& in, int y, int x, int r, ChannelMask channels, Row& out) { foreach (z, channels) { const float c = value[colourIndex(z)]; const float* inptr = in[z] + x; const float* END = inptr + (r - x); float* outptr = out.writable(z) + x; while (inptr < END) *outptr++ = *inptr++ + c; } } void Add::knobs(Knob_Callback f) \定义一个无返回值的函数来添加colorknob { AColor_knob(f, value, IRange(0, 4), "value"); \添加一个颜色knob } #include "DDImage/NukeWrapper.h" static Iop* build(Node* node) { return new NukeWrapper(new Add(node)); } \把Add类打包成节点 const Iop::Description Add::d("Add", "Color/Math/Add", build); \添加相关属性