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.color_format = {
|
||||
"A1R5G5B5",
|
||||
"B8G8R8",
|
||||
"B8G8R8A8",
|
||||
"Y8",
|
||||
["A1R5G5B5"] = true,
|
||||
["B8G8R8"] = true,
|
||||
["B8G8R8A8"] = true,
|
||||
["Y8"] = true,
|
||||
}
|
||||
tga_encoder.features.colormap = {
|
||||
}
|
||||
tga_encoder.features.compression = {
|
||||
"RAW",
|
||||
"RLE",
|
||||
["RAW"] = true,
|
||||
["RLE"] = true,
|
||||
}
|
||||
tga_encoder.features.scanline_order = {
|
||||
"bottom-top",
|
||||
"top-bottom",
|
||||
["bottom-top"] = true,
|
||||
["top-bottom"] = true,
|
||||
}
|
||||
|
||||
local image = setmetatable({}, {
|
||||
|
|
|
@ -60,11 +60,11 @@ local colormap_by_color_format = {
|
|||
["B8G8R8A8"] = colormap_32bpp,
|
||||
}
|
||||
|
||||
for _, color_format in ipairs(
|
||||
for color_format, _ in pairs(
|
||||
tga_encoder.features.color_format
|
||||
) do
|
||||
if ("Y8" ~= color_format) then
|
||||
for _, scanline_order in ipairs(
|
||||
for scanline_order, _ in pairs(
|
||||
tga_encoder.features.scanline_order
|
||||
) do
|
||||
local filename
|
||||
|
@ -167,13 +167,13 @@ local pixels_by_scanline_order_by_color_format = {
|
|||
["Y8"] = pixels_rgb_by_scanline_order,
|
||||
}
|
||||
|
||||
for _, color_format in ipairs(
|
||||
for color_format, _ in pairs(
|
||||
tga_encoder.features.color_format
|
||||
) do
|
||||
local pixels_by_scanline_order = pixels_by_scanline_order_by_color_format[
|
||||
color_format
|
||||
]
|
||||
for _, compression in ipairs(
|
||||
for compression, _ in pairs(
|
||||
tga_encoder.features.compression
|
||||
) do
|
||||
local tga_type
|
||||
|
@ -192,7 +192,7 @@ for _, color_format in ipairs(
|
|||
"Y8" == color_format and
|
||||
"RLE" == compression
|
||||
) then
|
||||
for _, scanline_order in ipairs(
|
||||
for scanline_order, _ in pairs(
|
||||
tga_encoder.features.scanline_order
|
||||
) do
|
||||
local filename = "type" .. tga_type ..
|
||||
|
|
Loading…
Reference in New Issue