From 0806af8ce7e47652adaecb08b52cbfe59d1c5f16 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 19 Mar 2014 03:37:29 +0100 Subject: move translate_to_integers and ramps_to_function to aux.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/__main__.py | 1 + src/aux.py | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/monitor.py | 38 +------------------------------------- 3 files changed, 58 insertions(+), 37 deletions(-) create mode 100644 src/aux.py (limited to 'src') diff --git a/src/__main__.py b/src/__main__.py index ad256c3..4197963 100755 --- a/src/__main__.py +++ b/src/__main__.py @@ -36,6 +36,7 @@ global monitor_controller, running, continuous_run, panic, _globals_, conf_stora global signal_SIGTERM, signal_SIGUSR1, signal_SIGUSR2 +from aux import * from icc import * from solar import * from curve import * diff --git a/src/aux.py b/src/aux.py new file mode 100644 index 0000000..ec94549 --- /dev/null +++ b/src/aux.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 + +# Copyright © 2014 Mattias Andrée (maandree@member.fsf.org) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +from curve import * + + +def translate_to_integers(): + ''' + Translate the curves from float to integer + + @param :(list, list, list) The red curve, the green curve and, + the blue curve mapped to integers + ''' + R_curve, G_curve, B_curve = [0] * i_size, [0] * i_size, [0] * i_size + for i_curve, o_curve in ((r_curve, R_curve), (g_curve, G_curve), (b_curve, B_curve)): + for i in range(i_size): + o_curve[i] = int(i_curve[i] * (o_size - 1) + 0.5) + if clip_result: + o_curve[i] = min(max(0, o_curve[i]), (o_size - 1)) + return (R_curve, G_curve, B_curve) + + +def ramps_to_function(r, g, b): + ''' + Convert a three colour curves to a function that applies those adjustments + + @param r:int The red colour curves as [0, 65535] integers + @param g:int The green colour curves as [0, 65535] integers + @param b:int The blue colour curves as [0, 65535] integers + @return :()→void Function to invoke to apply the curves that the parameters [r, g and b] represents + ''' + r = [y / 65535 for y in r] + g = [y / 65535 for y in g] + b = [y / 65535 for y in b] + def fcurve(R_curve, G_curve, B_curve): + for curve, cur in curves(R_curve, G_curve, B_curve): + for i in range(i_size): + y = int(curve[i] * (len(cur) - 1) + 0.5) + y = min(max(0, y), len(cur) - 1) + curve[i] = cur[y] + return lambda : fcurve(r, g, b) + diff --git a/src/monitor.py b/src/monitor.py index 90ae603..499864f 100644 --- a/src/monitor.py +++ b/src/monitor.py @@ -18,6 +18,7 @@ import sys from subprocess import Popen, PIPE +from aux import * from curve import * # /usr/lib @@ -36,22 +37,6 @@ except: pass ## Not compiled with DRM support -def translate_to_integers(): - ''' - Translate the curves from float to integer - - @param :(list, list, list) The red curve, the green curve and, - the blue curve mapped to integers - ''' - R_curve, G_curve, B_curve = [0] * i_size, [0] * i_size, [0] * i_size - for i_curve, o_curve in ((r_curve, R_curve), (g_curve, G_curve), (b_curve, B_curve)): - for i in range(i_size): - o_curve[i] = int(i_curve[i] * (o_size - 1) + 0.5) - if clip_result: - o_curve[i] = min(max(0, o_curve[i]), (o_size - 1)) - return (R_curve, G_curve, B_curve) - - def close_c_bindings(): ''' Close all C bindings and let them free resources and close connections @@ -68,27 +53,6 @@ def close_c_bindings(): drm_manager.close() -def ramps_to_function(r, g, b): - ''' - Convert a three colour curves to a function that applies those adjustments - - @param r:int The red colour curves as [0, 65535] integers - @param g:int The green colour curves as [0, 65535] integers - @param b:int The blue colour curves as [0, 65535] integers - @return :()→void Function to invoke to apply the curves that the parameters [r, g and b] represents - ''' - r = [y / 65535 for y in r] - g = [y / 65535 for y in g] - b = [y / 65535 for y in b] - def fcurve(R_curve, G_curve, B_curve): - for curve, cur in curves(R_curve, G_curve, B_curve): - for i in range(i_size): - y = int(curve[i] * (len(cur) - 1) + 0.5) - y = min(max(0, y), len(cur) - 1) - curve[i] = cur[y] - return lambda : fcurve(r, g, b) - - def randr_get(crtc = 0, screen = 0): ''' Gets the current colour curves using the X11 extension RandR -- cgit v1.2.3-70-g09d2