//- // ========================================================================== // Copyright (C) 1995 - 2005 Alias Systems Corp. and/or its licensors. All // rights reserved. // // The coded instructions, statements, computer programs, and/or related // material (collectively the "Data") in these files are provided by Alias // Systems Corp. ("Alias") and/or its licensors for the exclusive use of the // Customer (as defined in the Alias Software License Agreement that // accompanies this Alias software). Such Customer has the right to use, // modify, and incorporate the Data into other products and to distribute such // products for use by end-users. // // THE DATA IS PROVIDED "AS IS". ALIAS HEREBY DISCLAIMS ALL WARRANTIES // RELATING TO THE DATA, INCLUDING, WITHOUT LIMITATION, ANY AND ALL EXPRESS OR // IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND/OR FITNESS FOR A // PARTICULAR PURPOSE. IN NO EVENT SHALL ALIAS BE LIABLE FOR ANY DAMAGES // WHATSOEVER, WHETHER DIRECT, INDIRECT, SPECIAL, OR PUNITIVE, WHETHER IN AN // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, OR IN EQUITY, // ARISING OUT OF ACCESS TO, USE OF, OR RELIANCE UPON THE DATA. // ========================================================================== //+ /////////////////////////////////////////////////////// // // DESCRIPTION: Gamma correction utility node // /////////////////////////////////////////////////////// #include #include #include #include #include #include #include #include #include #include #include // // DESCRIPTION: /////////////////////////////////////////////////////// class Gamma:public MPxNode { public: Gamma(); virtual ~Gamma(); virtual MStatus compute( const MPlug&, MDataBlock& ); virtual void postConstructor(); static void * creator(); static MStatus initialize(); // Id tag for use with binary file format static MTypeId id; private: // Input attributes static MObject aColor; // Input color static MObject aGamma; // R, G, B correction // Output attributes static MObject aOutColor; }; // static data MTypeId Gamma::id( 0x81009 ); // Attributes MObject Gamma::aColor; MObject Gamma::aGamma; MObject Gamma::aOutColor; #define MAKE_INPUT(attr) \ CHECK_MSTATUS ( attr.setKeyable(true) ); \ CHECK_MSTATUS ( attr.setStorable(true) ); \ CHECK_MSTATUS ( attr.setReadable(true) ); \ CHECK_MSTATUS ( attr.setWritable(true) ); #define MAKE_OUTPUT(attr) \ CHECK_MSTATUS ( attr.setKeyable(false) ); \ CHECK_MSTATUS ( attr.setStorable(false) ); \ CHECK_MSTATUS ( attr.setReadable(true) ); \ CHECK_MSTATUS ( attr.setWritable(false) ); // // DESCRIPTION: /////////////////////////////////////////////////////// void Gamma::postConstructor( ) { setMPSafe(true); } // // DESCRIPTION: /////////////////////////////////////////////////////// Gamma::Gamma() { } // // DESCRIPTION: /////////////////////////////////////////////////////// Gamma::~Gamma() { } // // DESCRIPTION: /////////////////////////////////////////////////////// void *Gamma::creator() { return new Gamma(); } // // DESCRIPTION: /////////////////////////////////////////////////////// MStatus Gamma::initialize() { MFnNumericAttribute nAttr; // Input attributes aColor = nAttr.createColor( "color", "c" ); MAKE_INPUT(nAttr); aGamma = nAttr.createPoint( "gamma", "g" ); MAKE_INPUT(nAttr); CHECK_MSTATUS ( nAttr.setDefault(1.f, 1.f, 1.f) ); // Output attributes aOutColor= nAttr.createColor( "outColor", "oc" ); MAKE_OUTPUT(nAttr); // Add attributes to the node database. CHECK_MSTATUS ( addAttribute(aColor) ); CHECK_MSTATUS ( addAttribute(aGamma) ); CHECK_MSTATUS ( addAttribute(aOutColor) ); // All input affect the output color CHECK_MSTATUS ( attributeAffects( aColor, aOutColor )); CHECK_MSTATUS ( attributeAffects( aGamma, aOutColor )); return MS::kSuccess; } // // DESCRIPTION: /////////////////////////////////////////////////////// MStatus Gamma::compute(const MPlug &plug, MDataBlock &block) { if ((plug != aOutColor) && (plug.parent() != aOutColor)) return MS::kUnknownParameter; MFloatVector & icol = block.inputValue( aColor ).asFloatVector(); MFloatVector & igam = block.inputValue( aGamma ).asFloatVector(); MDataHandle och = block.outputValue( aOutColor ); MFloatVector & ocol = och.asFloatVector(); ocol[0]= powf(icol[0], 1.f/igam[0]); ocol[1]= powf(icol[1], 1.f/igam[1]); ocol[2]= powf(icol[2], 1.f/igam[2]); och.setClean(); return MS::kSuccess; } // // DESCRIPTION: /////////////////////////////////////////////////////// MStatus initializePlugin( MObject obj ) { const MString UserClassify( "utility/color" ); MFnPlugin plugin( obj, "Alias", "4.5", "Any"); CHECK_MSTATUS ( plugin.registerNode( "gammaNode", Gamma::id, Gamma::creator, Gamma::initialize, MPxNode::kDependNode, &UserClassify ) ); return MS::kSuccess; } // // DESCRIPTION: /////////////////////////////////////////////////////// MStatus uninitializePlugin( MObject obj ) { MFnPlugin plugin( obj ); CHECK_MSTATUS ( plugin.deregisterNode( Gamma::id ) ); return MS::kSuccess; }