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_dpi.c] - Rev 43

Go to most recent revision | 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 <stdio.h>
#include <conio.h>
#include <Python.h>
#include "vpi_user.h"
#include "py_dpi.h"
 
// --------------------------------------------------------------------
PyObject *g_dva_i;
 
// --------------------------------------------------------------------
void c_do_it()
{
  printf("^^^ | c_do_it()\n");
 
  /* result = instance.method(x,y) */
  PyObject *pmeth  = PyObject_GetAttrString(g_dva_i, "do_it");
  // Py_DECREF(pinst);
  // pargs  = Py_BuildValue("(ss)", arg1, arg2); /* convert to Python */
  // PyObject *pres = PyEval_CallObject(pmeth, pargs); /* call method(x,y) */
  PyObject *pres = PyEval_CallObject(pmeth, NULL);
  Py_DECREF(pmeth);
  // Py_DECREF(pargs);
  Py_DECREF(pres);
}
 
// --------------------------------------------------------------------
unsigned int *g_va = NULL;
 
void c_get_array(const svOpenArrayHandle va)
{
  int va_y = svSize(va, 1);
  int va_x = svSize(va, 2);
 
  printf("^^^ | c_get_array() | %dx%d\n", va_x, va_y);
 
  g_va = (unsigned int *)svGetArrElemPtr2(va, 0, 0);
 
  PyObject *pmeth = PyObject_GetAttrString(g_dva_i, "py_get_array");
  // pargs  = Py_BuildValue("(ss)", arg1, arg2); /* convert to Python */
  // PyObject *pres = PyEval_CallObject(pmeth, pargs); /* call method(x,y) */
  PyObject *pres = PyEval_CallObject(pmeth, NULL);
  Py_DECREF(pmeth);
  // Py_DECREF(pargs);
  Py_DECREF(pres);
}
 
// --------------------------------------------------------------------
int py_run_file
( const char *filename
, int argc
, const svOpenArrayHandle args
)
{
  printf("^^^ | py_run_file | %s |\n", filename);
 
  char *argv[4];  // limit of 4 args
  int i;
  for(i = 0; i < argc && i < 4; i++)
  {
    argv[i] = *(char **)svGetArrElemPtr1(args, i);
    printf( "^^^ | py_run_file | args[%d] = %s\n"
          , i
          , argv[i]
          );
  }
 
  PySys_SetArgv(argc, argv);
  PyObject *PyFileObject = PyFile_FromString((char *)filename, "r");
  return PyRun_SimpleFileEx(PyFile_AsFile(PyFileObject), filename, 1);
}
 
// --------------------------------------------------------------------
void init_py_dpi(int width, int height)
{
  printf("^^^ | init_py_dpi() | %dx%d\n", width, height);
  Py_Initialize();
  init_py_to_video_frame();
 
  PyObject *dva_m = PyImport_ImportModule("dpi_video_array");
  if(!dva_m)
  {
      PyErr_Print();
      printf("^^^ | init_py_dpi() | dva_m Error\n");
  }
 
  PyObject *dva_c = PyObject_GetAttrString(dva_m, "dpi_video_array");
  Py_DECREF(dva_m);
  if(!dva_c)
  {
      PyErr_Print();
      printf("^^^ | init_py_dpi() | dva_c Error\n");
  }
 
  PyObject *args = Py_BuildValue("(ii)", width, height);
  g_dva_i = PyObject_CallObject(dva_c, args);
  Py_DECREF(args);
  Py_DECREF(dva_c);
  if(!g_dva_i)
  {
      PyErr_Print();
      printf("^^^ | init_py_dpi() | g_dva_i Error\n");
      Py_DECREF(g_dva_i);
      g_dva_i = NULL;
  }
}
 
// --------------------------------------------------------------------
void exit_py_dpi()
{
  printf("^^^ | exit_py_dpi()\n");
 
  if(g_dva_i)
    Py_DECREF(g_dva_i);
 
  Py_Finalize();
}
 

Go to most recent revision | 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.