-
Notifications
You must be signed in to change notification settings - Fork 0
/
linear16.c
1342 lines (1185 loc) · 34.2 KB
/
linear16.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
/* $Id$
*
* Video Base Library:
* linear16.c - For 16bpp linear framebuffers
*
* PicoGUI small and efficient client/server GUI
* Copyright (C) 2000-2003 Micah Dowty <micahjd@users.sourceforge.net>
*
* This library 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 2.1 of the License, or (at your option) any later version.
*
* This library 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 this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contributors:
*
*
*
*/
#include <pgserver/common.h>
#include <pgserver/inlstring.h> /* inline-assembly __memcpy */
#include <pgserver/video.h>
#include <pgserver/render.h>
#include <pgserver/autoconf.h>
#include <stdlib.h> /* For alloca */
/* Macros to easily access the destination bitmap */
#define FB_MEM (((struct stdbitmap*)dest)->bits)
#define FB_BPL (((struct stdbitmap*)dest)->pitch)
#define FB_ISNORMAL(bmp,lgop) (lgop == PG_LGOP_NONE && ((struct stdbitmap*)bmp)->bpp == vid->bpp)
/* Macro for addressing framebuffer pixels. Note that this is only
* used when an accumulator won't do, but it is a macro so a line address
* lookup table might be implemented later if really needed.
*/
#define LINE(y) ((u16 *)((y)*FB_BPL+FB_MEM))
#define PIXELADDR(x,y) ((x)+LINE(y))
#define PIXEL(x,y) (*PIXELADDR(x,y))
#undef DEBUG
/* Lookup table for alpha blending */
#ifdef CONFIG_FAST_ALPHA
u8 alpha_table_7bit[256*128];
#endif
#ifdef CONFIG_FONTENGINE_FREETYPE
u8 alpha_table_8bit[256*256];
#define FAST_MUL_8x8(a,b) (alpha_table_8bit[((a)<<8)|(b)])
#endif
/************************************************** Minimum functionality */
void linear16_pixel(hwrbitmap dest, s16 x,s16 y,hwrcolor c,s16 lgop) {
if (!FB_ISNORMAL(dest,lgop)) {
def_pixel(dest,x,y,c,lgop);
return;
}
PIXEL(x,y) = c;
}
hwrcolor linear16_getpixel(hwrbitmap dest, s16 x,s16 y) {
#ifdef DRIVER_S1D13806
unsigned short * addr;
hwrcolor c;
#endif
if (!FB_ISNORMAL(dest,PG_LGOP_NONE))
return def_getpixel(dest,x,y);
#ifdef DRIVER_S1D13806
addr = PIXELADDR (x,y);
c = * addr;
return c << 8 | c >> 8;
#else
return PIXEL(x,y);
#endif
}
/*********************************************** Accelerated (?) primitives */
/* Several other default primitives are based on slab, so this is very helpful */
void linear16_slab(hwrbitmap dest, s16 x,s16 y,s16 w,hwrcolor c,s16 lgop) {
u16 *p;
if (!FB_ISNORMAL(dest,lgop)) {
def_slab(dest,x,y,w,c,lgop);
return;
}
p = PIXELADDR(x,y);
while (w--)
*(p++) = c;
}
/* Rectangle fill, with some acceleration for certain LGOPs */
void linear16_rect(hwrbitmap dest, s16 x, s16 y, s16 w, s16 h, hwrcolor c, s16 lgop) {
u16 *dst;
s16 i,offset_dst;
if (!FB_ISNORMAL(dest,PG_LGOP_NONE)) {
def_rect(dest,x,y,w,h,c,lgop);
return;
}
switch (lgop) {
case PG_LGOP_NONE:
case PG_LGOP_OR:
case PG_LGOP_AND:
case PG_LGOP_XOR:
#ifdef CONFIG_FAST_ALPHA
case PG_LGOP_ALPHA:
#endif
break;
/* Invert is easily handled beforehand */
case PG_LGOP_INVERT:
case PG_LGOP_INVERT_AND:
case PG_LGOP_INVERT_OR:
case PG_LGOP_INVERT_XOR:
c ^= -1;
break;
default:
def_rect(dest,x,y,w,h,c,lgop);
return;
}
dst = PIXELADDR(x,y);
offset_dst = (FB_BPL>>1) - w;
/* Normal rectangle fill loop */
#define RECTLOOP \
for (;h;h--,dst+=offset_dst) { \
for (i=w;i;i--,dst++) \
OP(dst); \
}
/* Operator to perform fast alpha blending */
#ifdef CONFIG_FAST_ALPHA
#if defined(CONFIG_FAST_ALPHA_565)
#define ALPHA_OP(d) \
{ \
u16 oldpixel = *d; \
u8 *atab = alpha_table_7bit + ((c >> 16) & 0x7F00); \
int or = (oldpixel&0xF800)>>8; \
int og = (oldpixel&0x07E0)>>3; \
int ob = (oldpixel&0x001F)<<3; \
*d = (((c>>16) + atab[or | (or >> 5)] ) << 8) & 0xF800 | \
(((c>>8) + atab[og | (og >> 6)] ) << 3) & 0x07E0 | \
(( c + atab[ob | (ob >> 5)] ) >> 3) & 0x001F; \
}
#elif defined(CONFIG_FAST_ALPHA_555)
#define ALPHA_OP(d) \
{ \
u16 oldpixel = *d; \
u8 *atab = alpha_table_7bit + ((c >> 16) & 0x7F00); \
*d = (((c>>16) + atab[(oldpixel&0x7C00)>>7] ) << 7) & 0x7C00 | \
(((c>>8) + atab[(oldpixel&0x03E0)>>2] ) << 2) & 0x03E0 | \
(( c + atab[(oldpixel&0x001F)<<3] ) >> 3) & 0x001F; \
}
#elif defined(CONFIG_FAST_ALPHA_444)
#define ALPHA_OP(d) \
{ \
u16 oldpixel = *d; \
u8 *atab = alpha_table_7bit + ((c >> 16) & 0x7F00); \
*d = (((c>>16) + atab[(oldpixel&0x0F00)>>4] ) << 4) & 0x0F00 | \
((c>>8) + atab[oldpixel&0x00F0 ] ) & 0x00F0 | \
(( c + atab[(oldpixel&0x000F)<<4] ) >> 4) & 0x000F; \
}
#else
#error Unsupported color mode for fast alpha blending
#endif
#endif /* CONFIG_FAST_ALPHA */
switch (lgop) {
case PG_LGOP_NONE:
case PG_LGOP_INVERT:
#define OP(d) (*d=c)
RECTLOOP;
#undef OP
break;
case PG_LGOP_INVERT_OR:
case PG_LGOP_OR:
#define OP(d) (*d|=c)
RECTLOOP;
#undef OP
break;
case PG_LGOP_INVERT_AND:
case PG_LGOP_AND:
#define OP(d) (*d&=c)
RECTLOOP;
#undef OP
break;
case PG_LGOP_INVERT_XOR:
case PG_LGOP_XOR:
#define OP(d) (*d^=c)
RECTLOOP;
#undef OP
break;
#ifdef CONFIG_FAST_ALPHA
case PG_LGOP_ALPHA:
#define OP(d) ALPHA_OP(d)
RECTLOOP;
#undef OP
break;
#endif
}
#undef RECTLOOP
#undef ALPHA_OP
}
/* Fun-fun-fun blit functions! */
void linear16_blit(hwrbitmap dest,
s16 dst_x, s16 dst_y,s16 w, s16 h,
hwrbitmap sbit,s16 src_x,s16 src_y,
s16 lgop) {
u16 *dst;
struct stdbitmap *srcbit = (struct stdbitmap *) sbit;
s16 i,offset_dst;
s16 offset_src;
u16 *src;
if (!FB_ISNORMAL(dest,PG_LGOP_NONE)) {
def_blit(dest,dst_x,dst_y,w,h,sbit,src_x,src_y,lgop);
return;
}
/* We support a few common LGOPs, but supporting all of them would just
* waste space. */
switch (lgop) {
case PG_LGOP_NONE:
case PG_LGOP_OR:
case PG_LGOP_AND:
case PG_LGOP_XOR:
#ifdef CONFIG_FAST_ALPHA
case PG_LGOP_ALPHA:
#endif
break;
default:
def_blit(dest,dst_x,dst_y,w,h,sbit,src_x,src_y,lgop);
return;
}
/* If we try to do alpha blending on a 16bpp source bitmap, we will
* get a bus error on platforms like ARM that don't allow unaligned access!
*/
if (lgop==PG_LGOP_ALPHA && srcbit->bpp!=32) {
/* Draw a red rectangle instead to let us know something's wrong */
vid->rect(dest,dst_x,dst_y,w,h,vid->color_pgtohwr(0xFF0000),PG_LGOP_NONE);
return;
}
dst = PIXELADDR(dst_x,dst_y);
offset_dst = (FB_BPL>>1) - w;
src = ((u16*)srcbit->bits) + ((src_x*srcbit->bpp)>>4) + src_y*(srcbit->pitch>>1);
offset_src = (srcbit->pitch>>1) - ((w*srcbit->bpp)>>4);
/* Normal blit loop */
#define BLITLOOP \
for (;h;h--,src+=offset_src,dst+=offset_dst) { \
for (i=w;i;i--,src++,dst++) \
OP(dst,src); \
}
/* Operator to perform fast alpha blending */
#ifdef CONFIG_FAST_ALPHA
#if defined(CONFIG_FAST_ALPHA_565)
#define ALPHA_OP(d,s) \
{ \
u32 rgba = *((u32*)(s++)); \
u16 oldpixel = *d; \
u8 *atab = alpha_table_7bit + ((rgba >> 16) & 0x7F00); \
int or = (oldpixel&0xF800)>>8; \
int og = (oldpixel&0x07E0)>>3; \
int ob = (oldpixel&0x001F)<<3; \
*d = (((rgba>>16) + atab[or | (or >> 5)] ) << 8) & 0xF800 | \
(((rgba>>8) + atab[og | (og >> 6)] ) << 3) & 0x07E0 | \
(( rgba + atab[ob | (ob >> 5)] ) >> 3) & 0x001F; \
}
#elif defined(CONFIG_FAST_ALPHA_555)
#define ALPHA_OP(d,s) \
{ \
u32 rgba = *((u32*)(s++)); \
u16 oldpixel = *d; \
u8 *atab = alpha_table_7bit + ((rgba >> 16) & 0x7F00); \
*d = (((rgba>>16) + atab[(oldpixel&0x7C00)>>7] ) << 7) & 0x7C00 | \
(((rgba>>8) + atab[(oldpixel&0x03E0)>>2] ) << 2) & 0x03E0 | \
(( rgba + atab[(oldpixel&0x001F)<<3] ) >> 3) & 0x001F; \
}
#elif defined(CONFIG_FAST_ALPHA_444)
#define ALPHA_OP(d,s) \
{ \
u32 rgba = *((u32*)(s++)); \
u16 oldpixel = *d; \
u8 *atab = alpha_table_7bit + ((rgba >> 16) & 0x7F00); \
*d = (((rgba>>16) + atab[(oldpixel&0x0F00)>>4] ) << 4) & 0x0F00 | \
((rgba>>8) + atab[oldpixel&0x00F0 ] ) & 0x00F0 | \
(( rgba + atab[(oldpixel&0x000F)<<4] ) >> 4) & 0x000F; \
}
#else
#error Unsupported color mode for fast alpha blending
#endif
#endif /* CONFIG_FAST_ALPHA */
switch (lgop) {
case PG_LGOP_NONE:
#ifdef CONFIG_NO_VRAM_MEMCPY
for (;h;h--,src+=offset_src,dst+=offset_dst) {
for (i=w;i;i--,src++,dst++)
*dst = *src;
}
#else
for (;h;h--,src+=(srcbit->pitch>>1),dst+=(FB_BPL>>1))
__memcpy(dst,src,w<<1);
#endif
break;
case PG_LGOP_OR:
#define OP(d,s) (*d|=*s)
BLITLOOP;
#undef OP
break;
case PG_LGOP_AND:
#define OP(d,s) (*d&=*s)
BLITLOOP;
#undef OP
break;
case PG_LGOP_XOR:
#define OP(d,s) (*d^=*s)
BLITLOOP;
#undef OP
break;
#ifdef CONFIG_FAST_ALPHA
case PG_LGOP_ALPHA:
#define OP(d,s) ALPHA_OP(d,s)
BLITLOOP;
#undef OP
break;
#endif
}
}
/* This is a backwards blit that handles overlapping cases blit() doesn't */
void linear16_scrollblit(hwrbitmap dest,
s16 dst_x, s16 dst_y,s16 w, s16 h,
hwrbitmap sbit,s16 src_x,s16 src_y,
s16 lgop) {
u16 *dst;
struct stdbitmap *srcbit = (struct stdbitmap *) sbit;
s16 i,offset_dst;
s16 offset_src;
u16 *src;
if ((dst_x < src_x) || (dst_y < src_y)) {
vid->blit(dest,dst_x,dst_y,w,h,sbit,src_x,src_y,lgop);
return;
}
if (!FB_ISNORMAL(dest,lgop)) {
def_scrollblit(dest,dst_x,dst_y,w,h,sbit,src_x,src_y,lgop);
return;
}
/* This blit starts at the lower-right, moves right-to-left, bottom-to-top */
dst = PIXELADDR(dst_x+w-1,dst_y+h-1);
offset_dst = (FB_BPL>>1) - w;
src = ((u16*)srcbit->bits) + (((src_x+w-1)*srcbit->bpp)>>4) + (src_y+h-1)*(srcbit->pitch>>1);
offset_src = (srcbit->pitch>>1) - ((w*srcbit->bpp)>>4);
for (;h;h--,src-=offset_src,dst-=offset_dst) {
for (i=w;i;i--,src--,dst--)
*dst = *src;
}
}
#ifdef CONFIG_FAST_BLUR
/* This is the standard blurring algorithm, but with
* optimizations for 16-bit 5-6-5 framebuffers
*/
void linear16_blur(hwrbitmap dest, s16 x, s16 y, s16 w, s16 h, s16 radius) {
int i, skip, fallback, stride;
register int p0,p1,p2; /* 3-pixel buffer for blurring */
register u16 *p, *stop;
s16 imgw, imgh;
/* Don't blur the edge pixel on the screen.
* Yeah, I'm a wimp for not making it wrap around :P
*/
vid->bitmap_getsize(dest,&imgw,&imgh);
if (x<=0) x = 1;
if (y<=0) y = 1;
if (x+w>=imgw) w = imgw-x-1;
if (y+h>=imgh) h = imgh-y-1;
stride = FB_BPL>>1;
skip = stride - w;
fallback = stride * (h-1) - 1;
while (radius--) {
/* Horizontal blur */
i = h;
p = PIXELADDR(x,y);
p1 = p[-1];
p2 = *p;
while (i--) {
stop = p+w;
while (++p < stop) {
/* Shift the buffer */
p0 = p1;
p1 = p2;
/* Shift in the new pixel, expanding it to 32 bits */
p2 = p[1];
p2 = (p2&0x1F) | ((p2<<3)&0x3F00) | ((p2<<5)&0x1F0000);
/* Now we have room to add them all at once, without masking off
* the individual color components
*/
p0 += p1 + p2;
/* Now squish it back into a 16-bit color, rolling the divide and shift
* operations into one divide.
*/
*p = ((((p0 & 0xFF0000) / 96) & 0xF800) |
(((p0 & 0x00FF00) / 24) & 0x07E0) |
(((p0 & 0x0000FF) / 3 ) & 0x001F));
}
p += skip;
}
/* Vertical blur */
i = w;
p = PIXELADDR(x,y);
p1 = p[-stride];
p2 = *p;
while (i--) {
stop = p+fallback;
while (p < stop) {
p += stride;
/* Shift the buffer */
p0 = p1;
p1 = p2;
/* Shift in the new pixel, expanding it to 32 bits */
p2 = p[stride];
p2 = (p2&0x1F) | ((p2<<3)&0x3F00) | ((p2<<5)&0x1F0000);
/* Now we have room to add them all at once, without masking off
* the individual color components
*/
p0 += p1 + p2;
/* Now squish it back into a 16-bit color, rolling the divide and shift
* operations into one divide.
*/
*p = ((((p0 & 0xFF0000) / 96) & 0xF800) |
(((p0 & 0x00FF00) / 24) & 0x07E0) |
(((p0 & 0x0000FF) / 3 ) & 0x001F));
}
p -= fallback;
}
}
}
#endif /* CONFIG_FAST_BLUR */
#ifdef CONFIG_FASTER_BLUR
/*
* This is a different algorigthm with longer buffers and no division.
* It forces the blur radius to be a power of two. It uses no buffer, just
* a set of accumulators. This way each pixel requires just a handful of
* bitshifts and ands, no division.
*/
void linear16_blur(hwrbitmap dest, s16 x, s16 y, s16 w, s16 h, s16 radius) {
int log_diameter, diameter, i, j;
int shiftsize,strideradius;
int r,g,b; /* Current color sums */
int bpl;
u16 *corner, *p, *line;
u16 color;
s16 imgw, imgh;
/* This algorithm is more intense than the usual one, so cut the radius in half */
diameter = radius;
/* This algorithm doesn't work with a radius of 1 */
if (diameter <= 2)
diameter = 4;
/* Leave room on the edges, so the p[radius]/p[-radius] stuff below is legal */
#if defined(CONFIG_ROTATIONBASE_90) || defined(CONFIG_ROTATIONBASE_270)
/* Vertical */
y += radius;
h -= radius<<1;
if (h<=0)
return;
#else
/* Horizontal */
x += radius;
w -= radius<<1;
if (w<=0)
return;
#endif
/* Find out the next highest power of two from radius, and the log of that */
for (i=0,j=diameter;j!=1;i++)
j >>= 1;
/* If that's the only bit set, the input was already
* a power of two and we can leave it alone
*/
if (diameter == 1<<i)
log_diameter = i;
else {
/* Otherwise get the next power of two */
log_diameter = 1+i;
diameter = 1<<log_diameter;
}
radius = diameter>>1;
bpl = FB_BPL;
strideradius = (bpl>>1)*radius;
corner = PIXELADDR(x,y);
r=g=b=0;
#if defined(CONFIG_ROTATIONBASE_90) || defined(CONFIG_ROTATIONBASE_270)
/* Vertical blur */
radius *= FB_BPL>>1;
for (line=corner,j=w;j;j--,line++) {
color = line[-radius];
r = (color & 0xF800) << log_diameter;
g = (color & 0x07E0) << log_diameter;
b = (color & 0x001F) << log_diameter;
for (p=line,i=h;i;i--,(u8*)p+=FB_BPL) {
/* Add the new pixel into the buffer */
color = p[radius];
r += color & 0xF800;
g += color & 0x07E0;
b += color & 0x001F;
/* Take the old one away */
color = p[-radius];
r -= color & 0xF800;
g -= color & 0x07E0;
b -= color & 0x001F;
/* Shift it into place */
*p = (((r >> log_diameter) & 0xF800) |
((g >> log_diameter) & 0x07E0) |
((b >> log_diameter) & 0x001F) );
}
}
#else /* 0 or 180 degrees */
/* Horizontal blur */
for (line=corner,j=h;j;j--,(u8*)line+=bpl) {
color = line[-radius];
r = (color & 0xF800) << log_diameter;
g = (color & 0x07E0) << log_diameter;
b = (color & 0x001F) << log_diameter;
for (p=line,i=w;i;i--,p++) {
/* Add the new pixel into the buffer */
color = p[radius];
r += color & 0xF800;
g += color & 0x07E0;
b += color & 0x001F;
/* Take the old one away */
color = p[-radius];
r -= color & 0xF800;
g -= color & 0x07E0;
b -= color & 0x001F;
/* Shift it into place */
*p = (((r >> log_diameter) & 0xF800) |
((g >> log_diameter) & 0x07E0) |
((b >> log_diameter) & 0x001F) );
}
}
#endif /* rotation base */
}
#endif /* CONFIG_FASTER_BLUR */
/* This should be helpful for running SDL apps on a rotated display :)
*/
void linear16_rotateblit(hwrbitmap dest, s16 dest_x, s16 dest_y,
hwrbitmap src, s16 src_x, s16 src_y, s16 src_w, s16 src_h,
struct pgquad *clip, s16 angle, s16 lgop) {
int i,j;
int ac,bd; /* Rotation matrix */
u16 *s, *pixeldest, *linedest;
struct stdbitmap *srcbit = (struct stdbitmap *) src;
int offset_src;
/* We don't handle anything funky */
if (!FB_ISNORMAL(dest,lgop)) {
def_rotateblit(dest,dest_x,dest_y,src,src_x,src_y,src_w,src_h,clip,angle,lgop);
return;
}
/* For each angle, set the rotation matrix. (premultiplied with pitch,
* columns added together) Also handle clipping here.
*
* FIXME: The only difference between these blocks of code are sign
* and x/y changes, this could be factored out into a common clipping
* function that takes pointers to the x/y variables and signs
*/
switch (angle) {
case 0:
ac = 1;
bd = FB_BPL>>1;
if ((i = clip->x1 - dest_x) > 0) {
src_x += i;
src_w -= i;
dest_x = clip->x1;
}
if ((i = clip->y1 - dest_y) > 0) {
src_y += i;
src_h -= i;
dest_y = clip->y1;
}
if ((i = dest_x + src_w - 1 - clip->x2) > 0)
src_w -= i;
if ((i = dest_y + src_h - 1 - clip->y2) > 0)
src_h -= i;
break;
case 90:
ac = -(FB_BPL>>1);
bd = 1;
if ((i = clip->x1 - dest_x) > 0) {
src_y += i;
src_h -= i;
dest_x = clip->x1;
}
if ((i = dest_y - clip->y2) > 0) {
src_x += i;
src_w -= i;
dest_y = clip->y2;
}
if ((i = dest_x + src_h - 1 - clip->x2) > 0)
src_h -= i;
if ((i = clip->y1 - dest_y + src_w - 1) > 0)
src_w -= i;
break;
case 180:
ac = -1;
bd = -(FB_BPL>>1);
if ((i = dest_x - clip->x2) > 0) {
src_x += i;
src_w -= i;
dest_x = clip->x2;
}
if ((i = dest_y - clip->y2) > 0) {
src_y += i;
src_h -= i;
dest_y = clip->y2;
}
if ((i = clip->x1 - dest_x + src_w - 1) > 0)
src_w -= i;
if ((i = clip->y1 - dest_y + src_h - 1) > 0)
src_h -= i;
break;
case 270:
ac = FB_BPL>>1;
bd = -1;
if ((i = dest_x - clip->x2) > 0) {
src_y += i;
src_h -= i;
dest_x = clip->x2;
}
if ((i = clip->y1 - dest_y) > 0) {
src_x += i;
src_w -= i;
dest_y = clip->y1;
}
if ((i = clip->x1 - dest_x + src_h - 1) > 0)
src_h -= i;
if ((i = dest_y + src_w - 1 - clip->y2) > 0)
src_w -= i;
break;
default:
return; /* Can't handle this angle! */
}
/* Initial source and destination positions. */
linedest = PIXELADDR(dest_x,dest_y);
s = ((u16*)srcbit->bits) + src_x + src_y*(srcbit->pitch>>1);
offset_src = (srcbit->pitch>>1) - src_w;
/* Blitter loop, moving the source as normal,
* but using the rotation matrix above to move the destination.
*/
for (j=0;j<src_h;j++,s+=offset_src) {
for (i=0,pixeldest=linedest;i<src_w;i++,s++) {
*pixeldest = *s;
pixeldest += ac;
}
linedest += bd;
}
}
void linear16_charblit_0(hwrbitmap dest, u8 *chardat,s16 dest_x, s16 dest_y,
s16 w,s16 h,s16 lines, hwrcolor c,struct pgquad *clip,
int char_pitch) {
int iw,hc;
int olines = lines;
int bit;
int flag=0;
int xpix,xmin,xmax;
unsigned char ch;
u16 *d,*dline;
int special = lines;
/* Is it at all in the clipping rect? */
if (clip && (dest_x>clip->x2 || dest_y>clip->y2 || (dest_x+w)<clip->x1 ||
(dest_y+h)<clip->y1)) return;
xmin = 0;
xmax = w;
hc = 0;
/* Do vertical clipping ahead of time (it does not require a special case) */
if (clip) {
if (clip->y2<(dest_y+h))
h = clip->y2-dest_y+1;
if (clip->y1>dest_y) {
hc = clip->y1-dest_y; /* Do it this way so skewing doesn't mess up when clipping */
while (lines < hc && olines) {
lines += olines;
dest_x--;
}
dest_y += hc;
chardat += hc*char_pitch;
}
/* Setup for horizontal clipping (if so, set a special case) */
if (clip->x1>dest_x) {
xmin = clip->x1-dest_x;
special = 1;
}
if (clip->x2<(dest_x+w)) {
xmax = clip->x2-dest_x+1;
special = 1;
}
}
dline = PIXELADDR(dest_x,dest_y);
if (special) {
/* General purpose */
for (;hc<h;hc++,(u8*)dline+=FB_BPL) {
if (olines && lines==hc) {
lines += olines;
dline--;
flag=1;
}
for (d=dline,iw=char_pitch,xpix=0;iw;iw--)
for (bit=8,ch=*(chardat++);bit;bit--,ch=ch<<1,d++,xpix++) {
if (ch&0x80 && xpix>=xmin && xpix<xmax)
*d = c;
}
if (flag) {
xmax++;
flag=0;
}
}
}
else {
/* Optimized for the most common case */
for (;hc<h;hc++,(u8*)dline+=FB_BPL)
for (d=dline,iw=char_pitch;iw;iw--) {
ch = *(chardat++);
if (ch & 0x80) *d = c;
d++;
if (ch & 0x40) *d = c;
d++;
if (ch & 0x20) *d = c;
d++;
if (ch & 0x10) *d = c;
d++;
if (ch & 0x08) *d = c;
d++;
if (ch & 0x04) *d = c;
d++;
if (ch & 0x02) *d = c;
d++;
if (ch & 0x01) *d = c;
d++;
}
}
}
void linear16_charblit_90(hwrbitmap dest, u8 *chardat,s16 dest_x, s16 dest_y,
s16 w,s16 h,s16 lines, hwrcolor c,struct pgquad *clip,
int char_pitch) {
int iw,hc;
int olines = lines;
int bit;
int flag=0;
int xpix,xmin,xmax;
unsigned char ch;
u16 *d,*dline;
int special = lines;
/* Is it at all in the clipping rect? */
if (clip && (dest_x>clip->x2 || (dest_y-w)>clip->y2 || (dest_x+h)<clip->x1 ||
dest_y<clip->y1)) return;
xmin = 0;
xmax = w;
hc = 0;
/* Do vertical clipping ahead of time (it does not require a special case) */
if (clip) {
if (clip->x2<(dest_x+h-1))
h = clip->x2-dest_x+1;
if (clip->x1>dest_x) {
hc = clip->x1-dest_x; /* Do it this way so skewing doesn't mess up when clipping */
while (lines < hc && olines) {
lines += olines;
dest_y++;
}
dest_x += hc;
chardat += hc*char_pitch;
}
/* Setup for horizontal clipping (if so, set a special case) */
if (clip->y1>dest_y-w+1) {
xmax = 1+dest_y-clip->y1;
special = 1;
}
if (clip->y2<(dest_y)) {
xmin = dest_y-clip->y2;
special = 1;
}
}
dline = PIXELADDR(dest_x,dest_y);
if (special) {
/* General purpose */
for (;hc<h;hc++,dline++) {
if (olines && lines==hc) {
lines += olines;
(u8*)dline += FB_BPL;
flag=1;
}
for (iw=char_pitch,d=dline,xpix=0;iw;iw--)
for (bit=8,ch=*(chardat++);bit;bit--,ch=ch<<1,(u8*)d-=FB_BPL,xpix++) {
if (ch&0x80 && xpix>=xmin && xpix<xmax)
*d = c;
}
if (flag) {
xmax++;
flag=0;
}
}
}
else {
/* Optimized for the most common case */
for (;hc<h;hc++,dline++)
for (d=dline,iw=char_pitch;iw;iw--) {
ch = *(chardat++);
if (ch & 0x80) *d = c;
(u8*)d-=FB_BPL;
if (ch & 0x40) *d = c;
(u8*)d-=FB_BPL;
if (ch & 0x20) *d = c;
(u8*)d-=FB_BPL;
if (ch & 0x10) *d = c;
(u8*)d-=FB_BPL;
if (ch & 0x08) *d = c;
(u8*)d-=FB_BPL;
if (ch & 0x04) *d = c;
(u8*)d-=FB_BPL;
if (ch & 0x02) *d = c;
(u8*)d-=FB_BPL;
if (ch & 0x01) *d = c;
(u8*)d-=FB_BPL;
}
}
}
void linear16_charblit_180(hwrbitmap dest, u8 *chardat,s16 dest_x, s16 dest_y,
s16 w,s16 h,s16 lines, hwrcolor c,struct pgquad *clip,
int char_pitch) {
int iw,hc,x;
int olines = lines;
int bit;
int flag=0;
int xpix,xmin,xmax;
unsigned char ch;
u16 *d,*dline;
int special = lines;
/* Is it at all in the clipping rect? */
if (clip && (dest_x<clip->x1 || dest_y<clip->y1 || (dest_x-w)>clip->x2 ||
(dest_y-h)>clip->y2)) return;
xmin = 0;
xmax = w;
hc = 0;
/* Do vertical clipping ahead of time (it does not require a special case) */
if (clip) {
if (clip->y1>(dest_y-h))
h = dest_y-clip->y1+1;
if (clip->y2<dest_y) {
hc = dest_y-clip->y2; /* Do it this way so skewing doesn't mess up when clipping */
while (lines < hc && olines) {
lines += olines;
dest_x--;
}
dest_y -= hc;
chardat += hc*char_pitch;
}
/* Setup for horizontal clipping (if so, set a special case) */
if (clip->x2<dest_x) {
xmin = dest_x-clip->x2;
special = 1;
}
if (clip->x1>(dest_x-w)) {
xmax = dest_x-clip->x1+1;
special = 1;
}
}
dline = PIXELADDR(dest_x,dest_y);
if (special) {
/* General purpose */
for (;hc<h;hc++,(u8*)dline-=FB_BPL) {
if (olines && lines==hc) {
lines += olines;
dline--;
flag=1;
}
for (d=dline,iw=char_pitch,xpix=0;iw;iw--)
for (bit=8,ch=*(chardat++);bit;bit--,ch=ch<<1,d--,xpix++) {
if (ch&0x80 && xpix>=xmin && xpix<xmax)
*d = c;
}
if (flag) {
xmax++;
flag=0;
}
}
}
else {
/* Optimized for the most common case */
for (;hc<h;hc++,(u8*)dline-=FB_BPL)
for (d=dline,iw=char_pitch;iw;iw--) {
ch = *(chardat++);
if (ch & 0x80) *d = c;
d--;
if (ch & 0x40) *d = c;
d--;
if (ch & 0x20) *d = c;
d--;
if (ch & 0x10) *d = c;