Fixes invalid buffer indexing in rawSemiPixelRectangle() method

This commit is contained in:
IgorTimofeev 2021-02-15 20:08:25 +03:00 committed by GitHub
parent 4d9ca1d0f2
commit bc50f9c31a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -434,20 +434,32 @@ local function semiPixelSet(x, y, color)
end end
local function drawSemiPixelRectangle(x, y, width, height, color) local function drawSemiPixelRectangle(x, y, width, height, color)
local index, indexStepForward, indexStepBackward, jPercentTwoEqualsZero, jFixed = bufferWidth * (mathCeil(y / 2) - 1) + x, (bufferWidth - width), width local index, evenYIndexStep, oddYIndexStep, realY, evenY =
for j = y, y + height - 1 do bufferWidth * (mathCeil(y / 2) - 1) + x,
jPercentTwoEqualsZero = j % 2 == 0 (bufferWidth - width),
width
for i = x, x + width - 1 do for pseudoY = y, y + height - 1 do
jFixed = mathCeil(j / 2) realY = mathCeil(pseudoY / 2)
semiPixelRawSet(index, color, jPercentTwoEqualsZero)
index = index + 1 if realY >= drawLimitY1 and realY <= drawLimitY2 then
evenY = pseudoY % 2 == 0
for pseudoX = x, x + width - 1 do
if pseudoX >= drawLimitX1 and pseudoX <= drawLimitX2 then
semiPixelRawSet(index, color, evenY)
end end
if jPercentTwoEqualsZero then index = index + 1
index = index + indexStepForward end
else else
index = index - indexStepBackward index = index + width
end
if evenY then
index = index + evenYIndexStep
else
index = index - oddYIndexStep
end end
end end
end end