2025-01-25 10:55:11 +01:00
|
|
|
#!/usr/bin/python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import os
|
|
|
|
import cffi
|
|
|
|
import numpy as np
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
c_header = '''
|
2025-01-25 15:08:53 +01:00
|
|
|
void test (void);
|
2025-01-25 10:55:11 +01:00
|
|
|
void print_table (void);
|
|
|
|
double ComputeRed (double);
|
|
|
|
double ComputeGreen (double);
|
|
|
|
double ComputeBlue (double);
|
|
|
|
'''
|
|
|
|
def plot_colors(C):
|
|
|
|
yr = []; yg = []; yb = [];
|
|
|
|
xs = np.arange(0.0, 256.0, 1.0)
|
|
|
|
for x in xs: yr.append (C.ComputeRed (x))
|
|
|
|
for x in xs: yg.append (C.ComputeGreen(x))
|
|
|
|
for x in xs: yb.append (C.ComputeBlue (x))
|
|
|
|
fig,ap = plt.subplots (1, figsize=(6.0,4.0))
|
|
|
|
fig.suptitle ('Color functions', fontsize=15)
|
|
|
|
ap.plot (xs, yr, 'r-')
|
|
|
|
ap.plot (xs, yg, 'g-')
|
|
|
|
ap.plot (xs, yb, 'b-')
|
|
|
|
ap.legend (['R','G','B'])
|
|
|
|
plt.grid()
|
|
|
|
plt.ylabel('Intenzity')
|
|
|
|
plt.xlabel('N')
|
2025-01-25 15:08:53 +01:00
|
|
|
plt.savefig('color.png')
|
|
|
|
#plt.show()
|
2025-01-25 10:55:11 +01:00
|
|
|
|
|
|
|
############################ MAIN ##############################################################
|
|
|
|
def main_func():
|
|
|
|
ffi = cffi.FFI()
|
|
|
|
ffi.cdef(c_header)
|
|
|
|
C = ffi.dlopen("./graph.so")
|
2025-01-25 15:08:53 +01:00
|
|
|
C.test()
|
2025-01-25 10:55:11 +01:00
|
|
|
plot_colors(C)
|
2025-01-25 15:08:53 +01:00
|
|
|
C.print_table()
|
2025-01-25 10:55:11 +01:00
|
|
|
ffi.dlclose(C)
|
|
|
|
return True
|
|
|
|
if __name__ == '__main__':
|
|
|
|
r = main_func()
|
|
|
|
print ('END {:s}'.format(str(r)))
|