/*! \brief The destructor to remove a user loaded module from OpenVX. * \param [in] context The handle to the implementation context. * \return A \ref vx_status_e enumeration. Returns errors if some or all kernels were not added * correctly. * \note This follows the function pointer definition of a \ref vx_unpublish_kernels_f * and uses the predefined name for the entry point, "vxUnpublishKernels". * \ingroup group_example_kernel */ /*VX_API_ENTRY*/ vx_status VX_API_CALL vxUnpublishKernels(vx_context context) { vx_status status = VX_FAILURE; vx_uint32 k = 0; for (k = 0; k < num_kernels; k++) { vx_kernel kernel = vxGetKernelByName(context, kernels[k]->name); vx_kernel kernelcpy = kernel; if (kernel) { status = vxReleaseKernel(&kernelcpy); if (status != VX_SUCCESS) { vxAddLogEntry((vx_reference)context, status, "Failed to release kernel[%u]=%s\n",k, kernels[k]->name); } else { kernelcpy = kernel; status = vxRemoveKernel(kernelcpy); if (status != VX_SUCCESS) { vxAddLogEntry((vx_reference)context, status, "Failed to remove kernel[%u]=%s\n",k, kernels[k]->name); } } } else { vxAddLogEntry((vx_reference)context, status, "Failed to get added kernel %s\n", kernels[k]->name); } } return status; }
vx_node vx_create_specific_sobel(vx_context context, vx_graph graph, vx_bool easy) { vx_node n = 0; if (easy == vx_false_e) { //! [firstmethod] vx_kernel kernel = vxGetKernelByEnum(context, VX_KERNEL_SOBEL_3x3); vx_node node = vxCreateGenericNode(graph, kernel); //! [firstmethod] #if defined(EXPERIMENTAL_USE_TARGET) vx_target target = vxGetTargetByName(context, "gpu"); vxAssignNodeAffinity(node, target); #endif #if defined(EXPERIMENTAL_USE_VARIANTS) //! [variant:firstmethod] vxChooseKernelVariant(node, "faster"); //! [variant:firstmethod] #endif n = node; } else { #if defined(EXPERIMENTAL_USE_VARIANTS) //! [variant:second] #if defined(EXPERIMENTAL_USE_TARGET) vx_kernel kernel = vxGetKernelByName(context, "cpu:org.khronos.openvx.sobel3x3:faster"); #else vx_kernel kernel = vxGetKernelByName(context, "org.khronos.openvx.sobel3x3:faster"); #endif vx_node node = vxCreateGenericNode(graph, kernel); //! [variant:second] #else /*defined(EXPERIMENTAL_USE_VARIANTS)*/ //! [secondmethod] vx_kernel kernel = vxGetKernelByName(context, "org.khronos.openvx.sobel3x3"); vx_node node = vxCreateGenericNode(graph, kernel); //! [secondmethod] #endif n = node; } return n; }
//! [node] vx_node vxXYZNode(vx_graph graph, vx_image input, vx_uint32 value, vx_image output, vx_array temp) { vx_uint32 i; vx_node node = 0; vx_context context = vxGetContext((vx_reference)graph); vx_status status = vxLoadKernels(context, "xyz"); if (status == VX_SUCCESS) { //! [xyz node] vx_kernel kernel = vxGetKernelByName(context, VX_KERNEL_NAME_KHR_XYZ); if (kernel) { node = vxCreateGenericNode(graph, kernel); if (vxGetStatus((vx_reference)node) == VX_SUCCESS) { vx_status statuses[4]; vx_scalar scalar = vxCreateScalar(context, VX_TYPE_INT32, &value); statuses[0] = vxSetParameterByIndex(node, 0, (vx_reference)input); statuses[1] = vxSetParameterByIndex(node, 1, (vx_reference)scalar); statuses[2] = vxSetParameterByIndex(node, 2, (vx_reference)output); statuses[3] = vxSetParameterByIndex(node, 3, (vx_reference)temp); vxReleaseScalar(&scalar); for (i = 0; i < dimof(statuses); i++) { if (statuses[i] != VX_SUCCESS) { status = VX_ERROR_INVALID_PARAMETERS; vxReleaseNode(&node); vxReleaseKernel(&kernel); node = 0; kernel = 0; break; } } } else { vxReleaseKernel(&kernel); } } else { vxUnloadKernels(context, "xyz"); } //! [xyz node] } return node; }
static VALUE Kernel_init(VALUE self, VALUE param) { Check_Type(self, T_DATA); switch (TYPE(param)) { case T_FIXNUM: DATA_PTR(self) = (void *)vxGetKernelByEnum(context, FIX2INT(param)); break; case T_STRING: DATA_PTR(self) = (void *)vxGetKernelByName(context, RSTRING(param)->ptr); break; default: REXT_PRINT("TYPE(param) = %d\n", TYPE(param)); rb_raise(rb_eTypeError, "wrong type"); break; } return Qnil; }
static VALUE Node_init(int argc, VALUE *args, VALUE self) { vx_graph graph = 0; vx_kernel kernel = 0; VALUE w,h,f; Check_Type(self, T_DATA); if (argc <= 1) rb_raise(rb_eArgError, "Not enough arguments"); graph = (vx_graph)DATA_PTR(args[0]); if (argc == 2) // Kernel { Check_Type(args[1], T_DATA); kernel = (vx_kernel)DATA_PTR(args[1]); DATA_PTR(self) = (void *)vxCreateNode(graph, kernel); } else if (argc == 3) // graph, [string|enum], array of hashes { vx_node node = 0; vx_uint32 p = 0; VALUE kern = args[1]; VALUE array = args[2]; long param = 0; if (TYPE(kern) == T_STRING) kernel = vxGetKernelByName(context, RSTRING(kern)->ptr); else if (TYPE(kern) == T_FIXNUM) kernel = vxGetKernelByEnum(context, FIX2INT(kern)); else if (TYPE(kern) == T_DATA) // a OpenVX::Kernel kernel = (vx_kernel)DATA_PTR(kern); else rb_raise(rb_eTypeError, "kernel must be a string, fixnum, or OpenVX::Kernel"); if (kernel == 0) rb_raise(rb_eNameError, "kernel could not be found in OpenVX"); Check_Type(array, T_ARRAY); node = vxCreateNode(graph, kernel); if (node == 0) rb_raise(rb_eTypeError, "node could not be created!"); REXT_PRINT("Array of parameters has len = %ld\n", RARRAY(array)->len); for (param = 0; param < RARRAY(array)->len ; param++) { VALUE dir,ref,hash; vx_reference ref2 = 0; vx_status status = 0; vx_enum type = VX_TYPE_INVALID; const char *name; hash = rb_ary_entry(array, param); Check_Type(hash, T_HASH); dir = rb_hash_aref(hash, ID2SYM(rb_intern("dir"))); ref = rb_hash_aref(hash, ID2SYM(rb_intern("ref"))); name = rb_obj_classname(ref); REXT_PRINT("rb_type(dir)=0x%x\n", TYPE(dir)); REXT_PRINT("ref class = %s\n", name); Check_Type(dir, T_FIXNUM); Check_Type(ref, T_DATA); REXT_PRINT("dir=%ld\n", FIX2UINT(dir)); ref2 = (vx_reference)DATA_PTR(ref); if (strcmp("OpenVX::Image", name) == 0) type = VX_TYPE_IMAGE; else if (strcmp("OpenVX::Buffer", name) == 0) type = VX_TYPE_BUFFER; else if (strcmp("OpenVX::Scalar", name) == 0) type = VX_TYPE_MAX; REXT_PRINT("vx type = %d (0x%08x)\n", type, type); if (type == VX_TYPE_IMAGE) // replace with format status = vxQueryImage(ref2, VX_QUERY_IMAGE_FORMAT, &type, sizeof(vx_fourcc)); else if (type == VX_TYPE_MAX) status = vxQueryReference(ref2, VX_QUERY_REF_TYPE, &type, sizeof(type)); REXT_PRINT("status = %d vx type = %d (0x%08x)\n", status, type, type); status = vxSetParameterByIndex(node, param, FIX2UINT(dir), type, ref2); REXT_PRINT("status = %d\n", status); } DATA_PTR(self) = (void *)node; } else { rb_raise(rb_eArgError, "incorrect number of arguments"); } return Qnil; }
static VALUE Node_init(int argc, VALUE *args, VALUE self) { vx_graph graph = 0; vx_kernel kernel = 0; Check_Type(self, T_DATA); if (argc <= 1) rb_raise(rb_eArgError, "Not enough arguments"); graph = (vx_graph)DATA_PTR(args[0]); if (argc == 2) // Kernel { Check_Type(args[1], T_DATA); kernel = (vx_kernel)DATA_PTR(args[1]); DATA_PTR(self) = (void *)vxCreateGenericNode(graph, kernel); } else if (argc == 3) // graph, [string|enum], array of hashes { vx_node node = 0; VALUE kern = args[1]; VALUE array = args[2]; long param = 0; if (TYPE(kern) == T_STRING) kernel = vxGetKernelByName(context, RSTRING_PTR(kern)); else if (TYPE(kern) == T_FIXNUM) kernel = vxGetKernelByEnum(context, FIX2INT(kern)); else if (TYPE(kern) == T_DATA) // a OpenVX::Kernel kernel = (vx_kernel)DATA_PTR(kern); else rb_raise(rb_eTypeError, "kernel must be a string, fixnum, or OpenVX::Kernel"); if (kernel == 0) rb_raise(rb_eNameError, "kernel could not be found in OpenVX"); Check_Type(array, T_ARRAY); node = vxCreateGenericNode(graph, kernel); if (node == 0) rb_raise(rb_eTypeError, "node could not be created!"); REXT_PRINT("Array of parameters has len = %ld\n", RARRAY_LEN(array)); for (param = 0; param < RARRAY_LEN(array) ; param++) { VALUE ref,hash; vx_reference ref2 = 0; vx_status status = 0; const char *name = NULL; hash = rb_ary_entry(array, param); Check_Type(hash, T_HASH); ref = rb_hash_aref(hash, ID2SYM(rb_intern("ref"))); name = rb_obj_classname(ref); REXT_PRINT("ref class = %s\n", name); Check_Type(ref, T_DATA); ref2 = (vx_reference)DATA_PTR(ref); status = vxSetParameterByIndex(node, param, ref2); REXT_PRINT("status = %d\n", status); } DATA_PTR(self) = (void *)node; } else { rb_raise(rb_eArgError, "incorrect number of arguments"); } return Qnil; }