void testVariable(SimdInterpreter &interp) { interp.loadModule ("testCppCall"); FunctionCallPtr func; // test calling a funcs with variable size arguments // this should fail because it is not supported { try { func = interp.newFunctionCall("cppCall::funcWVaryiable1"); assert(false); } catch(Iex::ArgExc e) { } try { func = interp.newFunctionCall("cppCall::funcWVaryiable2"); assert(false); } catch(Iex::ArgExc e) { } } }
void testVaryingLookup () { try { SimdInterpreter interp; interp.loadModule ("testVaryingLookup"); cout << "Testing table lookups with varying data" << endl; testLookup1D (interp); testLookupCubic1D (interp); testLookup3D (interp); testInterpolate1D (interp); testInterpolateCubic1D (interp); cout << "ok\n" << endl; } catch (const std::exception &e) { cerr << "ERROR -- caught exception: " << endl << e.what() << endl; assert (false); } }
void applyCtlExrToExr (Imf::Header inHeader, Imf::Header &outHeader, const Imf::Array2D<Imf::Rgba> &inPixels, Imf::Array2D<Imf::Rgba> &outPixels, int w, int h, const std::vector<std::string> &transformNames, const AttrMap &extraAttrs) { // // Make sure that the input and output headers contain // chromaticities and adoptedNeutral attributes. // if (!hasChromaticities (inHeader)) addChromaticities (inHeader, Chromaticities()); if (!hasAdoptedNeutral (inHeader)) addAdoptedNeutral (inHeader, chromaticities(inHeader).white); if (!hasChromaticities (outHeader)) addChromaticities (outHeader, chromaticities (inHeader)); if (!hasAdoptedNeutral (outHeader)) addAdoptedNeutral (outHeader, adoptedNeutral (inHeader)); // // Add extraAttrs to the input header, possibly overriding // the values of existing input header attributes. // for (AttrMap::const_iterator i = extraAttrs.begin(); i != extraAttrs.end(); ++i) { inHeader.insert (i->first.c_str(), *i->second); } // // Initialize an "environment" header with the same data that // would be available to rendering transforms in an image viewing // program. This allows transforms to bake color rendering into // the output file's pixels. // Header envHeader; initializeEnvHeader (envHeader); // // Set up input and output FrameBuffer objects for the transforms. // FrameBuffer inFb; initializeFrameBuffer (w, h, inPixels, inFb); FrameBuffer outFb; initializeFrameBuffer (w, h, outPixels, outFb); // // Run the CTL transforms // Box2i transformWindow (V2i (0, 0), V2i (w - 1, h - 1)); SimdInterpreter interpreter; #ifdef CTL_MODULE_BASE_PATH // // The configuration script has defined a default // location for CTL modules. Include this location // in the CTL module search path. // vector<string> paths = interpreter.modulePaths(); paths.push_back (CTL_MODULE_BASE_PATH); interpreter.setModulePaths (paths); #endif ImfCtl::applyTransforms (interpreter, transformNames, transformWindow, envHeader, inHeader, inFb, outHeader, outFb); }
void ctlToLut (vector<string> transformNames, Header inHeader, size_t lutSize, const half pixelValues[/*lutSize*/], half lut[/*lutSize*/]) { // // If we do not have an explicit set of transform names // then find suitable look modification, rendering and // display transforms. // if (transformNames.empty()) { if (hasLookModTransform (inHeader)) transformNames.push_back (lookModTransform (inHeader)); if (hasRenderingTransform (inHeader)) transformNames.push_back (renderingTransform (inHeader)); else transformNames.push_back ("transform_RRT"); transformNames.push_back (displayTransformName()); } // // Initialize an input and an environment header: // Make sure that the headers contain information about the primaries // and the white point of the image files an the display, and about // the display's white luminance and surround luminance. // Header envHeader; Header outHeader; if (!hasChromaticities (inHeader)) addChromaticities (inHeader, Chromaticities()); if (!hasAdoptedNeutral (inHeader)) addAdoptedNeutral (inHeader, chromaticities(inHeader).white); initializeEnvHeader (envHeader); // // Set up input and output FrameBuffer objects for the CTL transforms. // assert (lutSize % 4 == 0); FrameBuffer inFb; inFb.insert ("R", Slice (HALF, // type (char *)pixelValues, // base 4 * sizeof (half), // xStride 0)); // yStride inFb.insert ("G", Slice (HALF, // type (char *)(pixelValues + 1), // base 4 * sizeof (half), // xStride 0)); // yStride inFb.insert ("B", Slice (HALF, // type (char *)(pixelValues + 2), // base 4 * sizeof (half), // xStride 0)); // yStride FrameBuffer outFb; outFb.insert ("R_display", Slice (HALF, // type (char *)lut, // base 4 * sizeof (half), // xStride 0)); // yStride outFb.insert ("G_display", Slice (HALF, // type (char *)(lut + 1), // base 4 * sizeof (half), // xStride 0)); // yStride outFb.insert ("B_display", Slice (HALF, // type (char *)(lut + 2), // base 4 * sizeof (half), // xStride 0)); // yStride // // Run the CTL transforms. // SimdInterpreter interpreter; #ifdef CTL_MODULE_BASE_PATH // // The configuration scripts has defined a default // location for CTL modules. Include this location // in the CTL module search path. // vector<string> paths = interpreter.modulePaths(); paths.push_back (CTL_MODULE_BASE_PATH); interpreter.setModulePaths (paths); #endif ImfCtl::applyTransforms (interpreter, transformNames, Box2i (V2i (0, 0), V2i (lutSize / 4 - 1, 0)), envHeader, inHeader, inFb, outHeader, outFb); }
void applyCtl (vector<string> transformNames, Header inHeader, const Array<Rgba> &inPixels, int w, int h, Array<Rgba> &outPixels) { // // If we do not have an explicit set of transform names // then find suitable look modification, rendering and // display transforms. // if (transformNames.empty()) { if (hasLookModTransform (inHeader)) transformNames.push_back (lookModTransform (inHeader)); if (hasRenderingTransform (inHeader)) transformNames.push_back (renderingTransform (inHeader)); else transformNames.push_back ("transform_RRT"); transformNames.push_back (displayTransformName()); } // // Initialize an input and an environment header: // Make sure that the headers contain information about the primaries // and the white point of the image files an the display, and about // the display's white luminance and surround luminance. // if (!hasChromaticities (inHeader)) addChromaticities (inHeader, Chromaticities()); if (!hasAdoptedNeutral (inHeader)) addAdoptedNeutral (inHeader, chromaticities(inHeader).white); Header envHeader; initializeEnvHeader (envHeader); // // Set up input and output FrameBuffer objects for the transforms. // FrameBuffer inFb; initializeInFrameBuffer (w, h, inPixels, inFb); FrameBuffer outFb; initializeOutFrameBuffer (w, h, outPixels, outFb); // // Run the CTL transforms // Box2i transformWindow (V2i (0, 0), V2i (w - 1, h - 1)); SimdInterpreter interpreter; #ifdef CTL_MODULE_BASE_PATH // // The configuration scripts has defined a default // location for CTL modules. Include this location // in the CTL module search path. // vector<string> paths = interpreter.modulePaths(); paths.push_back (CTL_MODULE_BASE_PATH); interpreter.setModulePaths (paths); #endif Header outHeader; ImfCtl::applyTransforms (interpreter, transformNames, transformWindow, envHeader, inHeader, inFb, outHeader, outFb); }
void testSimple(SimdInterpreter &interp) { int numTries = 3; interp.loadModule ("testCppCall"); int numArgs; FunctionCallPtr func; FunctionArgPtr ret; // test return value of a simple function { func = interp.newFunctionCall("cppCall::funcRETi"); numArgs = func->numInputArgs(); assert(numArgs == 0); for(int i = 0; i < numTries; i++) { func->callFunction(1000); ret = func->returnValue(); int retVal = *(int*)(ret->data()); assert(retVal == 5); } } // test passing & return value of a simple function { func = interp.newFunctionCall("cppCall::funcINifbRETf"); numArgs = func->numInputArgs(); assert(numArgs == 3); float f = 1.2345; FunctionArgPtr arg1 = func->inputArg(1); assert(!arg1->isVarying()); ((float*)(arg1->data()))[0] = f; for(int i = 0; i < numTries; i++) { func->callFunction(1000); ret = func->returnValue(); float retVal = *(float*)(ret->data()); assert(retVal == f); } } // test passing w/ default value { func = interp.newFunctionCall("cppCall::funcINifbRETfD"); numArgs = func->numInputArgs(); assert(numArgs == 3); float f = 1.2345; FunctionArgPtr arg2 = func->inputArg(2); assert(!arg2->isVarying()); ((float*)(arg2->data()))[0] = f; for(int i = 0; i < numTries; i++) { func->callFunction(1000); ret = func->returnValue(); float retVal = *(float*)(ret->data()); assert(retVal == f); } } // test default value { func = interp.newFunctionCall("cppCall::funcINifbRETfD"); numArgs = func->numInputArgs(); assert(numArgs == 3); FunctionArgPtr arg2 = func->inputArg(2); assert(!arg2->isVarying()); arg2->setDefaultValue(); for(int i = 0; i < numTries; i++) { func->callFunction(1000); ret = func->returnValue(); float retVal = *(float*)(ret->data()); assert(retVal == 2.0); } } // test default value after setting to something else { func = interp.newFunctionCall("cppCall::funcINifbRETfD"); numArgs = func->numInputArgs(); assert(numArgs == 3); FunctionArgPtr arg2 = func->inputArg(2); ((float*)(arg2->data()))[0] = 1.2345; assert(!arg2->isVarying()); arg2->setDefaultValue(); for(int i = 0; i < numTries; i++) { func->callFunction(1000); ret = func->returnValue(); float retVal = *(float*)(ret->data()); assert(retVal == 2.0); } } // call set default value when none exists { func = interp.newFunctionCall("cppCall::funcINifbRETf"); numArgs = func->numInputArgs(); assert(numArgs == 3); float f = 1.2345; FunctionArgPtr arg1 = func->inputArg(1); assert(!arg1->isVarying()); arg1->setDefaultValue(); ((float*)(arg1->data()))[0] = f; arg1->setDefaultValue(); for(int i = 0; i < numTries; i++) { func->callFunction(1000); ret = func->returnValue(); float retVal = *(float*)(ret->data()); assert(retVal == f); } } // test value varying { func = interp.newFunctionCall("cppCall::funcINifbRETfD2"); numArgs = func->numInputArgs(); assert(numArgs == 3); FunctionArgPtr arg2 = func->inputArg(2); assert(arg2->isVarying()); float * data = (float*)(arg2->data()); int dataSize = 30; assert (interp.maxSamples() >= dataSize); for(int i = 0; i < dataSize; i++) { data[i] = i + .1; } func->callFunction(dataSize); ret = func->returnValue(); data = (float*)(ret->data()); for(int i = 0; i < dataSize; i++) { assert (equalWithRelError (data[i], i + .2f, 0.00001f)); } } }