Code quality

master
Lars Mueller 2021-07-22 15:13:59 +02:00
parent 2006e596b7
commit e75bce938f
2 changed files with 13 additions and 10 deletions

11
default_media/plane.obj Normal file
View File

@ -0,0 +1,11 @@
# Unit square
v 0 0 0
v 0 1 0
v 1 1 0
v 1 0 0
vt 0 0
vt 0 1
vt 1 1
vt 1 0
f 1/1 2/2 3/3
f 3/3 4/4 1/1

View File

@ -66,16 +66,8 @@ function dither(texture, closest_color_finder, matrix)
for index, diff in ipairs(line) do
local nx, ny = x + index + line.x_off-1, y+ydif-1
if nx >= 0 and ny >= 0 and nx <= texture.width-1 and ny <= texture.height-1 then
if not rgba_number_to_table(get_texture_color_at(texture, x, y)) then error("AAAA") end
local target_color = vector.floor(
vector.clamp(
vector.add(
rgba_number_to_table(get_texture_color_at(texture, x, y)),
vector.multiply_scalar(error, diff)
),
0, 255
)
)
local tab = assert(rgba_number_to_table(get_texture_color_at(texture, x, y)))
local target_color = vector.floor(vector.clamp(vector.add(tab, vector.multiply_scalar(error, diff)), 0, 255))
set_texture_color_at(texture, x, y, rgba_table_to_number(target_color))
end
end