From dd973cee8f0c8caafaede4865497ae873646caac Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 17 Aug 2016 22:07:51 +0200 Subject: ... MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/libcoopgamma_native.pyx.gpp | 160 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 146 insertions(+), 14 deletions(-) (limited to 'src/libcoopgamma_native.pyx.gpp') diff --git a/src/libcoopgamma_native.pyx.gpp b/src/libcoopgamma_native.pyx.gpp index 694e8f5..5c6b796 100644 --- a/src/libcoopgamma_native.pyx.gpp +++ b/src/libcoopgamma_native.pyx.gpp @@ -1476,7 +1476,7 @@ def libcoopgamma_native_get_gamma_recv(address : int, async : int): cdef libcoopgamma_filter_table_t table cdef bytes bs cdef libcoopgamma_ramps_t* rampsp - cdef bytes fclass + cdef char* fclass try: if libcoopgamma_filter_table_initialise(&table) < 0: return int(errno) @@ -1488,9 +1488,9 @@ def libcoopgamma_native_get_gamma_recv(address : int, async : int): ret = (False, (int(ctx.error.number), ctx.error.custom != 0, ctx.error.server_side != 0, desc)) else: filters = [None] * int(table.filter_count) - for i in range(int(table.filter_count)): - rampsp = &(table.filters[i].ramps) - fclass = table.filters[i].fclass + for j in range(int(table.filter_count)): + rampsp = &(table.filters[j].ramps) + fclass = table.filters[j].fclass red = [None] * rampsp.u_red_size green = [None] * rampsp.u_green_size blue = [None] * rampsp.u_blue_size @@ -1536,8 +1536,12 @@ def libcoopgamma_native_get_gamma_recv(address : int, async : int): 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) + ramps = (red, green, blue) + pclass = None + if fclass is not NULL: + bs = fclass + pclass = bs.decode('utf-8', 'strict') + filters[j] = (int(table.filters[j].priority), pclass, ramps) ret = (True, (int(table.red_size), int(table.green_size), int(table.blue_size), int(table.depth), filters)) finally: @@ -1565,7 +1569,7 @@ def libcoopgamma_native_get_gamma_sync(query, address : int): cdef libcoopgamma_filter_query_t qry cdef bytes bs cdef libcoopgamma_ramps_t* rampsp - cdef bytes fclass + cdef char* fclass crtc_bs = query.crtc.encode('utf-8') + bytes([0]) qry.high_priority = (query.high_priority) qry.low_priority = (query.low_priority) @@ -1589,9 +1593,9 @@ def libcoopgamma_native_get_gamma_sync(query, address : int): ret = (False, (int(ctx.error.number), ctx.error.custom != 0, ctx.error.server_side != 0, desc)) else: filters = [None] * int(table.filter_count) - for i in range(int(table.filter_count)): - rampsp = &(table.filters[i].ramps) - fclass = table.filters[i].fclass + for j in range(int(table.filter_count)): + rampsp = &(table.filters[j].ramps) + fclass = table.filters[j].fclass red = [None] * rampsp.u_red_size green = [None] * rampsp.u_green_size blue = [None] * rampsp.u_blue_size @@ -1637,8 +1641,12 @@ def libcoopgamma_native_get_gamma_sync(query, address : int): 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) + ramps = (red, green, blue) + pclass = None + if fclass is not NULL: + bs = fclass + pclass = bs.decode('utf-8', 'strict') + filters[j] = (int(table.filters[j].priority), pclass, ramps) ret = (True, (int(table.red_size), int(table.green_size), int(table.blue_size), int(table.depth), filters)) finally: @@ -1648,6 +1656,116 @@ def libcoopgamma_native_get_gamma_sync(query, address : int): return ret +def libcoopgamma_native_copy_ramps(intptr_t dest_address, src, libcoopgamma_depth_t depth): + ''' + Copy a Python ramp-trio into C ramp-trio + + @param dest_address:intptr_t The address of the C ramp-trio + @param src:Ramps The Python ramp-trio + @param depth:libcoopgamma_depth_t The data type of the ramp stops + ''' + cdef libcoopgamma_ramps_t* dest = dest_address + cdef uint8_t* r8 + cdef uint8_t* g8 + cdef uint8_t* b8 + cdef uint16_t* r16 + cdef uint16_t* g16 + cdef uint16_t* b16 + cdef uint32_t* r32 + cdef uint32_t* g32 + cdef uint32_t* b32 + cdef uint64_t* r64 + cdef uint64_t* g64 + cdef uint64_t* b64 + cdef float* rf + cdef float* gf + cdef float* bf + cdef double* rd + cdef double* gd + cdef double* bd + cdef size_t rn = len(src.red) + cdef size_t gn = len(src.green) + cdef size_t bn = len(src.blue) + if depth == 8: + r8 = malloc((rn + gn + bn) * sizeof(uint8_t)) + g8 = r8 + rn + b8 = g8 + gn + for i in range(int(rn)): + r8[i] = (src.red[i]) + for i in range(int(gn)): + g8[i] = (src.green[i]) + for i in range(int(bn)): + b8[i] = (src.blue[i]) + dest.u_red = r8 + dest.u_green = g8 + dest.u_blue = b8 + elif depth == 16: + r16 = malloc((rn + gn + bn) * sizeof(uint16_t)) + g16 = r16 + rn + b16 = g16 + gn + for i in range(int(rn)): + r16[i] = (src.red[i]) + for i in range(int(gn)): + g16[i] = (src.green[i]) + for i in range(int(bn)): + b16[i] = (src.blue[i]) + dest.u_red = r16 + dest.u_green = g16 + dest.u_blue = b16 + elif depth == 32: + r32 = malloc((rn + gn + bn) * sizeof(uint32_t)) + g32 = r32 + rn + b32 = g32 + gn + for i in range(int(rn)): + r32[i] = (src.red[i]) + for i in range(int(gn)): + g32[i] = (src.green[i]) + for i in range(int(bn)): + b32[i] = (src.blue[i]) + dest.u_red = r32 + dest.u_green = g32 + dest.u_blue = b32 + elif depth == 64: + r64 = malloc((rn + gn + bn) * sizeof(uint64_t)) + g64 = r64 + rn + b64 = g64 + gn + for i in range(int(rn)): + r64[i] = (src.red[i]) + for i in range(int(gn)): + g64[i] = (src.green[i]) + for i in range(int(bn)): + b64[i] = (src.blue[i]) + dest.u_red = r64 + dest.u_green = g64 + dest.u_blue = b64 + elif depth == -1: + rf = malloc((rn + gn + bn) * sizeof(float)) + gf = rf + rn + bf = gf + gn + for i in range(int(rn)): + rf[i] = (src.red[i]) + for i in range(int(gn)): + gf[i] = (src.green[i]) + for i in range(int(bn)): + bf[i] = (src.blue[i]) + dest.u_red = rf + dest.u_green = gf + dest.u_blue = bf + else: + rd = malloc((rn + gn + bn) * sizeof(double)) + gd = rd + rn + bd = gd + gn + for i in range(int(rn)): + rd[i] = (src.red[i]) + for i in range(int(gn)): + gd[i] = (src.green[i]) + for i in range(int(bn)): + bd[i] = (src.blue[i]) + dest.u_red = rd + dest.u_green = gd + dest.u_blue = bd + + def libcoopgamma_native_set_gamma_send(filtr, address : int, async : int): ''' Apply, update, or remove a gamma ramp adjustment, send request part @@ -1670,8 +1788,14 @@ def libcoopgamma_native_set_gamma_send(filtr, address : int, async : int): flr.lifespan = (filtr.lifespan) flr.depth = (filtr.depth) flr.fclass = NULL - flr.crtc = malloc(len(crtc_bs) * sizeof(char)) + flr.crtc = NULL + flr.ramps.u_red_size = len(filtr.ramps.red) + flr.ramps.u_green_size = len(filtr.ramps.green) + flr.ramps.u_blue_size = len(filtr.ramps.blue) + flr.ramps.u_red = NULL try: + libcoopgamma_native_copy_ramps(&(flr.ramps), filtr.ramps, flr.depth) + flr.crtc = malloc(len(crtc_bs) * sizeof(char)) if flr.crtc is NULL: return int(errno) flr.fclass = malloc(len(clss_bs) * sizeof(char)) @@ -1686,6 +1810,7 @@ def libcoopgamma_native_set_gamma_send(filtr, address : int, async : int): finally: free(flr.crtc) free(flr.fclass) + free(flr.ramps.u_red) return 0 @@ -1736,8 +1861,14 @@ def libcoopgamma_native_set_gamma_sync(filtr, address : int): flr.lifespan = (filtr.lifespan) flr.depth = (filtr.depth) flr.fclass = NULL - flr.crtc = malloc(len(crtc_bs) * sizeof(char)) + flr.crtc = NULL + flr.ramps.u_red_size = len(filtr.ramps.red) + flr.ramps.u_green_size = len(filtr.ramps.green) + flr.ramps.u_blue_size = len(filtr.ramps.blue) + flr.ramps.u_red = NULL try: + libcoopgamma_native_copy_ramps(&(flr.ramps), filtr.ramps, flr.depth) + flr.crtc = malloc(len(crtc_bs) * sizeof(char)) if flr.crtc is NULL: return int(errno) flr.fclass = malloc(len(clss_bs) * sizeof(char)) @@ -1756,5 +1887,6 @@ def libcoopgamma_native_set_gamma_sync(filtr, address : int): finally: free(flr.crtc) free(flr.fclass) + free(flr.ramps.u_red) return None -- cgit v1.2.3-70-g09d2