MineClone2/mods/CORE/tga_encoder/colormap_generator.lua
the-real-herowl b04493dcb6 Add 'mods/CORE/tga_encoder/' from commit 'aad231f5e406a7c1eaafe6595a64b9c55f230692'
git-subtree-dir: mods/CORE/tga_encoder
git-subtree-mainline: a5740f8edf894395605ce936272452cb84f1cd7f
git-subtree-split: aad231f5e406a7c1eaafe6595a64b9c55f230692
2024-03-19 19:28:16 +01:00

33 lines
1.0 KiB
Lua

dofile("init.lua")
-- This generates images necessary to colorize 16 Minetest nodes in 4096 colors.
-- It serves as a demonstration of what you can achieve using colormapped nodes.
-- It is be useful for grass or beam or glass nodes that need to blend smoothly.
-- Sample depth rescaling is done according to the algorithm presented in:
-- <https://www.w3.org/TR/2003/REC-PNG-20031110/#13Sample-depth-rescaling>
local max_sample_in = math.pow(2, 4) - 1
local max_sample_out = math.pow(2, 8) - 1
for r = 0,15 do
local pixels = {}
for g = 0,15 do
if nil == pixels[g + 1] then
pixels[g + 1] = {}
end
for b = 0,15 do
local color = {
math.floor((r * max_sample_out / max_sample_in) + 0.5),
math.floor((g * max_sample_out / max_sample_in) + 0.5),
math.floor((b * max_sample_out / max_sample_in) + 0.5),
}
pixels[g + 1][b + 1] = color
end
end
local filename = "colormap_" .. tostring(r) .. ".tga"
tga_encoder.image(pixels):save(
filename,
{ color_format="A1R5G5B5" } -- waste less bits
)
end