更改翻转“8bpp .bmp 图像”的代码水平翻转“1bpp .bmp 图像” x86 水平
你好,我开发了水平镜像/翻转 8 bpp .BMP 图像的代码。正确处理任何宽度,而不仅仅是 4 的倍数。现在我必须转换此代码以执行相同的操作,但对于 1 bpp 。使用 x86 的 bmp 图像(灰度)。困难的部分是我不知道如何超出个别位也许有人可以编辑此代码..
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
任何帮助将不胜感激。 提前致谢:)
ps 如果我能够执行此版本,那么我还必须将整个代码转换为 x86-64 版本,这方面的任何提示也会有所帮助。
Hello here I have developed the code for Mirror/flipping an 8 bpp .BMP image horizontally. Handling any width properly, not only multiples of 4. Now I have to convert this code to do the same but for a 1 bpp . bmp image(grayscale) using x86. The difficult part is that I dont know how to excess the individual 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 will be appreciated.
Thanks in advance :)
p.s if i will be able to do this version then I have to convert the whole code for x86-64 version also, any hints in this regard will also be helpful..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想知道如何从左到右翻转图像而不是从上到下翻转图像,请按以下方法操作。
首先,将位图的标题复制到另一个文件中。接下来,计算出每条扫描线末尾有多少位超过 imageWidth % 32:
在下面的示例中,
orphanedBits
为 19。将扫描线末尾的最后两个 DWORD 读入两个通用位中。目的寄存器:使用 SHRD 操作数将位从 ebx 移至 ecx,直到填满整个寄存器:
然后使用以下代码交换
eax
的位:写入调整后的 DWORD(现在按相反顺序) )进入新图像。重复此操作,直到读取整个扫描线。重复此操作直至读取所有扫描线。
编辑:最初只是 bswap,然后我记得它交换了字节,而不是位。
In case you want to know how to flip the image left to right instead of top to bottom, here's how you'd do that.
First, copy the headers of the bitmap into another file. Next, figure out how many bits past imageWidth % 32 are at the end of each scan line:
In the example below,
orphanedBits
is 19. Read the last two DWORDS from the end of the scanline into two general purpose registers:Use the SHRD operand to move bits from ebx into ecx until the entire register is filled up:
Then use the following code to swap the bits of
eax
:Write the adjusted DWORD (now in reverse order) into the new image. Repeat until the whole scanline is read. Repeat until all scanlines are read.
Edit: Originally had just bswap before I remembered it swapped bytes, not bits.
位图存储在扫描线中,每条扫描线有一行像素。您真正需要做的就是颠倒这些行的顺序。第一步是将位图的标题复制到另一个文件中。然后你应该计算每条扫描线的长度。因为每个扫描线始终是 32 位填充的,所以您需要一些数学运算:
接下来,将
scanlineLength
字节从旧文件复制到新文件中。向上移动一条扫描线并重复该过程,直到全部复制完毕。编辑:重读您的问题后,我仍然不确定您翻转图像的方式,所以我不确定这是否适用。
Bitmaps are stored in scanlines with one line of pixels per scan line. All you really have to do is reverse the order of these lines. The firs step would be to copy the headers of the bitmap into another file. Then you should calculate the length of each scanline. Because each scanline is always 32-bit padded, you'll need some math:
Next, copy
scanlineLength
bytes from the old file into the new file. Move up one scanline and repeat the process until they are all copied.Edit: After rereading your question I'm still not sure which way you're flipping the images so I'm not sure if this applies.