19682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall;
29682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall; x86 format converters for HERMES
39682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall; Some routines Copyright (c) 1998 Christian Nentwich (brn@eleet.mcb.at)
49682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall; This source code is licensed under the GNU LGPL
59682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall; 
69682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall; Please refer to the file COPYING.LIB contained in the distribution for
79682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall; licensing conditions		
89682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall;
99682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall; Most routines are (c) Glenn Fiedler (ptc@gaffer.org), used with permission
109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall; 
119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallBITS 32
139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall%include "common.inc"
159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_FUNC _ConvertX86p32_32BGR888
179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_FUNC _ConvertX86p32_32RGBA888
189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_FUNC _ConvertX86p32_32BGRA888
199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_FUNC _ConvertX86p32_24RGB888	
209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_FUNC _ConvertX86p32_24BGR888
219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_FUNC _ConvertX86p32_16RGB565
229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_FUNC _ConvertX86p32_16BGR565
239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_FUNC _ConvertX86p32_16RGB555
249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_FUNC _ConvertX86p32_16BGR555
259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSDL_FUNC _ConvertX86p32_8RGB332
269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallSECTION .text
289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall;; _Convert_*
309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall;; Paramters:	
319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall;;   ESI = source 
329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall;;   EDI = dest
339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall;;   ECX = amount (NOT 0!!! (the _ConvertX86 routine checks for that though))
349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall;; Destroys:
359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall;;   EAX, EBX, EDX
369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall_ConvertX86p32_32BGR888:
399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    ; check short
419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    cmp ecx,BYTE 32
429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    ja .L3
439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L1: ; short loop
459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    mov edx,[esi]
469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    bswap edx
479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    ror edx,8
489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    mov [edi],edx
499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    add esi,BYTE 4
509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    add edi,BYTE 4
519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    dec ecx
529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    jnz .L1
539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L2:
549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    retn
559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L3: ; save ebp
579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    push ebp
589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    ; unroll four times
609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    mov ebp,ecx
619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    shr ebp,2
629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    
639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    ; save count
649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    push ecx
659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L4:    mov eax,[esi]
679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov ebx,[esi+4]
689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        bswap eax
709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        bswap ebx
729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        ror eax,8
749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov ecx,[esi+8]
759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        ror ebx,8
779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov edx,[esi+12]
789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        bswap ecx
809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        bswap edx
829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        ror ecx,8
849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov [edi+0],eax
859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        ror edx,8
879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov [edi+4],ebx
889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov [edi+8],ecx
909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov [edi+12],edx
919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        add esi,BYTE 16
939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        add edi,BYTE 16
949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        dec ebp
969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        jnz .L4                 
979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    ; check tail
999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    pop ecx
1009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    and ecx,BYTE 11b
1019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    jz .L6
1029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L5: ; tail loop
1049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    mov edx,[esi]
1059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    bswap edx
1069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    ror edx,8
1079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    mov [edi],edx
1089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    add esi,BYTE 4
1099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    add edi,BYTE 4
1109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    dec ecx
1119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    jnz .L5
1129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L6: pop ebp
1149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    retn
1159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	
1169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	
1189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		
1199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall_ConvertX86p32_32RGBA888:
1209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	
1219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    ; check short
1229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    cmp ecx,BYTE 32
1239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    ja .L3
1249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L1: ; short loop
1269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    mov edx,[esi]
1279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    rol edx,8
1289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    mov [edi],edx
1299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    add esi,BYTE 4
1309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    add edi,BYTE 4
1319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    dec ecx
1329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    jnz .L1
1339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L2:
1349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    retn
1359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L3: ; save ebp
1379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    push ebp
1389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    ; unroll four times
1409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    mov ebp,ecx
1419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    shr ebp,2
1429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    
1439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    ; save count
1449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    push ecx
1459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L4:    mov eax,[esi]
1479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov ebx,[esi+4]
1489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        rol eax,8
1509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov ecx,[esi+8]
1519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        rol ebx,8
1539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov edx,[esi+12]
1549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        rol ecx,8
1569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov [edi+0],eax
1579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        rol edx,8
1599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov [edi+4],ebx
1609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov [edi+8],ecx
1629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov [edi+12],edx
1639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        add esi,BYTE 16
1659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        add edi,BYTE 16
1669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        dec ebp
1689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        jnz .L4                 
1699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    ; check tail
1719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    pop ecx
1729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    and ecx,BYTE 11b
1739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    jz .L6
1749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L5: ; tail loop
1769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    mov edx,[esi]
1779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    rol edx,8
1789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    mov [edi],edx
1799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    add esi,BYTE 4
1809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    add edi,BYTE 4
1819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    dec ecx
1829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    jnz .L5
1839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L6: pop ebp
1859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    retn
1869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	
1889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall_ConvertX86p32_32BGRA888:
1919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    ; check short
1939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    cmp ecx,BYTE 32
1949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    ja .L3
1959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L1: ; short loop
1979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    mov edx,[esi]
1989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    bswap edx
1999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    mov [edi],edx
2009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    add esi,BYTE 4
2019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    add edi,BYTE 4
2029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    dec ecx
2039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    jnz .L1
2049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L2:
2059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    retn
2069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L3: ; save ebp
2089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    push ebp
2099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    ; unroll four times
2119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    mov ebp,ecx
2129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    shr ebp,2
2139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    
2149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    ; save count
2159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    push ecx
2169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L4:    mov eax,[esi]
2189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov ebx,[esi+4]
2199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov ecx,[esi+8]
2219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov edx,[esi+12]
2229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        bswap eax
2249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        bswap ebx
2269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        bswap ecx
2289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        bswap edx
2309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov [edi+0],eax
2329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov [edi+4],ebx
2339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov [edi+8],ecx
2359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov [edi+12],edx
2369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        add esi,BYTE 16
2389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        add edi,BYTE 16
2399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        dec ebp
2419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        jnz .L4                 
2429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    ; check tail
2449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    pop ecx
2459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    and ecx,BYTE 11b
2469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    jz .L6
2479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L5: ; tail loop
2499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    mov edx,[esi]
2509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    bswap edx
2519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    mov [edi],edx
2529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    add esi,BYTE 4
2539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    add edi,BYTE 4
2549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    dec ecx
2559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    jnz .L5
2569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L6: pop ebp
2589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    retn
2599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	
2629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	
2639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall;; 32 bit RGB 888 to 24 BIT RGB 888
2649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall_ConvertX86p32_24RGB888:
2669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	; check short
2689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	cmp ecx,BYTE 32
2699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	ja .L3
2709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L1:	; short loop
2729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov al,[esi]
2739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov bl,[esi+1]
2749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov dl,[esi+2]
2759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi],al
2769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+1],bl
2779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+2],dl
2789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add esi,BYTE 4
2799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add edi,BYTE 3
2809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	dec ecx
2819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	jnz .L1
2829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L2:
2839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	retn
2849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L3:	;	 head
2869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov edx,edi
2879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	and edx,BYTE 11b
2889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	jz .L4
2899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov al,[esi]
2909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov bl,[esi+1]
2919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov dl,[esi+2]
2929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi],al
2939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+1],bl
2949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+2],dl
2959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add esi,BYTE 4
2969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add edi,BYTE 3
2979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	dec ecx
2989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	jmp SHORT .L3
2999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L4: ; unroll 4 times
3019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	push ebp
3029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov ebp,ecx
3039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr ebp,2
3049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    ; save count
3069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	push ecx
3079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L5:    mov eax,[esi]                   ; first dword            eax = [A][R][G][B]
3099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov ebx,[esi+4]                 ; second dword           ebx = [a][r][g][b]
3109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        shl eax,8                       ;                        eax = [R][G][B][.]
3129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov ecx,[esi+12]                ; third dword            ecx = [a][r][g][b]
3139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        shl ebx,8                       ;                        ebx = [r][g][b][.]
3159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov al,[esi+4]                  ;                        eax = [R][G][B][b]
3169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        ror eax,8                       ;                        eax = [b][R][G][B] (done)
3189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov bh,[esi+8+1]                ;                        ebx = [r][g][G][.]
3199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov [edi],eax
3219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        add edi,BYTE 3*4
3229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        shl ecx,8                       ;                        ecx = [r][g][b][.]
3249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov bl,[esi+8+0]                ;                        ebx = [r][g][G][B]
3259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        rol ebx,16                      ;                        ebx = [G][B][r][g] (done)
3279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov cl,[esi+8+2]                ;                        ecx = [r][g][b][R] (done)
3289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov [edi+4-3*4],ebx
3309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        add esi,BYTE 4*4
3319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        
3329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov [edi+8-3*4],ecx
3339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        dec ebp
3349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        jnz .L5
3369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    ; check tail
3389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	pop ecx
3399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	and ecx,BYTE 11b
3409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	jz .L7
3419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L6: ; tail loop
3439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov al,[esi]
3449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov bl,[esi+1]
3459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov dl,[esi+2]
3469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi],al
3479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+1],bl
3489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+2],dl
3499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add esi,BYTE 4
3509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add edi,BYTE 3
3519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	dec ecx
3529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	jnz .L6
3539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L7:	pop ebp
3559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	retn
3569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall;; 32 bit RGB 888 to 24 bit BGR 888
3619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall_ConvertX86p32_24BGR888:
3639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	; check short
3659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	cmp ecx,BYTE 32
3669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	ja .L3
3679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L1:	; short loop
3699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov dl,[esi]
3709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov bl,[esi+1]
3719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov al,[esi+2]
3729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi],al
3739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+1],bl
3749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+2],dl
3759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add esi,BYTE 4
3769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add edi,BYTE 3
3779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	dec ecx
3789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	jnz .L1
3799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L2:
3809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	retn
3819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L3: ; head
3839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov edx,edi
3849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	and edx,BYTE 11b
3859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	jz .L4
3869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov dl,[esi]
3879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov bl,[esi+1]
3889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov al,[esi+2]
3899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi],al
3909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+1],bl
3919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+2],dl
3929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add esi,BYTE 4
3939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add edi,BYTE 3
3949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	dec ecx
3959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	jmp SHORT .L3
3969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L4:	; unroll 4 times
3989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	push ebp
3999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov ebp,ecx
4009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr ebp,2
4019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	; save count
4039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	push ecx
4049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L5:
4069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov eax,[esi]                   ; first dword            eax = [A][R][G][B]
4079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov ebx,[esi+4]                 ; second dword           ebx = [a][r][g][b]
4089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        bswap eax                       ;                        eax = [B][G][R][A]
4109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        bswap ebx                       ;                        ebx = [b][g][r][a]
4129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov al,[esi+4+2]                ;                        eax = [B][G][R][r] 
4149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov bh,[esi+4+4+1]              ;                        ebx = [b][g][G][a]
4159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        ror eax,8                       ;                        eax = [r][B][G][R] (done)
4179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov bl,[esi+4+4+2]              ;                        ebx = [b][g][G][R]
4189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        ror ebx,16                      ;                        ebx = [G][R][b][g] (done)
4209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov [edi],eax
4219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    
4229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov [edi+4],ebx
4239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov ecx,[esi+12]                ; third dword            ecx = [a][r][g][b]
4249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        
4259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        bswap ecx                       ;                        ecx = [b][g][r][a]
4269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        
4279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov cl,[esi+8]                  ;                        ecx = [b][g][r][B] (done)
4289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        add esi,BYTE 4*4
4299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov [edi+8],ecx
4319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        add edi,BYTE 3*4
4329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        dec ebp
4349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        jnz .L5
4359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	; check tail
4379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	pop ecx
4389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	and ecx,BYTE 11b
4399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	jz .L7
4409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L6:	; tail loop
4429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov dl,[esi]
4439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov bl,[esi+1]
4449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov al,[esi+2]
4459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi],al
4469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+1],bl
4479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+2],dl
4489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add esi,BYTE 4
4499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add edi,BYTE 3
4509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	dec ecx
4519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	jnz .L6
4529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L7:
4549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	pop ebp
4559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	retn
4569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 
4579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	
4599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		
4609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall;; 32 bit RGB 888 to 16 BIT RGB 565 
4619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall_ConvertX86p32_16RGB565:
4639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	; check short
4649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	cmp ecx,BYTE 16
4659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	ja .L3
4669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L1: ; short loop
4689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov bl,[esi+0]    ; blue
4699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov al,[esi+1]    ; green
4709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov ah,[esi+2]    ; red
4719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr ah,3
4729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        and al,11111100b
4739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shl eax,3
4749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr bl,3
4759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add al,bl
4769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+0],al
4779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+1],ah
4789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add esi,BYTE 4
4799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add edi,BYTE 2
4809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	dec ecx
4819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	jnz .L1
4829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L2:				; End of short loop
4849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	retn
4859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
4869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	
4879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L3:	; head
4889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov ebx,edi
4899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	and ebx,BYTE 11b
4909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	jz .L4
4919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	
4929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov bl,[esi+0]    ; blue
4939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov al,[esi+1]    ; green
4949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov ah,[esi+2]    ; red
4959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr ah,3
4969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	and al,11111100b
4979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shl eax,3
4989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr bl,3
4999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add al,bl
5009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+0],al
5019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+1],ah
5029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add esi,BYTE 4
5039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add edi,BYTE 2
5049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	dec ecx
5059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L4:	 
5079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    ; save count
5089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	push ecx
5099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    ; unroll twice
5119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr ecx,1
5129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    
5139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    ; point arrays to end
5149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	lea esi,[esi+ecx*8]
5159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	lea edi,[edi+ecx*4]
5169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    ; negative counter 
5189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	neg ecx
5199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	jmp SHORT .L6
5209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L5:	    
5229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+ecx*4-4],eax
5239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L6:	
5249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov eax,[esi+ecx*8]
5259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        shr ah,2
5279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov ebx,[esi+ecx*8+4]
5289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        shr eax,3
5309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov edx,[esi+ecx*8+4]
5319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        shr bh,2
5339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov dl,[esi+ecx*8+2]
5349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        shl ebx,13
5369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        and eax,000007FFh
5379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        
5389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        shl edx,8
5399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        and ebx,07FF0000h
5409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        and edx,0F800F800h
5429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        add eax,ebx
5439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        add eax,edx
5459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        inc ecx
5469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        jnz .L5                 
5489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+ecx*4-4],eax
5509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    ; tail
5529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	pop ecx
5539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	test cl,1
5549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	jz .L7
5559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	
5569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov bl,[esi+0]    ; blue
5579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov al,[esi+1]    ; green
5589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov ah,[esi+2]    ; red
5599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr ah,3
5609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	and al,11111100b
5619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shl eax,3
5629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr bl,3
5639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add al,bl
5649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+0],al
5659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+1],ah
5669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add esi,BYTE 4
5679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add edi,BYTE 2
5689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L7:	
5709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	retn
5719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	
5759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall;; 32 bit RGB 888 to 16 BIT BGR 565 
5769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall_ConvertX86p32_16BGR565:
5789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	
5799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	; check short
5809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	cmp ecx,BYTE 16
5819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	ja .L3
5829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
5839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L1:	; short loop
5849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov ah,[esi+0]    ; blue
5859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov al,[esi+1]    ; green
5869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov bl,[esi+2]    ; red
5879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr ah,3
5889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	and al,11111100b
5899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shl eax,3
5909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr bl,3
5919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add al,bl
5929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+0],al
5939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+1],ah
5949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add esi,BYTE 4
5959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add edi,BYTE 2
5969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	dec ecx
5979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	jnz .L1
5989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L2:
5999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	retn
6009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L3:	; head
6029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov ebx,edi
6039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	and ebx,BYTE 11b
6049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	jz .L4   
6059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov ah,[esi+0]    ; blue
6069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov al,[esi+1]    ; green
6079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov bl,[esi+2]    ; red
6089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr ah,3
6099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	and al,11111100b
6109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shl eax,3
6119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr bl,3
6129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add al,bl
6139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+0],al
6149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+1],ah
6159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add esi,BYTE 4
6169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add edi,BYTE 2
6179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	dec ecx
6189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L4:	; save count
6209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	push ecx
6219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	; unroll twice
6239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr ecx,1
6249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    
6259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	; point arrays to end
6269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	lea esi,[esi+ecx*8]
6279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	lea edi,[edi+ecx*4]
6289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	; negative count
6309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	neg ecx
6319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	jmp SHORT .L6
6329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L5:
6349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+ecx*4-4],eax            
6359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L6:
6369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov edx,[esi+ecx*8+4]
6379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov bh,[esi+ecx*8+4]                       
6399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov ah,[esi+ecx*8]                       
6409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        shr bh,3
6429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov al,[esi+ecx*8+1]             
6439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        shr ah,3
6459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov bl,[esi+ecx*8+5]           
6469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        shl eax,3
6489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov dl,[esi+ecx*8+2]
6499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        shl ebx,19
6519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        and eax,0000FFE0h              
6529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                
6539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        shr edx,3
6549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        and ebx,0FFE00000h             
6559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        
6569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        and edx,001F001Fh               
6579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        add eax,ebx
6589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        add eax,edx
6609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        inc ecx
6619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        jnz .L5                 
6639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+ecx*4-4],eax            
6659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	; tail
6679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	pop ecx
6689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	and ecx,BYTE 1
6699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	jz .L7
6709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov ah,[esi+0]    ; blue
6719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov al,[esi+1]    ; green
6729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov bl,[esi+2]    ; red
6739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr ah,3
6749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	and al,11111100b
6759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shl eax,3
6769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr bl,3
6779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add al,bl
6789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+0],al
6799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+1],ah
6809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add esi,BYTE 4
6819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add edi,BYTE 2
6829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L7:
6849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	retn
6859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	
6889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	
6899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall;; 32 BIT RGB TO 16 BIT RGB 555
6909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall_ConvertX86p32_16RGB555:
6929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	; check short
6949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	cmp ecx,BYTE 16
6959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	ja .L3
6969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
6979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L1:	; short loop
6989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov bl,[esi+0]    ; blue
6999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov al,[esi+1]    ; green
7009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov ah,[esi+2]    ; red
7019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr ah,3
7029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	and al,11111000b
7039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shl eax,2
7049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr bl,3
7059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add al,bl
7069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+0],al
7079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+1],ah
7089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add esi,BYTE 4
7099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add edi,BYTE 2
7109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	dec ecx
7119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	jnz .L1
7129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L2:
7139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	retn
7149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L3:	; head
7169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov ebx,edi
7179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        and ebx,BYTE 11b
7189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	jz .L4   
7199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov bl,[esi+0]    ; blue
7209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov al,[esi+1]    ; green
7219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov ah,[esi+2]    ; red
7229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr ah,3
7239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	and al,11111000b
7249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shl eax,2
7259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr bl,3
7269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add al,bl
7279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+0],al
7289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+1],ah
7299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add esi,BYTE 4
7309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add edi,BYTE 2
7319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	dec ecx
7329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L4:	; save count
7349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	push ecx
7359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	; unroll twice
7379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr ecx,1
7389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    
7399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	; point arrays to end
7409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	lea esi,[esi+ecx*8]
7419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	lea edi,[edi+ecx*4]
7429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	; negative counter 
7449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	neg ecx
7459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	jmp SHORT .L6
7469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L5:
7489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+ecx*4-4],eax
7499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L6:
7509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov eax,[esi+ecx*8]
7519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        shr ah,3
7539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov ebx,[esi+ecx*8+4]
7549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        shr eax,3
7569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov edx,[esi+ecx*8+4]
7579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        shr bh,3
7599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov dl,[esi+ecx*8+2]
7609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        shl ebx,13
7629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        and eax,000007FFh
7639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        
7649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        shl edx,7
7659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        and ebx,07FF0000h
7669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        and edx,07C007C00h
7689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        add eax,ebx
7699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        add eax,edx
7719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        inc ecx
7729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        jnz .L5                 
7749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+ecx*4-4],eax
7769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	; tail
7789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	pop ecx
7799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	and ecx,BYTE 1
7809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	jz .L7
7819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov bl,[esi+0]    ; blue
7829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov al,[esi+1]    ; green
7839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov ah,[esi+2]    ; red
7849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr ah,3
7859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	and al,11111000b
7869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shl eax,2
7879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr bl,3
7889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add al,bl
7899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+0],al
7909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+1],ah
7919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add esi,BYTE 4
7929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add edi,BYTE 2
7939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L7:
7959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	retn
7969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
7999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall;; 32 BIT RGB TO 16 BIT BGR 555
8019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	
8029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall_ConvertX86p32_16BGR555:
8039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	
8049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	; check short
8059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	cmp ecx,BYTE 16
8069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	ja .L3
8079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L1:	; short loop
8109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov ah,[esi+0]    ; blue
8119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov al,[esi+1]    ; green
8129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov bl,[esi+2]    ; red
8139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr ah,3
8149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	and al,11111000b
8159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shl eax,2
8169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr bl,3
8179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add al,bl
8189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+0],al
8199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+1],ah
8209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add esi,BYTE 4
8219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add edi,BYTE 2
8229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	dec ecx
8239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	jnz .L1
8249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L2:
8259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	retn
8269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L3:	; head
8289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov ebx,edi
8299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        and ebx,BYTE 11b
8309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	jz .L4   
8319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov ah,[esi+0]    ; blue
8329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov al,[esi+1]    ; green
8339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov bl,[esi+2]    ; red
8349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr ah,3
8359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	and al,11111000b
8369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shl eax,2
8379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr bl,3
8389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add al,bl
8399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+0],al
8409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+1],ah
8419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add esi,BYTE 4
8429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add edi,BYTE 2
8439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	dec ecx
8449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L4:	; save count
8469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	push ecx
8479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	; unroll twice
8499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr ecx,1
8509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    
8519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	; point arrays to end
8529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	lea esi,[esi+ecx*8]
8539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	lea edi,[edi+ecx*4]
8549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	; negative counter 
8569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	neg ecx
8579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	jmp SHORT .L6
8589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L5:
8609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+ecx*4-4],eax            
8619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L6:
8629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov edx,[esi+ecx*8+4]
8639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov bh,[esi+ecx*8+4]                       
8659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov ah,[esi+ecx*8]                       
8669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        shr bh,3
8689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov al,[esi+ecx*8+1]             
8699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        shr ah,3
8719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov bl,[esi+ecx*8+5]           
8729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        shl eax,2
8749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov dl,[esi+ecx*8+2]
8759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        shl ebx,18
8779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        and eax,00007FE0h              
8789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall                
8799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        shr edx,3
8809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        and ebx,07FE00000h             
8819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        
8829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        and edx,001F001Fh               
8839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        add eax,ebx
8849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        add eax,edx
8869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        inc ecx
8879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        jnz .L5                 
8899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+ecx*4-4],eax            
8919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
8929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	; tail
8939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	pop ecx
8949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	and ecx,BYTE 1
8959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	jz .L7
8969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov ah,[esi+0]    ; blue
8979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov al,[esi+1]    ; green
8989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov bl,[esi+2]    ; red
8999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr ah,3
9009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	and al,11111000b
9019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shl eax,2
9029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr bl,3
9039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add al,bl
9049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+0],al
9059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi+1],ah
9069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add esi,BYTE 4
9079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add edi,BYTE 2
9089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L7:
9109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	retn
9119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	
9169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall;; FROM 32 BIT RGB to 8 BIT RGB (rrrgggbbb)
9179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall;; This routine writes FOUR pixels at once (dword) and then, if they exist
9189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall;; the trailing three pixels
9199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall_ConvertX86p32_8RGB332:
9209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	
9229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L_ALIGNED:
9239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	push ecx
9249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr ecx,2		; We will draw 4 pixels at once
9269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	jnz .L1
9279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	
9289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	jmp .L2			; short jump out of range :(
9299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	
9309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L1:
9319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov eax,[esi]		; first pair of pixels
9329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov edx,[esi+4]
9339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr dl,6
9359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov ebx,eax
9369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr al,6
9389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	and ah,0e0h
9399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr ebx,16
9419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	and dh,0e0h
9429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	
9439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr ah,3
9449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	and bl,0e0h
9459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr dh,3
9479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	
9489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	or al,bl
9499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	
9509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov ebx,edx	
9519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	or al,ah
9529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	
9539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr ebx,16
9549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	or dl,dh
9559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	and bl,0e0h
9579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	
9589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	or dl,bl
9599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov ah,dl
9619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	
9639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall		
9649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov ebx,[esi+8]		; second pair of pixels
9659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov edx,ebx
9679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	and bh,0e0h
9689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr bl,6
9709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	and edx,0e00000h
9719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr edx,16
9739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr bh,3
9759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	ror eax,16
9779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	or bl,dl
9789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov edx,[esi+12]
9809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	or bl,bh
9819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	
9829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov al,bl
9839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov ebx,edx
9859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	and dh,0e0h
9869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr dl,6
9889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	and ebx,0e00000h
9899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	
9909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr dh,3
9919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov ah,dl
9929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	shr ebx,16
9949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	or ah,dh
9959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	or ah,bl
9979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
9989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	rol eax,16
9999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add esi,BYTE 16
10009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall			
10019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov [edi],eax	
10029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	add edi,BYTE 4
10039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	
10049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	dec ecx
10059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	jz .L2			; L1 out of range for short jump :(
10069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	
10079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	jmp .L1
10089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L2:
10099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	
10109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	pop ecx
10119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	and ecx,BYTE 3		; mask out number of pixels to draw
10129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	
10139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	jz .L4			; Nothing to do anymore
10149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
10159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L3:
10169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	mov eax,[esi]		; single pixel conversion for trailing pixels
10179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
10189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov ebx,eax
10199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
10209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        shr al,6
10219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        and ah,0e0h
10229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
10239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        shr ebx,16
10249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
10259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        shr ah,3
10269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        and bl,0e0h
10279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
10289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        or al,ah
10299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        or al,bl
10309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
10319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        mov [edi],al
10329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
10339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        inc edi
10349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall        add esi,BYTE 4
10359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
10369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	dec ecx
10379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	jnz .L3
10389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	
10399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall.L4:	
10409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	retn
10419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
10429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall%ifidn __OUTPUT_FORMAT__,elf32
10439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallsection .note.GNU-stack noalloc noexec nowrite progbits
10449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall%endif
1045