OpenCores
URL https://opencores.org/ocsvn/qaz_libs/qaz_libs/trunk

Subversion Repositories qaz_libs

[/] [qaz_libs/] [trunk/] [BFM/] [sim/] [tests/] [tb_video_frame_dpi/] [py_to_video_frame_module.c] - Blame information for rev 43

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 43 qaztronic
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
//// Copyright (C) 2018 Authors and OPENCORES.ORG                 ////
4
////                                                              ////
5
//// This source file may be used and distributed without         ////
6
//// restriction provided that this copyright statement is not    ////
7
//// removed from the file and that any derivative work contains  ////
8
//// the original copyright notice and the associated disclaimer. ////
9
////                                                              ////
10
//// This source file is free software; you can redistribute it   ////
11
//// and/or modify it under the terms of the GNU Lesser General   ////
12
//// Public License as published by the Free Software Foundation; ////
13
//// either version 2.1 of the License, or (at your option) any   ////
14
//// later version.                                               ////
15
////                                                              ////
16
//// This source is distributed in the hope that it will be       ////
17
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
18
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
19
//// PURPOSE.  See the GNU Lesser General Public License for more ////
20
//// details.                                                     ////
21
////                                                              ////
22
//// You should have received a copy of the GNU Lesser General    ////
23
//// Public License along with this source; if not, download it   ////
24
//// from http://www.opencores.org/lgpl.shtml                     ////
25
////                                                              ////
26
//////////////////////////////////////////////////////////////////////
27
 
28
#include <Python.h>
29
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
30
#include <numpy/arrayobject.h>
31
 
32
extern unsigned int *g_va;
33
 
34
// --------------------------------------------------------------------
35
static PyObject* np_to_frame(PyObject* self, PyObject* args)
36
{
37
  printf("^^^ | np_to_frame()\n");
38
 
39
  if(g_va == NULL)
40
    return NULL;
41
 
42
  PyArrayObject *in_array;
43
  NpyIter *in_iter;
44
  NpyIter_IterNextFunc *in_iternext;
45
 
46
  /*  parse single numpy array argument */
47
  if(!PyArg_ParseTuple(args, "O!", &PyArray_Type, &in_array))
48
    return NULL;
49
 
50
  /*  create the iterators */
51
  in_iter = NpyIter_New
52
    ( in_array
53
    , NPY_ITER_READONLY
54
    , NPY_KEEPORDER
55
    , NPY_NO_CASTING
56
    , NULL
57
    );
58
 
59
  if(in_iter == NULL)
60
    return NULL;
61
 
62
  in_iternext = NpyIter_GetIterNext(in_iter, NULL);
63
 
64
  if(in_iternext == NULL)
65
  {
66
    NpyIter_Deallocate(in_iter);
67
    return NULL;
68
  }
69
  unsigned int **in_dataptr = (unsigned int **)NpyIter_GetDataPtrArray(in_iter);
70
  unsigned int *p = g_va;
71
 
72
  /*  iterate over the arrays */
73
  do
74
  {
75
    *p++ = **in_dataptr;
76
  } while(in_iternext(in_iter));
77
 
78
  /*  clean up and return the result */
79
  NpyIter_Deallocate(in_iter);
80
  g_va = NULL;
81
  return Py_BuildValue("");
82
}
83
 
84
// --------------------------------------------------------------------
85
/*  define functions in module */
86
static PyMethodDef py_to_video_frame_methods[] =
87
{ {"np_to_frame"
88
  , np_to_frame
89
  , METH_VARARGS
90
  , "numpy to video frame"
91
  },
92
  {NULL, NULL, 0, NULL}
93
};
94
 
95
// --------------------------------------------------------------------
96
#if PY_MAJOR_VERSION >= 3
97
/* module initialization */
98
/* Python version 3*/
99
static struct PyModuleDef cmod_py_to_video_frame =
100
{ PyModuleDef_HEAD_INIT
101
, "py_to_video_frame"
102
, "Some documentation"
103
, -1
104
, py_to_video_frame_methods
105
};
106
 
107
PyMODINIT_FUNC
108
PyInit_py_to_video_frame(void)
109
{
110
  PyObject *module = PyModule_Create(&cmod_py_to_video_frame);
111
 
112
  if(module != NULL)
113
    import_array();
114
 
115
  return module;
116
}
117
 
118
#else
119
 
120
/* module initialization */
121
/* Python version 2 */
122
PyMODINIT_FUNC
123
init_py_to_video_frame(void)
124
{
125
  printf("^^^ | init_py_to_video_frame()\n");
126
  (void) Py_InitModule("py_to_video_frame", py_to_video_frame_methods);
127
  import_array();
128
}
129
 
130
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2019 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.