-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSprite_t_k_cst.cpp
2183 lines (1928 loc) · 62.9 KB
/
Sprite_t_k_cst.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**************************************************************************************
// The following class creates Sprites in RAM, graphics can then be drawn in the Sprite
// and rendered quickly onto the TFT screen. The class inherits the graphics functions
// from the TFT_eSPI class. Some functions are overridden by this class so that the
// graphics are written to the Sprite rather than the TFT.
// Coded by Bodmer, see license file in root folder
***************************************************************************************/
/***************************************************************************************
// Color bytes are swapped when writing to RAM, this introduces a small overhead but
// there is a nett performance gain by using swapped bytes.
***************************************************************************************/
#include "Sprite_t_k_cst.h"
/***************************************************************************************
** Function name: TFT_eSprite_CST
** Description: Class constructor
*************************************************************************************x*/
//2018/10/5 ~ T.K CUSTOM//
TFT_eSprite_CST::TFT_eSprite_CST(TFT_eSPI *tft)
{
_tft = tft; // Pointer to tft class so we can call member functions
_iwidth = 0; // Initialise width and height to 0 (it does not exist yet)
_iheight = 0;
_bpp = 16;
_iswapBytes = false; // Do not swap pushImage colour bytes by default
_created = false;
_xs = 0; // window bounds for pushColor
_ys = 0;
_xe = 0;
_ye = 0;
_xptr = 0; // pushColor coordinate
_yptr = 0;
this->cursor_y = this->cursor_x = 0; // Text cursor position
}
/***************************************************************************************
** Function name: createSprite
** Description: Create a sprite (bitmap) of defined width and height
*************************************************************************************x*/
// cast returned value to (uint8_t*) for 8 bit or (uint16_t*) for 16 bit colours
void* TFT_eSprite_CST::createSprite(int16_t w, int16_t h, uint8_t frames)
{
if ( _created ) return _img8_1;
if ( w < 1 || h < 1 ) return NULL;
_iwidth = _dwidth = _bitwidth = w;
_iheight = _dheight = h;
this->cursor_x = 0;
this->cursor_y = 0;
// Default scroll rectangle and gap fill colour
_sx = 0;
_sy = 0;
_sw = w;
_sh = h;
_scolor = TFT_BLACK;
// Add one extra "off screen" pixel to point out-of-bounds setWindow() coordinates
// this means push/writeColor functions do not need additional bounds checks and
// hence will run faster in normal circumstances.
if (_bpp == 16)
{
_img8_1 = ( uint8_t*) calloc(w * h + 1, sizeof(uint16_t));
_img8_2 = _img8_1;
_img = (uint16_t*) _img8_1;
if (_img)
{
_created = true;
return _img;
}
}
else if (_bpp == 8)
{
_img8_1 = ( uint8_t*) calloc(w * h + 1, sizeof(uint8_t));
if (_img8_1)
{
_img8 = _img8_1;
_img8_2 = _img8_1;
_created = true;
return _img8;
}
}
else // Must be 1 bpp
{
//_dwidth Display width+height in pixels always in rotation 0 orientation
//_dheight Not swapped for sprite rotations
// Note: for 1bpp _iwidth and _iheight are swapped during Sprite rotations
w = (w+7) & 0xFFF8; // width should be the multiple of 8 bits to be compatible with epdpaint
_iwidth = w; // _iwidth is rounded up to be multiple of 8, so might not be = _dwidth
_bitwidth = w;
if (frames > 2) frames = 2; // Currently restricted to 2 frame buffers
if (frames < 1) frames = 1;
_img8 = ( uint8_t*) calloc(frames * (w>>3) * h + frames, sizeof(uint8_t)); // extra pixel added
if (_img8)
{
_created = true;
_img8_1 = _img8;
_img8_2 = _img8 + ( (w>>3) * h + 1 );
return _img8_1;
}
}
return NULL;
}
/***************************************************************************************
** Function name: frameBuffer
** Description: For 1 bpp Sprites, select the frame used for graphics
*************************************************************************************x*/
// Frames are numbered 1 and 2
void* TFT_eSprite_CST::frameBuffer(int8_t f)
{
if (!_created) return NULL;
if (_bpp == 16) return _img;
if (_bpp == 8) return _img8;
if ( f == 2 ) _img8 = _img8_2;
else _img8 = _img8_1;
return _img8;
}
/***************************************************************************************
** Function name: setDepth
** Description: Set bits per pixel for colour (8 or 16)
*************************************************************************************x*/
void* TFT_eSprite_CST::setColorDepth(int8_t b)
{
// Can't change an existing sprite's colour depth so delete it
if (_created) free(_img8_1);
// Now define the new colour depth
if ( b > 8 ) _bpp = 16; // Bytes per pixel
else if ( b > 1 ) _bpp = 8;
else _bpp = 1;
// If it existed, re-create the sprite with the new colour depth
if (_created)
{
_created = false;
return createSprite(_iwidth, _iheight);
}
return NULL;
}
/***************************************************************************************
** Function name: setBitmapColor
** Description: Set the foreground foreground and background colour
***************************************************************************************/
void TFT_eSprite_CST::setBitmapColor(uint16_t c, uint16_t b)
{
if (c == b) b = ~c;
_tft->bitmap_fg = c;
_tft->bitmap_bg = b;
}
/***************************************************************************************
** Function name: deleteSprite
** Description: Delete the sprite to free up memory (RAM)
*************************************************************************************x*/
void TFT_eSprite_CST::deleteSprite(void)
{
if (!_created ) return;
free(_img8_1);
_created = false;
}
/***************************************************************************************
** Function name: pushSprite
** Description: Push the sprite to the TFT at x, y
*************************************************************************************x*/
void TFT_eSprite_CST::pushSprite(int32_t x, int32_t y)
{
if (!_created) return;
if (_bpp == 16) _tft->pushImage(x, y, _iwidth, _iheight, _img );
else _tft->pushImage(x, y, _dwidth, _dheight, _img8, (bool)(_bpp == 8));
}
/***************************************************************************************
** Function name: pushSprite
** Description: Push the sprite to the TFT at x, y with transparent colour
*************************************************************************************x*/
void TFT_eSprite_CST::pushSprite(int32_t x, int32_t y, uint16_t transp)
{
if (!_created) return;
if (_bpp == 16) _tft->pushImage(x, y, _iwidth, _iheight, _img, transp );
else if (_bpp == 8)
{
transp = (uint8_t)((transp & 0xE000)>>8 | (transp & 0x0700)>>6 | (transp & 0x0018)>>3);
_tft->pushImage(x, y, _dwidth, _dheight, _img8, (uint8_t)transp, (bool)true);
}
else _tft->pushImage(x, y, _dwidth, _dheight, _img8, 0, (bool)false);
}
/***************************************************************************************
** Function name: readPixel
** Description: Read 565 colour of a pixel at defined coordinates
*************************************************************************************x*/
uint16_t TFT_eSprite_CST::readPixel(int32_t x, int32_t y)
{
if ((x < 0) || (x >= _iwidth) || (y < 0) || (y >= _iheight) || !_created) return 0;
if (_bpp == 16)
{
uint16_t color = _img[x + y * _iwidth];
return (color >> 8) | (color << 8);
}
if (_bpp == 8)
{
uint16_t color = _img8[x + y * _iwidth];
if (color != 0)
{
uint8_t blue[] = {0, 11, 21, 31};
color = (color & 0xE0)<<8 | (color & 0xC0)<<5
| (color & 0x1C)<<6 | (color & 0x1C)<<3
| blue[color & 0x03];
}
return color;
}
if (_rotation == 1)
{
uint16_t tx = x;
x = _dwidth - y - 1;
y = tx;
}
else if (_rotation == 2)
{
x = _dwidth - x - 1;
y = _dheight - y - 1;
}
else if (_rotation == 3)
{
uint16_t tx = x;
x = y;
y = _dheight - tx - 1;
}
uint16_t color = (_img8[(x + y * _bitwidth)>>3] << (x & 0x7)) & 0x80;
return color >> 7;
}
/***************************************************************************************
** Function name: pushImage
** Description: push 565 colour image into a defined area of a sprite
*************************************************************************************x*/
// TODO Need to add more area boundary checks
void TFT_eSprite_CST::pushImage(int32_t x, int32_t y, uint32_t w, uint32_t h, uint16_t *data)
{
if ((x >= _iwidth) || (y >= _iheight) || (w == 0) || (h == 0) || !_created) return;
if (_bpp == 16)
{
for (uint32_t yp = y; yp < y + h; yp++)
{
for (uint32_t xp = x; xp < x + w; xp++)
{
uint16_t color = *data++;
if(!_iswapBytes) color = color<<8 | color>>8;
_img[xp + yp * _iwidth] = color;
}
}
}
else if (_bpp == 8)
{
for (uint32_t yp = y; yp < y + h; yp++)
{
for (uint32_t xp = x; xp < x + w; xp++)
{
uint16_t color = *data++;
if(_iswapBytes) color = color<<8 | color>>8;
_img8[xp + yp * _iwidth] = (uint8_t)((color & 0xE000)>>8 | (color & 0x0700)>>6 | (color & 0x0018)>>3);
}
}
}
else // 1bpp
{
// Move coordinate rotation to support fn
if (_rotation == 1)
{
int32_t tx = x;
x = _dwidth - y - 1;
y = tx;
}
else if (_rotation == 2)
{
x = _dwidth - x - 1;
y = _dheight - y - 1;
}
else if (_rotation == 3)
{
int32_t tx = x;
x = y;
y = _dheight - tx - 1;
}
uint8_t* pdata = (uint8_t*) data;
uint32_t ww = (w+7) & 0xFFF8;
for (int32_t yp = 0; yp<h; yp++)
{
for (int32_t xp = 0; xp<ww; xp+=8)
{
uint8_t pbyte = *pdata++;
for (uint8_t xc = 0; xc < 8; xc++)
{
if (xp+xc<w) drawPixel(x+xp+xc, y+yp, (pbyte<<xc) & 0x80);
}
}
}
}
}
/***************************************************************************************
** Function name: pushImage
** Description: push 565 colour FLASH (PROGMEM) image into a defined area
*************************************************************************************x*/
// TODO Need to add more area boundary checks
void TFT_eSprite_CST::pushImage(int32_t x, int32_t y, uint32_t w, uint32_t h, const uint16_t *data)
{
if ((x >= _iwidth) || (y >= _iheight) || (w == 0) || (h == 0) || !_created) return;
if (_bpp == 16)
{
for (uint32_t yp = y; yp < y + h; yp++)
{
for (uint32_t xp = x; xp < x + w; xp++)
{
uint16_t color = pgm_read_word(data++);
if(!_iswapBytes) color = color<<8 | color>>8;
_img[xp + yp * _iwidth] = color;
}
}
}
else if (_bpp == 8)
{
for (uint32_t yp = y; yp < y + h; yp++)
{
for (uint32_t xp = x; xp < x + w; xp++)
{
uint16_t color = pgm_read_word(data++);
if(_iswapBytes) color = color<<8 | color>>8;
_img8[xp + yp * _iwidth] = (uint8_t)((color & 0xE000)>>8 | (color & 0x0700)>>6 | (color & 0x0018)>>3);
}
}
}
else // 1bpp
{
// Move coordinate rotation to support fn
if (_rotation == 1)
{
int32_t tx = x;
x = _dwidth - y - 1;
y = tx;
}
else if (_rotation == 2)
{
x = _dwidth - x - 1;
y = _dheight - y - 1;
}
else if (_rotation == 3)
{
int32_t tx = x;
x = y;
y = _dheight - tx - 1;
}
const uint8_t* pdata = (const uint8_t* ) data;
uint32_t ww = (w+7) & 0xFFF8;
for (int32_t yp = 0; yp<h; yp++)
{
for (int32_t xp = 0; xp<ww; xp+=8)
{
uint8_t pbyte = pgm_read_byte(pdata++);
for (uint8_t xc = 0; xc < 8; xc++)
{
if (xp+xc<w) drawPixel(x+xp+xc, y+yp, (pbyte<<xc) & 0x80);
}
}
}
}
}
/***************************************************************************************
** Function name: pushImage 8bitDIRECT FAST
** Description: push 565 colour image into a defined area of a sprite
*************************************************************************************x*/
/*
// TODO Need to add more area boundary checks
void TFT_eSprite_CST::pushImage_D8AD(int32_t x, int32_t y, uint32_t w, uint32_t h, uint8_t *data)
{
pushImage_D8(x,y,w,h,data,0);
}
void TFT_eSprite_CST::pushImage_D8AD(int32_t x, int32_t y, uint32_t w, uint32_t h, uint8_t *data,uint16_t m)
{
if ((x >= _iwidth) || (y >= _iheight) || (w == 0) || (h == 0) || !_created ||_bpp != 8) return;
int yp2;
switch(m){
case SPBB_NOR://NORMAL
default:
if(m&SPR_CLIP)//Clipping MODE
for (int32_t yp = 0; yp < h; yp++)
{
//Cliping
if(y+yp>=_iheight){break;}
else
if(y+yp<0){data+=w;continue;}
yp2=(y+yp)*_iwidth;dx=x;dx2=x+w;
if(dx<0){data+=dx*-1;dx=0;}
if(dx2>=_iwidth){dt=dx2-_iwidth;dx2=_iwidth;}
else
dt=0;
if(m&SPR_ZERO_T)//Transparent color(0) ON >Run
for (int32_t xp = dx; xp < dx2; xp++){
color = *data++;
if(color)_img8[xp + yp2] = color;
}
else
for (int32_t xp = dx; xp < dx2; xp++){
_img8[xp + yp2] = *data++;
}
data+=dt;
}
else//NORMAL
if(m&SPR_ZERO_T)//Transparent color(0) ON >Run
for (uint32_t yp = y; yp < y + h; yp++)
{
yp2=yp * _iwidth;
for (uint32_t xp = x; xp < x + w; xp++)
{
color = *data++;
if(color)_img8[xp + yp2] = color;
}
}
else//NO EFFECT
for (uint32_t yp = y; yp < y + h; yp++)
{
yp2=yp * _iwidth;
for (uint32_t xp = x; xp < x + w; xp++)
{
_img8[xp + yp2]= *data++;
}
}
break;
case SPBB_TRA://Fake_Translucent
if(m&SPR_CLIP)//Clipping MODE
for (int32_t yp = 0; yp < h; yp++)
{
//Cliping
if(y+yp>=_iheight){break;}
else
if(y+yp<0){data+=w;continue;}
yp2=(y+yp)*_iwidth;dx=x;dx2=x+w;
if(dx<0){data+=dx*-1;dx=0;}
if(dx2>=_iwidth){dt=dx2-_iwidth;dx2=_iwidth;}
else
dt=0;
for (int32_t xp = dx; xp < dx2; xp++){
_img8[xp + yp2]|= *data++;
}
data+=dt;
}
else//NORMAL
for (uint32_t yp = y; yp < y + h; yp++)
{
yp2=yp * _iwidth;
for (uint32_t xp = x; xp < x + w; xp++)
{
_img8[xp + yp2]|= *data++;
}
}
break;
case SPBB_RGC://R<>G REVERSE CONVERT(MSX)
if(m&SPR_CLIP)//Clipping MODE
for (int32_t yp = 0; yp < h; yp++)
{
//Cliping
if(y+yp>=_iheight){break;}
else
if(y+yp<0){data+=w;continue;}
yp2=(y+yp)*_iwidth;dx=x;dx2=x+w;
if(dx<0){data+=dx*-1;dx=0;}
if(dx2>=_iwidth){dt=dx2-_iwidth;dx2=_iwidth;}
else
dt=0;
for (int32_t xp = dx; xp < dx2; xp++){
color= *data++;
_img8[xp + yp2] = ((color>>3)&(0b00011100)) | ((color<<3)&(0b11100000)) | (color&3);
}
data+=dt;
}
else//NORMAL
for (uint32_t yp = y; yp < y + h; yp++)
{
yp2=yp * _iwidth;
for (uint32_t xp = x; xp < x + w; xp++)
{
color= *data++;
_img8[xp + yp2] = ((color>>3)&(0b00011100)) | ((color<<3)&(0b11100000)) | (color&3);
}
}
break;
}
}
*/
/***************************************************************************************
** Function name: pushImage 8bitDIRECT ADVANCE Clipping/Transparent 2018/10/5 T.K Add
*************************************************************************************x*/
// TODO Need to add more area boundary checks
void TFT_eSprite_CST::pushImage_D8AD(int32_t x, int32_t y, uint32_t w, uint32_t h, const uint8_t *data ,uint16_t m ,uint16_t cl,uint16_t ang,uint16_t scl,uint16_t tra)
{
if (!_created ||_bpp != 8 || (x >= _iwidth) || (y >= _iheight) || (w == 0) || (h == 0) ) return;
int yp2,dx,dx2,dt;
int lf,ri,tp,bt,ln;
byte color;
if(scl==0)return;
switch((m&15)){
case SPBB_MOD://NORMAL
ln=(int)sqrt(((w*scl)/10000.0f)*((w*scl)/10000.0f)+((h*scl)/10000.0f)*((h*scl)/10000.0f))/2+2;
lf=(x-ln);ri=(x+ln);tp=(y-ln);bt=(y+ln);
int rx,ry,rx2,ry2,lx,lx2,ly,ly2,ycc,ycs,xc,yc,dy;
int s,c;
int32_t pa,adr2;
rx=(w>>1);rx2=(w>>1)*-1;ry=(h>>1);ry2=(h>>1)*-1;
lx=ln*-1;lx2=ln;ly=ln*-1;ly2=ln;
s=(int)(sin(((float)(36000-ang)*3.14159265358979323844)/18000)*4096);
c=(int)(cos(((float)(36000-ang)*3.14159265358979323844)/18000)*4096);
if(y+ly<0)ly=ly+(0-(y+ly));
if(x+lx<0)lx=lx+(0-(x+lx));
if(y+ly2>_iheight)ly2=ly2-(y+ly2-_iheight);
if(x+lx2>_iwidth)lx2=lx2-(x+lx2-_iwidth);
for (int32_t yp=ly;yp<ly2;yp++ ) {
yc=(yp*10000)/scl;
ycs=yc*s;
ycc=yc*c;
for (int32_t xp=lx;xp<lx2;xp++ ) {
xc=(xp*10000)/scl;
dx=(int)(xc*c-ycs)>>12;
dy=(int)(xc*s+ycc)>>12;
if(dy<ry&&dy>=ry2&&dx<rx&&dx>=rx2);
else
continue;
//if(y+yp<0||y+yp>=_iheight||x+xp<0||x+xp>=_iwidth)continue;
color =data[(((h>>1)+dy)*w)+((w>>1)+dx)];
if(color)_img8[(y+yp)*_iwidth+x+xp] = color;
}
}
break;
case SPBB_NOR://NORMAL
default:
if(m&SPR_CLIP)//Clipping MODE
for (int32_t yp = 0; yp < h; yp++)
{
//Cliping
if(y+yp>=_iheight){break;}
else
if(y+yp<0){data+=w;continue;}
yp2=(y+yp)*_iwidth;dx=x;dx2=x+w;
if(dx<0){data+=dx*-1;dx=0;}
if(dx2>=_iwidth){dt=dx2-_iwidth;dx2=_iwidth;}
else
dt=0;
if(m&SPR_ZERO_T)//Transparent color(0) ON >Run
{
if(m&SPR_COLOR)
for (int32_t xp = dx+ yp2; xp < dx2+ yp2; xp++){
color = pgm_read_byte(data++);
if(color)_img8[xp] = cl;
}
else
for (int32_t xp = dx+ yp2; xp < dx2+ yp2; xp++){
color = pgm_read_byte(data++);
if(color)_img8[xp] = color;
}
}
else
for (int32_t xp = dx+ yp2; xp < dx2+ yp2; xp++){
_img8[xp] = pgm_read_byte(data++);
}
data+=dt;
}
else//NORMAL
if(m&SPR_ZERO_T)//Transparent color(0) ON >Run
for (uint32_t yp = y; yp < y + h; yp++)
{
yp2=yp * _iwidth;
for (uint32_t xp = x + yp2; xp < x + w + yp2; xp++)
{
color = pgm_read_byte(data++);
if(color)_img8[xp] = color;
}
}
else//NO EFFECT
for (uint32_t yp = y; yp < y + h; yp++)
{
yp2=yp * _iwidth;
for (uint32_t xp = x + yp2; xp < x + w + yp2; xp++)
{
_img8[xp]= pgm_read_byte(data++);
}
}
break;
case SPBB_TRA://Fake_Translucent
if(m&SPR_CLIP)//Clipping MODE
for (int32_t yp = 0; yp < h; yp++)
{
//Cliping
if(y+yp>=_iheight){break;}
else
if(y+yp<0){data+=w;continue;}
yp2=(y+yp)*_iwidth;dx=x;dx2=x+w;
if(dx<0){data+=dx*-1;dx=0;}
if(dx2>=_iwidth){dt=dx2-_iwidth;dx2=_iwidth;}
else
dt=0;
for (int32_t xp = dx + yp2; xp < dx2 + yp2; xp++){
_img8[xp]|= pgm_read_byte(data++);
}
data+=dt;
}
else//NORMAL
for (uint32_t yp = y; yp < y + h; yp++)
{
yp2=yp * _iwidth;
for (uint32_t xp = x + yp2; xp < x + w + yp2; xp++)
{
_img8[xp]|= pgm_read_byte(data++);
}
}
break;
case SPBB_RGC://R<>G REVERSE CONVERT(MSX)
if(m&SPR_CLIP)//Clipping MODE
for (int32_t yp = 0; yp < h; yp++)
{
//Cliping
if(y+yp>=_iheight){break;}
else
if(y+yp<0){data+=w;continue;}
yp2=(y+yp)*_iwidth;dx=x;dx2=x+w;
if(dx<0){data+=dx*-1;dx=0;}
if(dx2>=_iwidth){dt=dx2-_iwidth;dx2=_iwidth;}
else
dt=0;
for (int32_t xp = dx + yp2; xp < dx2 + yp2; xp++){
color= pgm_read_byte(data++);
_img8[xp] = ((color>>3)&(0b00011100)) | ((color<<3)&(0b11100000)) | (color&3);
}
data+=dt;
}
else//NORMAL
for (uint32_t yp = y; yp < y + h; yp++)
{
yp2=yp * _iwidth;
for (uint32_t xp = x + yp2; xp < x + w + yp2; xp++)
{
color= pgm_read_byte(data++);
_img8[xp] = ((color>>3)&(0b00011100)) | ((color<<3)&(0b11100000)) | (color&3);
}
}
break;
}
}
/***************************************************************************************
** Function name: pushPartImage 8bitDIRECT Source X,Y Size() ADD
** Description: push 565 colour image into a defined area of a sprite
*************************************************************************************x*/
// TODO Need to add more area boundary checks
/*
void TFT_eSprite_CST::pushPartImage_D8(int32_t x, int32_t y, uint16_t sx, uint16_t sy, uint16_t w, uint16_t h, uint16_t sw, uint8_t *data,uint16_t m,uint16_t m=SPBB_NOR)
{
if ((x >= _iwidth) || (y >= _iheight) || (w == 0) || (h == 0) || !_created ||_bpp != 8) return;
int bp,sbp;
byte color;
switch(m){
case SPBB_NOR://NORMAL
default:
if(m&SPR_ZERO_T)//Transparent color(0) ON >Run
for (uint32_t yp = 0; yp < h; yp++)
{
bp=(y+yp) * _iwidth +x;sbp=(sy+yp) * _iwidth+sx;
for (uint32_t xp = 0; xp < w; xp++)
{
color=data[xp + sbp];
if(color!=0)_img8[xp + bp] =color;
}
}
else//NOT T
for (uint32_t yp = 0; yp < h; yp++)
{
bp=(y+yp) * _iwidth +x;sbp=(sy+yp) * _iwidth+sx;
for (uint32_t xp = 0; xp < w; xp++)
{
_img8[xp + bp] = data[xp + sbp];
}
}
break;
case SPBB_TRA://Fake_Translucent
for (uint32_t yp = 0; yp < h; yp++)
{
bp=(y+yp) * _iwidth +x;sbp=(sy+yp) * _iwidth+sx;
for (uint32_t xp = 0; xp < w; xp++)
{
_img8[xp + bp]|= data[xp + sbp];
}
}
break;
case SPBB_RGC://R<>G REVERSE CONVERT(MSX)
for (uint32_t yp = 0; yp < h; yp++)
{
bp=(y+yp) * _iwidth +x;sbp=(sy+yp) * _iwidth+sx;
for (uint32_t xp = 0; xp < w; xp++)
{
color= data[xp + sbp];
_img8[xp + bp] = ((color>>3)&(0b00011100)) | ((color<<3)&(0b11100000)) | (color&3);
}
}
break;
}
}
*/
/***************************************************************************************
** Function name: pushImage 8bitDIRECT 2018/10/5 T.K Add
** Description: push 565 colour FLASH (PROGMEM) image into a defined area
*************************************************************************************x*/
// TODO Need to add more area boundary checks
//
void TFT_eSprite_CST::pushPartImage_D8(int32_t x, int32_t y, uint16_t sx, uint16_t sy, uint16_t w, uint16_t h, uint16_t sw, const uint8_t *data,uint16_t m ,uint16_t cl,uint16_t ang,uint16_t scl,uint16_t tra)
{
if (!_created ||_bpp != 8 || (x >= _iwidth) || (y >= _iheight) || (w == 0) || (h == 0) ) return;
uint32_t bp,sbp;
byte color;
switch((m&15)){
case SPBB_NOR://NORMAL
default:
if(m&SPR_CLIP)//Clipping MODE //Not supported
{
if(m&SPR_ZERO_T)//Transparent color(0) ON >Run
for (uint32_t yp = 0; yp < h; yp++)
{
//Cliping AHO CODE
if(y+yp>=_iheight){break;}
else
if(y+yp<0){continue;}
bp=(y+yp) * _iwidth +x;sbp=(uint32_t)data+(sy+yp) * sw+sx;
if(m&SPR_COLOR)
for (uint32_t xp = 0; xp < w; xp++)
{
//Cliping AHO CODE
if(x+xp>=_iwidth){break;}
else
if(x+xp<0){continue;}
color=pgm_read_byte(xp + sbp);
if(color!=0)_img8[xp + bp] =cl;
}
else
for (uint32_t xp = 0; xp < w; xp++)
{
//Cliping AHO CODE
if(x+xp>=_iwidth){break;}
else
if(x+xp<0){continue;}
color=pgm_read_byte(xp + sbp);
if(color!=0)_img8[xp + bp] =color;
}
}
else//NOT T
for (uint32_t yp = 0; yp < h; yp++)
{
//Cliping AHO CODE
if(y+yp>=_iheight){break;}
else
if(y+yp<0){continue;}
bp=(y+yp) * _iwidth +x;sbp=(sy+yp) * sw+sx;
for (uint32_t xp = 0; xp < w; xp++)
{
//Cliping AHO CODE
if(x+xp>=_iwidth){break;}
else
if(x+xp<0){continue;}
_img8[xp + bp] = pgm_read_byte(xp + sbp);
}
}
}
else
{
if(m&SPR_ZERO_T)//Transparent color(0) ON >Run
for (uint32_t yp = 0; yp < h; yp++)
{
bp=(y+yp) * _iwidth +x;sbp=(uint32_t)data+(sy+yp) * sw+sx;
if(m&SPR_COLOR)
for (uint32_t xp = 0; xp < w; xp++)
{
color=pgm_read_byte(xp + sbp);
if(color!=0)_img8[xp + bp] =cl;
}
else
for (uint32_t xp = 0; xp < w; xp++)
{
color=pgm_read_byte(xp + sbp);
if(color!=0)_img8[xp + bp] =color;
}
}
else//NOT T
for (uint32_t yp = 0; yp < h; yp++)
{
bp=(y+yp) * _iwidth +x;sbp=(sy+yp) * sw+sx;
for (uint32_t xp = 0; xp < w; xp++)
{
_img8[xp + bp] = pgm_read_byte(xp + sbp);
}
}
}
break;
case SPBB_TRA://Fake_Translucent
if(m&SPR_CLIP);//Clipping MODE //Not supported
else
for (uint32_t yp = 0; yp < h; yp++)
{
bp=(y+yp) * _iwidth +x;(uint32_t)data+(sy+yp) * sw+sx;
for (uint32_t xp = 0; xp < w; xp++)
{
_img8[xp + bp]|= pgm_read_byte(xp + sbp);
}
}
break;
case SPBB_RGC://R<>G REVERSE CONVERT(MSX)
if(m&SPR_CLIP);//Clipping MODE //Not supported
else
for (uint32_t yp = 0; yp < h; yp++)
{
bp=(y+yp) * _iwidth +x;sbp=(uint32_t)data+(sy+yp) * sw+sx;
for (uint32_t xp = 0; xp < w; xp++)
{
color= pgm_read_byte(xp + sbp);
_img8[xp + bp] = ((color>>3)&(0b00011100)) | ((color<<3)&(0b11100000)) | (color&3);
}
}
break;
}
}
/***************************************************************************************
** Function name: setSwapBytes
** Description: Used by 16 bit pushImage() to swap byte order in colours
***************************************************************************************/
void TFT_eSprite_CST::setSwapBytes(bool swap)
{
_iswapBytes = swap;
}
/***************************************************************************************
** Function name: getSwapBytes
** Description: Return the swap byte order for colours
***************************************************************************************/
bool TFT_eSprite_CST::getSwapBytes(void)
{
return _iswapBytes;
}
/***************************************************************************************
** Function name: setWindow
** Description: Set the bounds of a window for pushColor and writeColor
*************************************************************************************x*/
void TFT_eSprite_CST::setWindow(int32_t x0, int32_t y0, int32_t x1, int32_t y1)
{
bool duff_coord = false;
if (x0 > x1) swap_coord(x0, x1);
if (y0 > y1) swap_coord(y0, y1);
if (x0 < 0) x0 = 0;
if (x0 >= _iwidth) duff_coord = true;
if (x1 < 0) x1 = 0;
if (x1 >= _iwidth) x1 = _iwidth - 1;
if (y0 < 0) y0 = 0;
if (y0 >= _iheight) duff_coord = true;
if (y1 < 0) y1 = 0;
if (y1 >= _iheight) y1 = _iheight - 1;
if (duff_coord)
{ // Point to that extra "off screen" pixel
_xs = 0;
_ys = _iheight;
_xe = 0;
_ye = _iheight;
}
else
{
_xs = x0;
_ys = y0;
_xe = x1;
_ye = y1;
}
_xptr = _xs;
_yptr = _ys;
}
/***************************************************************************************
** Function name: pushColor
** Description: Send a new pixel to the set window
*************************************************************************************x*/
void TFT_eSprite_CST::pushColor(uint32_t color)
{
if (!_created ) return;
// Write the colour to RAM in set window
if (_bpp == 16)
_img [_xptr + _yptr * _iwidth] = (uint16_t) (color >> 8) | (color << 8);
else if (_bpp == 8)
_img8[_xptr + _yptr * _iwidth] = (uint8_t )((color & 0xE000)>>8 | (color & 0x0700)>>6 | (color & 0x0018)>>3);
else drawPixel(_xptr, _yptr, color);
// Increment x
_xptr++;
// Wrap on x and y to start, increment y if needed
if (_xptr > _xe)
{
_xptr = _xs;
_yptr++;
if (_yptr > _ye) _yptr = _ys;
}
}
/***************************************************************************************
** Function name: pushColor
** Description: Send a "len" new pixels to the set window
*************************************************************************************x*/
void TFT_eSprite_CST::pushColor(uint32_t color, uint16_t len)
{
if (!_created ) return;
uint16_t pixelColor;
if (_bpp == 16)
pixelColor = (uint16_t) (color >> 8) | (color << 8);
else if (_bpp == 8)
pixelColor = (color & 0xE000)>>8 | (color & 0x0700)>>6 | (color & 0x0018)>>3;
else
pixelColor = color;
while(len--) writeColor(pixelColor);
}
/***************************************************************************************
** Function name: writeColor
** Description: Write a pixel with pre-formatted colour to the set window
*************************************************************************************x*/
void TFT_eSprite_CST::writeColor(uint16_t color)
{
if (!_created ) return;
// Write 16 bit RGB 565 encoded colour to RAM
if (_bpp == 16) _img [_xptr + _yptr * _iwidth] = color;
// Write 8 bit RGB 332 encoded colour to RAM