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
|
{
Free Pascal port of the Hermes C library.
Copyright (C) 2001-2003 Nikolay Nikolov (nickysn@users.sourceforge.net)
Original C version by Christian Nentwich (c.nentwich@cs.ucl.ac.uk)
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
with the following modification:
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent modules,and
to copy and distribute the resulting executable under terms of your choice,
provided that you also meet, for each linked independent module, the terms
and conditions of the license of that module. An independent module is a
module which is not derived from or based on this library. If you modify
this library, you may extend this exception to your version of the library,
but you are not obligated to do so. If you do not wish to do so, delete this
exception statement from your 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
}
{
muhmuh converters for the HERMES library
Copyright (c) 1998 Christian Nentwich (c.nentwich@cs.ucl.ac.uk)
This source code is licensed under the GNU LGPL
Please refer to the file COPYING.LIB contained in the distribution for
licensing conditions
}
{ TO 32 RGB }
procedure ConvertP_muhmu32_32rgb888(source, dest: PUint8; count, inc_source: DWord); cdecl;
var
s_pixel: Uint32;
begin
repeat
s_pixel := PUint32(source)^;
PUint32(dest)^ := (s_pixel and $ff) or
((s_pixel and ($ff shl 10)) shr 2) or
((s_pixel and ($ff shl 20)) shr 4);
Inc(dest, 4);
Inc(source, 4);
Dec(count);
until count = 0;
end;
{ TO 32 BGR }
procedure ConvertP_muhmu32_32bgr888(source, dest: PUint8; count, inc_source: DWord); cdecl;
var
s_pixel: Uint32;
begin
repeat
s_pixel := PUint32(source)^;
PUint32(dest)^ := ((s_pixel and $ff) shl 16) or
((s_pixel and ($ff shl 10)) shr 2) or
((s_pixel shr 20) and $FF);
Inc(dest, 4);
Inc(source, 4);
Dec(count);
until count = 0;
end;
{ TO 32 RGBA }
procedure ConvertP_muhmu32_32rgba888(source, dest: PUint8; count, inc_source: DWord); cdecl;
var
s_pixel: Uint32;
begin
repeat
s_pixel := PUint32(source)^;
PUint32(dest)^ := (((s_pixel and $ff) or
((s_pixel and ($ff shl 10)) shr 2) or
((s_pixel and ($ff shl 20)) shr 4)) shl 8) or $FF;
Inc(dest, 4);
Inc(source, 4);
Dec(count);
until count = 0;
end;
{ TO 32 BGRA }
procedure ConvertP_muhmu32_32bgra888(source, dest: PUint8; count, inc_source: DWord); cdecl;
var
s_pixel: Uint32;
begin
repeat
s_pixel := PUint32(source)^;
PUint32(dest)^ := (((s_pixel and $ff) shl 24) or
((s_pixel and ($ff shl 10)) shl 6) or
((s_pixel shr 12) and $FF00)) or $FF;
Inc(dest, 4);
Inc(source, 4);
Dec(count);
until count = 0;
end;
{ TO 24 RGB }
procedure ConvertP_muhmu32_24rgb888(source, dest: PUint8; count, inc_source: DWord); cdecl;
var
s_pixel: Uint32;
s_point: PUint8;
begin
s_point := PUint8(@s_pixel) + (R_32 - R_24);
repeat
s_pixel := PUint32(source)^;
s_pixel := (s_pixel and $ff) or
((s_pixel and ($ff shl 10)) shr 2) or
((s_pixel and ($ff shl 20)) shr 4);
(dest+0)^ := (s_point+0)^;
(dest+1)^ := (s_point+1)^;
(dest+2)^ := (s_point+2)^;
Inc(source, 4);
Inc(dest, 3);
Dec(count);
until count = 0;
end;
{ TO 24 BGR }
procedure ConvertP_muhmu32_24bgr888(source, dest: PUint8; count, inc_source: DWord); cdecl;
var
s_pixel: Uint32;
s_point: PUint8;
begin
s_point := PUint8(@s_pixel) + (R_32 - R_24);
repeat
s_pixel := PUint32(source)^;
s_pixel := (s_pixel and $ff) or
((s_pixel and ($ff shl 10)) shr 2) or
((s_pixel and ($ff shl 20)) shr 4);
{ Note that R and B are swapped }
(dest+0)^ := (s_point+2)^;
(dest+1)^ := (s_point+1)^;
(dest+2)^ := (s_point+0)^;
Inc(source, 4);
Inc(dest, 3);
Dec(count);
until count = 0;
end;
{ TO 16 RGB 565 }
procedure ConvertP_muhmu32_16rgb565(source, dest: PUint8; count, inc_source: DWord); cdecl;
var
i: DWord;
r, g, b: Uint32;
s_pixel, d_pixelblock: Uint32;
d_pixel: Uint16;
begin
{ if the current pixel isn't dword aligned, try write one pixel first }
if (PtrUInt(dest) and $3) <> 0 then
begin
s_pixel := PUint32(source)^;
r := (s_pixel shr 12) and $f800;
g := (s_pixel shr 7) and $7e0;
b := (s_pixel shr 3) and $1f;
d_pixel := r or g or b;
PUint16(dest)^ := d_pixel;
Inc(source, 4);
Inc(dest, 2);
Dec(count);
end;
{ Write blocks of two pixels }
for i := 1 to count shr 1 do
begin
s_pixel := PUint32(source)^;
d_pixelblock := (((s_pixel shr 12) and $f800) or
((s_pixel shr 7) and $7e0) or
((s_pixel shr 3) and $1f)) shl DWORD_SMALLINT0_SHL;
s_pixel := (PUint32(source) + 1)^;
d_pixelblock := d_pixelblock or
((((s_pixel shr 12) and $f800) or
((s_pixel shr 7) and $7e0) or
((s_pixel shr 3) and $1f)) shl DWORD_SMALLINT1_SHL);
PUint32(dest)^ := d_pixelblock;
Inc(source, 8); Inc(dest, 4);
end;
{ Eventually, write a single odd pixel that might be left }
if (count and 1) <> 0 then
begin
s_pixel := PUint32(source)^;
r := (s_pixel shr 12) and $f800;
g := (s_pixel shr 7) and $7e0;
b := (s_pixel shr 3) and $1f;
d_pixel := r or g or b;
PUint16(dest)^ := d_pixel;
end;
end;
{ TO 16 BGR 565 }
procedure ConvertP_muhmu32_16bgr565(source, dest: PUint8; count, inc_source: DWord); cdecl;
var
i: DWord;
r, g, b: Uint32;
s_pixel, d_pixelblock: Uint32;
d_pixel: Uint16;
begin
{ if the current pixel isn't dword aligned, try write one pixel first }
if (PtrUInt(dest) and $3) <> 0 then
begin
s_pixel := PUint32(source)^;
r := (s_pixel shr 23) and $1f;
g := (s_pixel shr 7) and $7e0;
b := (s_pixel shl 8) and $f800;
d_pixel := r or g or b;
PUint16(dest)^ := d_pixel;
Inc(source, 4);
Inc(dest, 2);
Dec(count);
end;
{ Write blocks of two pixels }
for i := 1 to count shr 1 do
begin
s_pixel := PUint32(source)^;
d_pixelblock := (((s_pixel shr 23) and $1f) or
((s_pixel shr 7) and $7e0) or
((s_pixel shl 8) and $f800)) shl DWORD_SMALLINT0_SHL;
s_pixel := (PUint32(source) + 1)^;
d_pixelblock := d_pixelblock or
((((s_pixel shr 23) and $1f) or
((s_pixel shr 7) and $7e0) or
((s_pixel shl 8) and $f800)) shl DWORD_SMALLINT1_SHL);
PUint32(dest)^ := d_pixelblock;
Inc(source, 8); Inc(dest, 4);
end;
{ Eventually, write a single odd pixel that might be left }
if (count and 1) <> 0 then
begin
s_pixel := PUint32(source)^;
r := (s_pixel shr 23) and $1f;
g := (s_pixel shr 7) and $7e0;
b := (s_pixel shl 8) and $f800;
d_pixel := r or g or b;
PUint16(dest)^ := d_pixel;
end;
end;
{ TO 16 RGB 555 }
procedure ConvertP_muhmu32_16rgb555(source, dest: PUint8; count, inc_source: DWord); cdecl;
var
i: DWord;
r, g, b: Uint32;
s_pixel, d_pixelblock: Uint32;
d_pixel: Uint16;
begin
if (PtrUInt(dest) and $3) <> 0 then
begin
s_pixel := PUint32(source)^;
r := (s_pixel shr 13) and $7c00;
g := (s_pixel shr 8) and $3e0;
b := (s_pixel shr 3) and $1f;
d_pixel := r or g or b;
PUint16(dest)^ := d_pixel;
Inc(source, 4);
Inc(dest, 2);
Dec(count);
end;
for i := 1 to count shr 1 do
begin
s_pixel := PUint32(source)^;
d_pixelblock := (((s_pixel shr 13) and $7c00) or
((s_pixel shr 8) and $3e0) or
((s_pixel shr 3) and $1f)) shl DWORD_SMALLINT0_SHL;
s_pixel := (PUint32(source) + 1)^;
d_pixelblock := d_pixelblock or
((((s_pixel shr 13) and $7c00) or
((s_pixel shr 8) and $3e0) or
((s_pixel shr 3) and $1f)) shl DWORD_SMALLINT1_SHL);
PUint32(dest)^ := d_pixelblock;
Inc(source, 8); Inc(dest, 4);
end;
if (count and 1) <> 0 then
begin
s_pixel := PUint32(source)^;
r := (s_pixel shr 13) and $7c00;
g := (s_pixel shr 8) and $3e0;
b := (s_pixel shr 3) and $1f;
d_pixel := r or g or b;
PUint16(dest)^ := d_pixel;
end;
end;
{ TO 16 BGR 555 }
procedure ConvertP_muhmu32_16bgr555(source, dest: PUint8; count, inc_source: DWord); cdecl;
var
i: DWord;
r, g, b: Uint32;
s_pixel, d_pixelblock: Uint32;
d_pixel: Uint16;
begin
if (PtrUInt(dest) and $3) <> 0 then
begin
s_pixel := PUint32(source)^;
r := (s_pixel shr 23) and $1f;
g := (s_pixel shr 8) and $3e0;
b := (s_pixel shl 7) and $7c00;
d_pixel := r or g or b;
PUint16(dest)^ := d_pixel;
Inc(source, 4);
Inc(dest, 2);
Dec(count);
end;
for i := 1 to count shr 1 do
begin
s_pixel := PUint32(source)^;
d_pixelblock := (((s_pixel shr 23) and $1f) or
((s_pixel shr 8) and $3e0) or
((s_pixel shl 7) and $7c00)) shl DWORD_SMALLINT0_SHL;
s_pixel := (PUint32(source) + 1)^;
d_pixelblock := d_pixelblock or
((((s_pixel shr 23) and $1f) or
((s_pixel shr 8) and $3e0) or
((s_pixel shl 7) and $7c00)) shl DWORD_SMALLINT1_SHL);
PUint32(dest)^ := d_pixelblock;
Inc(source, 8); Inc(dest, 4);
end;
if (count and 1) <> 0 then
begin
s_pixel := PUint32(source)^;
r := (s_pixel shr 23) and $1f;
g := (s_pixel shr 8) and $3e0;
b := (s_pixel shl 7) and $7c00;
d_pixel := r or g or b;
PUint16(dest)^ := d_pixel;
end;
end;
{ TO 8 RGB 332 }
procedure ConvertP_muhmu32_8rgb332(source, dest: PUint8; count, inc_source: DWord); cdecl;
var
i: DWord;
s_pixel, d_block: Uint32;
d_pixel: Uint8;
begin
{ Process single pixels until we are dword aligned }
while (PtrUInt(dest) and $3) <> 0 do
begin
s_pixel := PUint32(source)^;
d_pixel := ((s_pixel shr 20) and $e0) or
((s_pixel shr 13) and $1c) or
((s_pixel shr 6) and $3);
dest^ := d_pixel;
Dec(count);
if count = 0 then
exit;
Inc(dest);
Inc(source, 4);
end;
{ Now process blocks of four pixels }
for i := 1 to count shr 2 do
begin
s_pixel := PUint32(source)^;
d_block := (((s_pixel shr 20) and $e0) or
((s_pixel shr 13) and $1c) or
((s_pixel shr 6) and $3)) shl DWORD_BYTE0_SHL;
s_pixel := (PUint32(source) + 1)^;
d_block := d_block or
((((s_pixel shr 20) and $e0) or
((s_pixel shr 13) and $1c) or
((s_pixel shr 6) and $3)) shl DWORD_BYTE1_SHL);
s_pixel := (PUint32(source) + 2)^;
d_block := d_block or
((((s_pixel shr 20) and $e0) or
((s_pixel shr 13) and $1c) or
((s_pixel shr 6) and $3)) shl DWORD_BYTE2_SHL);
s_pixel := (PUint32(source) + 3)^;
d_block := d_block or
((((s_pixel shr 20) and $e0) or
((s_pixel shr 13) and $1c) or
((s_pixel shr 6) and $3)) shl DWORD_BYTE3_SHL);
PUint32(dest)^ := d_block;
Inc(source, 16);
Inc(dest, 4);
end;
{ Write all possibly remaining pixel }
count := count and 3;
while count <> 0 do
begin
Dec(count);
dest^ := ((s_pixel shr 20) and $e0) or
((s_pixel shr 13) and $1c) or
((s_pixel shr 6) and $3);
Inc(dest);
Inc(source, 4);
end;
end;
{ -------------------------------------------------------------------------
STRETCH CONVERTERS
------------------------------------------------------------------------- }
procedure ConvertP_muhmu32_32rgb888_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
var
x: DWord;
s_pixel: DWord;
begin
x := 0;
while count > 0 do
begin
s_pixel := PUint32(source)^;
PUint32(dest)^ := (s_pixel and $ff) or
((s_pixel and ($ff shl 10)) shr 2) or
((s_pixel and ($ff shl 20)) shr 4);
Inc(x, inc_source);
Inc(source, (x shr 16)*4);
x := x and $FFFF;
Inc(dest, 4);
Dec(count);
end;
end;
procedure ConvertP_muhmu32_32bgr888_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
var
x: DWord;
s_pixel: DWord;
begin
x := 0;
while count > 0 do
begin
s_pixel := PUint32(source)^;
PUint32(dest)^ := ((s_pixel and $ff) shl 16) or
((s_pixel and ($ff shl 10)) shr 2) or
((s_pixel shr 20) and $FF);
Inc(x, inc_source);
Inc(source, (x shr 16)*4);
x := x and $FFFF;
Inc(dest, 4);
Dec(count);
end;
end;
procedure ConvertP_muhmu32_32rgba888_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
var
x: DWord;
s_pixel: DWord;
begin
x := 0;
while count > 0 do
begin
s_pixel := PUint32(source)^;
PUint32(dest)^ := (((s_pixel and $ff) or
((s_pixel and ($ff shl 10)) shr 2) or
((s_pixel and ($ff shl 20)) shr 4)) shl 8) or $FF;
Inc(x, inc_source);
Inc(source, (x shr 16)*4);
x := x and $FFFF;
Inc(dest, 4);
Dec(count);
end;
end;
procedure ConvertP_muhmu32_32bgra888_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
var
x: DWord;
s_pixel: DWord;
begin
x := 0;
while count > 0 do
begin
s_pixel := PUint32(source)^;
PUint32(dest)^ := (((s_pixel and $ff) shl 24) or
((s_pixel and ($ff shl 10)) shl 6) or
((s_pixel shr 12) and $FF00)) or $FF;
Inc(x, inc_source);
Inc(source, (x shr 16)*4);
x := x and $FFFF;
Inc(dest, 4);
Dec(count);
end;
end;
procedure ConvertP_muhmu32_24rgb888_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
var
x: DWord;
p1, p2, p3, p4: DWord;
c: DWord;
begin
x := 0;
while (PtrUInt(dest) and 3) <> 0 do
begin
p1 := (PUint32(source) + (x shr 16))^;
p1 := (p1 and $ff) or
((p1 and ($ff shl 10)) shr 2) or
((p1 and ($ff shl 20)) shr 4);
PUint8(dest + B_24)^ := p1 and $FF;
PUint8(dest + G_24)^ := (p1 shr 8) and $FF;
PUint8(dest + R_24)^ := p1 shr 16;
Inc(x, inc_source);
Inc(dest, 3);
Dec(count);
if count = 0 then
exit;
end;
c := count shr 2;
while c > 0 do
begin
p1 := (PUint32(source) + (x shr 16))^;
p2 := (PUint32(source) + ((x + inc_source) shr 16))^;
p3 := (PUint32(source) + ((x + 2*inc_source) shr 16))^;
p4 := (PUint32(source) + ((x + 3*inc_source) shr 16))^;
{$IFDEF FPC_LITTLE_ENDIAN}
PUint32(dest + 0)^ := ((p2 and $FF) shl 24) or ((p1 and $FF00000) shr 4) or ((p1 and $3FC00) shr 2) or (p1 and $FF);
PUint32(dest + 4)^ := ((p3 and $3FC00) shl 14) or ((p3 and $FF) shl 16) or ((p2 and $FF00000) shr 12) or ((p2 and $3FC00) shr 10);
PUint32(dest + 8)^ := ((p4 and $FF00000) shl 4) or ((p4 and $3FC00) shl 6) or ((p4 and $FF) shl 8) or ((p3 and $FF00000) shr 20);
{$ELSE FPC_LITTLE_ENDIAN}
PUint32(dest + 0)^ := ((p1 and $FF00000) shl 4) or ((p1 and $3FC00) shl 6) or ((p1 and $FF) shl 8) or ((p2 and $FF00000) shr 20);
PUint32(dest + 4)^ := ((p2 and $3FC00) shl 14) or ((p2 and $FF) shl 16) or ((p3 and $FF00000) shr 12) or ((p3 and $3FC00) shr 10);
PUint32(dest + 8)^ := ((p3 and $FF) shl 24) or ((p4 and $FF00000) shr 4) or ((p4 and $3FC00) shr 2) or (p4 and $FF);
{$ENDIF FPC_LITTLE_ENDIAN}
Dec(c);
Inc(x, inc_source*4);
Inc(dest, 12);
end;
count := count and 3;
while count > 0 do
begin
p1 := (PUint32(source) + (x shr 16))^;
p1 := (p1 and $ff) or
((p1 and ($ff shl 10)) shr 2) or
((p1 and ($ff shl 20)) shr 4);
PUint8(dest + B_24)^ := p1 and $FF;
PUint8(dest + G_24)^ := (p1 shr 8) and $FF;
PUint8(dest + R_24)^ := p1 shr 16;
Inc(x, inc_source);
Inc(dest, 3);
Dec(count);
end;
end;
procedure ConvertP_muhmu32_24bgr888_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
var
x: DWord;
p1, p2, p3, p4: DWord;
c: DWord;
begin
x := 0;
while (PtrUInt(dest) and 3) <> 0 do
begin
p1 := (PUint32(source) + (x shr 16))^;
p1 := ((p1 and $ff) shl 16) or
((p1 and ($ff shl 10)) shr 2) or
((p1 and ($ff shl 20)) shr 20);
PUint8(dest + B_24)^ := p1 and $FF;
PUint8(dest + G_24)^ := (p1 shr 8) and $FF;
PUint8(dest + R_24)^ := p1 shr 16;
Inc(x, inc_source);
Inc(dest, 3);
Dec(count);
if count = 0 then
exit;
end;
c := count shr 2;
while c > 0 do
begin
p1 := (PUint32(source) + (x shr 16))^;
p2 := (PUint32(source) + ((x + inc_source) shr 16))^;
p3 := (PUint32(source) + ((x + 2*inc_source) shr 16))^;
p4 := (PUint32(source) + ((x + 3*inc_source) shr 16))^;
{$IFDEF FPC_LITTLE_ENDIAN}
PUint32(dest + 0)^ := ((p2 and $FF00000) shl 4) or ((p1 and $FF) shl 16) or ((p1 and $3FC00) shr 2) or ((p1 and $FF00000) shr 20);
PUint32(dest + 4)^ := ((p3 and $3FC00) shl 14) or ((p3 and $FF00000) shr 4) or ((p2 and $FF) shl 8) or ((p2 and $3FC00) shr 10);
PUint32(dest + 8)^ := ((p4 and $FF) shl 24) or ((p4 and $3FC00) shl 6) or ((p4 and $FF00000) shr 12) or (p3 and $FF);
{$ELSE FPC_LITTLE_ENDIAN}
PUint32(dest + 0)^ := ((p1 and $FF) shl 24) or ((p1 and $3FC00) shl 6) or ((p1 and $FF00000) shr 12) or (p2 and $FF);
PUint32(dest + 4)^ := ((p2 and $3FC00) shl 14) or ((p2 and $FF00000) shr 4) or ((p3 and $FF) shl 8) or ((p3 and $3FC00) shr 10);
PUint32(dest + 8)^ := ((p3 and $FF00000) shl 4) or ((p4 and $FF) shl 16) or ((p4 and $3FC00) shr 2) or ((p4 and $FF00000) shr 20);
{$ENDIF FPC_LITTLE_ENDIAN}
Dec(c);
Inc(x, inc_source*4);
Inc(dest, 12);
end;
count := count and 3;
while count > 0 do
begin
p1 := (PUint32(source) + (x shr 16))^;
p1 := ((p1 and $ff) shl 16) or
((p1 and ($ff shl 10)) shr 2) or
((p1 and ($ff shl 20)) shr 20);
PUint8(dest + B_24)^ := p1 and $FF;
PUint8(dest + G_24)^ := (p1 shr 8) and $FF;
PUint8(dest + R_24)^ := p1 shr 16;
Inc(x, inc_source);
Inc(dest, 3);
Dec(count);
end;
end;
procedure ConvertP_muhmu32_16rgb565_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
var
x, c: DWord;
p: Uint32;
begin
x := 0;
{ Try to write 2 pixel blocks }
c := count shr 1;
while c <> 0 do
begin
Dec(c);
p := ((((PUint32(source) + (x shr 16))^ shr 12) and $f800) or
(((PUint32(source) + (x shr 16))^ shr 7) and $7e0) or
(((PUint32(source) + (x shr 16))^ shr 3) and $1f)) shl DWORD_SMALLINT0_SHL;
Inc(x, inc_source);
p := p or
(((((PUint32(source) + (x shr 16))^ shr 12) and $f800) or
(((PUint32(source) + (x shr 16))^ shr 7) and $7e0) or
(((PUint32(source) + (x shr 16))^ shr 3) and $1f)) shl DWORD_SMALLINT1_SHL);
Inc(x, inc_source);
PUint32(dest)^ := p;
Inc(dest, 4);
end;
{ Write trailing pixel }
if (count and 1) <> 0 then
PUint16(dest)^ := (((PUint32(source) + (x shr 16))^ shr 12) and $f800) or
(((PUint32(source) + (x shr 16))^ shr 7) and $7e0) or
(((PUint32(source) + (x shr 16))^ shr 3) and $1f);
end;
procedure ConvertP_muhmu32_16bgr565_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
var
x, c: DWord;
p: Uint32;
begin
x := 0;
{ Try to write 2 pixel blocks }
c := count shr 1;
while c <> 0 do
begin
Dec(c);
p := ((((PUint32(source) + (x shr 16))^ shr 23) and $1f) or
(((PUint32(source) + (x shr 16))^ shr 7) and $7e0) or
(((PUint32(source) + (x shr 16))^ shl 8) and $f800)) shl DWORD_SMALLINT0_SHL;
Inc(x, inc_source);
p := p or
(((((PUint32(source) + (x shr 16))^ shr 23) and $1f) or
(((PUint32(source) + (x shr 16))^ shr 7) and $7e0) or
(((PUint32(source) + (x shr 16))^ shl 8) and $f800)) shl DWORD_SMALLINT1_SHL);
Inc(x, inc_source);
PUint32(dest)^ := p;
Inc(dest, 4);
end;
{ Write trailing pixel }
if (count and 1) <> 0 then
PUint16(dest)^ := (((PUint32(source) + (x shr 16))^ shr 23) and $1f) or
(((PUint32(source) + (x shr 16))^ shr 7) and $7e0) or
(((PUint32(source) + (x shr 16))^ shl 8) and $f800);
end;
procedure ConvertP_muhmu32_16rgb555_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
var
x, c: DWord;
p: Uint32;
begin
x := 0;
{ Try to write 2 pixel blocks }
c := count shr 1;
while c <> 0 do
begin
Dec(c);
p := ((((PUint32(source) + (x shr 16))^ shr 13) and $7c00) or
(((PUint32(source) + (x shr 16))^ shr 8) and $3e0) or
(((PUint32(source) + (x shr 16))^ shr 3) and $1f)) shl DWORD_SMALLINT0_SHL;
Inc(x, inc_source);
p := p or
(((((PUint32(source) + (x shr 16))^ shr 13) and $7c00) or
(((PUint32(source) + (x shr 16))^ shr 8) and $3e0) or
(((PUint32(source) + (x shr 16))^ shr 3) and $1f)) shl DWORD_SMALLINT1_SHL);
Inc(x, inc_source);
PUint32(dest)^ := p;
Inc(dest, 4);
end;
{ Write trailing pixel }
if (count and 1) <> 0 then
PUint16(dest)^ := (((PUint32(source) + (x shr 16))^ shr 13) and $7c00) or
(((PUint32(source) + (x shr 16))^ shr 8) and $3e0) or
(((PUint32(source) + (x shr 16))^ shr 3) and $1f);
end;
procedure ConvertP_muhmu32_16bgr555_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
var
x, c: DWord;
p: Uint32;
begin
x := 0;
{ Try to write 2 pixel blocks }
c := count shr 1;
while c <> 0 do
begin
Dec(c);
p := ((((PUint32(source) + (x shr 16))^ shr 23) and $1f) or
(((PUint32(source) + (x shr 16))^ shr 8) and $3e0) or
(((PUint32(source) + (x shr 16))^ shl 7) and $7c00)) shl DWORD_SMALLINT0_SHL;
Inc(x, inc_source);
p := p or
(((((PUint32(source) + (x shr 16))^ shr 23) and $1f) or
(((PUint32(source) + (x shr 16))^ shr 8) and $3e0) or
(((PUint32(source) + (x shr 16))^ shl 7) and $7c00)) shl DWORD_SMALLINT1_SHL);
Inc(x, inc_source);
PUint32(dest)^ := p;
Inc(dest, 4);
end;
{ Write trailing pixel }
if (count and 1) <> 0 then
PUint16(dest)^ := (((PUint32(source) + (x shr 16))^ shr 23) and $1f) or
(((PUint32(source) + (x shr 16))^ shr 8) and $3e0) or
(((PUint32(source) + (x shr 16))^ shl 7) and $7c00);
end;
procedure ConvertP_muhmu32_8rgb332_S(source, dest: PUint8; count, inc_source: DWord); cdecl;
var
x, c: DWord;
p: Uint32;
begin
x := 0;
{ Write single pixels until the destination address is aligned mod 4 }
while (PtrUInt(dest) and $3) <> 0 do
begin
dest^ := (((PUint32(source) + (x shr 16))^ shr 20) and $e0) or
(((PUint32(source) + (x shr 16))^ shr 13) and $1c) or
(((PUint32(source) + (x shr 16))^ shr 6) and $3);
Inc(x, inc_source);
Inc(dest);
Dec(count);
if count = 0 then
exit;
end;
{ Write blocks of four pixels now }
c := count shr 2;
while c <> 0 do
begin
Dec(c);
p := ((((PUint32(source) + (x shr 16))^ shr 20) and $e0) or
(((PUint32(source) + (x shr 16))^ shr 13) and $1c) or
(((PUint32(source) + (x shr 16))^ shr 6) and $3)) shl DWORD_BYTE0_SHL;
Inc(x, inc_source);
p := p or
(((((PUint32(source) + (x shr 16))^ shr 20) and $e0) or
(((PUint32(source) + (x shr 16))^ shr 13) and $1c) or
(((PUint32(source) + (x shr 16))^ shr 6) and $3)) shl DWORD_BYTE1_SHL);
Inc(x, inc_source);
p := p or
(((((PUint32(source) + (x shr 16))^ shr 20) and $e0) or
(((PUint32(source) + (x shr 16))^ shr 13) and $1c) or
(((PUint32(source) + (x shr 16))^ shr 6) and $3)) shl DWORD_BYTE2_SHL);
Inc(x, inc_source);
p := p or
(((((PUint32(source) + (x shr 16))^ shr 20) and $e0) or
(((PUint32(source) + (x shr 16))^ shr 13) and $1c) or
(((PUint32(source) + (x shr 16))^ shr 6) and $3)) shl DWORD_BYTE3_SHL);
Inc(x, inc_source);
PUint32(dest)^ := p;
Inc(dest, 4);
end;
{ Write up to three trailing pixels }
c := count and $3;
while c <> 0 do
begin
Dec(c);
dest^ := (((PUint32(source) + (x shr 16))^ shr 20) and $e0) or
(((PUint32(source) + (x shr 16))^ shr 13) and $1c) or
(((PUint32(source) + (x shr 16))^ shr 6) and $3);
Inc(x, inc_source);
Inc(dest);
end;
end;
|