flat assembler
Message board for the users of flat assembler.
Index
> Main > MMX color replace |
Author |
|
revolution 30 Sep 2019, 12:53
Use the PAND and the PANDN to isolate the bits you want, and then POR to put in the replacements.
PANDN: 0201FFFF 04FE03FF source 00000000 FFFFFFFF mask (inverted by PANDN) ------------------------------ 00000000 04FE03FF output-0 PAND: FFFFFFFF 00000000 mask 0000FFFF 0000FFFF replacement ----------------------------- 0000FFFF 00000000 output-1 POR: 00000000 04FE03FF output-0 0000FFFF 00000000 output-1 ----------------------------- 0000FFFF 04FE03FF result |
|||
30 Sep 2019, 12:53 |
|
Abruzzi 30 Sep 2019, 13:26
Thank you very much, that was clever.
|
|||
30 Sep 2019, 13:26 |
|
revolution 30 Sep 2019, 13:30
Abruzzi wrote: Thank you very much, that was clever. |
|||
30 Sep 2019, 13:30 |
|
Tomasz Grysztar 30 Sep 2019, 13:32
Are you limited to the original MMX instruction set, or is your constraint that you just need to use MMX registers? This would determine if you could use some of the later instructions, for example MASKMOVQ which could be used to selectively write pixel data from MMX register to memory, but it was introduced by SSE and therefore not available in classic MMX CPUs.
|
|||
30 Sep 2019, 13:32 |
|
Abruzzi 30 Sep 2019, 14:17
For some reason it works pretty well for first two pixels then things get messy. Maybe if I post the code it would be easy to follow.
Code: mov esi, dword[esp+4] ; ESI = pointer to Bitmap -> Scan0 ; 0000FFFF 0000FFFF FFFFFFFF FFFFFFFF 0000FFFF 0000FFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF 0000FFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFF mov edi, dword[esp+8] ; EDI = pointer to a structure Info {dword NumberOfPixels; dword Color; dword Replace} ; Info -> NumberOfPixels = 16; Info -> Color = 0000FFFF; Info -> Replace = 808080FF mov ecx, dword[edi] ; ECX = Info -> NumberOfPixels = 16 mov edx, dword[edi+4] ; EDX = Info -> Color movd mm0, edx punpckldq mm0,mm0 ; MM0 = 0000FFFF 0000FFFF mov edx, dword[edi+8] ; EDX = Info -> Replace movd mm1, edx punpckldq mm1,mm1 ; MM1 = 808080FF 808080FF _next: pcmpeqd mm0, [esi] movq mm2, mm0 pandn mm0, [esi] pand mm1, mm2 por mm0, mm1 movq [esi], mm0 add esi, 8 sub ecx, 2 jnz _next ret 8 I am not sure but I think add esi,8 is not the proper way to move to next two pixels. @Tomasz yes, I am constraint to use MMX registers without SSE instructions BTW is there any debugger that I could use to follow the code step by step? |
|||
30 Sep 2019, 14:17 |
|
revolution 30 Sep 2019, 14:26
You need to protect the compare and replacement values in mm0 and mm1. After the first time through the loop they get altered and are no longer valid for the following iterations.
|
|||
30 Sep 2019, 14:26 |
|
Abruzzi 30 Sep 2019, 14:32
This is why I tried to protect them before the loop but I forgot that they are destination registers in some instructions. Thank you very much, again.
|
|||
30 Sep 2019, 14:32 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.