From 5c4e823b99ce422285ff7053f5073d6e6dbaacba Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 24 Feb 2014 16:10:21 +0100 Subject: improve print_curves with compact parameters + fix lower_resolution MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- info/blueshift.texinfo | 4 ++++ src/curve.py | 16 ++++++++-------- src/monitor.py | 28 ++++++++++++++++++++++------ 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/info/blueshift.texinfo b/info/blueshift.texinfo index 3afd3e3..1a6aab5 100644 --- a/info/blueshift.texinfo +++ b/info/blueshift.texinfo @@ -600,6 +600,10 @@ arguments. The monitors are indexed from zero. The screen by can be selected by adding the argument @code{screen = X}, where @code{X} is the index of the screen. +@code{print_curves} has a third optional +parameters: @code{compact}, if it is set +to @code{True}, the curves will be printed +with run-length encoding. If you want to write your own curve flushing fucntion @code{translate_to_integers} can be diff --git a/src/curve.py b/src/curve.py index c559e73..905b7dc 100644 --- a/src/curve.py +++ b/src/curve.py @@ -461,7 +461,7 @@ def manipulate(r, g = None, b = None): curve[i] = f(curve[i]) -# TODO document this elsewhere, and make it possible to have non-round x_colours +# TODO document this elsewhere def lower_resolution(x_colours = None, y_colours = None): ''' Emulates low colour resolution @@ -471,14 +471,14 @@ def lower_resolution(x_colours = None, y_colours = None): ''' if x_colours is None: x_colours = i_size if y_colours is None: y_colours = o_size - x_r = i_size / x_colours - y_r = o_size / y_colours - for curve in (r_curve, g_curve, b_curve): + x_, y_, i_ = x_colours - 1, y_colours - 1, i_size - 1 + for i_curve, o_curve in curves([0] * i_size, [0] * i_size, [0] * i_size): for i in range(i_size): - x = int(x_r * int(i / x_r)) - y = curve[x] * 2 ** 16 - y = int(y_r * int(y / y_r)) - curve[i] = y / 2 ** 16 + x = int(i * x_colours / i_size) + x = int(x * i_ / x_) + y = int(i_curve[x] * y_ + 0.5) + o_curve[i] = y / y_ + i_curve[:] = o_curve def start_over(): diff --git a/src/monitor.py b/src/monitor.py index 71343a4..67c2c16 100644 --- a/src/monitor.py +++ b/src/monitor.py @@ -178,17 +178,33 @@ def vidmode(*crtcs, screen = 0): pass # Happens on exit by TERM signal -def print_curves(*crtcs, screen = 0): +def print_curves(*crtcs, screen = 0, compact = False): ''' Prints the curves to stdout - @param crtcs:*int Dummy parameter - @param screen:int Dummy parameter + @param crtcs:*int Dummy parameter + @param screen:int Dummy parameter + @param compact:bool Whether to print in compact form ''' (R_curve, G_curve, B_curve) = translate_to_integers() - print(R_curve) - print(G_curve) - print(B_curve) + if compact: + for curve in (R_curve, G_curve, B_curve): + print('[', end = '') + last = None + count = 0 + for i in range(i_size): + if curve[i] == last: + count += 1 + else: + if last is not None: + print('%i {%i}, ' % (last, count), end = '') + last = curve[i] + count = 1 + print('%i {%i}]' % (last, count)) + else: + print(R_curve) + print(G_curve) + print(B_curve) -- cgit v1.2.3-70-g09d2