Пример #1
0
void rubyext_objects(VALUE parent, rext_object_t *objects, long numObjects)
{
    long obj, m;
    for (obj = 0; obj < numObjects; obj++)
    {
        if (parent == Qnil) {
            objects[obj].typeVal = rb_define_class(objects[obj].name,
                                                   *objects[obj].base);
            REXT_PRINT("Object %s=%ld\n", objects[obj].name, objects[obj].typeVal);
        } else {
            objects[obj].typeVal = rb_define_class_under(parent,
                                                     objects[obj].name,
                                                     *objects[obj].base);
            REXT_PRINT("Object %s=%ld (under %ld)\n", objects[obj].name, objects[obj].typeVal, parent);
        }
        if (objects[obj].typeVal == 0)
            continue;

        rb_define_alloc_func(objects[obj].typeVal, objects[obj].allocate);

        rubyext_constants(objects[obj].typeVal,
                          objects[obj].constants,
                          objects[obj].numConstants);

        rubyext_methods(objects[obj].typeVal,
                        REXT_METHOD_NORMAL,
                        objects[obj].methods,
                        objects[obj].numMethods);
     }
}
Пример #2
0
static VALUE Image_init(int argc, VALUE *args, VALUE self)
{
    vx_uint32 width = 0, height = 0;
    vx_fourcc format = FOURCC_VIRT;
    VALUE w,h,f;

    Check_Type(self, T_DATA);

    if (argc == 0) // Virtual Image
    {
        REXT_PRINT("Virtal Image\n");
        DATA_PTR(self) = (void *)vxCreateVirtualImage(context);
    }
    else if (argc == 1)
    {
        VALUE hash = args[0];
        Check_Type(hash, T_HASH);

        REXT_PRINT("Image from Hash\n");
        w = rb_hash_aref(hash, ID2SYM(rb_intern("width")));
        h = rb_hash_aref(hash, ID2SYM(rb_intern("height")));
        f = rb_hash_aref(hash, ID2SYM(rb_intern("format")));
        Check_Type(w, T_FIXNUM);
        Check_Type(h, T_FIXNUM);
        Check_Type(f, T_FIXNUM);
        width = FIX2UINT(w);
        height = FIX2UINT(h);
        format = FIX2UINT(f);
        DATA_PTR(self) = (void *)vxCreateImage(context, width, height, format);
    }
    else if (argc == 3)
    {
        REXT_PRINT("Image from Parameters\n");
        w = args[0];
        h = args[1];
        f = args[2];
        Check_Type(w, T_FIXNUM);
        Check_Type(h, T_FIXNUM);
        Check_Type(f, T_FIXNUM);
        width = FIX2UINT(w);
        height = FIX2UINT(h);
        format = FIX2UINT(f);
        DATA_PTR(self) = (void *)vxCreateImage(context, width, height, format);
    }
    else
        rb_raise(rb_eArgError, "incorrect number of arguments");
    return Qnil;
}
Пример #3
0
static VALUE OpenVX_targets_list(VALUE self)
{
    vx_uint32 t,value = 0;
    vx_status status = VX_FAILURE;
    vx_char targetname[VX_MAX_TARGET_NAME];
    vx_target target = 0;
    VALUE array;
    status = vxQueryContext(context, VX_QUERY_CONTEXT_NUMTARGETS, &value, sizeof(value));
    REXT_PRINT("status = %d, targets = %d\n", status, value);
    if (status == VX_SUCCESS)
    {
        array = rb_ary_new2(value);
        for (t = 0; t < value; t++)
        {
            target = vxGetTargetByIndex(context, t);
            if (target)
            {
                status = vxQueryTarget(target, VX_QUERY_TARGET_NAME, targetname, sizeof(targetname));
                if (status == VX_SUCCESS)
                    rb_ary_push(array, rb_str_new2(targetname));
            }
        }
    }
    return array;
}
Пример #4
0
static VALUE OpenVX_load(VALUE self, VALUE name)
{
    vx_status status = VX_FAILURE;
    Check_Type(name, T_STRING);
    status = vxLoadModule(context, RSTRING(name)->ptr);
    REXT_PRINT("status = %d\n", status);
    return Qnil;
}
Пример #5
0
static VALUE OpenVX_load(VALUE self, VALUE name)
{
    vx_status status = VX_FAILURE;
    Check_Type(name, T_STRING);
    status = vxLoadKernels(context, RSTRING_PTR(name));
    REXT_PRINT("status = %d\n", status);
    return Qnil;
}
Пример #6
0
void rubyext_constants(VALUE parent, rext_const_t *constants, long numConstants)
{
    int c;
    for (c = 0; c < numConstants; c++)
    {
        if (constants[c].type == T_FLOAT)
        {
            rb_define_const(parent,
                            constants[c].name,
                            rb_float_new(constants[c].value.f));
            REXT_PRINT("Constants %s type=%d (under %ld) = %lf\n", constants[c].name, constants[c].type, parent, constants[c].value.f);
        } else if (constants[c].type == T_FIXNUM) {
            rb_define_const(parent,
                            constants[c].name,
                            INT2FIX(constants[c].value.l));
            REXT_PRINT("Constants %s type=%d (under %ld) = 0x%x=%ld\n", constants[c].name, constants[c].type, parent, constants[c].value.l, constants[c].value.l);
         }
    }
}
Пример #7
0
static VALUE Graph_nodes(VALUE self)
{
    vx_graph graph = 0;
    vx_uint32 numNodes = 0;
    vx_status status;
    Check_Type(self, T_DATA);
    graph = (vx_graph)DATA_PTR(self);
    status = vxQueryGraph(graph, VX_QUERY_GRAPH_NUMNODES, &numNodes, sizeof(numNodes));
    REXT_PRINT("status = %d, numNodes = %u\n", status, numNodes);
    return INT2FIX(numNodes);
}
Пример #8
0
static VALUE OpenVX_references(VALUE self)
{
    vx_uint32 value = 0;
    vx_status status = VX_FAILURE;
    status = vxQueryContext(context, VX_QUERY_CONTEXT_NUMREFS, &value, sizeof(value));
    REXT_PRINT("status = %d, references = %d\n", status, value);
    if (status == VX_SUCCESS)
        return INT2FIX(value);
    else
        return INT2FIX(0);
}
Пример #9
0
static VALUE OpenVX_targets(VALUE self)
{
    vx_uint32 value = 0;
    vx_status status = VX_FAILURE;
    status = vxQueryContext(context, VX_CONTEXT_ATTRIBUTE_TARGETS, &value, sizeof(value));
    REXT_PRINT("status = %d, targets = %d\n", status, value);
    if (status == VX_SUCCESS)
        return INT2FIX(value);
    else
        return INT2FIX(0);
}
Пример #10
0
static VALUE OpenVX_kernels(VALUE self)
{
    vx_uint32 value = 0;
    vx_status status = VX_FAILURE;
    status = vxQueryContext(context, VX_CONTEXT_ATTRIBUTE_UNIQUE_KERNELS, &value, sizeof(value));
    REXT_PRINT("status = %d, numkernels = %d\n", status, value);
    if (status == VX_SUCCESS)
        return INT2FIX(value);
    else
        return INT2FIX(0);
}
Пример #11
0
static VALUE Kernel_params(VALUE self)
{
    vx_uint32 numParams = 0;
    vx_kernel kernel = 0;
    vx_status status = VX_FAILURE;
    Check_Type(self, T_DATA);
    kernel = (vx_kernel)DATA_PTR(self);
    status = vxQueryKernel(kernel, VX_QUERY_KERNEL_NUMPARAMS, &numParams, sizeof(numParams));
    REXT_PRINT("status = %d, numParams = %u\n", status, numParams);
    return INT2FIX(numParams);
}
Пример #12
0
void Init_openvxruby()
{
    context = vxCreateContext();
    vx_status status = vxQueryContext(context, VX_QUERY_CONTEXT_IMPLEMENTATION, implementation, sizeof(implementation));
    if (status != VX_SUCCESS)
    {
        REXT_PRINT("context = "VX_FMT_REF" status = %d\n", context, status);
        strncpy(implementation, "khronos.sample (bad)", sizeof(implementation));
    }
    rb_mOpenVXString = rb_str_new2(implementation);
    rubyext_modules(Qnil, modules, dimof(modules));
    // there is no "unload"
}
Пример #13
0
void rubyext_modules(VALUE parent, rext_module_t *modules, long numModules)
{
    long mod;

    for (mod = 0; mod < numModules; mod++)
    {
        rext_const_t *constants = modules[mod].constants;
        rext_object_t *objects = modules[mod].objects;
        rext_method_t *methods = modules[mod].methods;

        if (parent == Qnil) {
            modules[mod].module = rb_define_module(modules[mod].name);
            REXT_PRINT("Module %s=%ld\n", modules[mod].name, modules[mod].module);
        } else {
            modules[mod].module = rb_define_module_under(parent, modules[mod].name);
            REXT_PRINT("Module %s=%ld (under %ld)\n", modules[mod].name, modules[mod].module, parent);
        }
        if (modules[mod].module)
        {
            rubyext_constants(modules[mod].module,
                              modules[mod].constants,
                              modules[mod].numConstants);

            rubyext_methods(modules[mod].module,
                            0,
                            modules[mod].methods,
                            modules[mod].numMethods);

            rubyext_objects(modules[mod].module,
                            modules[mod].objects,
                            modules[mod].numObjects);
        }
        else
        {
            printf("Module %s failed to be defined!\n", modules[mod].name);
        }
    }
}
Пример #14
0
static VALUE Graph_process(VALUE self)
{
    vx_graph graph = 0;
    vx_status status = VX_FAILURE;
    Check_Type(self, T_DATA);
    graph = (vx_graph)DATA_PTR(self);
    status = vxProcessGraph(graph);
    REXT_PRINT("status = %d\n", status);
    switch (status)
    {
        case VX_SUCCESS:
            break;
        default:
            rb_raise(rb_eException, "Process failed.");
            break;
    }
    return Qnil;
}
Пример #15
0
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;
}
Пример #16
0
void rubyext_methods(VALUE parent,
                     long type,
                     rext_method_t *methods,
                     long numMethods)
{
    long m;
    for (m = 0; m < numMethods; m++)
    {
        REXT_PRINT("Methods %s type=%ld (under %ld)\n", methods[m].name, type, parent);
        switch (type)
        {
            case REXT_METHOD_SINGLETON:
                rb_define_singleton_method(parent,
                                           methods[m].name,
                                           methods[m].func,
                                           methods[m].argc);
                break;
            case REXT_METHOD_NORMAL:
                rb_define_method(parent,
                                 methods[m].name,
                                 methods[m].func,
                                 methods[m].argc);
                break;
            case REXT_METHOD_MODULE:
                rb_define_module_method(parent,
                                        methods[m].name,
                                        methods[m].func,
                                        methods[m].argc);
                break;
            case REXT_METHOD_GLOBAL:
                rb_define_global_method(methods[m].name,
                                        methods[m].func,
                                        methods[m].argc);
                break;
            default:
                break;
        }
    }
}
Пример #17
0
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;
}
Пример #18
0
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;
}