![](/img/trans.png)
[英]How to implement Bresenham's line algorithm in C when trying to draw a line in bmp file?
[英]How does endianess influence drawing pixels in BMP file using Bresenham algorithm in MIPS?
我想在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算法的問題。
大/小尾數是字中的字節順序,而不是位。
如果您的像素在每個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,其原點是左下角,並且線條偏移為負( 當biHeight為正時 )
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.