From 821d2d98207c4f01e9f5482f0f308192ee16b3f9 Mon Sep 17 00:00:00 2001 From: Bob van Loosen Date: Mon, 18 Feb 2013 18:38:41 +0100 Subject: [PATCH] added: disable dither by default, and enable it when the -s argument is passed --- src/bitx11/bitx11.cpp | 22 +++++++++++++++------- src/bitx11/bitx11.h | 1 + 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/bitx11/bitx11.cpp b/src/bitx11/bitx11.cpp index 801f714..b47d602 100644 --- a/src/bitx11/bitx11.cpp +++ b/src/bitx11/bitx11.cpp @@ -32,12 +32,13 @@ CBitX11::CBitX11(int argc, char *argv[]) m_port = 1337; m_address = NULL; m_fps = 30.0f; + m_dither = false; m_destwidth = 120; m_destheight = 48; m_debug = false; m_debugscale = 2; - const char* flags = "p:a:f:d:"; + const char* flags = "p:a:f:d:s"; int c; while ((c = getopt(argc, argv, flags)) != -1) { @@ -80,6 +81,10 @@ CBitX11::CBitX11(int argc, char *argv[]) m_debugscale = scale; } + else if (c == 's') //dither + { + m_dither = true; + } } //if no address is specified, turn on the debug window instead @@ -205,7 +210,7 @@ void CBitX11::Process() } avg /= m_destwidth * m_destheight * 2; - //quantize the planes, apply Floy-Steinberg dithering, and write into the buffer for the socket + //quantize the planes, optionally apply Floy-Steinberg dithering, and write into the buffer for the socket CTcpData data; data.SetData(":00"); for (int y = 0; y < m_destheight; y++) @@ -244,14 +249,17 @@ void CBitX11::Process() ledpos++; } - //apply Floyd-Steinberg dither quanterror = *line - quantval; *line = quantval; - line[1] += quanterror * 7 / 16; - line[m_destwidth - 1] += quanterror * 3 / 16; - line[m_destwidth] += quanterror * 5 / 16; - line[m_destwidth + 1] += quanterror / 16; + //apply Floyd-Steinberg dither + if (m_dither) + { + line[1] += quanterror * 7 / 16; + line[m_destwidth - 1] += quanterror * 3 / 16; + line[m_destwidth] += quanterror * 5 / 16; + line[m_destwidth + 1] += quanterror / 16; + } line++; } diff --git a/src/bitx11/bitx11.h b/src/bitx11/bitx11.h index 8bf9d50..658382a 100644 --- a/src/bitx11/bitx11.h +++ b/src/bitx11/bitx11.h @@ -42,6 +42,7 @@ class CBitX11 int m_port; const char* m_address; float m_fps; + bool m_dither; CTcpClientSocket m_socket;