📄 pixelcore.pas
字号:
mov eax,[TheSurfaceDesc.lpitch] // width of surface
mul [y2] // multiply with end-point y
add esi,eax // add to surface start pointer
mov ebx,[x2] // add end-point x position
imul ebx,3
add esi,ebx // esi = starting position of first pixel
mov eax,[x2]
mov ebx,[x1] // set initial values *}
mov ecx,[y2]
mov edx,[y1] // line from (eax,ecx) to (ebx,edx) => (x2,y2) to (x1,y1) *}
jmp @continue
@rightOk:
mov eax,[TheSurfaceDesc.lpitch] // width of surface
mul [y1] // multiply with start-point y
add esi,eax // add to surface start pointer
mov ebx,[x1] // add start-point x position
imul ebx,3
add esi,ebx // esi = starting position of first pixel
mov eax,[x1]
mov ebx,[x2] // set initial values *}
mov ecx,[y1]
mov edx,[y2] // line from (eax,ecx) to (ebx,edx) => (x1,y1) to (x2,y2) *}
@continue:
sub ebx,eax // ebx = deltaX
mov eax,[color] // eax = color
push ebp // save ebp to abuse it
mov ebp,[TheSurfaceDesc.lpitch] // ebp = pitch
sub edx,ecx // edx = deltaY
js @RightUp // draw line right up
cmp ebx,edx // test gradient, below 1 or not
jl @RightDownSteep // line right-down-ward and steep
mov ecx,ebx // prepare spill-element ecx
shr ecx,1
neg ecx
add ecx,edx // ecx = -(deltaX)/2 + deltaY
mov edi,ebx // prepare counter edi (equal to deltaX)
dec edi // prevention of single dot crash
mov ds:[esi],ax // set first pixel
ror eax,16
mov ds:[esi+2],al
@loopRDSh: // loop for Right Down Shallow
or ecx,ecx // check spill-element
js @skipRDSh // if signed skip
sub ecx,ebx // reset spill-element
add esi,ebp // calculate vertical step
@skipRDSh:
add ecx,edx // increase spill-element by deltaY
add esi,3 // mov pixel onward
mov ds:[esi],ax // set pixel
ror eax,16
mov ds:[esi+2],al
dec edi // decrement counter
jns @loopRDSh // loop until signed
jmp @ende // terminate
@RightDownSteep:
mov ecx,edx // prepare spill-element CX
shr ecx,1
neg ecx
add ecx,ebx // ecx = -(deltaY)/2 + deltaX
mov edi,edx // prepare counter edi (equal to deltaY)
dec edi // prevention of single dot crash
mov ds:[esi],ax // set pixel
ror eax,16
mov ds:[esi+2],al
@loopRDSt: // loop for Right Down Steep
or ecx,ecx // check spill-element
js @skipRDSt // if signed skip
sub ecx,edx // reset spill-element
add esi,3 // mov pixel onward
@skipRDSt:
add ecx,ebx // increase spill-element by deltaX
add esi,ebp // calculate new pixel offset
mov ds:[esi],ax // set pixel
ror eax,16
mov ds:[esi+2],al
dec edi // decrement counter
jns @loopRDSt // loop until signed
jmp @ende // terminate
@RightUp:
neg edx // reallign DX
cmp ebx,edx // test gradient, below 1 or not
jl @RightUpSteep // line right-up-ward and steep
mov ecx,ebx // prepare spill-element CX
shr ecx,1
neg ecx
add ecx,edx // CX = -(deltaX)/2 + deltaY
mov edi,ebx // prepare counter edi (equal to deltaX)
dec edi // prevention of single dot crash
mov ds:[esi],ax // set pixel
ror eax,16
mov ds:[esi+2],al
@loopRUSh: // loop for Right Up Shallow
or ecx,ecx // check spill-element
js @skipRUSh // if signed skip
sub ecx,ebx // reset spill-element
sub esi,ebp // calculate vertical step
@skipRUSh:
add ecx,edx // increase spill-element by deltaY
add esi,3 // next pixel
mov ds:[esi],ax // set pixel
ror eax,16
mov ds:[esi+2],al
dec edi // decrement counter
jns @loopRUSh // loop until signed
jmp @ende // terminate
@RightUpSteep:
mov ecx,edx // prepare spill-element CX
shr ecx,1
neg ecx
add ecx,ebx // ecx = -(deltaY)/2 + deltaX
mov edi,edx // prepare counter edi (equal to deltaY)
dec edi // prevention of single dot crash
mov ds:[esi],ax // set pixel
ror eax,16
mov ds:[esi+2],al
@loopRUSt: // loop for Right Up Steep
or ecx,ecx // check spill-element
js @skipRUSt // if signed skip
sub ecx,edx // reset spill-element
add esi,3 // vertical step
@skipRUSt:
add ecx,ebx // increase spill-element by deltaX
sub esi,ebp // calculate new pixel offset
mov ds:[esi],ax // set pixel
ror eax,16
mov ds:[esi+2],al
dec edi // decrement counter
jns @loopRUSt // loop until signed
@ende:
pop ebp
popa
pop esi
pop edi
pop ebp
pop ebx
end;
end;
procedure Line32(x1,y1,x2,y2,color : integer);
{ no clipping is performed }
begin
asm
push ebx
push ebp
push edi
push esi
pusha
mov esi,TheSurfaceDesc.lpSurface
mov eax,[x1] // eax = x1
mov ebx,[x2] // ebx = x2
sub ebx,eax // ebx = x2-x1
jns @rightOk // if negative, then swap start/end point
mov eax,[TheSurfaceDesc.lpitch] // width of surface
mul [y2] // multiply with end-point y
add esi,eax // add to surface start pointer
mov ebx,[x2] // add end-point x position
shl ebx,2
add esi,ebx // esi = starting position of first pixel
mov eax,[x2]
mov ebx,[x1] // set initial values *}
mov ecx,[y2]
mov edx,[y1] // line from (eax,ecx) to (ebx,edx) => (x2,y2) to (x1,y1) *}
jmp @continue
@rightOk:
mov eax,[TheSurfaceDesc.lpitch] // width of surface
mul [y1] // multiply with start-point y
add esi,eax // add to surface start pointer
mov ebx,[x1] // add start-point x position
shl ebx,2
add esi,ebx // esi = starting position of first pixel
mov eax,[x1]
mov ebx,[x2] // set initial values *}
mov ecx,[y1]
mov edx,[y2] // line from (eax,ecx) to (ebx,edx) => (x1,y1) to (x2,y2) *}
@continue:
sub ebx,eax // ebx = deltaX
mov eax,[color] // eax = color
push ebp // save ebp to abuse it
mov ebp,[TheSurfaceDesc.lpitch] // ebp = pitch
sub edx,ecx // edx = deltaY
js @RightUp // draw line right up
cmp ebx,edx // test gradient, below 1 or not
jl @RightDownSteep // line right-down-ward and steep
mov ecx,ebx // prepare spill-element ecx
shr ecx,1
neg ecx
add ecx,edx // ecx = -(deltaX)/2 + deltaY
mov edi,ebx // prepare counter edi (equal to deltaX)
dec edi // prevention of single dot crash
mov ds:[esi],eax // set pixel
@loopRDSh: // loop for Right Down Shallow
or ecx,ecx // check spill-element
js @skipRDSh // if signed skip
sub ecx,ebx // reset spill-element
add esi,ebp // calculate vertical step
@skipRDSh:
add ecx,edx // increase spill-element by deltaY
add esi,4 // mov pixel onward
mov ds:[esi],eax // set pixel
dec edi // decrement counter
jns @loopRDSh // loop until signed
jmp @ende // terminate
@RightDownSteep:
mov ecx,edx // prepare spill-element CX
shr ecx,1
neg ecx
add ecx,ebx // ecx = -(deltaY)/2 + deltaX
mov edi,edx // prepare counter edi (equal to deltaY)
dec edi // prevention of single dot crash
mov ds:[esi],eax // set pixel
@loopRDSt: // loop for Right Down Steep
or ecx,ecx // check spill-element
js @skipRDSt // if signed skip
sub ecx,edx // reset spill-element
add esi,4 // mov pixel onward
@skipRDSt:
add ecx,ebx // increase spill-element by deltaX
add esi,ebp // calculate new pixel offset
mov ds:[esi],eax // set pixel
dec edi // decrement counter
jns @loopRDSt // loop until signed
jmp @ende // terminate
@RightUp:
neg edx // reallign DX
cmp ebx,edx // test gradient, below 1 or not
jl @RightUpSteep // line right-up-ward and steep
mov ecx,ebx // prepare spill-element CX
shr ecx,1
neg ecx
add ecx,edx // CX = -(deltaX)/2 + deltaY
mov edi,ebx // prepare counter edi (equal to deltaX)
dec edi // prevention of single dot crash
mov ds:[esi],eax // set first pixel
@loopRUSh: // loop for Right Up Shallow
or ecx,ecx // check spill-element
js @skipRUSh // if signed skip
sub ecx,ebx // reset spill-element
sub esi,ebp // calculate vertical step
@skipRUSh:
add ecx,edx // increase spill-element by deltaY
add esi,4 // next pixel
mov ds:[esi],eax // set first pixel
dec edi // decrement counter
jns @loopRUSh // loop until signed
jmp @ende // terminate
@RightUpSteep:
mov ecx,edx // prepare spill-element CX
shr ecx,1
neg ecx
add ecx,ebx // ecx = -(deltaY)/2 + deltaX
mov edi,edx // prepare counter edi (equal to deltaY)
dec edi // prevention of single dot crash
mov ds:[esi],eax // set first pixel
@loopRUSt: // loop for Right Up Steep
or ecx,ecx // check spill-element
js @skipRUSt // if signed skip
sub ecx,edx // reset spill-element
add esi,4 // vertical step
@skipRUSt:
add ecx,ebx // increase spill-element by deltaX
sub esi,ebp // calculate new pixel offset
mov ds:[esi],eax // set current pixel
dec edi // decrement counter
jns @loopRUSt // loop until signed
@ende:
pop ebp
popa
pop esi
pop edi
pop ebp
pop ebx
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -