1
0
mirror of git://projects.qi-hardware.com/ben-blinkenlights.git synced 2024-11-16 18:05:19 +02:00

ubb-la/gui.c: move sample retrieval to new function get_sample

Better than open-coding this non-trivial formula over and over again.
This commit is contained in:
Werner Almesberger 2013-02-01 12:06:32 -03:00
parent 9c3caf282f
commit 47e5859c5b

View File

@ -112,6 +112,15 @@ static SDL_Surface *surf;
static int user_ref = -1;
/* ----- Helper functions -------------------------------------------------- */
static inline uint8_t get_sample(const uint8_t *buf, unsigned i)
{
return (buf[i >> 1] >> 4*(~i & 1)) & 0xf;
}
/* ----- SDL initialization and screen-wide functions ---------------------- */
@ -254,7 +263,7 @@ static void show_buffer_zoom_in(const uint8_t *buf, int skip, int nibbles,
skip, nibbles, nibbles-skip, x0, x1, x1-x0, f, f*(nibbles-skip));
x = x0;
for (i = skip; i != nibbles; i++) {
v = (buf[i >> 1] >> 4*(~i & 1)) & 0xf;
v = get_sample(buf, i);
for (j = 0; j != 4; j++) {
bit = (v >> j) & 1;
if (bit == last[j] || last[j] == -1) {
@ -288,7 +297,7 @@ static void show_buffer_zoom_out(const uint8_t *buf, int skip, int nibbles,
changes[j] = 0;
}
while (i != n) {
v = (buf[i >> 1] >> 4*(~i & 1)) & 0xf;
v = get_sample(buf, i);
for (j = 0; j != 4; j++) {
bit = (v >> j) & 1;
if (bit != next[j]) {