gpt4 book ai didi

algorithm - 在 MIPS 中使用 Bresenham 算法,字节顺序如何影响 BMP 文件中的绘图像素?

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:22:37 24 4
gpt4 key购买 nike

我想在 MIPS 汇编中创建一个程序,它制作并保存一个 1 bpp BMP 文件,其中将使用 Bresenham 算法绘制一个不同半径长度的圆(由用户在控制台上提供)。

目前,我有一个用于直径整数值的定义明确的 BMP 文件,但是我还在为另外两件事而苦苦挣扎:

这是我在文本段中的部分代码,负责在正确的地址位置绘制像素:

    # $t2 - length of row + padding
# $t3 - initial address of a bitmap (header)
# $t4 - pointer to move values from BMP header parameters onto the heap

.macro drawPixel(%x,%y)
addiu $t4, $t3, 62 # starting address of a pixel map
mult %y, $t2 # pixel y-value multiplied by row length
mflo $a2
addu $t4, $t4, $a2 # y-value pixel address computation
divu $a2, %x, 8 # pixel x-value divided by 8 to obtain number of bytes
addu $t4, $t4, $a2 # x-value pixel address computation
mfhi $a3

#addiu $a3, $a3, -1
li $a2, 1
srlv $a2, $a2, $a3
lb $a3, ($t4) # loading byte at the address of pixel map start (="white" byte)
or $a3, $a3, $a2 # adds a new coloured byte to a "white" byte
sb $a3, ($t4) # loads byte with a coloured pixel
.end_macro
enter code here

下面部分是一个简单的示例,用于测试目的,显示像素未显示在指定位置:

    li  $a0, 0
li $a1, 0
drawPixel($a0, $a1)

li $a0, 4
li $a1, 0
drawPixel($a0, $a1)

尽管我的程序绘制了像素,但它们的顺序却以某种方式相反。我想知道这是否与 MIPS 汇编中的不同大/小端有关,如果是,我该如何解决?

非常感谢您的帮助,如果您能在这部分指导我,那么关于 Bresenham 算法的第二个问题就不需要了。

最佳答案

Big/little-endiannes 用于字中的字节顺序,而不是位。

如果您的像素在每个 8 像素组中从左到右反射,请查看在单色位图中设置像素的示例 (x86 asm)。对您来说重要的部分 - MaskToSetABit = 0x80 shr (X mod 8)

 mov ecx,edx //X coordinate
and ecx, 7 //X mod 8
mov edx, $80
shr edx,cl //mask to isolate needed bit
or ebx,ebx
jz @@IsZero
or eax,edx //set bit to 1

如果所有的线都是从上到下反射的,那么你必须考虑大多数位图包含自下而上的DIB,它的原点是左下角,并且线线偏移是负的(when biHeight is positive )

关于algorithm - 在 MIPS 中使用 Bresenham 算法,字节顺序如何影响 BMP 文件中的绘图像素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27595017/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com