Change the code from flipping "8bpp.bmp image" horizontally to flip the image "1bpp.bmp" horizontally in x86

Hello, here I developed the code for Mirror / flipping 8 bpp.BMP image horizontally. Handle any width properly, not just a multiple of 4. Now I need to convert this code to do the same, but for 1 bpp. bmp (grayscale) using x86. The hard part is that I don’t know how to increase my bit, maybe someone can edit this code.

        section     .text
    global      mirrorbmp8
mirrorbmp8:
    push        ebp
    mov     ebp, esp
    push        ebx
    push        esi
    push        edi

    mov     ebx, [ebp+12]       ;width - without padding
    and     ebx, 11b
    je      init            ;checking if there is a padding
    mov     edi, 4
    sub     edi, ebx
    add     [ebp+12], edi       ;width - with padding

init:
    mov     ebx, [ebp+16]   
    ;calculating the distance between top&bottom pixel
    dec     ebx
    mov     eax, [ebp+12]
    mul     ebx
    mov     esi, eax

    mov     edi, [ebp+8]    ;the first bottom pixel
    mov     edx, edi            ;the first top pixel
    mov     eax, edi
    add     eax, esi
    mov     ecx, [ebp+12]   
            ;register responsible for calc left columns

loop0:
    push        esi
    mov     esi, [ebp+12]

loop1:
    mov     bl, [edi]               ;changing pixels
    xchg        bl, [eax]
    mov     [edi], bl

    add     edi, esi        ;next pixel in this column
    sub     eax, esi
    cmp     edi, eax
    jl      loop1


    inc     edx             ;next bottom pixel
    mov     edi, edx

    mov     eax, edi                ;next top pixel
    pop     esi
    add     eax, esi

    dec     ecx         ;decrement number of columns left
    jnz     loop0           ;was that the last column?



end:
    pop     edi
    pop     esi 
    pop     ebx

    mov     esp, ebp
    pop     ebp
    ret

Any help would be appreciated. Thanks in advance:)

ps, if I can make this version, then I will have to convert all the code for version x86-64, and any hints in this regard will also be useful.

+3
source
2

, , , .

. , imageWidth% 32 :

orphanBits = imageWidth % 32

orphanedBits 19. DWORDS :

ebx = 10001010 11010101 00101010 10101010
eax = 01010101 01011000 00000000 00000000
  END OF SCAN LINE ^

SHRD ebx ecx , :

shrd eax, ebx, orphanBits

ebx = 00000000 00000000 00010001 01011010
eax = 10100101 01010101 01001010 10101011
                       END OF SCAN LINE ^

eax:

mov edx,eax
shr eax,1
and edx,055555555h
and eax,055555555h
lea eax,[2*edx+eax]
mov edx,eax
shr eax,2
and edx,033333333h
and eax,033333333h
lea eax,[4*edx+eax]
mov edx,eax
shr eax,4
and edx,0F0F0F0Fh
and eax,0F0F0F0Fh
shl edx,4
add eax,edx
bswap eax

eax = 11010101 01010010 10101010 10100101
      ^ END OF SCAN LINE

DWORD ( ) . , . , .

Edit: bswap, , , .

+1

. , , . . . 32 , :

scanlineLength = imageWidth / 8
IF imageWidth % 32 != 0
  scanlineLength += 1
ENDIF

scanlineLength . , .

: , , , , .

0

Source: https://habr.com/ru/post/1787124/


All Articles