Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Assembly 将代码从“翻转”更改为“翻转”;8bpp.bmp图像“;水平翻转一个";1bpp.bmp图像“;在x86中水平_Assembly_Image Processing_Bitmap_X86_X86 64 - Fatal编程技术网

Assembly 将代码从“翻转”更改为“翻转”;8bpp.bmp图像“;水平翻转一个";1bpp.bmp图像“;在x86中水平

Assembly 将代码从“翻转”更改为“翻转”;8bpp.bmp图像“;水平翻转一个";1bpp.bmp图像“;在x86中水平,assembly,image-processing,bitmap,x86,x86-64,Assembly,Image Processing,Bitmap,X86,X86 64,您好,我已经开发了镜像/水平翻转8bpp.BMP图像的代码。正确处理任何宽度,而不仅仅是4的倍数。现在,我必须将这段代码转换为与此相同的代码,但转换为1 bpp。bmp图像(灰度)使用x86。困难的是,我不知道如何超出单个位,也许有人可以编辑此代码 section .text global mirrorbmp8 mirrorbmp8: push ebp mov ebp, esp push ebx

您好,我已经开发了镜像/水平翻转8bpp.BMP图像的代码。正确处理任何宽度,而不仅仅是4的倍数。现在,我必须将这段代码转换为与此相同的代码,但转换为1 bpp。bmp图像(灰度)使用x86。困难的是,我不知道如何超出单个位,也许有人可以编辑此代码

        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
任何帮助都将不胜感激。 提前感谢:)


p、 s如果我能完成这个版本,那么我还必须将整个代码转换为x86-64版本,这方面的任何提示都会有所帮助。

位图存储在扫描线中,每扫描线有一行像素。你真正需要做的就是颠倒这些行的顺序。第一步是将位图的标题复制到另一个文件中。然后,您应该计算每条扫描线的长度。因为每个扫描线始终是32位填充的,所以您需要一些数学:

scanlineLength = imageWidth / 8
IF imageWidth % 32 != 0
  scanlineLength += 1
ENDIF
接下来,将
scanlinegth
字节从旧文件复制到新文件中。向上移动一条扫描线并重复该过程,直到它们全部被复制


编辑:在重新阅读您的问题后,我仍然不确定您以何种方式翻转图像,因此我不确定这是否适用。

如果您想知道如何从左向右翻转图像,而不是从上到下翻转图像,以下是您的操作方法

首先,将位图的标题复制到另一个文件中。接下来,计算每个扫描行末尾超过imageWidth%32的位数:

orphanBits = imageWidth % 32
在下面的示例中,
孤立位
为19。将扫描线末端的最后两个DWORD读入两个通用寄存器:

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(现在按相反顺序)写入新图像。重复此操作,直到读取整个扫描线。重复此操作,直到读取所有扫描线


编辑:在我记起之前,最初只有bswap交换字节,而不是位。

在我看来,代码是垂直翻转图像,而不是水平翻转图像。我遗漏了什么吗?这是水平翻转而不是垂直:)我在水平翻转图像,我唯一想知道的是如何对1 bpp的图像执行此操作,因为在x86寄存器中,不可能访问单个位,因为最小的寄存器是8位。