-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathd_gSheets.cpp
91 lines (85 loc) · 1.89 KB
/
d_gSheets.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <Python.h>
#include <ndspy.h>
#include <sstream>
PtDspyError DspyImageOpen(
PtDspyImageHandle *image,
const char *drivername,
const char *filename,
int width,
int height,
int paramCount,
const UserParameter *parameters,
int formatCount,
PtDspyDevFormat *format,
PtFlagStuff *flagstuff)
{
// Initialise the python interpreter
// (ensure cwd ends up part of sys.path)
//
Py_SetProgramName("d_gSheets");
Py_Initialize();
char *argv0 = nullptr;
PySys_SetArgv(0, &argv0);
char cmd[1024];
sprintf(cmd,
"import py_gSheets\n"
"gBuffer = py_gSheets.GBuffer(%d, %d, ['%s',])\n",
width, height, "rgba"
);
PyRun_SimpleString(cmd);
return PkDspyErrorNone;
}
PtDspyError DspyImageData(
PtDspyImageHandle image,
int xmin,
int xmax_plus_one,
int ymin,
int ymax_plus_one,
int entrysize,
const unsigned char *data)
{
std::stringstream ss;
ss << "gBuffer.updateCells("
<< ymin << "," << ymax_plus_one << ","
<< xmin << "," << xmax_plus_one << ","
<< "[";
const float *fData = reinterpret_cast<const float*>(data);
for(int i = 0; i < (xmax_plus_one-xmin) * (ymax_plus_one-ymin); ++i)
{
ss << "(" << fData[i*4+1] << "," << fData[i*4+2] << "," <<fData[i*4+3] << "),";
}
ss << "])\n";
PyRun_SimpleString(ss.str().c_str());
return PkDspyErrorNone;
}
PtDspyError DspyImageClose(
PtDspyImageHandle pvImage)
{
Py_Finalize();
return PkDspyErrorNone;
}
PtDspyError DspyImageQuery(
PtDspyImageHandle pvImage,
PtDspyQueryType type,
int size,
void *p)
{
switch(type)
{
case PkSizeQuery:
case PkOverwriteQuery:
case PkNextDataQuery:
case PkRedrawQuery:
case PkRenderingStartQuery:
case PkSupportsCheckpointing:
case PkPointCloudQuery:
case PkGridQuery:
case PkMultiResolutionQuery:
case PkQuantizationQuery:
case PkMemoryUsageQuery:
case PkElapsedTimeQuery:
return PkDspyErrorUnsupported;
default:
return PkDspyErrorUndefined;
}
}