-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathegi_symbol.c
1535 lines (1310 loc) · 45.9 KB
/
egi_symbol.c
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
/*----------------------------------------------------------------------------
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation.
For test only!
1. Symbols may be icons,fonts, image, a serial motion picture.... etc.
2. One img symbol page size is a 240x320x2Bytes data , 2Bytes for 16bit color.
each row has 240 pixels. usually it is a pure color data file.
3. One mem symbol page size is MAX.240X320X2Bytes, usually it is smaller because
its corresponding img symbol page has blank space.
Mem symbol page is read and converted from img symbol page, mem symbol page
stores symbol pixels data row by row consecutively for each symbol. and it
is more efficient for storage and search.
A mem symbol page may be saved as a file.
5. All symbols in a page MUST have the same height, and each row MUST has the same
number of symbols.
6. The first symbol in a img page shuld not be used, code '0' usually will be treated
as and end token for a char string.
7. when you edit a symbol image, don't forget to update:
7.1 sympg->maxnum;
7.2 xxx_width[N] >= sympg->maxnu;
7.3 modify symbol structre in egi_symbol.h accordingly.
TODO:
0. different type symbol now use same writeFB function !!!!! font and icon different writeFB func????
0. if image file is not complete.
1. void symbol_save_pagemem( )
2. void symbol_writeFB( ) ... copy all data if no transp. pixel applied.
3. data encode.
4. symbol linear enlarge and shrink.
5. To read FBDE vinfo to get all screen/fb parameters as in fblines.c, it's improper in other source files.
Journal:
2021-03-10:
1. symbol_writeFB(): Add check zbuff.
2021-03-25:
1. symbol_writeFB(): Add zpos for zbuff[].
2022-05-27:
1. Add member 'color' for EGI_SYMPAGE.
2. symbol_writeFB(): If sym_page has color data, then assign pcolor=sym_page->color[poff].
Midas Zhou
[email protected](Not in use since 2022_03_01)
----------------------------------------------------------------------------*/
//#define _GNU_SOURCE /* for O_CLOEXEC flag */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h> /*close*/
#include <stdint.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include "egi_fbgeom.h"
#include "egi_image.h"
#include "egi_symbol.h"
#include "egi_debug.h"
#include "egi_log.h"
#include "egi_timer.h"
#include "egi_math.h"
/*--------------------( testfont )------------------------
1. ascii 0-127 symbol width,
2. 5-pixel blank space for nonprintable symbols, though 0-pixel seems also OK.
3. Please change the 'space' width according to your purpose.
*/
static int testfont_width[16*8] = /* check with maxnum */
{
/* give return code a 0 width in a txt display */
// 5,5,5,5,5,5,5,5,5,5,0,5,5,5,5,5, /* nonprintable symbol, give it 5 pixel wide blank */
// 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, /* nonprintable symbol, give it 5 pixel wide blank */
0,0,0,0,0,0,0,0,0,30,0,0,0,0,0,0, /* 9-TAB 50pixels, nonprintable symbol */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
5,7,8,10,11,15,14,5,6,6,10,10,5,6,5,8, /* space,!"#$%&'()*+,-./ */
11,11,11,11,11,11,11,11,11,11,6,6,10,10,10,10, /* 0123456789:;<=>? */
19,12,11,11,13,10,10,13,13,5,7,11,9,18,14,14, /* @ABCDEFGHIJKLMNO */
11,14,11,10,10,13,12,19,11,10,10,6,8,6,10,10, /* PQRSTUVWXYZ[\]^_ */
6,10,11,9,11,10,6,10,11,5,5,10,5,17,11,10, /* uppoint' abcdefghijklmnop */
11,11,7,8,7,11,9,15,9,10,8,7,10,7,10,5 /*pqrstuvwxyz{|}~ blank */
};
/* symbole page struct for testfont */
EGI_SYMPAGE sympg_testfont=
{
.symtype=symtype_font,
#ifdef LETS_NOTE
.path="/home/midas-zhou/egi/testfont.img",
#else
.path="/home/testfont.img",
#endif
.bkcolor=0xffff,
.data=NULL,
.maxnum=128-1,
.sqrow=16,
.symheight=26,
.symwidth=testfont_width, /* width list */
};
/*--------------------------( numbfont )-----------------------------------
big number font 0123456789:
*/
static int numbfont_width[16*8] = /* check with maxnum */
{
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* nonprintable symbol */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
15,15,15,15,15,15,15,15,15,15,15,0,0,0,0,0, /* 0123456789: */
};
/* symbole page struct for numbfont */
EGI_SYMPAGE sympg_numbfont=
{
.symtype=symtype_font,
#ifdef LETS_NOTE
.path="/home/midas-zhou/egi/numbfont.img",
#else
.path="/home/numbfont.img",
#endif
.bkcolor=0x0000,
.data=NULL,
.maxnum=16*4-1,
.sqrow=16,
.symheight=20,
.symwidth=numbfont_width, /* width list */
};
/*--------------------------( buttons H60 )-----------------------------------*/
static int buttons_width[4*5] = /* check with maxnum */
{
60,60,60,60,
60,60,60,60,
60,60,60,60,
60,60,60,60,
60,60,60,60,
};
EGI_SYMPAGE sympg_buttons=
{
.symtype=symtype_icon,
#ifdef LETS_NOTE
.path="/home/midas-zhou/egi/buttons.img",
#else
.path="/home/buttons.img",
#endif
.bkcolor=0x0000,
.data=NULL,
.maxnum=4*5-1, /* 5 rows of ioncs */
.sqrow=4, /* 4 icons per row */
.symheight=60,
.symwidth=buttons_width, /* width list */
};
/*--------------------------( small buttons W48H60 )-----------------------------------*/
static int sbuttons_width[5*3] = /* check with maxnum */
{
48,48,48,48,
48,48,48,48,
48,48,48,48,
};
EGI_SYMPAGE sympg_sbuttons=
{
.symtype=symtype_icon,
#ifdef LETS_NOTE
.path="/home/midas-zhou/egi/sbuttons.img",
#else
.path="/home/sbuttons.img",
#endif
.bkcolor=0x0000,
.data=NULL,
.maxnum=5*3-1, /* 5 rows of ioncs */
.sqrow=5, /* 4 icons per row */
.symheight=48, /*60, */
.symwidth=sbuttons_width, /* width list */
};
/*--------------------------( 30x30 icons for Home Head-Bar )-----------------------------------*/
static int icons_width[8*12] = /* element number MUST >= maxnum */
{
30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,
};
EGI_SYMPAGE sympg_icons=
{
.symtype=symtype_font,
#ifdef LETS_NOTE
.path="/home/midas-zhou/egi/icons.img",
#else
.path="/home/icons.img",
#endif
.bkcolor=0x0000,
.data=NULL,
.maxnum=11*8-1, /* 11 rows of ioncs */
.sqrow=8, /* 8 icons per row */
.symheight=30,
.symwidth=icons_width, /* width list */
};
/* put load motion icon array for CPU load
!!! put code 0 as end of string */
char symmic_cpuload[6][5]= /* sym for motion icon */
{
{40,41,42,43,0}, /* very light loadavg 1 */
{44,45,46,47,0}, /* light loadavg 2 */
{48,49,50,51,0}, /* moderate loadavg 3 */
{52,53,54,55,0}, /* heavy loadavg 4 */
{56,57,58,59,0}, /* very heavy loadavg 5 */
{60,61,62,63,0}, /* red alarm loadavg 6 >5 overload*/
};
/* IoT mmic */
char symmic_iotload[9]=
{ 16,17,18,19,20,21,22,23,0}; /* with end token /0 */
/*------------------( 60x60 icons for PLAYS and ARROWS )-----------------*/
static int icons_2_width[4*5] = /* element number MUST >= maxnum */
{
60,60,60,60,
60,60,60,60,
60,60,60,60,
60,60,60,60,
60,60,60,60,
};
/* symbole page struct for testfont */
EGI_SYMPAGE sympg_icons_2=
{
.symtype=symtype_icon,
#ifdef LETS_NOTE
.path="/home/midas-zhou/egi/icons_2.img",
#else
.path="/home/icons_2.img",
#endif
.bkcolor=0x0000,
.data=NULL,
.maxnum=4*5-1, /* 5 rows of ioncs */
.sqrow=4, /* 8 icons per row */
.symheight=60,
.symwidth=icons_2_width, /* width list */
};
/* for HeWeather Icons */
static int heweather_width[1*1] =
{
60
};
EGI_SYMPAGE sympg_heweather =
{
.symtype=symtype_icon,
.path=NULL, /* NOT applied */
.bkcolor=-1, /* <0, no transpcolor applied */
.data=NULL, /* 16bit per pixle image data */
.alpha=NULL, /* 8bit per pixle alpha data */
.maxnum=1*1-1,
.sqrow=1, /* 1 icons per row */
.symheight=60,
.symwidth=heweather_width, /* width list */
};
/* ----- All static functions ----- */
static uint16_t *symbol_load_page(EGI_SYMPAGE *sym_page);
/* ----------------------------------------------------------------------
TODO: Only for one symbol NOW!!!!!
load a symbol_page struct from a EGI_IMGBUF
@sym_page: pointer to a symbol_page.
@imgbuf: a EGI_IMGBUF holding that image data
Return:
0 ok
<0 fails
------------------------------------------------------------------------*/
int symbol_load_page_from_imgbuf(EGI_SYMPAGE *sym_page, EGI_IMGBUF *imgbuf)
{
int i;
int off;
int data_size;
if(imgbuf==NULL || imgbuf->imgbuf==NULL || sym_page==NULL) {
printf("%s: Invalid input data!\n",__func__);
return -1;
}
data_size=(imgbuf->height)*(imgbuf->width)*2; /* 16bpp color */
/* malloc mem for symbol_page.symoffset */
sym_page->symoffset = calloc(1, ((sym_page->maxnum)+1) * sizeof(int) );
if(sym_page->symoffset == NULL) {
printf("%s: fail to malloc sym_page->symoffset!\n",__func__);
return -1;
}
/* set symoffset */
off=0;
for(i=0; i<=sym_page->maxnum; i++)
{
sym_page->symoffset[i]=off;
off += sym_page->symwidth[i] * (sym_page->symheight) ;/* in pixel */
}
/* copy color data */
printf("copy color data...\n");
sym_page->data=calloc(1,data_size);
if(sym_page->data==NULL) {
printf("%s: Fail to alloc sym_page->data!\n",__func__);
return -2;
}
memcpy(sym_page->data, imgbuf->imgbuf, data_size);
/* copy alpha */
printf("copy alpha value...\n");
if(imgbuf->alpha) {
sym_page->alpha=calloc(1,data_size>>1); /* 8bpp for alpha */
if(sym_page->alpha==NULL) {
printf("%s: Fail to alloc sym_page->alpha!\n",__func__);
free(sym_page->data);
return -3;
}
memcpy(sym_page->alpha, imgbuf->alpha, data_size>>1);
sym_page->bkcolor=-1; /* use alpha instead of bkcolor */
}
return 0;
}
/*---------------------------------------------------------
Load all symbol files into mem pages
! Don't forget to change symbol_free_allpages() accordingly !
return:
0 OK
<0 Fail
---------------------------------------------------------*/
int symbol_load_allpages(void)
{
/* load testfont */
if(symbol_load_page(&sympg_testfont)==NULL)
goto FAIL;
/* load numbfont */
if(symbol_load_page(&sympg_numbfont)==NULL)
goto FAIL;
/* load buttons icons */
if(symbol_load_page(&sympg_buttons)==NULL)
goto FAIL;
/* load small buttons icons */
if(symbol_load_page(&sympg_sbuttons)==NULL)
goto FAIL;
/* load icons for home head-bar*/
if(symbol_load_page(&sympg_icons)==NULL)
goto FAIL;
/* load icons for PLAYERs */
if(symbol_load_page(&sympg_icons_2)==NULL)
goto FAIL;
return 0;
FAIL:
symbol_release_allpages();
return -1;
}
/* --------------------------------------
Free all mem pages
----------------------------------------*/
void symbol_release_allpages(void)
{
symbol_release_page(&sympg_testfont);
symbol_release_page(&sympg_numbfont);
symbol_release_page(&sympg_buttons);
symbol_release_page(&sympg_sbuttons);
symbol_release_page(&sympg_icons);
symbol_release_page(&sympg_icons_2);
}
/*----------------------------------------------------------------
load an img page file
1. direct mmap.
or
2. load to a mem page. (current implementation)
path: path to the symbol image file
num: total number of symbols,or MAX code number-1;
height: heigh of all symbols
width: list for all symbol widthes
sqrow: symbol number in each row of an img page
------------------------------------------------------------------*/
static uint16_t *symbol_load_page(EGI_SYMPAGE *sym_page)
{
int fd;
int datasize; /* memsize for all symbol data */
int i,j;
int x0=0,y0=0; /* origin position of a symbol in a image page, left top of a symbol */
int nr,no;
int offset=0; /* in pixel, offset of data mem for each symbol, NOT of img file */
int all_height; /* height for all symbol in a page */
int width; /* width of a symbol */
if(sym_page==NULL)
return NULL;
/* open symbol image file */
fd=open(sym_page->path, O_RDONLY|O_CLOEXEC);
if(fd<0)
{
printf("fail to open symbol file %s!\n",sym_page->path);
perror("open symbol image file");
return NULL;
}
#if 1 /*------------ check an ((unloaded)) page structure -----------*/
/* check for maxnum */
if(sym_page->maxnum < 0 )
{
printf("symbol_load_page(): symbol number less than 1! fail to load page.\n");
return NULL;
}
/* check for data */
if(sym_page->data != NULL)
{
printf("symbol_load_page(): sym_page->data is NOT NULL! symbol page may be already \
loaded in memory!\n");
return sym_page->data;
}
/* check for symb_index */
if(sym_page->symwidth == NULL)
{
printf("symbol_load_page(): symbol width list is empty! fail to load symbole page.\n");
return NULL;
}
#endif
/* get height for all symbols */
all_height=sym_page->symheight;
/* malloc mem for symbol_page.symoffset */
sym_page->symoffset = malloc( ((sym_page->maxnum)+1) * sizeof(int) );
if(sym_page->symoffset == NULL) {
printf("symbol_load_page():fail to malloc sym_page->symoffset!\n");
return NULL;
}
/* calculate symindex->sym_offset for each symbol
and mem size needed for all symbols */
datasize=0;
for(i=0;i<=sym_page->maxnum;i++)
{
sym_page->symoffset[i]=datasize;
datasize += sym_page->symwidth[i] * all_height ;/* in pixel */
}
/* malloc mem for symbol_page.data */
sym_page->data= malloc( datasize*sizeof(uint16_t) ); /* memsize in pixel of 16bit color*/
{
if(sym_page->data == NULL)
{
EGI_PLOG(LOGLV_ERROR,"symbol_load_page(): fail to malloc sym_page->data! ???Maybe element number of symwidth[] is less than symbol_page.maxnum \n");
symbol_release_page(sym_page);
return NULL;
}
}
/* read symbol pixel data from image file to sym_page.data */
for(i=0; i<=sym_page->maxnum; i++) /* i for each symbol */
{
/* a symbol width MUST NOT be zero.! --- zero also OK, */
/*
if( sym_page->symwidth[i]==0 )
{
printf("symbol_load_page(): sym_page->symwidth[%d]=0!, a symbol width MUST NOT be zero!\n",i);
symbol_release_page(sym_page);
return NULL;
}
*/
nr=i/(sym_page->sqrow); /* locate row number of the page */
no=i%(sym_page->sqrow); /* in symbol,locate order number of a symbol in a row */
if(no==0) /* reset x0 for each row */
x0=0;
else
x0 += sym_page->symwidth[i-1]; /* origin pixel order in a row */
y0 = nr * all_height; /* origin pixel order in a column */
//printf("x0=%d, y0=%d \n",x0,y0);
offset=sym_page->symoffset[i]; /* in pixel, offset of the symbol in mem data */
width=sym_page->symwidth[i]; /* width of the symbol */
#if 0 /* for test -----------------------------------*/
if(i=='M')
printf(" width of 'M' is %d, offset is %d \n",width,offset);
#endif /* test end -----------------------------------*/
for(j=0;j<all_height;j++) /* for each pixel row of a symbol */
{
/* in image file: seek position for pstart of a row, in bytes. 2bytes per pixel */
if( lseek(fd,(y0+j)*SYM_IMGPAGE_WIDTH*2+x0*2,SEEK_SET)<0 ) /* in bytes */
{
perror("lseek symbol image file");
//EGI_PLOG(LOGLV_ERROR,"lseek symbol image fails.%s \n",strerror(errno));
symbol_release_page(sym_page);
return NULL;
}
/* in mem data: read each row pixel data form image file to sym_page.data,
2bytes per pixel, read one row pixel data each time */
if( read(fd, (uint8_t *)(sym_page->data+offset+width*j), width*2) < width*2 )
{
perror("read symbol image file");
symbol_release_page(sym_page);
return NULL;
}
}
}
printf("finish reading %s.\n",sym_page->path);
#if 0 /* for test ---------------------------------- */
i='M';
offset=sym_page->symoffset[i];
width=sym_page->symwidth[i];
for(j=0;j<all_height;j++)
{
for(k=0;k<width;k++)
{
if( *(uint16_t *)(sym_page->data+offset+width*j+k) != 0xFFFF)
printf("*");
else
printf(" ");
}
printf("\n");
}
#endif /* test end -----------------------------------*/
close(fd);
EGI_PLOG(LOGLV_INFO,"symbol_load_page(): succeed to load symbol image file %s!\n", sym_page->path);
//printf("sym_page->data = %p \n",sym_page->data);
return (uint16_t *)sym_page->data;
}
/*--------------------------------------------------
Release data in a symbol page
---------------------------------------------------*/
void symbol_release_page(EGI_SYMPAGE *sym_page)
{
if(sym_page==NULL)
return;
if(sym_page->data != NULL) {
//printf("%s: free(sym_page->data) ...\n",__func__);
free(sym_page->data);
sym_page->data=NULL;
}
if(sym_page->alpha != NULL) {
//printf("%s: free(sym_page->alpah) ...\n",__func__);
free(sym_page->alpha);
sym_page->alpha=NULL;
}
if(sym_page->symoffset != NULL) {
//printf("%s: free(sym_page->symoffset) ...\n",__func__);
free(sym_page->symoffset);
sym_page->symoffset=NULL;
}
/* TODO: 1. For symbol page: symwidth is NOT dynamically allocated
* 2. For FTsymbol page: symwidth is dynamically allocated
*/
// sym_page->symwidth=NULL;
// if(sym_page->symwidth != NULL) {
// printf("%s: free(sym_page->symwidth) ...\n",__func__);
// free(sym_page->symwidth);
// sym_page->symwidth=NULL;
// }
/* ? static value */
// sym_page->path=NULL;
}
/*-----------------------------------------------------------------------
check integrity of a ((loaded)) page structure
sym_page: a loaded page
func: function name of the caller
return:
0 OK
<0 fails
-----------------------------------------------------------------------*/
int symbol_check_page(const EGI_SYMPAGE *sym_page, char *func)
{
/* check sym_page */
if(sym_page==NULL)
{
printf("%s(): symbol_page is NULL! .\n",func);
return -1;
}
/* check for maxnum */
if(sym_page->maxnum < 0 )
{
printf("%s(): symbol number less than 1! fail to load page.\n",func);
return -2;
}
/* check for data */
if(sym_page->data == NULL)
{
printf("%s(): sym_page->data is NULL! the symbol page has not been loaded?!\n",func);
return -3;
}
/* check for symb_index */
if(sym_page->symwidth == NULL)
{
printf("%s(): symbol width list is empty!\n",func);
return -4;
}
return 0;
}
/*--------------------------------------------------------------------------
print all symbol in a mem page.
print '*' if the pixel data is not 0.
sym_page: a mem symbol page pointer.
transpcolor: color treated as transparent.
black =0x0000; white = 0xffff;
----------------------------------------------------------------------------*/
void symbol_print_symbol( const EGI_SYMPAGE *sym_page, int symbol, uint16_t transpcolor)
{
int i;
int j,k;
/* check page first */
if(symbol_check_page(sym_page,"symbol_print_symbol") != 0)
return;
i=symbol;
#if 1 /* TEST ---------- */
printf("symheight=%d, symwidth=%d \n", sym_page->symheight, sym_page->symwidth[i]);
#endif
for(j=0;j<sym_page->symheight;j++) /*for each row of a symbol */
{
for(k=0;k<sym_page->symwidth[i];k++)
{
/* if not transparent color, then print the pixel */
if(sym_page->alpha==NULL) {
if( *(uint16_t *)( sym_page->data+(sym_page->symoffset)[i] \
+(sym_page->symwidth)[i]*j +k ) != transpcolor ) {
printf("*");
}
else
printf(" ");
}
else { /* use alpha value */
if( *(unsigned char *)(sym_page->alpha+(sym_page->symoffset)[i] \
+(sym_page->symwidth)[i]*j +k ) > 0 ) {
printf("*");
}
else
printf(" ");
}
}
printf("\n"); /* end of each row */
}
}
/*-----------------------------------------------------
save mem of a symbol page to a file
-------------------------------------------------------*/
void symbol_save_pagemem(EGI_SYMPAGE *sym_page)
{
}
/*------------------------------------------
Get string length in pixel.
@str string
@font font for the string
-------------------------------------------*/
int symbol_string_pixlen(char *str, const EGI_SYMPAGE *font)
{
int i;
int len=strlen(str);
int pixlen=0;
if( len==0 || font==NULL)
return 0;
for(i=0;i<len;i++)
{
/* only if in code range */
if( str[i] <= font->maxnum )
pixlen += font->symwidth[ (unsigned int)str[i] ];
}
return pixlen;
}
/*------------------------------------------------------------------------------------------
write a symbol/font pixel data to FB device
1. Write a symbol data to FB.
2. Alpha data is available in a FT2 symbol page, use WEGI_COLOR_BLACK as default front
color.
4. Note: put page check in symbol_string_writeFB()!!!
5. Points out of fb_map page(one screen buffer) will be ruled out.
@fbdev: FB device
or Virt FB
@sym_page: symbol page, if it has alpha value, then blends with opaque.
@transpcolor: >=0 transparent pixel will not be written to FB, so backcolor is shown there.
<0 no transparent pixel
@fontcolor: font color(symbol color for a symbol)
>= 0, use given font color.
<0 , use default color in img data.
use following COLOR:
#define SYM_NOSUB_COLOR -1 --- no substitute color defined for a symbol or font
#define SYM_NOTRANSP_COLOR -1 --- no transparent color defined for a symbol or font
@x0,y0: start position coordinate in screen, left top point of a symbol.
@sym_code: symbol code number
@opaque: Set aplha value (0-255) for all pixels, if sym_page also has alpha value
then the final alpha value would be: sym_alpha*opaque/255;
Normally set it as 255.
<0 Lumiance decrement value; No effect, or use symbol alpha value.
alpha =0
0 100% back ground color/transparent, alpha=0
255 100% front color, alpha=255
>255 alpha=255
-----------------------------------------------------------------------------------------*/
inline void symbol_writeFB(FBDEV *fb_dev, const EGI_SYMPAGE *sym_page, \
int fontcolor, int transpcolor, int x0, int y0, unsigned int sym_code, int opaque)
{
/* check data */
if( sym_page==NULL || (sym_page->data==NULL && sym_page->alpha==NULL) ) {
printf("%s: Input symbol page has no valid data inside.\n",__func__); /* Example: A Freetype char with no bitmap */
return;
}
int i,j;
FBPIX fpix;
long int pos; /* offset position in fb map */
long int zpos; /* for zbuff[] pos */
int xres;
int yres;
int mapx=0,mapy=0; /* if need ROLLBACK effect,then map x0,y0 to LCD coordinate range when they're out of range*/
uint16_t pcolor;
uint32_t pargb; /* ARGB, !!! init for non FT type fonts, alpha is 255. */
uint32_t prgb; /* RGB */
unsigned char palpha=0; /* pixel alpha value if applicable */
unsigned char *map=NULL; /* the pointer to map FB or back buffer */
uint16_t *data=sym_page->data; /* symbol pixel data in a mem page, for FT2 sympage, it's NULL! */
int offset;
long poff;
int height=sym_page->symheight;
int width;
EGI_IMGBUF *virt_fb;
int sumalpha;
int lumdev=0; /* luminance decrement value */
/* <<<<<< FB BUFFER SELECT >>>>>> */
#if defined(ENABLE_BACK_BUFFER) || defined(LETS_NOTE)
map=fb_dev->map_bk; /* write to back buffer */
#else
map=fb_dev->map_fb; /* write directly to FB map */;
#endif
//long int screensize=fb_dev->screensize;
/* check page */
#if 0 /* not here, put page check in symbol_string_writeFB() */
if(symbol_check_page(sym_page, "symbol_writeFB") != 0)
return;
#endif
/* check sym_code */
if( sym_code > sym_page->maxnum && sym_page->symtype!=symtype_FT2 ) {
EGI_PDEBUG(DBG_SYMBOL,"symbole code number out of range! sympg->path: %s\n", sym_page->path);
return;
}
/* set xres and yres */
virt_fb=fb_dev->virt_fb;
if(virt_fb) { /* for virtual FB */
xres=virt_fb->width;
yres=virt_fb->height;
}
else { /* for FB */
//xres=fb_dev->vinfo.xres;
#ifdef LETS_NOTE
xres=fb_dev->finfo.line_length>>2;
#else
xres=fb_dev->finfo.line_length>>1;
#endif
yres=fb_dev->vinfo.yres;
}
/* get symbol/font width, only 1 character in FT2 symbol page NOW!!! */
if(sym_page->symtype==symtype_FT2) {
width=sym_page->ftwidth;
offset=0;
}
else {
width=sym_page->symwidth[sym_code];
offset=sym_page->symoffset[sym_code];
}
/* check and reset opaque to [0 255] */
if( opaque < 0 ) {
lumdev=opaque; /* As luminance decrement value */
opaque=255;
}
else if( opaque > 255) {
opaque=255;
}
/* Init palpha for non FT symobls */
if(sym_page->alpha == NULL) {
palpha=255;
pargb=255<<24; /* For LETS_NOTE */
}
/* get symbol pixel and copy it to FB mem */
//printf("%s:symbol H=%d, W=%d\n",__func__, height, width);
for(i=0;i<height;i++)
{
for(j=0;j<width;j++)
{
/* skip pixels according to opaque value, skipped pixels
make trasparent area to the background */
// if(opaque>0)
// {
// if( ((i%2)*(opaque/2)+j)%(opaque) != 0 ) /* make these points transparent */
// continue;
// }
#ifdef FB_SYMOUT_ROLLBACK /* NOTE !!! FB pos_rotate NOT applied */
/*--- map x for every (i,j) symbol pixel---*/
if( x0+j<0 )
{
mapx=xres-(-x0-j)%xres; /* here mapx=1-240, if real FB */
mapx=mapx%xres;
}
else if( x0+j>xres-1 )
mapx=(x0+j)%xres;
else
mapx=x0+j;
/*--- map Y for every (i,j) symbol pixel---*/
if ( y0+i<0 )
{
/* in case y0=0 and i=0,then mapy=320!!!!, then function will returns
and abort drawing the symbol., don't forget -1 */
mapy=yres-(-y0-i)%yres; /* here mapy=1-320 */
mapy=mapy%yres;
}
else if(y0+i>yres-1)
mapy=(y0+i)%yres;
else
mapy=y0+i;
#else /*--- if NO ROLLBACK ---*/
/* ----- FB ROTATION POSITION MAPPING -----
* IF 90 Deg rotated: Y maps to (xres-1)-FB.X, X maps to FB.Y
*/
switch(fb_dev->pos_rotate) {
case 0: /* FB defaul position */
mapx=x0+j;
mapy=y0+i;
break;
case 1: /* Clockwise 90 deg */
mapx=(xres-1)-(y0+i);
mapy=x0+j;
break;
case 2: /* Clockwise 180 deg */
mapx=(xres-1)-(x0+j);
mapy=(yres-1)-(y0+i);
break;
case 3: /* Clockwise 270 deg */
mapx=y0+i;
mapy=(yres-1)-(x0+j);
break;
}
/* LIMIT CHECK: ignore out ranged points */
if(mapx>(xres-1) || mapx<0 )
continue;
if(mapy>(yres-1) || mapy<0 )
continue;
#endif
/*x(i,j),y(i,j) mapped to LCD(xy),
however, pos may also be out of FB screensize ? */
pos=mapy*xres+mapx; /* in pixel, LCD fb mem position */
//pos=mapy*(fb_dev->finfo.line_length>>3)+mapx;
poff=offset+width*i+j; /* offset to pixel data */
/* Check Z */
if( fb_dev->zbuff_on ) {
zpos=mapy*fb_dev->vinfo.xres+mapx;
if( fb_dev->zbuff[zpos] > fb_dev->pixz )
continue;
else {
fb_dev->zbuff[zpos]=fb_dev->pixz;
}
}
if(sym_page->alpha)
palpha=*(sym_page->alpha+poff); /* get pixel alpha */
/* for FT font sympage, only alpah value, and data is NULL. */
if( data==NULL ) {
pcolor=WEGI_COLOR_BLACK; /* pcolor will(may) be re_assigned to fontcolor later ... */
}
/* get symbol pixel in page data */
else {
pcolor=*(data+poff);
}
/* ------- Assign color data one by one,faster than memcpy --------
Write to FB only if:
0. Lumadev<0 (opaque<0), then transparent pixel to be darkened!
1. alpha value exists, then use alpha to blend image instead of transpcolor.
2. OR(no transp. color applied)
3. OR (write only untransparent pixel)
otherwise,if pcolor==transpcolor, DO NOT write to FB
*/
/* To darken transparent pixel of symbol img page! */
if( pcolor == transpcolor && lumdev < 0 && sym_page->alpha==NULL ) {
#ifdef LETS_NOTE
#endif
pos<<=1; /*pixel to byte, pos=pos*2 */
/* adjust background pixel luma */
pcolor=egi_colorLuma_adjust(*(uint16_t *)(map+pos), lumdev);
*(uint16_t *)(map+pos) = pcolor;
}
else if( sym_page->alpha || transpcolor<0 || pcolor!=transpcolor ) /* transpcolor applied befor COLOR FLIP! */
{
/* push original fb data to FB FILO, before write new color */
if(fb_dev->filo_on) { /* For real FB device */
#ifdef LETS_NOTE /*--- 4 bytes per pixel ---*/
fpix.position=pos<<2; /* pixel to bytes, !!! FAINT !!! */
fpix.argb=*(uint32_t *)(map+(pos<<2));
#else /*--- 2 bytes per pixel ---*/
fpix.position=pos<<1; /* pixel to bytes, !!! FAINT !!! */
fpix.color=*(uint16_t *)(map+(pos<<1));
//printf("symbol push FILO: pos=%ld.\n",fpix.position);
#endif