here is my problem:
Imagine a real life image with high resolution. In my game I will pixelate that image and then create pixels that the user can draw on (coloring pixels clone). The problem is the color palette. There are 1000s of colors in a single image. I need to decrease that to K colors.
In javascript i did that before with a library but I can't find any in love / lua.
So I tried myself for days now with the k-means algorithm, but it just doesn't work.
Now I want to ask, has anbody here worked with color quant before or do you know of any library that does that?
Important: I don't mean shaders. I need to apply the recoloring to the actual image data. I get this data already in this form:
Code: Select all
local function generatePixelsFromImage(imageData, pixelSize, totalColors)
local pixels = {}
local pixelSize = pixelSize or 10
local totalColors = totalColors or 10
local w = math.floor(imageData:getWidth() / pixelSize)
local h = math.floor(imageData:getHeight() / pixelSize)
for y = 0, h - 1 do
for x = 0, w - 1 do
local r, g, b = imageData:getPixel(x * pixelSize, y * pixelSize)
table.insert(pixels, pixel(x, y, color(r, g, b)))
end
end
return pixels
end