From a8cede88dc170cf39f430e44fd9d659d3173032b Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 16 Aug 2016 11:53:49 +0200 Subject: ... MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- Makefile | 19 ++++- src/include-libcoopgamma.h | 9 +++ src/libcoopgamma_native.pyx.gpp | 172 ++++++++++++++++++++-------------------- 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 + +#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] = ((rampsp.red))[i] - for i in range(rampsp.green_size): - green[i] = ((rampsp.green))[i] - for i in range(rampsp.blue_size): - blue[i] = ((rampsp.blue))[i] + for i in range(rampsp.u_red_size): + red[i] = ((rampsp.u_red))[i] + for i in range(rampsp.u_green_size): + green[i] = ((rampsp.u_green))[i] + for i in range(rampsp.u_blue_size): + blue[i] = ((rampsp.u_blue))[i] elif table.depth == -1: - for i in range(rampsp.red_size): - red[i] = ((rampsp.red))[i] - for i in range(rampsp.green_size): - green[i] = ((rampsp.green))[i] - for i in range(rampsp.blue_size): - blue[i] = ((rampsp.blue))[i] + for i in range(rampsp.u_red_size): + red[i] = ((rampsp.u_red))[i] + for i in range(rampsp.u_green_size): + green[i] = ((rampsp.u_green))[i] + for i in range(rampsp.u_blue_size): + blue[i] = ((rampsp.u_blue))[i] elif table.depth == 8: - for i in range(rampsp.red_size): - red[i] = ((rampsp.red))[i] - for i in range(rampsp.green_size): - green[i] = ((rampsp.green))[i] - for i in range(rampsp.blue_size): - blue[i] = ((rampsp.blue))[i] + for i in range(rampsp.u_red_size): + red[i] = ((rampsp.u_red))[i] + for i in range(rampsp.u_green_size): + green[i] = ((rampsp.u_green))[i] + for i in range(rampsp.u_blue_size): + blue[i] = ((rampsp.u_blue))[i] elif table.depth == 16: - for i in range(rampsp.red_size): - red[i] = ((rampsp.red))[i] - for i in range(rampsp.green_size): - green[i] = ((rampsp.green))[i] - for i in range(rampsp.blue_size): - blue[i] = ((rampsp.blue))[i] + for i in range(rampsp.u_red_size): + red[i] = ((rampsp.u_red))[i] + for i in range(rampsp.u_green_size): + green[i] = ((rampsp.u_green))[i] + for i in range(rampsp.u_blue_size): + blue[i] = ((rampsp.u_blue))[i] elif table.depth == 32: - for i in range(rampsp.red_size): - red[i] = ((rampsp.red))[i] - for i in range(rampsp.green_size): - green[i] = ((rampsp.green))[i] - for i in range(rampsp.blue_size): - blue[i] = ((rampsp.blue))[i] + for i in range(rampsp.u_red_size): + red[i] = ((rampsp.u_red))[i] + for i in range(rampsp.u_green_size): + green[i] = ((rampsp.u_green))[i] + for i in range(rampsp.u_blue_size): + blue[i] = ((rampsp.u_blue))[i] elif table.depth == 64: - for i in range(rampsp.red_size): - red[i] = ((rampsp.red))[i] - for i in range(rampsp.green_size): - green[i] = ((rampsp.green))[i] - for i in range(rampsp.blue_size): - blue[i] = ((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] = ((rampsp.u_red))[i] + for i in range(rampsp.u_green_size): + green[i] = ((rampsp.u_green))[i] + for i in range(rampsp.u_blue_size): + blue[i] = ((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] = ((rampsp.red))[i] - for i in range(rampsp.green_size): - green[i] = ((rampsp.green))[i] - for i in range(rampsp.blue_size): - blue[i] = ((rampsp.blue))[i] + for i in range(rampsp.u_red_size): + red[i] = ((rampsp.u_red))[i] + for i in range(rampsp.u_green_size): + green[i] = ((rampsp.u_green))[i] + for i in range(rampsp.u_blue_size): + blue[i] = ((rampsp.u_blue))[i] elif table.depth == -1: - for i in range(rampsp.red_size): - red[i] = ((rampsp.red))[i] - for i in range(rampsp.green_size): - green[i] = ((rampsp.green))[i] - for i in range(rampsp.blue_size): - blue[i] = ((rampsp.blue))[i] + for i in range(rampsp.u_red_size): + red[i] = ((rampsp.u_red))[i] + for i in range(rampsp.u_green_size): + green[i] = ((rampsp.u_green))[i] + for i in range(rampsp.u_blue_size): + blue[i] = ((rampsp.u_blue))[i] elif table.depth == 8: - for i in range(rampsp.red_size): - red[i] = ((rampsp.red))[i] - for i in range(rampsp.green_size): - green[i] = ((rampsp.green))[i] - for i in range(rampsp.blue_size): - blue[i] = ((rampsp.blue))[i] + for i in range(rampsp.u_red_size): + red[i] = ((rampsp.u_red))[i] + for i in range(rampsp.u_green_size): + green[i] = ((rampsp.u_green))[i] + for i in range(rampsp.u_blue_size): + blue[i] = ((rampsp.u_blue))[i] elif table.depth == 16: - for i in range(rampsp.red_size): - red[i] = ((rampsp.red))[i] - for i in range(rampsp.green_size): - green[i] = ((rampsp.green))[i] - for i in range(rampsp.blue_size): - blue[i] = ((rampsp.blue))[i] + for i in range(rampsp.u_red_size): + red[i] = ((rampsp.u_red))[i] + for i in range(rampsp.u_green_size): + green[i] = ((rampsp.u_green))[i] + for i in range(rampsp.u_blue_size): + blue[i] = ((rampsp.u_blue))[i] elif table.depth == 32: - for i in range(rampsp.red_size): - red[i] = ((rampsp.red))[i] - for i in range(rampsp.green_size): - green[i] = ((rampsp.green))[i] - for i in range(rampsp.blue_size): - blue[i] = ((rampsp.blue))[i] + for i in range(rampsp.u_red_size): + red[i] = ((rampsp.u_red))[i] + for i in range(rampsp.u_green_size): + green[i] = ((rampsp.u_green))[i] + for i in range(rampsp.u_blue_size): + blue[i] = ((rampsp.u_blue))[i] elif table.depth == 64: - for i in range(rampsp.red_size): - red[i] = ((rampsp.red))[i] - for i in range(rampsp.green_size): - green[i] = ((rampsp.green))[i] - for i in range(rampsp.blue_size): - blue[i] = ((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] = ((rampsp.u_red))[i] + for i in range(rampsp.u_green_size): + green[i] = ((rampsp.u_green))[i] + for i in range(rampsp.u_blue_size): + blue[i] = ((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)) -- cgit v1.2.3-70-g09d2