From e9cee7a2326b2de5b9f3af353cc95b4ef241a168 Mon Sep 17 00:00:00 2001 From: true Date: Sun, 5 Nov 2023 14:43:52 -0800 Subject: [PATCH] Added flying toasters --- data/toast0.bmp | Bin 0 -> 5174 bytes data/toast1.bmp | Bin 0 -> 5174 bytes data/toast1.png | Bin 1823 -> 0 bytes data/toast2.bmp | Bin 0 -> 5174 bytes data/toast3.bmp | Bin 0 -> 5174 bytes data/toast4.bmp | Bin 0 -> 5174 bytes data/toast5.bmp | Bin 0 -> 5174 bytes include/bmp.h | 254 ++++++++++++++++++++++++++++++++++++++++++++++++ src/main.cpp | 125 ++++++++++++++++++------ 9 files changed, 347 insertions(+), 32 deletions(-) create mode 100644 data/toast0.bmp create mode 100644 data/toast1.bmp delete mode 100644 data/toast1.png create mode 100644 data/toast2.bmp create mode 100644 data/toast3.bmp create mode 100644 data/toast4.bmp create mode 100644 data/toast5.bmp create mode 100644 include/bmp.h diff --git a/data/toast0.bmp b/data/toast0.bmp new file mode 100644 index 0000000000000000000000000000000000000000..d1b3969ee171d23d4cfd820a3f903a344d588b3e GIT binary patch literal 5174 zcmeH~L5`b15JdrFY@k6JDTl~@q^zUtvzs&cDszUp%B-`Tv&KDGLp-( zjiLXmUsVm0{QCXlTc!BXR@HYL{q%QTopqice`b4EHGc42Rm;=U(^5S@<9%74FPG)z z0xds!-+`&eFIUzfMHx8?o)efjwKSUx{LaSd0YeY_t%c-$cbErU4f+onyNdl@EIe#-4-lsgd2jFnN24Y~%&xD-Wu@Qm<{FMOI#1eM&DSJPM5Qso_ zz63xQzSc8+CZDHi3L*2r5p?5uofQWjppwPE%ulz6& z+s~%40F{6yU=AK;AlI9^sfXscZax&?2EedEMgVWRr0FTIw*(4lsGq0Rxza z8BeX%KOWq`j$_~w5bzA}8>TM|&^>|{Ry`^)^@!{a2;4`8$VOl-@GgYf^B>JRva>rt zXhGlkO^be|5g4AITod(l4z*&cTeLtmYEalhaT8N!i&Ow=Fu+lAyN3Ue9nS6`H~=?q zG++fp3NR!bksP~(Xxs?30A@iOen1POo)#D|$Ur9vh;ksP2jHBp12GgG$SNR+dfX&H zwJl310nC8N46M7*F3A8+22AmA<^ZgOXn|)yC@N5cl@k|b0F%RhXaT@_0Z;>r@KS+L z-Q@?1v>~EI0^ne^U<4_YD`~M7!Mbot4PXmafGl_))krGkMTo2eWcVhC09jZGG@)rp znt#YVjj#cTDXYPYz<=&-nz0wTp2uRC{4~u3a17A`J4pZ;h${%28?&EIGk)d-jY0@# z2vk)e%wfQ+Jnj0WJz5YPVH2ese&}&me)0$9N}yx)pBg#Q_kcgYYu5EBJ!nM;dL*i9 z--;3ks(0m>Kx!{`JVS_vy*nK6gyX3J|NdE1ZjM#}T4@MpfF$)su=yD)u-#ro1eFZm zX&X`gGa9hn%`4iW**48r?;J;fKcRM3+&<+M1iM?)-o7o$uO@(Q&UJU@Yi=I_NLi0&Kf9d4SIHT2m8@s!v*ZfQ|G%mmFgWo@vl+=1 z88GmE{i<#n=jX5IZ$a@~h439mKm1dK2c75U_h_F`;0r$?OplL`Q+Rs9=QKT?PSeZF z%XGqingY(9r`Oll>Fw=pdVhbP&gb*=@$rFcxC-|Ex%c2c2maqVaJOUY zQ6yUX8!@{LaN?`7$~w1d7_R)p?ax$hkYHx~$$x_XLc(zfl+0|AT~Mg}%tXfFA>$j7 zs|vD?Qdz(Sz7o0SLA3|BM!vwsOuf%mzG zg@p^gY?>Z;rgdNvO%r?^mNjg6X3uzxk;fFkc28i0fwgA++Y(WI!g!4J>D%hpx-{4X?;!uNEq$P2?yIU*ei*!miJuRgR6_>wmYmspw8aFJA6Z(P zKuN~uf`3JN=0_BwBl=QWRO5(;JQiAJe60W)db6#=f_IT%huJQs5CWLH!X0{ zkU8yqBWqpb^S2g`u|?n?vcrQrNCH&JK~#bKiAQqGD8oY`0jt64gokZFF!9HPLjw6J z@ZfU;(`<{{nFZgeVO7NvOyJ-G=pz#CN#H5-_Mr-{2N*?A)`H@YE$~c|nBPfFQ!n`r zBZn2KVp_9sa0P$tT_U{_4WIKL`7m)wW7=#%9&A2Q*6IMtz=#z21%L{;x=J8fP#?Vt zYFI-#jNU%j_3_g#3CMzqFa=1cm&ph1aT&xfoh5!e4!MS01pc|_Xi{R$_=SD|(Bp&-ef_(HN2hNk)2Ku95Y(Ji>lIC#=Q#zU$vi0o&`hd~rq3$`|+CFaNs^ F`~eU7kBtBT literal 0 HcmV?d00001 diff --git a/data/toast1.png b/data/toast1.png deleted file mode 100644 index f614efbaab379e7f0bf6efe785ac57a5f69b2077..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1823 zcmV+)2jKXLP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGxh5!H^h5=oo6M+B#02XvbSaefwW^{L9 za%BK;VQFr3E^cLXAT%y9Oz*}2000J(NklbX$kR=l~?2 z%{sy^?ZWIo#3~pSK#hDh%L?U>2w>=f<`v+4`D?(Cyu@Pwu_A77Z@aC2e%JM)DuBMy z2c#wL1E0_5vzwcnW_xM{aNf@hqdI`0(swk=CF#q{({8KG&CO%C)$&>23w=v0q97CkV`{Gp(?Tc)Ao;Q4HPR*Fb2}$wVZzwJbUfRP z%YAwS`1$ka#=(e#MeQ6Bq03=VM48Y}^fvir*DN3_mBMv$)mMCye4Sb)Ez1eb5 zxa$DCoD@Ku`I=cTiAVfAK3lJ^udAoX%d|>LXhyS8!TS;$0chO|eLzoHx~FQOQ5;;p zMm&}%1LC>AM&2jO$wVRc1*)(n0Da+bG5-*Q+f_b_Gt+Q%bhMt0+5jMv67jv#`iJ>) zxqSBnN+E#W1D!eAXo&t0t4DCCI6z?i{AaM6;y$U+c9@}+ej zXIxWWqoRbAP`lA;DoxkAWu*wdC)!&!5NaL+^GOn0ZWJTfckZL;qpVQD|GU zZ*N`!88O7E^02i8YEBZDMa>K;1n}}_mL)B5%014!S5QrVwWQYoT>uFq3xq)fgCYGI z7&OPnwI8qaIu4?=w_=yshvG$W-)Qh6D|==>lg(P#RURe>!2i)xu2cg9(V+TZ@OqHS z%HHKNX*?OY1&NEU;BQxU0%|(oNFwT186(ktO8(wL%3wtg3dD} zum06KL$eQisQ@}(E|;T1C{g+>eGJLdiW+&?DS)=q_V0E0ddzDNp*9E|>&G+e`iEFs zZF$*Gm4}U=!~`eg39##D3k^WDgSeRSCvnV>22=Z}?D#U!d0O$0K3&@7$B2t205&{? zu>k;s;1QW$U#SNEg5&OP`+J0=fJ)M$B=1a-hjj(;U0)&e1;BCq9G;;N1Ydq?iQ*;c zC_hzPY*c_km>K~1;A+1#`J=UqLrH#DaWUur233L{0{u)0!0|BpsF7B?FLALBz~$8n z-wycvVgQK*!!Ux%h-uJd7 z>*wQd5|$T&TncUw7!D(&nPz@NZgeh>J{{2xHq{zsY3egSja#MTKVMd1Jd N002ovPDHLkV1jkYRe=Bi diff --git a/data/toast2.bmp b/data/toast2.bmp new file mode 100644 index 0000000000000000000000000000000000000000..3942385f44e4d18acda14acc311d56562cf32d2c GIT binary patch literal 5174 zcmeH~O>WyT5QQm5rbCJ{5TJ+XK0ww*_ub_TzDmxJt7P4!&yp*s@68M;Qn6FFs}}G$ z`myZq&6^=bIp2RgeQ^>`qjO(z_RY4z-OF|Eejapl1Kx0RZh3fkSlr_yw&U`6JTA}A z&&v_VWpTK6T3%jWme<$U3?x+pPz;Iq?6^f&DGo4tR_9+LhW}@QoQ1K5U z7Zt=hN@W2Xyc3~^q|s?f?M`|%n0FlN2uM9r4A@yB#<(g7KK4A|T@Ac}UWKV}ILvcV zpnc!-gv}`rAvExzhAHTvX@2d!-%axrEMlaD`mU&+s0W=h4e!GNDN$nyrF%F_5v)NP zW&WAphdGgES`8MAlGn%?Z@ICA4evvkfESk5H!v=c)!iAM*&BRKO9mvinHzQ)2KxLy zbhz5iq9LZq0E7t7Qp)G}l0C{$Yg%%+PMC+Bgw9)@=_{TzJxj$kW{fca*FQO?P5uqf zQBtotCV9o6Lrt2ugYtNQ>*a3bB2!ApRG{Ba+iQ@HCYQ%5brOgqJlTM2=8!5U9Kt>xxf#BLJRwBOop8cumgi6Q-vMSpF0( zzX@pm$O6{nsIJd>GLJSz7S5R-jBP z&EN5yqI#F&AF{i9bC69yMWmeCz%*k7ihs~t5)rr&1`$vTa<>v}L;DZ$!tVKB%~G~APUk-TvQk3k*N5Zf6v>Tk5NLa1uDqG-?RcK1A|%TFNXo^c@+=~(no6~ zHP}vB|E(LqM;kvm6alf&D8P~QviP7qKDzKrr^RVut-*@GKldC>N~{_pbl9e+76mvA z#ez*INKk`;yqEEff((U7&_oI6_~<;Boep{rG)+r3sUU&r&9|5FUZM1kj5v{F!jCP< zb!jJk$g(7|XltHXA^kZ{4~+!6$-w%^>!SBJ@EN_^rGKvjzW^*ZjbQ)) literal 0 HcmV?d00001 diff --git a/data/toast3.bmp b/data/toast3.bmp new file mode 100644 index 0000000000000000000000000000000000000000..1a7fff8919fcb442da6654d991110cf74e442f6e GIT binary patch literal 5174 zcmeH~L2lbH6htLimQ9Kj5TJ+XK0ww*_ub_TzDmxJt7P3}&XOyrGxJG`l+9?5`u6s=zQ4b(A0Hq14&Q?P-oI<`JqP~ZIdJ-7b826N^5xF? z5Mx}T%V)lHbU@W&{1RsuI|pOqm*t+qklMAr^V!`ZTwT%keWrD6F92Q4DXE$ z7M-F|x}H1G3K%Yb;5NVJGh9myEM439ISV8l0t20`l@vHr7ap9< z$uCM!aAYWWEwZcJ5@3!!1O-rZbd??0;UzqM_(RJR_PMnKC)g{x_YeWkK~KEZemKr?o~+^0(pYx- z#^A#O8VTgT z1mNX9pWPW3w<*g7W9PA<*;Kj1)4t&BJ{n`QiJ$PSwFEc)Yo34vGMojjd5D^7899c4 zz&y{<+><{laP3cAXOC6wiF@$#?6Ii_ICF~^-Z{jodEyW#n_?)I1t|SDd?Y{Y{WpP9 zRlJcv!;hnrKLX?n&Htvr6>s#=`{B4vzE&X1;^-#cv&G-RoY{f4-*mx!ftrq){cRZC4_nrWruL!2hwN}p30i?VKKdWgft(*SA4$TyUIG@u zZkSTOt$R=CfcKU20Dm=VFe~z;k z3Xy&%P~&jG3P*R3AC|4#oli-k{MHym-?{kq=`5jM)BE;ipPuD}wf5;{-(UX675E2@ C^pR}< literal 0 HcmV?d00001 diff --git a/data/toast4.bmp b/data/toast4.bmp new file mode 100644 index 0000000000000000000000000000000000000000..3942385f44e4d18acda14acc311d56562cf32d2c GIT binary patch literal 5174 zcmeH~O>WyT5QQm5rbCJ{5TJ+XK0ww*_ub_TzDmxJt7P4!&yp*s@68M;Qn6FFs}}G$ z`myZq&6^=bIp2RgeQ^>`qjO(z_RY4z-OF|Eejapl1Kx0RZh3fkSlr_yw&U`6JTA}A z&&v_VWpTK6T3%jWme<$U3?x+pPz;Iq?6^f&DGo4tR_9+LhW}@QoQ1K5U z7Zt=hN@W2Xyc3~^q|s?f?M`|%n0FlN2uM9r4A@yB#<(g7KK4A|T@Ac}UWKV}ILvcV zpnc!-gv}`rAvExzhAHTvX@2d!-%axrEMlaD`mU&+s0W=h4e!GNDN$nyrF%F_5v)NP zW&WAphdGgES`8MAlGn%?Z@ICA4evvkfESk5H!v=c)!iAM*&BRKO9mvinHzQ)2KxLy zbhz5iq9LZq0E7t7Qp)G}l0C{$Yg%%+PMC+Bgw9)@=_{TzJxj$kW{fca*FQO?P5uqf zQBtotCV9o6Lrt2ugYtNQ>*a3bB2!ApRG{Ba+iQ@HCYQ%5brOgqJlTM2=8!5U9Kt>xxf#BLJRwBOop8cumgi6Q-vMSpF0( zzX@pm$O6{nsIJd>GLJSz7S5R-jBP z&EN5yqI#F&AF{i9bC69yMWmeCz%*k7ihs~t5)rr&1`$vTa<>v}L;DZ$!tVKB%~G~APUk-TvQk3k*N5Zf6v>Tk5NLa1uDqG-?RcK1A|%TFNXo^c@+=~(no6~ zHP}vB|E(LqM;kvm6alf&D8P~QviP7qKDzKrr^RVut-*@GKldC>N~{_pbl9e+76mvA z#ez*INKk`;yqEEff((U7&_oI6_~<;Boep{rG)+r3sUU&r&9|5FUZM1kj5v{F!jCP< zb!jJk$g(7|XltHXA^kZ{4~+!6$-w%^>!SBJ@EN_^rGKvjzW^*ZjbQ)) literal 0 HcmV?d00001 diff --git a/data/toast5.bmp b/data/toast5.bmp new file mode 100644 index 0000000000000000000000000000000000000000..98ab2dd2e1800ef2f250ee47a6f4d39bc33df330 GIT binary patch literal 5174 zcmeH~L2jc!5JejdI6#9GX$~>_NLi0&Kf9d4SIHT2m8@s!v*ZfQ|G%mmFgWo@vl+=1 z88GmE{i<#n=jX5IZ$a@~h439mKm1dK2c75U_h_F`;0r$?OplL`Q+Rs9=QKT?PSeZF z%XGqingY(9r`Oll>Fw=pdVhbP&gb*=@$rFcxC-|Ex%c2c2maqVaJOUY zQ6yUX8!@{LaN?`7$~w1d7_R)p?ax$hkYHx~$$x_XLc(zfl+0|AT~Mg}%tXfFA>$j7 zs|vD?Qdz(Sz7o0SLA3|BM!vwsOuf%mzG zg@p^gY?>Z;rgdNvO%r?^mNjg6X3uzxk;fFkc28i0fwgA++Y(WI!g!4J>D%hpx-{4X?;!uNEq$P2?yIU*ei*!miJuRgR6_>wmYmspw8aFJA6Z(P zKuN~uf`3JN=0_BwBl=QWRO5(;JQiAJe60W)db6#=f_IT%huJQs5CWLH!X0{ zkU8yqBWqpb^S2g`u|?n?vcrQrNCH&JK~#bKiAQqGD8oY`0jt64gokZFF!9HPLjw6J z@ZfU;(`<{{nFZgeVO7NvOyJ-G=pz#CN#H5-_Mr-{2N*?A)`H@YE$~c|nBPfFQ!n`r zBZn2KVp_9sa0P$tT_U{_4WIKL`7m)wW7=#%9&A2Q*6IMtz=#z21%L{;x=J8fP#?Vt zYFI-#jNU%j_3_g#3CMzqFa=1cm&ph1aT&xfoh5!e4!MS01pc|_Xi{R$_=SD|(Bp&-ef_(HN2hNk)2Ku95Y(Ji>lIC#=Q#zU$vi0o&`hd~rq3$`|+CFaNs^ F`~eU7kBtBT literal 0 HcmV?d00001 diff --git a/include/bmp.h b/include/bmp.h new file mode 100644 index 0000000..cb1b84d --- /dev/null +++ b/include/bmp.h @@ -0,0 +1,254 @@ +/******************************************************************************* + * BMP Class + * + * Rewrite from: https://github.com/Jaycar-Electronics/Arduino-Picture-Frame.git + ******************************************************************************/ +#ifndef _BMPCLASS_H_ +#define _BMPCLASS_H_ + + +#include + + +typedef void(BMP_DRAW_CALLBACK)(int16_t x, int16_t y, uint16_t *bitmap, int16_t w, int16_t h); + +class BmpClass +{ +public: + void draw( + File *f, BMP_DRAW_CALLBACK *bmpDrawCallback, bool useBigEndian, + int16_t x, int16_t y, int16_t widthLimit, int16_t heightLimit) + { + _bmpDrawCallback = bmpDrawCallback; + _useBigEndian = useBigEndian; + _heightLimit = heightLimit; + + int16_t u, v; + uint32_t xend; + + getbmpparms(f); + + //validate bitmap + if ((bmtype == 19778) && (bmwidth > 0) && (bmheight > 0) && (bmbpp > 0)) + { + //centre image + u = (widthLimit - bmwidth) / 2; + v = (heightLimit - bmheight) / 2; + u = (u < 0) ? x : x + u; + v = (v < 0) ? y : y + v; + xend = (bmwidth > widthLimit) ? widthLimit : bmwidth; + + bmpRow = (uint16_t *)malloc(xend * 2); + if (!bmpRow) + { + Serial.println(F("bmpRow malloc failed.")); + } + if (bmbpp < 9) + { + bmplt = (uint16_t *)malloc(bmpltsize * 2); + if (!bmplt) + { + Serial.println(F("bmplt malloc failed.")); + } + bmloadplt(f); //load palette if palettized + drawbmpal(f, u, v, xend); + free(bmplt); + } + else if (bmbpp == 16) + { + // TODO: bpp 16 should have 3 pixel types + drawbmRgb565(f, u, v, xend); + } + else + { + drawbmtrue(f, u, v, xend); + } + free(bmpRow); + } + } + +private: + void bmloadplt(File *f) + { + byte r, g, b; + if (bmpltsize == 0) + { + bmpltsize = 1 << bmbpp; //load default palette size + } + f->seek(54); //palette position in type 0x28 bitmaps + for (int16_t i = 0; i < bmpltsize; i++) + { + b = f->read(); + g = f->read(); + r = f->read(); + f->read(); //dummy byte + bmplt[i] = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3); + } + } + + void drawbmpal(File *f, int16_t u, int16_t v, uint32_t xend) + { + byte bmbitmask; + int16_t i, ystart, bmppb, p, d; + int16_t x, y; + uint16_t c; + bmbpl = ((bmbpp * bmwidth + 31) / 32) * 4; //bytes per line + bmppb = 8 / bmbpp; //pixels/byte + bmbitmask = ((1 << bmbpp) - 1); //mask for each pixel + ystart = 0; + if (bmheight > _heightLimit) + { + ystart = bmheight - _heightLimit; //don't draw if it's outside screen + } + for (y = ystart; y < bmheight; y++) + { //invert in calculation (y=0 is bottom) + f->seek(bmdataptr + y * bmbpl); //seek to start of line + x = 0; + p = 0; + while (x < xend) + { + if (p < 1) + { + d = f->read(); + p = bmppb; + } + d = d << bmbpp; + c = bmplt[(bmbitmask & (d >> 8))]; + bmpRow[x] = (_useBigEndian) ? ((c >> 8) | (c << 8)) : c; + + p--; + x++; + } + _bmpDrawCallback(u, v + bmheight - 1 - y, bmpRow, xend, 1); + } + } + + // draw 16-bit colour (RGB565) bitmap + void drawbmRgb565(File *f, int16_t u, int16_t v, uint32_t xend) + { + int16_t i, ystart; + uint32_t x, y; + byte lo, hi; + bmbpl = ((bmbpp * bmwidth + 31) / 32) * 4; //bytes per line, due to 32bit chunks + ystart = 0; + if (bmheight > _heightLimit) + { + ystart = bmheight - _heightLimit; //don't draw if it's outside screen + } + Serial.println(xend); + for (y = ystart; y < bmheight; y++) + { //invert in calculation (y=0 is bottom) + f->seek(bmdataptr + (y * bmbpl)); //seek at start of line + for (x = 0; x < xend; x++) + { + lo = f->read(); + hi = f->read(); + if (_useBigEndian) + { + bmpRow[x] = hi | lo << 8; + } + else + { + bmpRow[x] = lo | hi << 8; + } + } + _bmpDrawCallback(u, v + bmheight - 1 - y, bmpRow, xend, 1); + } + } + + // draw true colour bitmap at (u,v) handles 24/32 not 16bpp yet + void drawbmtrue(File *f, int16_t u, int16_t v, uint32_t xend) + { + int16_t i, ystart; + uint32_t x, y; + byte r, g, b; + bmbpl = ((bmbpp * bmwidth + 31) / 32) * 4; //bytes per line, due to 32bit chunks + ystart = 0; + if (bmheight > _heightLimit) + { + ystart = bmheight - _heightLimit; //don't draw if it's outside screen + } + for (y = ystart; y < bmheight; y++) + { //invert in calculation (y=0 is bottom) + f->seek(bmdataptr + y * bmbpl); //seek at start of line + for (x = 0; x < xend; x++) + { + b = f->read(); + g = f->read(); + r = f->read(); + if (bmbpp == 32) + { + f->read(); //dummy byte for 32bit + } + bmpRow[x] = (_useBigEndian) ? ((r & 0xf8) | (g >> 5) | ((g & 0x1c) << 11) | ((b & 0xf8) << 5)) : (((r & 0xf8) << 8) | ((g & 0xfc) << 3) | (b >> 3)); + } + _bmpDrawCallback(u, v + bmheight - 1 - y, bmpRow, xend, 1); + } + } + + void getbmpparms(File *f) + { //load into globals as ints-some parameters are 32 bit, but we can't handle this size anyway + byte h[48]; //header is 54 bytes typically, but we don't need it all + int16_t i; + f->seek(0); //set start of file + for (i = 0; i < 48; i++) + { + h[i] = f->read(); //read header + } + bmtype = h[0] + (h[1] << 8); //offset 0 'BM' + bmdataptr = h[10] + (h[11] << 8); //offset 0xA pointer to image data + bmhdrsize = h[14] + (h[15] << 8); //dib header size (0x28 is usual) + //files may vary here, if !=28, unsupported type, put default values + bmwidth = 0; + bmheight = 0; + bmbpp = 0; + bmpltsize = 0; + if ((bmhdrsize == 0x28) || (bmhdrsize == 0x38)) + { + bmwidth = h[18] + (h[19] << 8); //width + bmheight = h[22] + (h[23] << 8); //height + bmbpp = h[28] + (h[29] << 8); //bits per pixel + bmpltsize = h[46] + (h[47] << 8); //palette size + } + // Serial.printf("bmtype: %d, bmhdrsize: %d, bmwidth: %d, bmheight: %d, bmbpp: %d\n", bmtype, bmhdrsize, bmwidth, bmheight, bmbpp); + } + + byte isbmp(char n[]) + { //check if bmp extension + int16_t k; + k = strlen(n); + if (k < 5) + { + return 0; //name not long enough + } + if (n[k - 1] != 'P') + { + return 0; + } + if (n[k - 2] != 'M') + { + return 0; + } + if (n[k - 3] != 'B') + { + return 0; + } + if (n[k - 4] != '.') + { + return 0; + } + return 1; //passes all tests + } + + BMP_DRAW_CALLBACK *_bmpDrawCallback; + bool _useBigEndian; + int16_t _heightLimit; + + uint16_t bmtype, bmdataptr; //from header + uint32_t bmhdrsize, bmwidth, bmheight, bmbpp, bmpltsize; //from DIB Header + uint16_t bmbpl; //bytes per line- derived + uint16_t *bmplt; //palette- stored encoded for LCD + uint16_t *bmpRow; +}; + +#endif // _BMPCLASS_H_ \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index e17dfd1..45b680f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,10 +12,8 @@ extern "C" { #include #include -// png is not working, getting error 1 on working on the file -#include -#include "pngfile.h" -PNG png; +#include "bmp.h" +static BmpClass bmp; #include "btn.h" @@ -391,55 +389,118 @@ void bg_radarsweep(int16_t rot, int16_t offset, uint8_t lines) } } + +#define MAX_TOASTERS 5 +#define TOAST_RANDOM 9 + + struct Toasters { - uint16_t x; - uint16_t y; + int16_t x; + int16_t y; uint16_t speed; uint8_t type; uint8_t frame; } Toasters; -static struct Toasters toast[8]; + +static struct Toasters toast[MAX_TOASTERS]; uint8_t toaster_count; +uint8_t toaster_frametimer; -int16_t png_x, png_y; -void png_draw(PNGDRAW *pDraw) +static void bmp_cb(int16_t x, int16_t y, uint16_t *bitmap, int16_t w, int16_t h) { - uint16_t usPixels[320]; - uint8_t usMask[320]; + // Serial.printf("Draw pos = %d, %d. size = %d x %d\n", x, y, w, h); + drot->draw16bitRGBBitmap(x, y, bitmap, w, h); +} - Serial.printf("Draw pos = 0,%d. size = %d x 1\n", pDraw->y, pDraw->iWidth); - png.getLineAsRGB565(pDraw, usPixels, PNG_RGB565_LITTLE_ENDIAN, 0x00000000); - png.getAlphaMask(pDraw, usMask, 1); - dout->draw16bitRGBBitmapWithMask(png_x, png_y + pDraw->y, usPixels, usMask, pDraw->iWidth, 1); +void print_toast(char *fn, int16_t out_x, int16_t out_y) +{ + int16_t x, y; + int16_t nx, ny; + + uint16_t *src, *dst; + + uint16_t src_pxl; + + // framebuffer pointers + src = drot->getFramebuffer(); + dst = dout->getFramebuffer(); + + // load toast file + File fbmp = LittleFS.open(fn, "r"); + bmp.draw(&fbmp, bmp_cb, false /* useBigEndian */, 0 /* x */, 0 /* y */, 64, 64); + fbmp.close(); + + // copy to destination with transparency + for (y = 0; y < 64; y++) { + for (x = 0; x < 64; x++) { + src_pxl = src[x + (y * ROT_SIZE)]; + if (src_pxl != TRANSPARENT_BG) { + nx = x + out_x; + ny = y + out_y; + + if ((nx < 0) || (ny < 0)) break; + if ((nx >= 240) || (ny >= 240)) break; + + dst[nx + (ny*240)] = src_pxl; + } + } + } } void bg_toasters() { - int rc; + uint16_t i; + + // frame counter + toaster_frametimer++; + if (toaster_frametimer >= 2) { + toaster_frametimer = 0; + for (i = 0; i < MAX_TOASTERS; i++) { + if (toast[i].type) { + toast[i].frame++; + if (toast[i].frame >= 6) toast[i].frame = 0; + } + } + } + // clear screen dout->fillScreen(BLACK); - png_x = 120; - png_y = 120; - - rc = png.open("toast1.png", png_open, png_close, png_read, png_seek, png_draw); + // determine if we are doing new toasts + if (random(200) < TOAST_RANDOM) { + for (i = 0; i < MAX_TOASTERS; i++) { + if (!toast[i].type) { + toast[i].type = 1; + toast[i].frame = 0; + toast[i].x = 240; + toast[i].y = 64 - random(240); + break; + } + } + } - if (rc == PNG_SUCCESS) { - int16_t pw = png.getWidth(); - int16_t ph = png.getHeight(); + for (i = 0; i < MAX_TOASTERS; i++) { + char fn[20]; - png_x = (240 - pw) / 2; - png_y = (240 - ph) / 2; + switch (toast[i].type) { + case 0: continue; + case 1: { // normal toast + if (toast[i].x < -64) { + // toast is toasted + toast[i].type = 0; + } else { + // select toast file + sprintf(fn, "toast%i.bmp", toast[i].frame); + // move toast + toast[i].x -= 3; + toast[i].y += 2; - rc = png.decode(NULL, 0); - - Serial.printf("errcode: %d, Draw offset: (%d, %d); image specs: (%d x %d), %d bpp, pixel type: %d\n", - rc, png_x, png_y, png.getWidth(), png.getHeight(), png.getBpp(), png.getPixelType()); - png.close(); - } else { - Serial.println("failed to open png"); + print_toast(fn, toast[i].x, toast[i].y); + } + } + } } }