flat assembler
Message board for the users of flat assembler.

Index > Main > Fade effect using MMX assembler

Author
Thread Post new topic Reply to topic
Laaca



Joined: 12 Aug 2007
Posts: 3
Laaca 12 Aug 2007, 20:45
Who can provide me a fadding routine for 16-bit graphics mode in MMX assembly?
Lets say that I work in 32-bit protected mode and have a buffer with image data in ES:EDI and in EAX is the buffer size (in bytes)
Pixel format is this: "rrrrrggg gggbbbbb"
Red and blue components should be decreased by 1 and green component by 2.
So, please, write for me the fade cycle....
Thanks!
Post 12 Aug 2007, 20:45
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 13 Aug 2007, 11:24
^o) why is it so complicated? Usually you will win performance-wise if you converted it to 24-bit, then faded and converted the 24-bit back to 16.

MMX is for unified data, this algorithm suggestion is not and very hard to make it take advantage of SIMD. If you really can't afford the convert, then I will try to make one, but I won't start one if you're not 100% sure!
Post 13 Aug 2007, 11:24
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
r22



Joined: 27 Dec 2004
Posts: 805
r22 13 Aug 2007, 18:54
The color format makes it difficult to optimize.

Here's a straight forward solution. Someone can likely take it and optimize it further if necessary.
Code:
.data
align 16
MaskB dq 001F001F001F001Fh
align 16
MaskG dq 07E007E007E007E0h
align 16
MaskR dq F800F800F800F800h
align 16
Sub1 dq 0000000100000001h
align 16
Sub2 dq 0000000200000002h

.code
;;example fade loop
mov ebx,32
mov edi,PixelBuffer
mov eax,640*480*2
.fade2black:
call FadeMMX
call RenderToScreen
sub ebx,1
jnz .fade2black
;;
;;...
;;

FadeMMX:
mov ecx,eax
sub ecx,16
movq mm0,[Sub1]
movq mm7,[Sub2]
;;assumes EAX will always be greater than 15
;;this loop also assumes EAX will be divisible by 16
;;unless your using an odd resolution this should be fine
.fade:
;;load and copy
movq mm1,[esi+ecx]
movq mm2,[esi+ecx+8]
movq mm3,mm1
movq mm4,mm2
movq mm5,mm1
movq mm6,mm2
;;mask the needed bits
pand mm1,qword[MaskB]
pand mm2,qword[MaskB]
pand mm3,qword[MaskG]
pand mm4,qword[MaskG]
pand mm5,qword[MaskR]
pand mm6,qword[MaskR]
;;get the bits to the lowest byte
psrlw mm3,5
psrlw mm4,5
psrlw mm5,11
psrlw mm6,11
;;subtract with saturate
psubusb mm1,mm0
psubusb mm2,mm0
psubusb mm3,mm7
psubusb mm4,mm7
psubusb mm5,mm0
psubusb mm6,mm0
;;shift the bits back into position
psllw mm3,5
psllw mm4,5
psllw mm5,11
psllw mm6,11
;;combine the bits back into the 16bit color
por mm1,mm3
por mm2,mm4
por mm1,mm5
por mm2,mm6
;;store
movq qword[esi+ecx],mm1
movq qword[esi+ecx+8],mm2
sub ecx,16
jns .fade ;; loop while ecx >= 0
ret 0
    


This wasn't tested and was written in the webbrowser reply window, but there's a good chance it could be useful.
Post 13 Aug 2007, 18:54
View user's profile Send private message AIM Address Yahoo Messenger Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1905
DOS386 14 Aug 2007, 06:32
Welcome to FASM forum Smile

Laaca wrote:
Who can provide me a fadding routine for 16-bit graphics mode in MMX assembly? Thanks!


Just make it darker ?

Code:
; IN:  Buffer: [ES:EDI] || size: ECX 
; OUT: Nothing
; TSH: EDI, EAX, ECX

; rrrrrggg gggbbbbb rrrrrggg gggbbbbb

dark: 
    shr ecx,2

dark2:

    mov eax,[es:edi]    ; Pick 2 pixels

;   movntq [es:edi],mm0 ; Uncomment if trouble required Laughing
        
    and   eax,$FFDFFFDF ; Remove 2 offending green bits
 
    test  al,$1F    ; Test blue 5 bits 
    jz    @f
    dec   al        ; DEC blue 
@@: test  eax,$07E0 ; Test green 5/6 bits
    jz    @f
    sub   eax,$20   ; DEC green
@@: test  eax,$F800 ; Test red 5 bits
    jz    @f
     sub   eax,$800
@@:
    test  eax,$001F0000 ; Test blue 5 bits 
    jz    @f
    sub   eax,$10000    ; DEC blue 
@@: test  eax,$07E00000 ; Test green 5/6 bits
    jz    @f
    sub   eax,$00200000 ; DEC green
@@: test  eax,$F8000000 ; Test red 5 bits
    jz    @f
        sub   eax,$08000000
@@:
      stosd           ; And write them back
       
    loop dark2
  ret
;------
    


Sorry no MMX Shocked

Untested, no 16bpp VESA available Neutral

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
Post 14 Aug 2007, 06:32
View user's profile Send private message Reply with quote
Laaca



Joined: 12 Aug 2007
Posts: 3
Laaca 15 Aug 2007, 16:29
Wow! Thanks r22, I'll try it.

NTOSKRNL_VXE: Your code is not optimized at all. Your jumps very slow down the routine.
Post 15 Aug 2007, 16:29
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1905
DOS386 15 Aug 2007, 22:07
> is not optimized at all

For compatibility. Idea

> jumps very slow down

Feel free to compare and post results.
Post 15 Aug 2007, 22:07
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.