From c801d096449be9bb329d88949967e14faea758a9 Mon Sep 17 00:00:00 2001 From: Makuna Date: Sat, 16 Apr 2016 12:52:21 -0700 Subject: [PATCH 1/2] Buffers --- examples/NeoPixelBufferCylon/Cylon.pdn | Bin 0 -> 3953 bytes examples/NeoPixelBufferCylon/CylonGrb.h | 30 ++ examples/NeoPixelBufferCylon/CylonGrbw.h | 30 ++ .../NeoPixelBufferCylon.ino | 72 +++++ examples/NeoPixelCylon/NeoPixelCylon.ino | 2 +- keywords.txt | 15 + src/NeoPixelBus.h | 16 ++ src/internal/Layouts.h | 1 + src/internal/NeoBufferContext.h | 48 ++++ src/internal/NeoColorFeatures.h | 134 ++++++++- src/internal/NeoMosaic.h | 64 ++++- src/internal/NeoPixelBuffer.h | 154 +++++++++++ src/internal/NeoPixelBufferMethods.h | 258 ++++++++++++++++++ src/internal/NeoPixelSpriteSheet.h | 163 +++++++++++ src/internal/NeoTexture.h | 95 +++++++ src/internal/NeoTiles.h | 64 ++++- src/internal/NeoTopology.h | 20 +- src/internal/RgbColor.cpp | 12 +- src/internal/RgbwColor.cpp | 13 + src/internal/RgbwColor.h | 6 +- 20 files changed, 1150 insertions(+), 47 deletions(-) create mode 100644 examples/NeoPixelBufferCylon/Cylon.pdn create mode 100644 examples/NeoPixelBufferCylon/CylonGrb.h create mode 100644 examples/NeoPixelBufferCylon/CylonGrbw.h create mode 100644 examples/NeoPixelBufferCylon/NeoPixelBufferCylon.ino create mode 100644 src/internal/NeoBufferContext.h create mode 100644 src/internal/NeoPixelBuffer.h create mode 100644 src/internal/NeoPixelBufferMethods.h create mode 100644 src/internal/NeoPixelSpriteSheet.h create mode 100644 src/internal/NeoTexture.h diff --git a/examples/NeoPixelBufferCylon/Cylon.pdn b/examples/NeoPixelBufferCylon/Cylon.pdn new file mode 100644 index 0000000000000000000000000000000000000000..e90048c37b2d3f9800d7e0e118387df1370d8838 GIT binary patch literal 3953 zcmWG=@iRWe$Y4{DlINM5n4YRoo|#gTVXI_lrlgROnwg$aVyk3iprnwKSeaT>Y^!9f zq)?n#mYNctS&|W!T2!2wpJ%INqGzdRYGGobXKY|%Y^G#qlU!O{lAmj5Q<71do1{>X zmu{<+8Rq04RBqtyo}TaM=;-Jd9Gc-8n(pZ6=mg?AhB`Y&IyyQ!yG9ln8iPe5{DOlF zJROUQO_I$5K_WqUfuV*@j*iY1S>F9XLE(_9Z@ zkipJA!J$D;VJ;Z~1ySBkF8Pk>&aNRP71~7sW+edyp}yHc{@(6J9>v}%#(s%~q5d9u zPUXqo{<&qY-pPR(ZWb;EewqHhCgJ{pZc%c+6BouZu#Lx#x9m#9yx(U8JRf-jwa!y5ncr*g$7|BAWu5F=D3Aq z2bTusIy);V=-b)o!va_z7H@V8j0}tn3=IGO|Njr785kHCc$gR%82kbfGxJJZ@=N?u zOY~e4OA>VyVDW|;Z8{3hr8y;~MX9!Vsih@Fi8(q70i{VfnaSR%l_B}rsd=_}r8zmQ zAj3sa%*;0hl$osOomv@|m{Xb>keFGNU=$qVqmWyioL`ianS>k|26_g1 z282T)$=p2AG}+Y5(9+l>)xg3sR)>~`$41A3JkP+%%)r1Pz`(#D!oa}5$pRu+85kH? zLBiO>45WswAh9SluSCGHs3@@#6p-5SnV`VtM-nK`tV$I^;+H{kH47^P1J-y3IfsJ- zL~?@C0w+5I0|UqvAm^}vEJceZkPutEZ(>${5nH@(W*&%gD$UGE;fxPTEz1OzAfUv` z!NI`+Qp(A|z;Hv1f#FFR0|PtAOmMOW$uK_|5fRSvJQc11IOw%h#OgCraVqjo!u>tWFGE;1oj15ec6mnAYAk|YzWkIT~l97@EShuZG zvb$SBQeI$bQf`=mr%Pa|ud|7%qob`YsKjLa`v3obP{6YBFfcH1!>uqhWaDLEV9-a{ zVPt6rwZlkB0b+$Q+zQ8ZM~HEsV8-#I8fU}?%A@8;##tCajkACmX9_nCRO2~1x`K*$ zh_UZs#tNYtYs@Chz`%fFtTFM%3V^aGCh0k|v&*AWFp`30#(C7G$k?8T);X^F|H0$@pPMCHK^5dha6 zJPbFK*0}IAO}()kD@>URIYfExjzq{|3O=AabI zsRl9zl-@yU2_?$aK{BAU4~lj+4Nxiw@DEc6DN4-Df!NOQpYhuN|NlWQ02>O*8el`U zL0Un11jA4rkPIllfDP3JwM1O*^@8$qASs0QN5`LUF=yLz4A$L?+fSF-? zc_kmjL{LEmR>TmFto#Q*6VH<*wzgkY9Lre#Y-fK|#bKLu?twYG;PWX)ZvS ebb}d=opnWD`(8=g6gsYq6JTSgoBY8JWC8%Od~n79 literal 0 HcmV?d00001 diff --git a/examples/NeoPixelBufferCylon/CylonGrb.h b/examples/NeoPixelBufferCylon/CylonGrb.h new file mode 100644 index 0000000..852c209 --- /dev/null +++ b/examples/NeoPixelBufferCylon/CylonGrb.h @@ -0,0 +1,30 @@ +// To recreate the data below, use the Paint.Net plugin "Arduino Progmem NeoPixel FileType" +// to save as/export the included Cylon.pdn +// Paint.Net - http://www.getpaint.net/download.html#download +// Plugin - http://forums.getpaint.net/index.php?/topic/107921-arduino-neopixel-sketch-exporter/ +// This uses Flatten, GRB, Hexadecimal +// + +const uint16_t myImageWidth = 16; +const uint16_t myImageHeight = 20; +const uint8_t PROGMEM myImage[] = { // (16 x 20) GRB in Hexadecimal + 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x3f, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x7f, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x7f, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x7f, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x7f, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x7f, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x7f, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x3f, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xff, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xff, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xff, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xff, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xff, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; diff --git a/examples/NeoPixelBufferCylon/CylonGrbw.h b/examples/NeoPixelBufferCylon/CylonGrbw.h new file mode 100644 index 0000000..9314f2f --- /dev/null +++ b/examples/NeoPixelBufferCylon/CylonGrbw.h @@ -0,0 +1,30 @@ +// To recreate the data below, use the Paint.Net plugin "Arduino Progmem NeoPixel FileType" +// to save as/export the included Cylon.pdn +// Paint.Net - http://www.getpaint.net/download.html#download +// Plugin - http://forums.getpaint.net/index.php?/topic/107921-arduino-neopixel-sketch-exporter/ +// This uses Flatten, GRBW, Hexadecimal +// + +const uint16_t myImageWidth = 16; +const uint16_t myImageHeight = 20; +const uint8_t PROGMEM myImage[] = { // (16 x 20) GRBW in Hexadecimal + 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x3f, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; diff --git a/examples/NeoPixelBufferCylon/NeoPixelBufferCylon.ino b/examples/NeoPixelBufferCylon/NeoPixelBufferCylon.ino new file mode 100644 index 0000000..d343750 --- /dev/null +++ b/examples/NeoPixelBufferCylon/NeoPixelBufferCylon.ino @@ -0,0 +1,72 @@ +// NeoPixelBufferCylon +// This example will move a Cylon Red Eye back and forth across the +// the full collection of pixels on the strip. +// +// This will demonstrate the use of the NeoPixelVerticalSpriteSheet +// + +#include +#include + +// The actual image is contained in the data structure in one of the Cylon*.h files +// You will need to use the one that has the same color feature as your NeoPixelBus +// There are two provided, but you can create your own easily enough using +// free versions of Paint.Net and the plugin +#include "CylonGrb.h" +typedef NeoGrbFeature MyPixelColorFeature; + +// #include "CylonGrbw.h" +// typedef NeoGrbwFeature MyPixelColorFeature; + +const uint16_t PixelCount = 16; // the sample images are meant for 16 pixels +const uint16_t PixelPin = 2; +const uint16_t AnimCount = 1; // we only need one + +NeoPixelBus strip(PixelCount, PixelPin); +NeoPixelAnimator animations(AnimCount); // NeoPixel animation management object + +// sprite sheet stored in progmem using the same pixel feature as the NeoPixelBus +NeoPixelVerticalSpriteSheet> spriteSheet( + myImageWidth, // image width and sprite width since its vertical sprite sheet + myImageHeight, // image height + 1, // sprite is only one pixel high + myImage); + +uint16_t indexSprite; + +void LoopAnimUpdate(const AnimationParam& param) +{ + // wait for this animation to complete, + // we are using it as a timer of sorts + if (param.state == AnimationState_Completed) + { + // done, time to restart this position tracking animation/timer + animations.RestartAnimation(param.index); + + // draw the next frame in the sprite + spriteSheet.Blt(strip, 0, indexSprite); + indexSprite = (indexSprite + 1) % myImageHeight; // increment and wrap + } +} + +void setup() +{ + strip.Begin(); + strip.Show(); + + indexSprite = 0; + + // we use the index 0 animation to time how often we rotate all the pixels + animations.StartAnimation(0, 60, LoopAnimUpdate); +} + + +void loop() +{ + // this is all that is needed to keep it running + // and avoiding using delay() is always a good thing for + // any timing related routines + animations.UpdateAnimations(); + strip.Show(); +} + diff --git a/examples/NeoPixelCylon/NeoPixelCylon.ino b/examples/NeoPixelCylon/NeoPixelCylon.ino index 4ffd027..71b230d 100644 --- a/examples/NeoPixelCylon/NeoPixelCylon.ino +++ b/examples/NeoPixelCylon/NeoPixelCylon.ino @@ -1,5 +1,5 @@ // NeoPixelCylon -// This example will move a Cylong Red Eye back and forth across the +// This example will move a Cylon Red Eye back and forth across the // the full collection of pixels on the strip. // // This will demonstrate the use of the NeoEase animation ease methods; that provide diff --git a/keywords.txt b/keywords.txt index 2fc6e10..8c97b01 100644 --- a/keywords.txt +++ b/keywords.txt @@ -59,6 +59,12 @@ NeoHueBlendShortestDistance KEYWORD1 NeoHueBlendLongestDistance KEYWORD1 NeoHueBlendClockwiseDirection KEYWORD1 NeoHueBlendCounterClockwiseDirection KEYWORD1 +NeoBufferContext KEYWORD1 +LayoutMapCallback KEYWORD1 +NeoPixelBufferMethod KEYWORD1 +NeoPixelBufferProgmemMethod KEYWORD1 +NeoPixelBuffer KEYWORD1 +NeoPixelVerticalSpriteSheet KEYWORD1 ####################################### # Methods and Functions (KEYWORD2) @@ -121,10 +127,17 @@ CircularOut KEYWORD2 CircularInOut KEYWORD2 Gamma KEYWORD2 Map KEYWORD2 +MapProbe KEYWORD2 getWidth KEYWORD2 getHeight KEYWORD2 TopologyHint KEYWORD2 Correct KEYWORD2 +SpriteWidth KEYWORD2 +SpriteHeight KEYWORD2 +SpriteCount KEYWORD2 +Blt KEYWORD2 +Width KEYWORD2 +Height KEYWORD2 ####################################### # Constants (LITERAL1) @@ -141,3 +154,5 @@ AnimationState_Completed LITERAL1 NeoTopologyHint_FirstOnPanel LITERAL1 NeoTopologyHint_InPanel LITERAL1 NeoTopologyHint_LastOnPanel LITERAL1 +NeoTopologyHint_OutOfBounds LITERAL1 +PixelIndex_OutOfBounds LITERAL1 \ No newline at end of file diff --git a/src/NeoPixelBus.h b/src/NeoPixelBus.h index ee49421..8f9857f 100644 --- a/src/NeoPixelBus.h +++ b/src/NeoPixelBus.h @@ -40,6 +40,11 @@ License along with NeoPixel. If not, see #include "internal/NeoTiles.h" #include "internal/NeoMosaic.h" +#include "internal/NeoBufferContext.h" +#include "internal/NeoPixelBufferMethods.h" +#include "internal/NeoPixelBuffer.h" +#include "internal/NeoPixelSpriteSheet.h" + #include "internal/NeoEase.h" #include "internal/NeoGamma.h" @@ -57,6 +62,9 @@ License along with NeoPixel. If not, see #error "Platform Currently Not Supported, please add an Issue at Github/Makuna/NeoPixelBus" #endif + + + // '_state' flags for internal state #define NEO_DIRTY 0x80 // a change was made to pixel data that requires a show @@ -77,6 +85,12 @@ public: } + operator NeoBufferContext() + { + Dirty(); // we assume you are playing with bits + return NeoBufferContext(_method.getPixels(), _method.getPixelsSize()); + } + void Begin() { _method.Initialize(); @@ -267,7 +281,9 @@ public: Dirty(); } } + + private: const uint16_t _countPixels; // Number of RGB LEDs in strip diff --git a/src/internal/Layouts.h b/src/internal/Layouts.h index 9a3184a..0df0049 100644 --- a/src/internal/Layouts.h +++ b/src/internal/Layouts.h @@ -28,6 +28,7 @@ License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ +const uint16_t PixelIndex_OutOfBounds = 0xffff; //----------------------------------------------------------------------------- // RowMajor diff --git a/src/internal/NeoBufferContext.h b/src/internal/NeoBufferContext.h new file mode 100644 index 0000000..8b57344 --- /dev/null +++ b/src/internal/NeoBufferContext.h @@ -0,0 +1,48 @@ +/*------------------------------------------------------------------------- +NeoPixel library + +Written by Michael C. Miller. + +I invest time and resources providing this open source code, +please support me by dontating (see https://github.com/Makuna/NeoPixelBus) + +------------------------------------------------------------------------- +This file is part of the Makuna/NeoPixelBus library. + +NeoPixelBus is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation, either version 3 of +the License, or (at your option) any later version. + +NeoPixelBus is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with NeoPixel. If not, see +. +-------------------------------------------------------------------------*/ +#pragma once + +// This is used to allow a template classes that share common buffer concept to +// be able to pass that common information to functions +// The template classes just need to expose a conversion operator to this type +template struct NeoBufferContext +{ + NeoBufferContext(uint8_t* pixels, + size_t sizePixels) : + Pixels(pixels), + SizePixels(sizePixels) + { + } + + uint16_t PixelCount() const + { + return SizePixels / T_COLOR_FEATURE::PixelSize; + }; + + uint8_t* Pixels; + const size_t SizePixels; + +}; \ No newline at end of file diff --git a/src/internal/NeoColorFeatures.h b/src/internal/NeoColorFeatures.h index 36f0510..9922363 100644 --- a/src/internal/NeoColorFeatures.h +++ b/src/internal/NeoColorFeatures.h @@ -35,8 +35,12 @@ public: { return pPixels + indexPixel * PixelSize; } + static const uint8_t* getPixelAddress(const uint8_t* pPixels, uint16_t indexPixel) + { + return pPixels + indexPixel * PixelSize; + } - static void replicatePixel(uint8_t* pPixelDest, uint8_t* pPixelSrc, uint16_t count) + static void replicatePixel(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) { uint8_t* pEnd = pPixelDest + (count * PixelSize); while (pPixelDest < pEnd) @@ -47,7 +51,7 @@ public: } } - static void movePixelsInc(uint8_t* pPixelDest, uint8_t* pPixelSrc, uint16_t count) + static void movePixelsInc(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) { uint8_t* pEnd = pPixelDest + (count * PixelSize); while (pPixelDest < pEnd) @@ -58,10 +62,22 @@ public: } } - static void movePixelsDec(uint8_t* pPixelDest, uint8_t* pPixelSrc, uint16_t count) + static void movePixelsInc_P(uint8_t* pPixelDest, PGM_VOID_P pPixelSrc, uint16_t count) + { + uint8_t* pEnd = pPixelDest + (count * PixelSize); + const uint8_t* pSrc = (const uint8_t*)pPixelSrc; + while (pPixelDest < pEnd) + { + *pPixelDest++ = pgm_read_byte(pSrc++); + *pPixelDest++ = pgm_read_byte(pSrc++); + *pPixelDest++ = pgm_read_byte(pSrc++); + } + } + + static void movePixelsDec(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) { uint8_t* pDestBack = pPixelDest + (count * PixelSize); - uint8_t* pSrcBack = pPixelSrc + (count * PixelSize); + const uint8_t* pSrcBack = pPixelSrc + (count * PixelSize); while (pDestBack > pPixelDest) { *--pDestBack = *--pSrcBack; @@ -82,11 +98,15 @@ public: { return pPixels + indexPixel * PixelSize; } + static const uint8_t* getPixelAddress(const uint8_t* pPixels, uint16_t indexPixel) + { + return pPixels + indexPixel * PixelSize; + } - static void replicatePixel(uint8_t* pPixelDest, uint8_t* pPixelSrc, uint16_t count) + static void replicatePixel(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) { uint32_t* pDest = (uint32_t*)pPixelDest; - uint32_t* pSrc = (uint32_t*)pPixelSrc; + const uint32_t* pSrc = (const uint32_t*)pPixelSrc; uint32_t* pEnd = pDest + count; while (pDest < pEnd) @@ -95,10 +115,10 @@ public: } } - static void movePixelsInc(uint8_t* pPixelDest, uint8_t* pPixelSrc, uint16_t count) + static void movePixelsInc(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) { uint32_t* pDest = (uint32_t*)pPixelDest; - uint32_t* pSrc = (uint32_t*)pPixelSrc; + const uint32_t* pSrc = (uint32_t*)pPixelSrc; uint32_t* pEnd = pDest + count; while (pDest < pEnd) { @@ -106,12 +126,23 @@ public: } } - static void movePixelsDec(uint8_t* pPixelDest, uint8_t* pPixelSrc, uint16_t count) + static void movePixelsInc_P(uint8_t* pPixelDest, PGM_VOID_P pPixelSrc, uint16_t count) { uint32_t* pDest = (uint32_t*)pPixelDest; - uint32_t* pSrc = (uint32_t*)pPixelSrc; + const uint32_t* pSrc = (const uint32_t*)pPixelSrc; + uint32_t* pEnd = pDest + count; + while (pDest < pEnd) + { + *pDest++ = pgm_read_dword(pSrc++); + } + } + + static void movePixelsDec(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint32_t* pDest = (uint32_t*)pPixelDest; + const uint32_t* pSrc = (uint32_t*)pPixelSrc; uint32_t* pDestBack = pDest + count; - uint32_t* pSrcBack = pSrc + count; + const uint32_t* pSrcBack = pSrc + count; while (pDestBack > pDest) { *--pDestBack = *--pSrcBack; @@ -144,6 +175,19 @@ public: return color; } + + static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel); + + color.G = pgm_read_byte(p++); + color.R = pgm_read_byte(p++); + color.B = pgm_read_byte(p); + + return color; + } + }; class NeoGrbwFeature : public Neo4Elements @@ -172,6 +216,20 @@ public: return color; } + + static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel); + + color.G = pgm_read_byte(p++); + color.R = pgm_read_byte(p++); + color.B = pgm_read_byte(p++); + color.W = pgm_read_byte(p); + + return color; + } + }; class NeoRgbwFeature : public Neo4Elements @@ -199,6 +257,20 @@ public: return color; } + + static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel); + + color.R = pgm_read_byte(p++); + color.G = pgm_read_byte(p++); + color.B = pgm_read_byte(p++); + color.W = pgm_read_byte(p); + + return color; + } + }; class NeoRgbFeature : public Neo3Elements @@ -224,6 +296,19 @@ public: return color; } + + static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel); + + color.R = pgm_read_byte(p++); + color.G = pgm_read_byte(p++); + color.B = pgm_read_byte(p); + + return color; + } + }; class NeoBrgFeature : public Neo3Elements @@ -249,6 +334,19 @@ public: return color; } + + static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel); + + color.B = pgm_read_byte(p++); + color.R = pgm_read_byte(p++); + color.G = pgm_read_byte(p); + + return color; + } + }; class NeoRbgFeature : public Neo3Elements @@ -274,4 +372,18 @@ public: return color; } + + + static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel); + + color.R = pgm_read_byte(p++); + color.B = pgm_read_byte(p++); + color.G = pgm_read_byte(p); + + return color; + } + }; diff --git a/src/internal/NeoMosaic.h b/src/internal/NeoMosaic.h index f023d84..551bd53 100644 --- a/src/internal/NeoMosaic.h +++ b/src/internal/NeoMosaic.h @@ -53,8 +53,29 @@ public: { } - uint16_t Map(uint16_t x, uint16_t y) const + uint16_t Map(int16_t x, int16_t y) const { + uint16_t totalWidth = getWidth(); + uint16_t totalHeight = getHeight(); + + if (x >= totalWidth) + { + x = totalWidth - 1; + } + else if (x < 0) + { + x = 0; + } + + if (y >= totalHeight) + { + y = totalHeight - 1; + } + else if (y < 0) + { + y = 0; + } + uint16_t localIndex; uint16_t tileOffset; @@ -63,8 +84,34 @@ public: return localIndex + tileOffset; } - NeoTopologyHint TopologyHint(uint16_t x, uint16_t y) const + uint16_t MapProbe(int16_t x, int16_t y) const { + uint16_t totalWidth = getWidth(); + uint16_t totalHeight = getHeight(); + + if (x < 0 || x >= totalWidth || y < 0 || y >= totalHeight) + { + return totalWidth * totalHeight; // count, out of bounds + } + + uint16_t localIndex; + uint16_t tileOffset; + + calculate(x, y, &localIndex, &tileOffset); + + return localIndex + tileOffset; + } + + NeoTopologyHint TopologyHint(int16_t x, int16_t y) const + { + uint16_t totalWidth = getWidth(); + uint16_t totalHeight = getHeight(); + + if (x < 0 || x >= totalWidth || y < 0 || y >= totalHeight) + { + return NeoTopologyHint_OutOfBounds; + } + uint16_t localIndex; uint16_t tileOffset; NeoTopologyHint result; @@ -105,19 +152,6 @@ private: void calculate(uint16_t x, uint16_t y, uint16_t* pLocalIndex, uint16_t* pTileOffset) const { - uint16_t totalWidth = getWidth(); - uint16_t totalHeight = getHeight(); - - if (x >= totalWidth) - { - x = totalWidth - 1; - } - - if (y >= totalHeight) - { - y = totalHeight - 1; - } - uint16_t tileX = x / _topoWidth; uint16_t topoX = x % _topoWidth; diff --git a/src/internal/NeoPixelBuffer.h b/src/internal/NeoPixelBuffer.h new file mode 100644 index 0000000..216e519 --- /dev/null +++ b/src/internal/NeoPixelBuffer.h @@ -0,0 +1,154 @@ +/*------------------------------------------------------------------------- +NeoPixel library + +Written by Michael C. Miller. + +I invest time and resources providing this open source code, +please support me by dontating (see https://github.com/Makuna/NeoPixelBus) + +------------------------------------------------------------------------- +This file is part of the Makuna/NeoPixelBus library. + +NeoPixelBus is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation, either version 3 of +the License, or (at your option) any later version. + +NeoPixelBus is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with NeoPixel. If not, see +. +-------------------------------------------------------------------------*/ +#pragma once + +template class NeoPixelBuffer +{ +public: + NeoPixelBuffer(uint16_t width, + uint16_t height, + PGM_VOID_P pixels) : + _method(width, height, pixels) + { + } + + operator NeoBufferContext() + { + return _method; + } + + uint16_t PixelCount() const + { + return _method.PixelCount(); + }; + + uint16_t Width() const + { + return _method.Width(); + }; + + uint16_t Height() const + { + return _method.Height(); + }; + + void SetPixelColor(uint16_t indexSprite, + int16_t x, + int16_t y, + typename T_BUFFER_METHOD::ColorObject color) + { + _method.SetPixelColor(pixelIndex(x, y), color); + }; + + typename T_BUFFER_METHOD::ColorObject GetPixelColor(uint16_t indexSprite, + int16_t x, + int16_t y) const + { + return _method.GetPixelColor(pixelIndex(x, y)); + }; + + void ClearTo(typename T_BUFFER_METHOD::ColorObject color) + { + _method.ClearTo(color); + }; + + void Blt(NeoBufferContext destBuffer, + uint16_t indexPixel) + { + uint16_t destPixelCount = destBuffer.PixelCount(); + // validate indexPixel + if (indexPixel >= destPixelCount) + { + return; + } + + // calc how many we can copy + uint16_t copyCount = destPixelCount - indexPixel; + uint16_t srcPixelCount = PixelCount(); + if (copyCount > srcPixelCount) + { + copyCount = srcPixelCount; + } + + uint8_t* pDest = T_BUFFER_METHOD::ColorFeature::getPixelAddress(destBuffer.Pixels, indexPixel); + _method.CopyPixels(pDest, _method.Pixels(), copyCount); + } + + void Blt(NeoBufferContext destBuffer, + int16_t xDest, + int16_t yDest, + int16_t xSrc, + int16_t ySrc, + int16_t wSrc, + int16_t hSrc, + LayoutMapCallback layoutMap) + { + uint16_t destPixelCount = destBuffer.PixelCount(); + + for (int16_t y = 0; y < hSrc; y++) + { + for (int16_t x = 0; x < wSrc; x++) + { + uint16_t indexDest = layoutMap(xDest + x, yDest + y); + + if (indexDest < destPixelCount) + { + const uint8_t* pSrc = T_BUFFER_METHOD::ColorFeature::getPixelAddress(_method.Pixels(), pixelIndex(xSrc + x, ySrc + y)); + uint8_t* pDest = T_BUFFER_METHOD::ColorFeature::getPixelAddress(destBuffer.Pixels, indexDest); + + _method.CopyPixels(pDest, pSrc, 1); + } + } + } + } + + void Blt(NeoBufferContext destBuffer, + int16_t xDest, + int16_t yDest, + LayoutMapCallback layoutMap) + { + Blt(destBuffer, xDest, yDest, 0, 0, Width(), Height(), layoutMap); + } + +private: + T_BUFFER_METHOD _method; + + uint16_t pixelIndex( + int16_t x, + int16_t y) + { + uint16_t result = PixelIndex_OutOfBounds; + + if (x >= 0 && + x < Width() && + y >= 0 && + y < Height()) + { + result = x + y * Width(); + } + return result; + } +}; \ No newline at end of file diff --git a/src/internal/NeoPixelBufferMethods.h b/src/internal/NeoPixelBufferMethods.h new file mode 100644 index 0000000..fffdaee --- /dev/null +++ b/src/internal/NeoPixelBufferMethods.h @@ -0,0 +1,258 @@ +/*------------------------------------------------------------------------- +NeoPixel library + +Written by Michael C. Miller. + +I invest time and resources providing this open source code, +please support me by dontating (see https://github.com/Makuna/NeoPixelBus) + +------------------------------------------------------------------------- +This file is part of the Makuna/NeoPixelBus library. + +NeoPixelBus is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation, either version 3 of +the License, or (at your option) any later version. + +NeoPixelBus is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with NeoPixel. If not, see +. +-------------------------------------------------------------------------*/ + +#pragma once + + +#ifdef ARDUINO_ARCH_AVR + +typedef uint16_t(*LayoutMapCallback)(int16_t x, int16_t y); + +#else + +#undef max +#undef min +#include +typedef std::function LayoutMapCallback; + +#endif + +template class NeoPixelBufferMethod +{ +public: + NeoPixelBufferMethod(uint16_t width, uint16_t height, PGM_VOID_P pixels = NULL) : + _width(width), + _height(height) + { + _pixels = (uint8_t*)malloc(PixelsSize()); + if (pixels) + { + // copy from progmem to initialize + T_COLOR_FEATURE::movePixelsInc_P(_pixels, pixels, PixelCount()); + } + } + + operator NeoBufferContext() + { + return NeoBufferContext(Pixels(), PixelsSize()); + } + + uint8_t* Pixels() const + { + return _pixels; + }; + + size_t PixelsSize() const + { + return PixelSize() * PixelCount(); + }; + + size_t PixelSize() const + { + return T_COLOR_FEATURE::PixelSize; + }; + + uint16_t PixelCount() const + { + return _width * _height; + }; + + uint16_t Width() const + { + return _width; + }; + + uint16_t Height() const + { + return _height; + }; + + void SetPixelColor(uint16_t indexPixel, typename T_COLOR_FEATURE::ColorObject color) + { + if (indexPixel < PixelCount()) + { + T_COLOR_FEATURE::applyPixelColor(_pixels, indexPixel, color); + } + }; + + void SetPixelColor(int16_t x, int16_t y, typename T_COLOR_FEATURE::ColorObject color) + { + if (x < 0 || x >= _width || y < 0 || y >= _height) + { + return; + } + + uint16_t indexPixel = x + y * _width; + T_COLOR_FEATURE::applyPixelColor(_pixels, indexPixel, color); + }; + + typename T_COLOR_FEATURE::ColorObject GetPixelColor(uint16_t indexPixel) const + { + if (indexPixel >= PixelCount()) + { + // Pixel # is out of bounds, this will get converted to a + // color object type initialized to 0 (black) + return 0; + } + + return T_COLOR_FEATURE::retrievePixelColor(_pixels, indexPixel); + }; + + typename T_COLOR_FEATURE::ColorObject GetPixelColor(int16_t x, int16_t y) const + { + if (x < 0 || x >= _width || y < 0 || y >= _height) + { + // Pixel # is out of bounds, this will get converted to a + // color object type initialized to 0 (black) + return 0; + } + + uint16_t indexPixel = x + y * _width; + return T_COLOR_FEATURE::retrievePixelColor(_pixels, indexPixel); + }; + + void ClearTo(typename T_COLOR_FEATURE::ColorObject color) + { + uint8_t temp[T_COLOR_FEATURE::PixelSize]; + + T_COLOR_FEATURE::applyPixelColor(temp, 0, color); + + T_COLOR_FEATURE::replicatePixel(_pixels, temp, PixelCount()); + }; + + void CopyPixels(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + T_COLOR_FEATURE::movePixelsInc(pPixelDest, pPixelSrc, count); + } + + typedef typename T_COLOR_FEATURE::ColorObject ColorObject; + typedef T_COLOR_FEATURE ColorFeature; + +private: + const uint16_t _width; + const uint16_t _height; + uint8_t* _pixels; +}; + +template class NeoPixelBufferProgmemMethod +{ +public: + NeoPixelBufferProgmemMethod(uint16_t width, uint16_t height, PGM_VOID_P pixels) : + _width(width), + _height(height), + _pixels(pixels) + { + } + + operator NeoBufferContext() + { + return NeoBufferContext(Pixels(), PixelsSize()); + } + + uint8_t* Pixels() const + { + return (uint8_t*)_pixels; + }; + + size_t PixelsSize() const + { + return PixelSize() * PixelCount(); + }; + + size_t PixelSize() const + { + return T_COLOR_FEATURE::PixelSize; + }; + + uint16_t PixelCount() const + { + return _width * _height; + }; + + uint16_t Width() const + { + return _width; + }; + + uint16_t Height() const + { + return _height; + }; + + void SetPixelColor(uint16_t indexPixel, typename T_COLOR_FEATURE::ColorObject color) + { + // PROGMEM is read only, this will do nothing + }; + + void SetPixelColor(uint16_t x, uint16_t y, typename T_COLOR_FEATURE::ColorObject color) + { + // PROGMEM is read only, this will do nothing + }; + + typename T_COLOR_FEATURE::ColorObject GetPixelColor(uint16_t indexPixel) const + { + if (indexPixel >= PixelCount()) + { + // Pixel # is out of bounds, this will get converted to a + // color object type initialized to 0 (black) + return 0; + } + + return T_COLOR_FEATURE::retrievePixelColor_P(_pixels, indexPixel); + }; + + typename T_COLOR_FEATURE::ColorObject GetPixelColor(int16_t x, int16_t y) const + { + if (x < 0 || x >= _width || y < 0 || y >= _height) + { + // Pixel # is out of bounds, this will get converted to a + // color object type initialized to 0 (black) + return 0; + } + + uint16_t indexPixel = x + y * _width; + return T_COLOR_FEATURE::retrievePixelColor_P(_pixels, indexPixel); + }; + + void ClearTo(typename T_COLOR_FEATURE::ColorObject color) + { + // PROGMEM is read only, this will do nothing + }; + + void CopyPixels(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + T_COLOR_FEATURE::movePixelsInc_P(pPixelDest, pPixelSrc, count); + } + + typedef typename T_COLOR_FEATURE::ColorObject ColorObject; + typedef T_COLOR_FEATURE ColorFeature; + +private: + const uint16_t _width; + const uint16_t _height; + PGM_VOID_P _pixels; +}; + diff --git a/src/internal/NeoPixelSpriteSheet.h b/src/internal/NeoPixelSpriteSheet.h new file mode 100644 index 0000000..fe6c8f3 --- /dev/null +++ b/src/internal/NeoPixelSpriteSheet.h @@ -0,0 +1,163 @@ +/*------------------------------------------------------------------------- +NeoPixel library + +Written by Michael C. Miller. + +I invest time and resources providing this open source code, +please support me by dontating (see https://github.com/Makuna/NeoPixelBus) + +------------------------------------------------------------------------- +This file is part of the Makuna/NeoPixelBus library. + +NeoPixelBus is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation, either version 3 of +the License, or (at your option) any later version. + +NeoPixelBus is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with NeoPixel. If not, see +. +-------------------------------------------------------------------------*/ +#pragma once + + +template class NeoPixelVerticalSpriteSheet +{ +public: + NeoPixelVerticalSpriteSheet(uint16_t width, + uint16_t height, + uint16_t spriteHeight, + PGM_VOID_P pixels) : + _method(width, height, pixels), + _spriteHeight(spriteHeight), + _spriteCount(height / spriteHeight) + { + } + + operator NeoBufferContext() + { + return _method; + } + + uint16_t SpriteWidth() const + { + return _method.Width(); + }; + + uint16_t SpriteHeight() const + { + return _spriteHeight; + }; + + uint16_t SpriteCount() const + { + return _spriteCount; + } + + void SetPixelColor(uint16_t indexSprite, + int16_t x, + int16_t y, + typename T_BUFFER_METHOD::ColorObject color) + { + _method.SetPixelColor(pixelIndex(indexSprite, x, y), color); + }; + + typename T_BUFFER_METHOD::ColorObject GetPixelColor(uint16_t indexSprite, + int16_t x, + int16_t y) const + { + return _method.GetPixelColor(pixelIndex(indexSprite, x, y)); + }; + + void ClearTo(typename T_BUFFER_METHOD::ColorObject color) + { + _method.ClearTo(color); + }; + + void Blt(NeoBufferContext destBuffer, + uint16_t indexPixel, + uint16_t indexSprite) + { + uint16_t destPixelCount = destBuffer.PixelCount(); + // validate indexPixel + if (indexPixel >= destPixelCount) + { + return; + } + + // validate indexSprite + if (indexSprite >= _spriteCount) + { + return; + } + // calc how many we can copy + uint16_t copyCount = destPixelCount - indexPixel; + + if (copyCount > SpriteWidth()) + { + copyCount = SpriteWidth(); + } + + uint8_t* pDest = T_BUFFER_METHOD::ColorFeature::getPixelAddress(destBuffer.Pixels, indexPixel); + const uint8_t* pSrc = T_BUFFER_METHOD::ColorFeature::getPixelAddress(_method.Pixels(), pixelIndex(indexSprite, 0, 0)); + _method.CopyPixels(pDest, pSrc, copyCount); + } + + void Blt(NeoBufferContext destBuffer, + int16_t x, + int16_t y, + uint16_t indexSprite, + LayoutMapCallback layoutMap) + { + if (indexSprite >= _spriteCount) + { + return; + } + uint16_t destPixelCount = destBuffer.PixelCount(); + + for (int16_t srcY = 0; srcY < SpriteHeight(); srcY++) + { + for (int16_t srcX = 0; srcX < SpriteWidth(); srcX++) + { + uint16_t indexDest = layoutMap(srcX + x, srcY + y); + + if (indexDest < destPixelCount) + { + const uint8_t* pSrc = T_BUFFER_METHOD::ColorFeature::getPixelAddress(_method.Pixels(), pixelIndex(indexSprite, srcX, srcY)); + uint8_t* pDest = T_BUFFER_METHOD::ColorFeature::getPixelAddress(destBuffer.Pixels, indexDest); + + _method.CopyPixels(pDest, pSrc, 1); + } + } + } + + } + +private: + T_BUFFER_METHOD _method; + + const uint16_t _spriteHeight; + const uint16_t _spriteCount; + + uint16_t pixelIndex(uint16_t indexSprite, + int16_t x, + int16_t y) + { + uint16_t result = PixelIndex_OutOfBounds; + + if (indexSprite < _spriteCount && + x >= 0 && + x < SpriteWidth() && + y >= 0 && + y < SpriteHeight()) + { + result = x + y * SpriteWidth() + indexSprite * _spriteHeight * SpriteWidth(); + } + return result; + } +}; \ No newline at end of file diff --git a/src/internal/NeoTexture.h b/src/internal/NeoTexture.h new file mode 100644 index 0000000..a304d60 --- /dev/null +++ b/src/internal/NeoTexture.h @@ -0,0 +1,95 @@ +/*------------------------------------------------------------------------- +Teture provides a texture object that can contain a matrix of Color +values + +Written by Michael C. Miller. + +I invest time and resources providing this open source code, +please support me by dontating (see https://github.com/Makuna/NeoPixelBus) + +------------------------------------------------------------------------- +This file is part of the Makuna/NeoPixelBus library. + +NeoPixelBus is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation, either version 3 of +the License, or (at your option) any later version. + +NeoPixelBus is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with NeoPixel. If not, see +. +-------------------------------------------------------------------------*/ +#pragma once + +NOTES: +Where does the data come from? + * Loaded by external routine + + + +template class Texture +{ +public: + Texture(uint16_t width, uint16_t height, T_COLOR* pixels) : + _width(width), + _height(height), + _pixels(pixels) + { + }; + + const T_COLOR* Blend(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, float progress) + { + x1 = constrain(x1, 0, _width - 1); + y1 = constrain(y1, 0, _height - 1); + x2 = constrain(x2, 0, _width - 1); + y2 = constrain(y2, 0, _height - 1); + + // calc cordinate of the four nearby pixels + // first lerp our cordinates + float xf = (static_cast(x2) - x1) * progress + x1; + float yf = (static_cast(y2) - y1) * progress + y1; + + uint16_t x = static_cast(xf); // truncates to lower uint + uint16_t y = static_cast(yf); // truncates to lower uint + uint16_t xn = x + 1; + uint16_t yn = y + 1; + + T_COLOR c00 = PixelAt(x, y); + T_COLOR c01 = PixelAt(x, yn); + T_COLOR c10 = PixelAt(xn, y); + T_COLOR c11 = PixelAt(xn, yn); + + // unitize progress cordinate to these pixels + xf -= x; + yf -= y; + + return T_COLOR::BilinearBlend(c00, c01, c10, c11, xf, yf); + }; + + const T_COLOR& PixelAt(uint16_t x, uint16_t y) + { + uint16_t xSafe = constrain(x, 0, _width - 1); + uint16_t ySafe = constrain(y, 0, _height - 1); + return pixelAt(xSafe, ySafe); + } + +private: + const uint16_t _width; + const uint16_t _height; + const T_COLOR* _pixels; + + const T_COLOR& pixelAt(uint16_t x, uint16_t y) + { + return *(_pixels + x + y * _width); + } +}; + +typedef Texture RgbTexture; +typedef Texture RgbwTexture; +typedef Texture HtmlTexture; + diff --git a/src/internal/NeoTiles.h b/src/internal/NeoTiles.h index 8babebd..2c0ca83 100644 --- a/src/internal/NeoTiles.h +++ b/src/internal/NeoTiles.h @@ -47,8 +47,29 @@ public: { } - uint16_t Map(uint16_t x, uint16_t y) const + uint16_t Map(int16_t x, int16_t y) const { + uint16_t totalWidth = getWidth(); + uint16_t totalHeight = getHeight(); + + if (x >= totalWidth) + { + x = totalWidth - 1; + } + else if (x < 0) + { + x = 0; + } + + if (y >= totalHeight) + { + y = totalHeight - 1; + } + else if (y < 0) + { + y = 0; + } + uint16_t localIndex; uint16_t tileOffset; @@ -57,8 +78,34 @@ public: return localIndex + tileOffset; } - NeoTopologyHint TopologyHint(uint16_t x, uint16_t y) const + uint16_t MapProbe(int16_t x, int16_t y) const { + uint16_t totalWidth = getWidth(); + uint16_t totalHeight = getHeight(); + + if (x < 0 || x >= totalWidth || y < 0 || y >= totalHeight) + { + return totalWidth * totalHeight; // count, out of bounds + } + + uint16_t localIndex; + uint16_t tileOffset; + + calculate(x, y, &localIndex, &tileOffset); + + return localIndex + tileOffset; + } + + NeoTopologyHint TopologyHint(int16_t x, int16_t y) const + { + uint16_t totalWidth = getWidth(); + uint16_t totalHeight = getHeight(); + + if (x < 0 || x >= totalWidth || y < 0 || y >= totalHeight) + { + return NeoTopologyHint_OutOfBounds; + } + uint16_t localIndex; uint16_t tileOffset; NeoTopologyHint result; @@ -98,19 +145,6 @@ private: void calculate(uint16_t x, uint16_t y, uint16_t* pLocalIndex, uint16_t* pTileOffset) const { - uint16_t totalWidth = getWidth(); - uint16_t totalHeight = getHeight(); - - if (x >= totalWidth) - { - x = totalWidth - 1; - } - - if (y >= totalHeight) - { - y = totalHeight - 1; - } - uint16_t tileX = x / _topo.getWidth(); uint16_t topoX = x % _topo.getWidth(); diff --git a/src/internal/NeoTopology.h b/src/internal/NeoTopology.h index f4ec63a..224c1db 100644 --- a/src/internal/NeoTopology.h +++ b/src/internal/NeoTopology.h @@ -32,6 +32,7 @@ enum NeoTopologyHint NeoTopologyHint_FirstOnPanel, NeoTopologyHint_InPanel, NeoTopologyHint_LastOnPanel, + NeoTopologyHint_OutOfBounds }; template class NeoTopology @@ -44,16 +45,33 @@ public: } - uint16_t Map(uint16_t x, uint16_t y) const + uint16_t Map(int16_t x, int16_t y) const { if (x >= _width) { x = _width - 1; } + else if (x < 0) + { + x = 0; + } if (y >= _height) { y = _height - 1; } + else if (y < 0) + { + y = 0; + } + return T_LAYOUT::Map(_width, _height, x, y); + } + + uint16_t MapProbe(int16_t x, int16_t y) const + { + if (x < 0 || x >= _width || y < 0 || y >= _height) + { + return _width * _height; // count, out of bounds + } return T_LAYOUT::Map(_width, _height, x, y); } diff --git a/src/internal/RgbColor.cpp b/src/internal/RgbColor.cpp index 261c920..29ae434 100644 --- a/src/internal/RgbColor.cpp +++ b/src/internal/RgbColor.cpp @@ -48,10 +48,16 @@ static float _CalcColor(float p, float q, float t) return p; } -RgbColor::RgbColor(const HtmlColor& color) : - R((color.Color >> 16) & 0xff), G((color.Color >> 8) & 0xff), B(color.Color & 0xff) +RgbColor::RgbColor(const HtmlColor& color) { -} + uint32_t temp = color.Color; + + B = (temp & 0xff); + temp = temp >> 8; + G = (temp & 0xff); + temp = temp >> 8; + R = (temp & 0xff); +}; RgbColor::RgbColor(const HslColor& color) { diff --git a/src/internal/RgbwColor.cpp b/src/internal/RgbwColor.cpp index a1ee31e..062834d 100644 --- a/src/internal/RgbwColor.cpp +++ b/src/internal/RgbwColor.cpp @@ -28,6 +28,19 @@ License along with NeoPixel. If not, see #include "HslColor.h" #include "HsbColor.h" #include "RgbwColor.h" +#include "HtmlColor.h" + +RgbwColor::RgbwColor(const HtmlColor& color) +{ + uint32_t temp = color.Color; + B = (temp & 0xff); + temp = temp >> 8; + G = (temp & 0xff); + temp = temp >> 8; + R = (temp & 0xff); + temp = temp >> 8; + W = (temp & 0xff); +}; RgbwColor::RgbwColor(const HslColor& color) { diff --git a/src/internal/RgbwColor.h b/src/internal/RgbwColor.h index e47c708..38f2530 100644 --- a/src/internal/RgbwColor.h +++ b/src/internal/RgbwColor.h @@ -65,8 +65,12 @@ struct RgbwColor B(color.B), W(0) { + }; - } + // ------------------------------------------------------------------------ + // Construct a RgbwColor using HtmlColor + // ------------------------------------------------------------------------ + RgbwColor(const HtmlColor& color); // ------------------------------------------------------------------------ // Construct a RgbwColor using HslColor From 91c07103e3f25c1b00c552d7cb6a49136bb06c64 Mon Sep 17 00:00:00 2001 From: Makuna Date: Sat, 16 Apr 2016 13:02:37 -0700 Subject: [PATCH 2/2] Version Update --- library.json | 2 +- library.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library.json b/library.json index 4f1e339..8715cbb 100644 --- a/library.json +++ b/library.json @@ -7,7 +7,7 @@ "type": "git", "url": "https://github.com/Makuna/NeoPixelBus" }, - "version": "2.0.91", + "version": "2.1.0", "frameworks": "arduino", "platforms": "*" } diff --git a/library.properties b/library.properties index f693306..c873575 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=NeoPixelBus by Makuna -version=2.0.91 +version=2.1.0 author=Michael C. Miller (makuna@live.com) maintainer=Michael C. Miller (makuna@live.com) sentence=A library that makes controlling NeoPixels (WS2811, WS2812 & SK6812) easy.