aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2016-08-16 11:53:49 +0200
committerMattias Andrée <maandree@kth.se>2016-08-16 11:53:49 +0200
commita8cede88dc170cf39f430e44fd9d659d3173032b (patch)
treed3e905e8b2c8a6cdfca8769f0262c0e1af812830
parentCorrections to libcoopgamma_native.pyx.gpp (diff)
downloadpylibcoopgamma-a8cede88dc170cf39f430e44fd9d659d3173032b.tar.gz
pylibcoopgamma-a8cede88dc170cf39f430e44fd9d659d3173032b.tar.bz2
pylibcoopgamma-a8cede88dc170cf39f430e44fd9d659d3173032b.tar.xz
...
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--Makefile19
-rw-r--r--src/include-libcoopgamma.h9
-rw-r--r--src/libcoopgamma_native.pyx.gpp172
3 files changed, 113 insertions, 87 deletions
diff --git a/Makefile b/Makefile
index 6d39412..e3dd8b8 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,17 @@
GPP = gpp
CYTHON = cython
+PKGCONFIG = pkg-config
-all: obj/libcoopgamma_native.c
+PY_MAJOR = 3
+
+OPTIMISE = -O2
+LIBS = python$(PY_MAJOR)
+
+CC_FLAGS = $$($(PKGCONFIG) --cflags $(LIBS)) -std=c99 $(OPTIMISE) -fPIC $(CFLAGS) $(CPPFLAGS)
+LD_FLAGS = $$($(PKGCONFIG) --libs $(LIBS)) -lcoopgamma -std=c99 $(OPTIMISE) -shared $(LDFLAGS)
+
+
+all: bin/libcoopgamma_native.so
obj/libcoopgamma_native.pyx: src/libcoopgamma_native.pyx.gpp
@mkdir -p obj
@@ -10,3 +20,10 @@ obj/libcoopgamma_native.pyx: src/libcoopgamma_native.pyx.gpp
obj/%.c: obj/%.pyx
if ! $(CYTHON) -3 -v $< ; then rm $@ ; false ; fi
+obj/%.o: obj/%.c src/*.h
+ $(CC) $(CC_FLAGS) -iquote"src" -c -o $@ $<
+
+bin/%.so: obj/%.o
+ @mkdir -p bin
+ $(CC) $(LD_FLAGS) -o $@ $^
+
diff --git a/src/include-libcoopgamma.h b/src/include-libcoopgamma.h
index 19d83e4..5150bf3 100644
--- a/src/include-libcoopgamma.h
+++ b/src/include-libcoopgamma.h
@@ -17,3 +17,12 @@
*/
#include <libcoopgamma.h>
+
+#define fclass class
+#define u_red_size u8.red_size
+#define u_green_size u8.green_size
+#define u_blue_size u8.blue_size
+#define u_red u8.red
+#define u_green u8.green
+#define u_blue u8.blue
+
diff --git a/src/libcoopgamma_native.pyx.gpp b/src/libcoopgamma_native.pyx.gpp
index f5a4925..e750b02 100644
--- a/src/libcoopgamma_native.pyx.gpp
+++ b/src/libcoopgamma_native.pyx.gpp
@@ -46,17 +46,17 @@ cdef extern from "include-libcoopgamma.h":
ctypedef struct libcoopgamma_ramps_t:
# Gamma ramp structure
- size_t red_size
+ size_t u_red_size
# The number of stops in the red ramp
- size_t green_size
+ size_t u_green_size
# The number of stops in the green ramp
- size_t blue_size
+ size_t u_blue_size
# The number of stops in the blue ramp
- void* red
+ void* u_red
# The red ramp
- void* green
+ void* u_green
# The green ramp
- void* blue
+ void* u_blue
# The blue ramp
ctypedef struct libcoopgamma_filter_t:
@@ -1446,52 +1446,52 @@ def libcoopgamma_native_get_gamma_recv(address : int, async : int):
for i in range(int(table.filter_count)):
rampsp = &(table.filters[i].ramps)
fclass = table.filters[i].fclass
- red = [None] * rampsp.red_size
- green = [None] * rampsp.green_size
- blue = [None] * rampsp.blue_size
+ red = [None] * rampsp.u_red_size
+ green = [None] * rampsp.u_green_size
+ blue = [None] * rampsp.u_blue_size
if table.depth == -2:
- for i in range(rampsp.red_size):
- red[i] = (<double*>(rampsp.red))[i]
- for i in range(rampsp.green_size):
- green[i] = (<double*>(rampsp.green))[i]
- for i in range(rampsp.blue_size):
- blue[i] = (<double*>(rampsp.blue))[i]
+ for i in range(rampsp.u_red_size):
+ red[i] = (<double*>(rampsp.u_red))[i]
+ for i in range(rampsp.u_green_size):
+ green[i] = (<double*>(rampsp.u_green))[i]
+ for i in range(rampsp.u_blue_size):
+ blue[i] = (<double*>(rampsp.u_blue))[i]
elif table.depth == -1:
- for i in range(rampsp.red_size):
- red[i] = (<float*>(rampsp.red))[i]
- for i in range(rampsp.green_size):
- green[i] = (<float*>(rampsp.green))[i]
- for i in range(rampsp.blue_size):
- blue[i] = (<float*>(rampsp.blue))[i]
+ for i in range(rampsp.u_red_size):
+ red[i] = (<float*>(rampsp.u_red))[i]
+ for i in range(rampsp.u_green_size):
+ green[i] = (<float*>(rampsp.u_green))[i]
+ for i in range(rampsp.u_blue_size):
+ blue[i] = (<float*>(rampsp.u_blue))[i]
elif table.depth == 8:
- for i in range(rampsp.red_size):
- red[i] = (<uint8_t*>(rampsp.red))[i]
- for i in range(rampsp.green_size):
- green[i] = (<uint8_t*>(rampsp.green))[i]
- for i in range(rampsp.blue_size):
- blue[i] = (<uint8_t*>(rampsp.blue))[i]
+ for i in range(rampsp.u_red_size):
+ red[i] = (<uint8_t*>(rampsp.u_red))[i]
+ for i in range(rampsp.u_green_size):
+ green[i] = (<uint8_t*>(rampsp.u_green))[i]
+ for i in range(rampsp.u_blue_size):
+ blue[i] = (<uint8_t*>(rampsp.u_blue))[i]
elif table.depth == 16:
- for i in range(rampsp.red_size):
- red[i] = (<uint16_t*>(rampsp.red))[i]
- for i in range(rampsp.green_size):
- green[i] = (<uint16_t*>(rampsp.green))[i]
- for i in range(rampsp.blue_size):
- blue[i] = (<uint16_t*>(rampsp.blue))[i]
+ for i in range(rampsp.u_red_size):
+ red[i] = (<uint16_t*>(rampsp.u_red))[i]
+ for i in range(rampsp.u_green_size):
+ green[i] = (<uint16_t*>(rampsp.u_green))[i]
+ for i in range(rampsp.u_blue_size):
+ blue[i] = (<uint16_t*>(rampsp.u_blue))[i]
elif table.depth == 32:
- for i in range(rampsp.red_size):
- red[i] = (<uint32_t*>(rampsp.red))[i]
- for i in range(rampsp.green_size):
- green[i] = (<uint32_t*>(rampsp.green))[i]
- for i in range(rampsp.blue_size):
- blue[i] = (<uint32_t*>(rampsp.blue))[i]
+ for i in range(rampsp.u_red_size):
+ red[i] = (<uint32_t*>(rampsp.u_red))[i]
+ for i in range(rampsp.u_green_size):
+ green[i] = (<uint32_t*>(rampsp.u_green))[i]
+ for i in range(rampsp.u_blue_size):
+ blue[i] = (<uint32_t*>(rampsp.u_blue))[i]
elif table.depth == 64:
- for i in range(rampsp.red_size):
- red[i] = (<uint64_t*>(rampsp.red))[i]
- for i in range(rampsp.green_size):
- green[i] = (<uint64_t*>(rampsp.green))[i]
- for i in range(rampsp.blue_size):
- blue[i] = (<uint64_t*>(rampsp.blue))[i]
- ramps = (rampsp.red_size, rampsp.green_size, rampsp.blue_size, red, green, blue)
+ for i in range(rampsp.u_red_size):
+ red[i] = (<uint64_t*>(rampsp.u_red))[i]
+ for i in range(rampsp.u_green_size):
+ green[i] = (<uint64_t*>(rampsp.u_green))[i]
+ for i in range(rampsp.u_blue_size):
+ blue[i] = (<uint64_t*>(rampsp.u_blue))[i]
+ ramps = (rampsp.u_red_size, rampsp.u_green_size, rampsp.u_blue_size, red, green, blue)
filters[i] = (int(table.filters[i].priority), fclass.decode('utf-8', 'strict'), ramps)
ret = (True, (int(table.red_size), int(table.green_size), int(table.blue_size),
int(table.depth), filters))
@@ -1547,52 +1547,52 @@ def libcoopgamma_native_get_gamma_sync(query, address : int):
for i in range(int(table.filter_count)):
rampsp = &(table.filters[i].ramps)
fclass = table.filters[i].fclass
- red = [None] * rampsp.red_size
- green = [None] * rampsp.green_size
- blue = [None] * rampsp.blue_size
+ red = [None] * rampsp.u_red_size
+ green = [None] * rampsp.u_green_size
+ blue = [None] * rampsp.u_blue_size
if table.depth == -2:
- for i in range(rampsp.red_size):
- red[i] = (<double*>(rampsp.red))[i]
- for i in range(rampsp.green_size):
- green[i] = (<double*>(rampsp.green))[i]
- for i in range(rampsp.blue_size):
- blue[i] = (<double*>(rampsp.blue))[i]
+ for i in range(rampsp.u_red_size):
+ red[i] = (<double*>(rampsp.u_red))[i]
+ for i in range(rampsp.u_green_size):
+ green[i] = (<double*>(rampsp.u_green))[i]
+ for i in range(rampsp.u_blue_size):
+ blue[i] = (<double*>(rampsp.u_blue))[i]
elif table.depth == -1:
- for i in range(rampsp.red_size):
- red[i] = (<float*>(rampsp.red))[i]
- for i in range(rampsp.green_size):
- green[i] = (<float*>(rampsp.green))[i]
- for i in range(rampsp.blue_size):
- blue[i] = (<float*>(rampsp.blue))[i]
+ for i in range(rampsp.u_red_size):
+ red[i] = (<float*>(rampsp.u_red))[i]
+ for i in range(rampsp.u_green_size):
+ green[i] = (<float*>(rampsp.u_green))[i]
+ for i in range(rampsp.u_blue_size):
+ blue[i] = (<float*>(rampsp.u_blue))[i]
elif table.depth == 8:
- for i in range(rampsp.red_size):
- red[i] = (<uint8_t*>(rampsp.red))[i]
- for i in range(rampsp.green_size):
- green[i] = (<uint8_t*>(rampsp.green))[i]
- for i in range(rampsp.blue_size):
- blue[i] = (<uint8_t*>(rampsp.blue))[i]
+ for i in range(rampsp.u_red_size):
+ red[i] = (<uint8_t*>(rampsp.u_red))[i]
+ for i in range(rampsp.u_green_size):
+ green[i] = (<uint8_t*>(rampsp.u_green))[i]
+ for i in range(rampsp.u_blue_size):
+ blue[i] = (<uint8_t*>(rampsp.u_blue))[i]
elif table.depth == 16:
- for i in range(rampsp.red_size):
- red[i] = (<uint16_t*>(rampsp.red))[i]
- for i in range(rampsp.green_size):
- green[i] = (<uint16_t*>(rampsp.green))[i]
- for i in range(rampsp.blue_size):
- blue[i] = (<uint16_t*>(rampsp.blue))[i]
+ for i in range(rampsp.u_red_size):
+ red[i] = (<uint16_t*>(rampsp.u_red))[i]
+ for i in range(rampsp.u_green_size):
+ green[i] = (<uint16_t*>(rampsp.u_green))[i]
+ for i in range(rampsp.u_blue_size):
+ blue[i] = (<uint16_t*>(rampsp.u_blue))[i]
elif table.depth == 32:
- for i in range(rampsp.red_size):
- red[i] = (<uint32_t*>(rampsp.red))[i]
- for i in range(rampsp.green_size):
- green[i] = (<uint32_t*>(rampsp.green))[i]
- for i in range(rampsp.blue_size):
- blue[i] = (<uint32_t*>(rampsp.blue))[i]
+ for i in range(rampsp.u_red_size):
+ red[i] = (<uint32_t*>(rampsp.u_red))[i]
+ for i in range(rampsp.u_green_size):
+ green[i] = (<uint32_t*>(rampsp.u_green))[i]
+ for i in range(rampsp.u_blue_size):
+ blue[i] = (<uint32_t*>(rampsp.u_blue))[i]
elif table.depth == 64:
- for i in range(rampsp.red_size):
- red[i] = (<uint64_t*>(rampsp.red))[i]
- for i in range(rampsp.green_size):
- green[i] = (<uint64_t*>(rampsp.green))[i]
- for i in range(rampsp.blue_size):
- blue[i] = (<uint64_t*>(rampsp.blue))[i]
- ramps = (rampsp.red_size, rampsp.green_size, rampsp.blue_size, red, green, blue)
+ for i in range(rampsp.u_red_size):
+ red[i] = (<uint64_t*>(rampsp.u_red))[i]
+ for i in range(rampsp.u_green_size):
+ green[i] = (<uint64_t*>(rampsp.u_green))[i]
+ for i in range(rampsp.u_blue_size):
+ blue[i] = (<uint64_t*>(rampsp.u_blue))[i]
+ ramps = (rampsp.u_red_size, rampsp.u_green_size, rampsp.u_blue_size, red, green, blue)
filters[i] = (int(table.filters[i].priority), fclass.decode('utf-8', 'strict'), ramps)
ret = (True, (int(table.red_size), int(table.green_size), int(table.blue_size),
int(table.depth), filters))