Use keys with truthy values in features table
If the features table uses keys with truthy values, it is easy to check for the presence of some feature by checking if the corresponding table entry (e.g. “tga_encoder.features.color_format.A1R5G5B5”) is truthy.
This commit is contained in:
parent
e329052c7f
commit
e599c9fe83
16
init.lua
16
init.lua
|
@ -2,20 +2,20 @@ tga_encoder = {}
|
||||||
|
|
||||||
tga_encoder.features = {}
|
tga_encoder.features = {}
|
||||||
tga_encoder.features.color_format = {
|
tga_encoder.features.color_format = {
|
||||||
"A1R5G5B5",
|
["A1R5G5B5"] = true,
|
||||||
"B8G8R8",
|
["B8G8R8"] = true,
|
||||||
"B8G8R8A8",
|
["B8G8R8A8"] = true,
|
||||||
"Y8",
|
["Y8"] = true,
|
||||||
}
|
}
|
||||||
tga_encoder.features.colormap = {
|
tga_encoder.features.colormap = {
|
||||||
}
|
}
|
||||||
tga_encoder.features.compression = {
|
tga_encoder.features.compression = {
|
||||||
"RAW",
|
["RAW"] = true,
|
||||||
"RLE",
|
["RLE"] = true,
|
||||||
}
|
}
|
||||||
tga_encoder.features.scanline_order = {
|
tga_encoder.features.scanline_order = {
|
||||||
"bottom-top",
|
["bottom-top"] = true,
|
||||||
"top-bottom",
|
["top-bottom"] = true,
|
||||||
}
|
}
|
||||||
|
|
||||||
local image = setmetatable({}, {
|
local image = setmetatable({}, {
|
||||||
|
|
|
@ -60,11 +60,11 @@ local colormap_by_color_format = {
|
||||||
["B8G8R8A8"] = colormap_32bpp,
|
["B8G8R8A8"] = colormap_32bpp,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, color_format in ipairs(
|
for color_format, _ in pairs(
|
||||||
tga_encoder.features.color_format
|
tga_encoder.features.color_format
|
||||||
) do
|
) do
|
||||||
if ("Y8" ~= color_format) then
|
if ("Y8" ~= color_format) then
|
||||||
for _, scanline_order in ipairs(
|
for scanline_order, _ in pairs(
|
||||||
tga_encoder.features.scanline_order
|
tga_encoder.features.scanline_order
|
||||||
) do
|
) do
|
||||||
local filename
|
local filename
|
||||||
|
@ -167,13 +167,13 @@ local pixels_by_scanline_order_by_color_format = {
|
||||||
["Y8"] = pixels_rgb_by_scanline_order,
|
["Y8"] = pixels_rgb_by_scanline_order,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, color_format in ipairs(
|
for color_format, _ in pairs(
|
||||||
tga_encoder.features.color_format
|
tga_encoder.features.color_format
|
||||||
) do
|
) do
|
||||||
local pixels_by_scanline_order = pixels_by_scanline_order_by_color_format[
|
local pixels_by_scanline_order = pixels_by_scanline_order_by_color_format[
|
||||||
color_format
|
color_format
|
||||||
]
|
]
|
||||||
for _, compression in ipairs(
|
for compression, _ in pairs(
|
||||||
tga_encoder.features.compression
|
tga_encoder.features.compression
|
||||||
) do
|
) do
|
||||||
local tga_type
|
local tga_type
|
||||||
|
@ -192,7 +192,7 @@ for _, color_format in ipairs(
|
||||||
"Y8" == color_format and
|
"Y8" == color_format and
|
||||||
"RLE" == compression
|
"RLE" == compression
|
||||||
) then
|
) then
|
||||||
for _, scanline_order in ipairs(
|
for scanline_order, _ in pairs(
|
||||||
tga_encoder.features.scanline_order
|
tga_encoder.features.scanline_order
|
||||||
) do
|
) do
|
||||||
local filename = "type" .. tga_type ..
|
local filename = "type" .. tga_type ..
|
||||||
|
|
Loading…
Reference in New Issue