2 ; x86 format converters for HERMES
3 ; Some routines Copyright (c) 1998 Christian Nentwich (brn@eleet.mcb.at)
4 ; This source code is licensed under the GNU LGPL
6 ; Please refer to the file COPYING.LIB contained in the distribution for
9 ; Most routines are (c) Glenn Fiedler (ptc@gaffer.org), used with permission
16 SDL_FUNC _ConvertX86p32_32BGR888
17 SDL_FUNC _ConvertX86p32_32RGBA888
18 SDL_FUNC _ConvertX86p32_32BGRA888
19 SDL_FUNC _ConvertX86p32_24RGB888
20 SDL_FUNC _ConvertX86p32_24BGR888
21 SDL_FUNC _ConvertX86p32_16RGB565
22 SDL_FUNC _ConvertX86p32_16BGR565
23 SDL_FUNC _ConvertX86p32_16RGB555
24 SDL_FUNC _ConvertX86p32_16BGR555
25 SDL_FUNC _ConvertX86p32_8RGB332
33 ;; ECX = amount (NOT 0!!! (the _ConvertX86 routine checks for that though))
38 _ConvertX86p32_32BGR888:
119 _ConvertX86p32_32RGBA888:
190 _ConvertX86p32_32BGRA888:
263 ;; 32 bit RGB 888 to 24 BIT RGB 888
265 _ConvertX86p32_24RGB888:
308 .L5 mov eax,[esi] ; first dword eax = [A][R][G][B]
309 mov ebx,[esi+4] ; second dword ebx = [a][r][g][b]
311 shl eax,8 ; eax = [R][G][B][.]
312 mov ecx,[esi+12] ; third dword ecx = [a][r][g][b]
314 shl ebx,8 ; ebx = [r][g][b][.]
315 mov al,[esi+4] ; eax = [R][G][B][b]
317 ror eax,8 ; eax = [b][R][G][B] (done)
318 mov bh,[esi+8+1] ; ebx = [r][g][G][.]
323 shl ecx,8 ; ecx = [r][g][b][.]
324 mov bl,[esi+8+0] ; ebx = [r][g][G][B]
326 rol ebx,16 ; ebx = [G][B][r][g] (done)
327 mov cl,[esi+8+2] ; ecx = [r][g][b][R] (done)
360 ;; 32 bit RGB 888 to 24 bit BGR 888
362 _ConvertX86p32_24BGR888:
407 mov eax,[esi] ; first dword eax = [A][R][G][B]
408 mov ebx,[esi+4] ; second dword ebx = [a][r][g][b]
410 bswap eax ; eax = [B][G][R][A]
412 bswap ebx ; ebx = [b][g][r][a]
414 mov al,[esi+4+2] ; eax = [B][G][R][r]
415 mov bh,[esi+4+4+1] ; ebx = [b][g][G][a]
417 ror eax,8 ; eax = [r][B][G][R] (done)
418 mov bl,[esi+4+4+2] ; ebx = [b][g][G][R]
420 ror ebx,16 ; ebx = [G][R][b][g] (done)
424 mov ecx,[esi+12] ; third dword ecx = [a][r][g][b]
426 bswap ecx ; ecx = [b][g][r][a]
428 mov cl,[esi+8] ; ecx = [b][g][r][B] (done)
461 ;; 32 bit RGB 888 to 16 BIT RGB 565
463 _ConvertX86p32_16RGB565:
469 mov bl,[esi+0] ; blue
470 mov al,[esi+1] ; green
484 .L2: ; End of short loop
493 mov bl,[esi+0] ; blue
494 mov al,[esi+1] ; green
514 ; point arrays to end
523 mov [edi+ecx*4-4],eax
528 mov ebx,[esi+ecx*8+4]
531 mov edx,[esi+ecx*8+4]
550 mov [edi+ecx*4-4],eax
557 mov bl,[esi+0] ; blue
558 mov al,[esi+1] ; green
576 ;; 32 bit RGB 888 to 16 BIT BGR 565
578 _ConvertX86p32_16BGR565:
585 mov ah,[esi+0] ; blue
586 mov al,[esi+1] ; green
606 mov ah,[esi+0] ; blue
607 mov al,[esi+1] ; green
626 ; point arrays to end
635 mov [edi+ecx*4-4],eax
637 mov edx,[esi+ecx*8+4]
665 mov [edi+ecx*4-4],eax
671 mov ah,[esi+0] ; blue
672 mov al,[esi+1] ; green
690 ;; 32 BIT RGB TO 16 BIT RGB 555
692 _ConvertX86p32_16RGB555:
699 mov bl,[esi+0] ; blue
700 mov al,[esi+1] ; green
720 mov bl,[esi+0] ; blue
721 mov al,[esi+1] ; green
740 ; point arrays to end
749 mov [edi+ecx*4-4],eax
754 mov ebx,[esi+ecx*8+4]
757 mov edx,[esi+ecx*8+4]
776 mov [edi+ecx*4-4],eax
782 mov bl,[esi+0] ; blue
783 mov al,[esi+1] ; green
801 ;; 32 BIT RGB TO 16 BIT BGR 555
803 _ConvertX86p32_16BGR555:
811 mov ah,[esi+0] ; blue
812 mov al,[esi+1] ; green
832 mov ah,[esi+0] ; blue
833 mov al,[esi+1] ; green
852 ; point arrays to end
861 mov [edi+ecx*4-4],eax
863 mov edx,[esi+ecx*8+4]
891 mov [edi+ecx*4-4],eax
897 mov ah,[esi+0] ; blue
898 mov al,[esi+1] ; green
917 ;; FROM 32 BIT RGB to 8 BIT RGB (rrrgggbbb)
918 ;; This routine writes FOUR pixels at once (dword) and then, if they exist
919 ;; the trailing three pixels
920 _ConvertX86p32_8RGB332:
926 shr ecx,2 ; We will draw 4 pixels at once
929 jmp .L2 ; short jump out of range :(
932 mov eax,[esi] ; first pair of pixels
965 mov ebx,[esi+8] ; second pair of pixels
1006 jz .L2 ; L1 out of range for short jump :(
1012 and ecx,BYTE 3 ; mask out number of pixels to draw
1014 jz .L4 ; Nothing to do anymore
1017 mov eax,[esi] ; single pixel conversion for trailing pixels
1043 %ifidn __OUTPUT_FORMAT__,elf
1044 section .note.GNU-stack noalloc noexec nowrite progbits