Generate TGA type 3 test textures from RGB input

This commit is contained in:
Nils Dagsson Moskopp 2023-10-20 01:00:47 +02:00
parent c0cc855a02
commit e329052c7f
Signed by: erle
GPG Key ID: A3BC671C35191080
1 changed files with 42 additions and 68 deletions

View File

@ -33,38 +33,6 @@ local pixels_colormapped_by_scanline_order = {
["top-bottom"] = pixels_colormapped_tb,
}
local _ = { 0 }
local R = { 127 }
local G = { 255 }
local B = { 191 }
local pixels_grayscale_bt = {
{ _, _, _, _, _, B, _, B, },
{ _, _, _, _, _, B, B, B, },
{ _, _, G, G, G, B, _, B, },
{ _, _, G, _, G, B, B, B, },
{ _, R, G, _, _, _, _, _, },
{ _, R, G, G, G, _, _, _, },
{ _, R, _, _, _, _, _, _, },
{ R, R, R, _, _, _, _, _, },
}
local pixels_grayscale_tb = {
{ R, R, R, _, _, _, _, _, },
{ _, R, _, _, _, _, _, _, },
{ _, R, G, G, G, _, _, _, },
{ _, R, G, _, _, _, _, _, },
{ _, _, G, _, G, B, B, B, },
{ _, _, G, G, G, B, _, B, },
{ _, _, _, _, _, B, B, B, },
{ _, _, _, _, _, B, _, B, },
}
local pixels_grayscale_by_scanline_order = {
["bottom-top"] = pixels_grayscale_bt,
["top-bottom"] = pixels_grayscale_tb,
}
local colormap_32bpp = {
{ 0, 0, 0, 127 },
{ 255, 0, 0, 255 },
@ -95,20 +63,12 @@ local colormap_by_color_format = {
for _, color_format in ipairs(
tga_encoder.features.color_format
) do
for _, scanline_order in ipairs(
tga_encoder.features.scanline_order
) do
local filename
local pixels
if ("Y8" == color_format) then
filename = "type3" ..
'_' .. color_format ..
'_' .. scanline_order ..
'.tga'
pixels = pixels_grayscale_by_scanline_order[
scanline_order
]
else
if ("Y8" ~= color_format) then
for _, scanline_order in ipairs(
tga_encoder.features.scanline_order
) do
local filename
local pixels
filename = "type1" ..
'_' .. color_format ..
'_' .. scanline_order ..
@ -116,18 +76,18 @@ for _, color_format in ipairs(
pixels = pixels_colormapped_by_scanline_order[
scanline_order
]
local colormap = colormap_by_color_format[
color_format
]
local properties = {
colormap = colormap,
color_format = color_format,
scanline_order = scanline_order,
}
print(filename)
local image = tga_encoder.image(pixels)
image:save(filename, properties)
end
local colormap = colormap_by_color_format[
color_format
]
local properties = {
colormap = colormap,
color_format = color_format,
scanline_order = scanline_order,
}
print(filename)
local image = tga_encoder.image(pixels)
image:save(filename, properties)
end
end
@ -204,28 +164,42 @@ local pixels_by_scanline_order_by_color_format = {
["A1R5G5B5"] = pixels_rgba_by_scanline_order,
["B8G8R8"] = pixels_rgb_by_scanline_order,
["B8G8R8A8"] = pixels_rgba_by_scanline_order,
["Y8"] = pixels_rgb_by_scanline_order,
}
for _, color_format in ipairs(
tga_encoder.features.color_format
) do
local pixels_by_scanline_order = pixels_by_scanline_order_by_color_format[
color_format
]
for _, compression in ipairs(
tga_encoder.features.compression
) do
for _, scanline_order in ipairs(
tga_encoder.features.scanline_order
) do
if ("Y8" ~= color_format) then
local tga_type = tga_type_by_compression[
compression
]
local filename = "type" .. tga_type ..
local tga_type
if (
"Y8" == color_format and
"RAW" == compression
) then
tga_type = "3"
else
tga_type = tga_type_by_compression[
compression
]
end
-- tga_encoder can not encode grayscale RLE (type 11)
if not(
"Y8" == color_format and
"RLE" == compression
) then
for _, scanline_order in ipairs(
tga_encoder.features.scanline_order
) do
local filename = "type" .. tga_type ..
'_' .. color_format ..
'_' .. scanline_order ..
'.tga'
local pixels = pixels_by_scanline_order_by_color_format[
color_format
][
local pixels = pixels_by_scanline_order[
scanline_order
]
local properties = {