- UID
- 2546
- 积分
- 159
- 帖子
- 30
- 主题
- 5
- 论坛币
- 868
- 威望
- 0
- EP值
- 134
- MP值
- 0
- 阅读权限
- 50
- 注册时间
- 2015-5-9
- 在线时间
- 52 小时
- 最后登录
- 2024-10-20
|
本帖最后由 Seekladoom 于 2022-3-31 02:29 编辑
def tcaxPy_Main的C语言源码定义- void **tcaxpy_script_func_main(const PY_pTcaxPy pTcaxPy, int iLine, int iText, int nTexts, int start, int end, int timeDiff, int time, int x, int y, int advance, const wchar_t *text) {
- PyObject *pyArgs; /* params to user tcax py script's tcaxPy_Main function */
- PyObject *pyReturnedBuf; /* the value returned from tcaxPy_Main function */
- void **pBufToReturn; /* value return to tcax module */
- PyObject *pyAssList;
- PyObject *pyTcasList;
- pyArgs = PyTuple_New(11);
- PyTuple_SetItem(pyArgs, 0, PyLong_FromLong(iLine));
- PyTuple_SetItem(pyArgs, 1, PyLong_FromLong(iText));
- PyTuple_SetItem(pyArgs, 2, PyLong_FromLong(nTexts));
- PyTuple_SetItem(pyArgs, 3, PyLong_FromLong(start));
- PyTuple_SetItem(pyArgs, 4, PyLong_FromLong(end));
- PyTuple_SetItem(pyArgs, 5, PyLong_FromLong(timeDiff));
- PyTuple_SetItem(pyArgs, 6, PyLong_FromLong(time));
- PyTuple_SetItem(pyArgs, 7, PyLong_FromLong(x));
- PyTuple_SetItem(pyArgs, 8, PyLong_FromLong(y));
- PyTuple_SetItem(pyArgs, 9, PyLong_FromLong(advance));
- PyTuple_SetItem(pyArgs, 10, PyUnicode_FromUnicode((const Py_UNICODE *)text, wcslen(text)));
- pyReturnedBuf = PyObject_CallObject(pTcaxPy->pyMainFunc, pyArgs);
- Py_CLEAR(pyArgs);
- if (!pyReturnedBuf) {
- PyErr_Print();
- /* PyErr_Clear(); */
- return NULL;
- }
- if (!PyTuple_Check(pyReturnedBuf)) {
- Py_CLEAR(pyReturnedBuf);
- /* fwprintf_s(stderr, L"Error: return value from py script is invalid\n"); */
- return NULL;
- }
- pBufToReturn = (void **)malloc(4 * sizeof(void *));
- pyAssList = PyTuple_GET_ITEM(pyReturnedBuf, 0);
- if (PyList_Check(pyAssList)) {
- int i, count, size, offset;
- wchar_t *assBuf;
- wchar_t **pAssLine;
- int *assLineSize;
- count = PyList_GET_SIZE(pyAssList);
- if (0 == count) {
- pBufToReturn[0] = (void *)0;
- pBufToReturn[1] = NULL;
- } else {
- assLineSize = (int *)malloc(count * sizeof(int));
- pAssLine = (wchar_t **)malloc(count * sizeof(wchar_t *));
- size = 0;
- for (i = 0; i < count; i ++) {
- pAssLine[i] = (wchar_t *)PyUnicode_AS_UNICODE(PyList_GET_ITEM(pyAssList, i));
- assLineSize[i] = wcslen(pAssLine[i]);
- size += assLineSize[i];
- }
- assBuf = (wchar_t *)malloc((size + 1) * sizeof(wchar_t));
- offset = 0;
- for (i = 0; i < count; i ++) {
- memcpy(assBuf + offset, pAssLine[i], assLineSize[i] * sizeof(wchar_t));
- offset += assLineSize[i];
- }
- assBuf[size] = L'\0';
- free(pAssLine);
- free(assLineSize);
- pBufToReturn[0] = (void *)size;
- pBufToReturn[1] = (void *)assBuf;
- }
- } else {
- pBufToReturn[0] = (void *)0;
- pBufToReturn[1] = NULL;
- }
- pyTcasList = PyTuple_GET_ITEM(pyReturnedBuf, 1);
- if (PyList_Check(pyTcasList)) {
- int i, count;
- PyObject *pyTcasItem;
- short x, y;
- unsigned long RGB;
- unsigned char alpha;
- unsigned long *tcasBuf;
- count = PyList_GET_SIZE(pyTcasList);
- if (0 == count) {
- pBufToReturn[2] = (void *)0;
- pBufToReturn[3] = NULL;
- }
- else {
- /* tcas buffer from user tcax py script: (Start, End, Layer_Type_Pair, PosX, PosY, RGB, Alpha) */
- /* a raw tcas chunk defined in TCAS file format specification: (Start, End, Layer_Type_Pair, Pos, RGBA) */
- tcasBuf = (unsigned long *)malloc(count * 5 * sizeof(unsigned long));
- for (i = 0; i < count; i ++) {
- pyTcasItem = PyList_GET_ITEM(pyTcasList, i);
- x = (short)PyLong_AsLong(PyTuple_GET_ITEM(pyTcasItem, 3));
- y = (short)PyLong_AsLong(PyTuple_GET_ITEM(pyTcasItem, 4));
- RGB = (unsigned long)PyLong_AsUnsignedLong(PyTuple_GET_ITEM(pyTcasItem, 5));
- alpha = (unsigned char)PyLong_AsLong(PyTuple_GET_ITEM(pyTcasItem, 6));
- tcasBuf[5 * i + 0] = (long)PyLong_AsLong(PyTuple_GET_ITEM(pyTcasItem, 0)); /* Start */
- tcasBuf[5 * i + 1] = (long)PyLong_AsLong(PyTuple_GET_ITEM(pyTcasItem, 1)); /* End */
- tcasBuf[5 * i + 2] = (unsigned long)PyLong_AsUnsignedLong(PyTuple_GET_ITEM(pyTcasItem, 2)); /* Layer_Type_Pair */
- tcasBuf[5 * i + 3] = (x | ((unsigned long)y << 16));
- tcasBuf[5 * i + 4] = (RGB | ((unsigned long)alpha << 24));
- }
- pBufToReturn[2] = (void *)count;
- pBufToReturn[3] = tcasBuf;
- }
- } else {
- pBufToReturn[2] = (void *)0;
- pBufToReturn[3] = NULL;
- }
- Py_CLEAR(pyReturnedBuf);
- return pBufToReturn;
- }
复制代码 |
|