From 94b88c177a99c462e760d6cd6bcdd2d9fbcd9a08 Mon Sep 17 00:00:00 2001 From: MightyPork Date: Sun, 22 Mar 2015 12:22:35 +0100 Subject: [PATCH] Added ZigZag RGB rendering function, improved HSL fn --- devel/lib/hsl.c | 13 +++++++++++++ devel/lib/hsl.h | 3 --- devel/lib/ws_rgb.h | 37 +++++++++++++++++++++++++++++++++---- 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/devel/lib/hsl.c b/devel/lib/hsl.c index 8e0bc8b..7b96c86 100644 --- a/devel/lib/hsl.c +++ b/devel/lib/hsl.c @@ -3,6 +3,19 @@ #include "colors.h" #include "hsl.h" +#ifdef HSL_LINEAR + const uint8_t FADE_128[] = { + 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, + 5, 5, 6, 6, 6, 7, 7, 8, 8, 8, 9, 10, 10, 10, 11, 12, 13, 14, + 14, 15, 16, 17, 18, 20, 21, 22, 24, 26, 27, 28, 30, 31, 32, 34, 35, 36, + 38, 39, 40, 41, 42, 44, 45, 46, 48, 49, 50, 52, 54, 56, 58, 59, 61, 63, + 65, 67, 68, 69, 71, 72, 74, 76, 78, 80, 82, 85, 88, 90, 92, 95, 98, 100, + 103, 106, 109, 112, 116, 119, 122, 125, 129, 134, 138, 142, 147, 151, + 153, 156, 160, 163, 165, 170, 175, 180, 185, 190, 195, 200, 207, 214, 218, + 221, 225, 228, 232, 234, 241, 248, 254, 255 + }; +#endif + // based on: https://github.com/lewisd32/avr-hsl2rgb xrgb_t hsl2xrgb(const hsl_t cc) { diff --git a/devel/lib/hsl.h b/devel/lib/hsl.h index b2bd5a1..528e784 100644 --- a/devel/lib/hsl.h +++ b/devel/lib/hsl.h @@ -7,9 +7,6 @@ #include "colors.h" // Define HSL_LINEAR to get more linear brightness in hsl->rgb conversion -#ifdef HSL_LINEAR -# include "linear_fade.h" -#endif // HSL data structure typedef struct { diff --git a/devel/lib/ws_rgb.h b/devel/lib/ws_rgb.h index 80223c2..9772c79 100644 --- a/devel/lib/ws_rgb.h +++ b/devel/lib/ws_rgb.h @@ -90,9 +90,38 @@ #define ws_send_rgb6_array(io, rgbs, length) __ws_send_array_proto(io_pack(io), (rgbs), (length), rgb6) // prototype for sending array. it's ugly, sorry. -#define __ws_send_array_proto(io, rgbs, length, style) do { \ - for (uint8_t __ws_tmp_sap_i = 0; __ws_tmp_sap_i < length; __ws_tmp_sap_i++) { \ - style ## _t __ws_tmp_sap2 = (rgbs)[__ws_tmp_sap_i]; \ - ws_send_ ## style(io_pack(io), __ws_tmp_sap2); \ +#define __ws_send_array_proto(io, rgbs, length, style) do { \ + for (uint8_t __ws_sap_i = 0; __ws_sap_i < length; __ws_sap_i++) { \ + style ## _t __ws_sap2 = (rgbs)[__ws_sap_i]; \ + ws_send_ ## style(io_pack(io), __ws_sap2); \ + } \ +} while(0) + +/** Send a 2D array to a zig-zag display */ +#define ws_send_xrgb_array_zigzag(io, rgbs, width, height) do { \ + int8_t __ws_sxaz_y, __ws_sxaz_x; \ + for(__ws_sxaz_y = 0; __ws_sxaz_y < (height); __ws_sxaz_y ++) { \ + for(__ws_sxaz_x = 0; __ws_sxaz_x < (width); __ws_sxaz_x++) { \ + ws_send_xrgb(io_pack(io), (rgbs)[__ws_sxaz_y][__ws_sxaz_x]); \ + } \ + __ws_sxaz_y++; \ + for(__ws_sxaz_x = (width) - 1; __ws_sxaz_x >= 0; __ws_sxaz_x--) { \ + ws_send_xrgb(io_pack(io), (rgbs)[__ws_sxaz_y][__ws_sxaz_x]); \ + } \ + } \ +} while(0) + + +/** Send a linear array to a zig-zag display as a n*m board (row-by-row) */ +#define ws_send_xrgb_array_zigzag_linear(io, rgbs, width, height) do { \ + int8_t __ws_sxazl_x, __ws_sxazl_y; \ + for(__ws_sxazl_y = 0; __ws_sxazl_y < (height); __ws_sxazl_y++) { \ + for(__ws_sxazl_x = 0; __ws_sxazl_x < (width); __ws_sxazl_x++) { \ + ws_send_xrgb(io_pack(io), (rgbs)[__ws_sxazl_y * (width) + __ws_sxazl_x]); \ + } \ + __ws_sxazl_y++; \ + for(__ws_sxazl_x = width-1; __ws_sxazl_x >=0; __ws_sxazl_x--) { \ + ws_send_xrgb(io_pack(io), (rgbs)[__ws_sxazl_y * (width) + __ws_sxazl_x]); \ + } \ } \ } while(0)