Вот и второй алгоритм:
Куда быстрее предыдущего, но имеет только черно-белые цвета
-- ordered bayer dither --
local threshold_map = {
{0, 8, 2, 10},
{12, 4, 14, 6},
{3, 11, 1, 9},
{15, 7, 13, 5}
}
function Dither.ordered_bayer_dither(matrix, bool_matrix, width, height)
for y=1, height-1 do
for x=2, width-1 do
local grey = Dither.greyscale_pixel(colors.toRGB(matrix[y][x]))
grey = grey / Dither.MAX_COLOR -- Dither.MAX_COLOR is 255
if grey < threshold_map[(y%4)+1][(x%4)+1] * (1/16) then
matrix[y][x] = colors.black
bool_matrix[CEIL(y/3)][CEIL(x/2)] = true
else
matrix[y][x] = colors.white
bool_matrix[CEIL(y/3)][CEIL(x/2)] = true
end
end
end
return matrix, bool_matrix
end