From 233a40052651c9ca908266623fe189bb794d04fe Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 5 Apr 2014 02:24:39 +0200 Subject: portability MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- TODO | 1 - src/blueshift_drm.pyx | 71 +++++++++++++++++++++++------------------------ src/blueshift_randr.pyx | 31 ++++++++++----------- src/blueshift_vidmode.pyx | 32 ++++++++++----------- 4 files changed, 63 insertions(+), 72 deletions(-) diff --git a/TODO b/TODO index c09cecb..72d0edb 100644 --- a/TODO +++ b/TODO @@ -15,7 +15,6 @@ Low priority: https://en.wikipedia.org/wiki/Monotone_cubic_interpolation https://en.wikipedia.org/wiki/Spline_interpolation https://en.wikipedia.org/wiki/Lanczos_resampling - Increase portability of .pyx code Use curve sizes returned from RandR/VidMode/... Future stuff: diff --git a/src/blueshift_drm.pyx b/src/blueshift_drm.pyx index c8770c0..b0b4fdd 100644 --- a/src/blueshift_drm.pyx +++ b/src/blueshift_drm.pyx @@ -17,6 +17,7 @@ cimport cython from libc.stdlib cimport malloc, free +from libc.stdint cimport * cdef extern void blueshift_drm_close() @@ -79,9 +80,7 @@ Return the size of the gamma ramps on a CRTC ''' cdef extern int blueshift_drm_get_gamma_ramps(int connection, int crtc_index, int gamma_size, - unsigned short int* red, - unsigned short int* green, - unsigned short int* blue) + uint16_t* red, uint16_t* green, uint16_t* blue) ''' Get the current gamma ramps of a monitor @@ -95,9 +94,7 @@ Get the current gamma ramps of a monitor ''' cdef extern int blueshift_drm_set_gamma_ramps(int connection, int crtc_index, int gamma_size, - unsigned short int* red, - unsigned short int* green, - unsigned short int* blue) + uint16_t* red, uint16_t* green, uint16_t* blue) ''' Set the gamma ramps of the of a monitor @@ -196,9 +193,9 @@ Get the extended display identification data for the monitor connected to a conn -cdef unsigned short int* r_shared -cdef unsigned short int* g_shared -cdef unsigned short int* b_shared +cdef uint16_t* r_shared +cdef uint16_t* g_shared +cdef uint16_t* b_shared r_shared = NULL g_shared = NULL b_shared = NULL @@ -302,19 +299,19 @@ def drm_get_gamma_ramps(int connection, int crtc_index, int gamma_size, threadsa @return :(r:list, g:list, b:list)? The current red, green and blue colour curves ''' global r_shared, g_shared, b_shared - cdef unsigned short int* r - cdef unsigned short int* g - cdef unsigned short int* b + cdef uint16_t* r + cdef uint16_t* g + cdef uint16_t* b if not threadsafe: if r_shared is NULL: - r_shared = malloc(gamma_size * 2) + r_shared = malloc(gamma_size * sizeof(uint16_t)) if g_shared is NULL: - g_shared = malloc(gamma_size * 2) + g_shared = malloc(gamma_size * sizeof(uint16_t)) if b_shared is NULL: - b_shared = malloc(gamma_size * 2) - r = malloc(gamma_size * 2) if threadsafe else r_shared - g = malloc(gamma_size * 2) if threadsafe else g_shared - b = malloc(gamma_size * 2) if threadsafe else b_shared + b_shared = malloc(gamma_size * sizeof(uint16_t)) + r = malloc(gamma_size * sizeof(uint16_t)) if threadsafe else r_shared + g = malloc(gamma_size * sizeof(uint16_t)) if threadsafe else g_shared + b = malloc(gamma_size * sizeof(uint16_t)) if threadsafe else b_shared if (r is NULL) or (g is NULL) or (b is NULL): raise MemoryError() rc = blueshift_drm_get_gamma_ramps(connection, crtc_index, gamma_size, r, g, b) @@ -341,30 +338,30 @@ def drm_set_gamma_ramps(int connection, crtc_indices, int gamma_size, r_curve, g ''' Set the gamma ramps of the of a monitor - @param connection The identifier for the connection to the card - @param crtc_index:list The index of the CRTC to read from - @param gamma_size The size a gamma ramp - @param r_curve:list The red gamma ramp - @param g_curve:list The green gamma ramp - @param b_curve:list The blue gamma ramp - @param threadsafe:bool Whether to decrease memory efficiency and performace so - multiple threads can use DRM concurrently - @return :int Zero on success + @param connection The identifier for the connection to the card + @param crtc_index:list The index of the CRTC to read from + @param gamma_size The size a gamma ramp + @param r_curve:list The red gamma ramp + @param g_curve:list The green gamma ramp + @param b_curve:list The blue gamma ramp + @param threadsafe:bool Whether to decrease memory efficiency and performace so + multiple threads can use DRM concurrently + @return :int Zero on success ''' global r_shared, g_shared, b_shared - cdef unsigned short int* r - cdef unsigned short int* g - cdef unsigned short int* b + cdef uint16_t* r + cdef uint16_t* g + cdef uint16_t* b if not threadsafe: if r_shared is NULL: - r_shared = malloc(gamma_size * 2) + r_shared = malloc(gamma_size * sizeof(uint16_t)) if g_shared is NULL: - g_shared = malloc(gamma_size * 2) + g_shared = malloc(gamma_size * sizeof(uint16_t)) if b_shared is NULL: - b_shared = malloc(gamma_size * 2) - r = malloc(gamma_size * 2) if threadsafe else r_shared - g = malloc(gamma_size * 2) if threadsafe else g_shared - b = malloc(gamma_size * 2) if threadsafe else b_shared + b_shared = malloc(gamma_size * sizeof(uint16_t)) + r = malloc(gamma_size * sizeof(uint16_t)) if threadsafe else r_shared + g = malloc(gamma_size * sizeof(uint16_t)) if threadsafe else g_shared + b = malloc(gamma_size * sizeof(uint16_t)) if threadsafe else b_shared if (r is NULL) or (g is NULL) or (b is NULL): raise MemoryError() for i in range(gamma_size): @@ -483,7 +480,7 @@ def drm_get_edid(int connection, int connector_index): cdef bytes rc size = 256 - edid = malloc(size + 1) + edid = malloc((size + 1) * sizeof(char)) if edid is NULL: raise MemoryError() got = blueshift_drm_get_edid(connection, connector_index, edid, size, 1) diff --git a/src/blueshift_randr.pyx b/src/blueshift_randr.pyx index 7e8a1a9..de6c54f 100644 --- a/src/blueshift_randr.pyx +++ b/src/blueshift_randr.pyx @@ -17,6 +17,7 @@ cimport cython from libc.stdlib cimport malloc, free +from libc.stdint cimport * cdef extern int blueshift_randr_open(int use_screen, char* display) @@ -28,7 +29,7 @@ Start stage of colour curve control @return Zero on success ''' -cdef extern unsigned short int* blueshift_randr_read(int use_crtc) +cdef extern uint16_t* blueshift_randr_read(int use_crtc) ''' Gets the current colour curves @@ -40,9 +41,7 @@ Gets the current colour curves ''' cdef extern int blueshift_randr_apply(unsigned long long int use_crtcs, - unsigned short int* r_curve, - unsigned short int* g_curve, - unsigned short int* b_curve) + uint16_t* r_curve, uint16_t* g_curve, uint16_t* b_curve) ''' Apply stage of colour curve control @@ -60,17 +59,17 @@ Resource freeing stage of colour curve control -cdef unsigned short int* r_c +cdef uint16_t* r_c ''' Storage space for the red colour curve in C native data structure ''' -cdef unsigned short int* g_c +cdef uint16_t* g_c ''' Storage space for the green colour curve in C native data structure ''' -cdef unsigned short int* b_c +cdef uint16_t* b_c ''' Storage space for the blue colour curve in C native data structure ''' @@ -91,9 +90,9 @@ def randr_open(int use_screen, display): if display is not None: display_ = display # Allocate the storage space for the C native colour curves - r_c = malloc(256 * 2) - g_c = malloc(256 * 2) - b_c = malloc(256 * 2) + r_c = malloc(256 * sizeof(uint16_t)) + g_c = malloc(256 * sizeof(uint16_t)) + b_c = malloc(256 * sizeof(uint16_t)) # Check for out-of-memory error if (r_c is NULL) or (g_c is NULL) or (b_c is NULL): raise MemoryError() @@ -108,7 +107,7 @@ def randr_read(int use_crtc): @param use_crtc The CRTC to use @return :(r:list, g:list, b:list) The current red, green and blue colour curves ''' - cdef unsigned short int* got + cdef uint16_t* got # Read the current curves got = blueshift_randr_read(use_crtc) if got is NULL: @@ -131,11 +130,11 @@ def randr_apply(unsigned long long use_crtcs, r_curve, g_curve, b_curve): ''' Apply stage of colour curve control - @param use_crtcs Mask of CRTC:s to use - @param r_curve:list The red colour curve - @param g_curve:list The green colour curve - @param b_curve:list The blue colour curve - @return Zero on success + @param use_crtcs Mask of CRTC:s to use + @param r_curve:list The red colour curve + @param g_curve:list The green colour curve + @param b_curve:list The blue colour curve + @return Zero on success ''' # Convert curves to 16-bit C integers for i in range(256): diff --git a/src/blueshift_vidmode.pyx b/src/blueshift_vidmode.pyx index a4be816..4133548 100644 --- a/src/blueshift_vidmode.pyx +++ b/src/blueshift_vidmode.pyx @@ -17,6 +17,7 @@ cimport cython from libc.stdlib cimport malloc, free +from libc.stdint cimport * cdef extern int blueshift_vidmode_open(int use_screen, char* display) @@ -28,10 +29,7 @@ Start stage of colour curve control @return Zero on error, otherwise the size of colours curves ''' -cdef extern int blueshift_vidmode_read(int use_crtc, - unsigned short int* r_curve, - unsigned short int* g_curve, - unsigned short int* b_curve) +cdef extern int blueshift_vidmode_read(int use_crtc, uint16_t* r_curve, uint16_t* g_curve, uint16_t* b_curve) ''' Gets the current colour curves @@ -43,9 +41,7 @@ Gets the current colour curves ''' cdef extern int blueshift_vidmode_apply(unsigned long long int use_crtcs, - unsigned short int* r_curve, - unsigned short int* g_curve, - unsigned short int* b_curve) + uint16_t* r_curve, uint16_t* g_curve, uint16_t* b_curve) ''' Apply stage of colour curve control @@ -70,17 +66,17 @@ The size of the curves vidmode_gamma_size = 0 -cdef unsigned short int* r_c +cdef uint16_t* r_c ''' Storage space for the red colour curve in C native data structure ''' -cdef unsigned short int* g_c +cdef uint16_t* g_c ''' Storage space for the green colour curve in C native data structure ''' -cdef unsigned short int* b_c +cdef uint16_t* b_c ''' Storage space for the blue colour curve in C native data structure ''' @@ -101,9 +97,9 @@ def vidmode_open(int use_screen, display): if display is not None: display_ = display # Allocate the storage space for the C native colour curves - r_c = malloc(256 * 2) - g_c = malloc(256 * 2) - b_c = malloc(256 * 2) + r_c = malloc(256 * sizeof(uint16_t)) + g_c = malloc(256 * sizeof(uint16_t)) + b_c = malloc(256 * sizeof(uint16_t)) # Check for out-of-memory error if (r_c is NULL) or (g_c is NULL) or (b_c is NULL): raise MemoryError() @@ -136,11 +132,11 @@ def vidmode_apply(unsigned long long use_crtcs, r_curve, g_curve, b_curve): ''' Apply stage of colour curve control - @param use_crtcs Mask of CRTC:s to use - @param r_curve:list The red colour curve - @param g_curve:list The green colour curve - @param b_curve:list The blue colour curve - @return Zero on success + @param use_crtcs Mask of CRTC:s to use + @param r_curve:list The red colour curve + @param g_curve:list The green colour curve + @param b_curve:list The blue colour curve + @return Zero on success ''' # Convert curves to 16-bit C integers for i in range(256): -- cgit v1.2.3-70-g09d2