mirror of
git://projects.qi-hardware.com/ben-blinkenlights.git
synced 2024-11-05 11:10:39 +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:
parent
9c3caf282f
commit
47e5859c5b
13
ubb-la/gui.c
13
ubb-la/gui.c
@ -112,6 +112,15 @@ static SDL_Surface *surf;
|
|||||||
static int user_ref = -1;
|
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 ---------------------- */
|
/* ----- 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));
|
skip, nibbles, nibbles-skip, x0, x1, x1-x0, f, f*(nibbles-skip));
|
||||||
x = x0;
|
x = x0;
|
||||||
for (i = skip; i != nibbles; i++) {
|
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++) {
|
for (j = 0; j != 4; j++) {
|
||||||
bit = (v >> j) & 1;
|
bit = (v >> j) & 1;
|
||||||
if (bit == last[j] || last[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;
|
changes[j] = 0;
|
||||||
}
|
}
|
||||||
while (i != n) {
|
while (i != n) {
|
||||||
v = (buf[i >> 1] >> 4*(~i & 1)) & 0xf;
|
v = get_sample(buf, i);
|
||||||
for (j = 0; j != 4; j++) {
|
for (j = 0; j != 4; j++) {
|
||||||
bit = (v >> j) & 1;
|
bit = (v >> j) & 1;
|
||||||
if (bit != next[j]) {
|
if (bit != next[j]) {
|
||||||
|
Loading…
Reference in New Issue
Block a user