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] - Rev 43

Compare with Previous | Blame | View Log

//////////////////////////////////////////////////////////////////////
////                                                              ////
//// Copyright (C) 2018 Authors and OPENCORES.ORG                 ////
////                                                              ////
//// This source file may be used and distributed without         ////
//// restriction provided that this copyright statement is not    ////
//// removed from the file and that any derivative work contains  ////
//// the original copyright notice and the associated disclaimer. ////
////                                                              ////
//// This source file is free software; you can redistribute it   ////
//// and/or modify it under the terms of the GNU Lesser General   ////
//// Public License as published by the Free Software Foundation; ////
//// either version 2.1 of the License, or (at your option) any   ////
//// later version.                                               ////
////                                                              ////
//// This source is distributed in the hope that it will be       ////
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
//// PURPOSE.  See the GNU Lesser General Public License for more ////
//// details.                                                     ////
////                                                              ////
//// You should have received a copy of the GNU Lesser General    ////
//// Public License along with this source; if not, download it   ////
//// from http://www.opencores.org/lgpl.shtml                     ////
////                                                              ////
//////////////////////////////////////////////////////////////////////
 
#include <Python.h>
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#include <numpy/arrayobject.h>
 
extern unsigned int *g_va;
 
// --------------------------------------------------------------------
static PyObject* np_to_frame(PyObject* self, PyObject* args)
{
  printf("^^^ | np_to_frame()\n");
 
  if(g_va == NULL)
    return NULL;
 
  PyArrayObject *in_array;
  NpyIter *in_iter;
  NpyIter_IterNextFunc *in_iternext;
 
  /*  parse single numpy array argument */
  if(!PyArg_ParseTuple(args, "O!", &PyArray_Type, &in_array))
    return NULL;
 
  /*  create the iterators */
  in_iter = NpyIter_New
    ( in_array
    , NPY_ITER_READONLY
    , NPY_KEEPORDER
    , NPY_NO_CASTING
    , NULL
    );
 
  if(in_iter == NULL)
    return NULL;
 
  in_iternext = NpyIter_GetIterNext(in_iter, NULL);
 
  if(in_iternext == NULL)
  {
    NpyIter_Deallocate(in_iter);
    return NULL;
  }
  unsigned int **in_dataptr = (unsigned int **)NpyIter_GetDataPtrArray(in_iter);
  unsigned int *p = g_va;
 
  /*  iterate over the arrays */
  do
  {
    *p++ = **in_dataptr;
  } while(in_iternext(in_iter));
 
  /*  clean up and return the result */
  NpyIter_Deallocate(in_iter);
  g_va = NULL;
  return Py_BuildValue("");
}
 
// --------------------------------------------------------------------
/*  define functions in module */
static PyMethodDef py_to_video_frame_methods[] =
{ {"np_to_frame"
  , np_to_frame
  , METH_VARARGS
  , "numpy to video frame"
  },
  {NULL, NULL, 0, NULL}
};
 
// --------------------------------------------------------------------
#if PY_MAJOR_VERSION >= 3
/* module initialization */
/* Python version 3*/
static struct PyModuleDef cmod_py_to_video_frame =
{ PyModuleDef_HEAD_INIT
, "py_to_video_frame"
, "Some documentation"
, -1
, py_to_video_frame_methods
};
 
PyMODINIT_FUNC
PyInit_py_to_video_frame(void)
{
  PyObject *module = PyModule_Create(&cmod_py_to_video_frame);
 
  if(module != NULL)
    import_array();
 
  return module;
}
 
#else
 
/* module initialization */
/* Python version 2 */
PyMODINIT_FUNC
init_py_to_video_frame(void)
{
  printf("^^^ | init_py_to_video_frame()\n");
  (void) Py_InitModule("py_to_video_frame", py_to_video_frame_methods);
  import_array();
}
 
#endif
 

Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

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