Compare commits

...

2 Commits

Author SHA1 Message Date
Nils Dagsson Moskopp 50466ca08b
Encode alpha channel for colormapped A1R5G5B5 images 2024-03-19 11:55:15 +01:00
Nils Dagsson Moskopp 9497a0303c
Add 2×2 white square to bottom left corner of test textures
As the alpha channel of the color is above 127, the square should
show as opaque white in TGA images with the color format A1R5G5B5.
2024-03-19 11:49:08 +01:00
2 changed files with 20 additions and 13 deletions

View File

@ -135,7 +135,8 @@ function image:encode_colormap(properties)
local max_sample_out = math.pow(2, 5) - 1
for i = 1,#colormap,1 do
local color = colormap[i]
local colorword = 32768 +
local colorword = 0 +
((math.floor((color[4] / max_sample_in) + 0.5)) * 32768) + -- transparent if alpha < 128
((math.floor((color[1] * max_sample_out / max_sample_in) + 0.5)) * 1024) +
((math.floor((color[2] * max_sample_out / max_sample_in) + 0.5)) * 32) +
((math.floor((color[3] * max_sample_out / max_sample_in) + 0.5)) * 1)

View File

@ -5,10 +5,11 @@ local _ = { 0 }
local R = { 1 }
local G = { 2 }
local B = { 3 }
local W = { 4 }
local pixels_colormapped_bt = {
{ _, _, _, _, _, B, _, B, },
{ _, _, _, _, _, B, B, B, },
{ W, W, _, _, _, B, _, B, },
{ W, W, _, _, _, B, B, B, },
{ _, _, G, G, G, B, _, B, },
{ _, _, G, _, G, B, B, B, },
{ _, R, G, _, _, _, _, _, },
@ -24,8 +25,8 @@ local pixels_colormapped_tb = {
{ _, R, G, _, _, _, _, _, },
{ _, _, G, _, G, B, B, B, },
{ _, _, G, G, G, B, _, B, },
{ _, _, _, _, _, B, B, B, },
{ _, _, _, _, _, B, _, B, },
{ W, W, _, _, _, B, B, B, },
{ W, W, _, _, _, B, _, B, },
}
local pixels_colormapped_by_scanline_order = {
@ -38,6 +39,7 @@ local colormap_32bpp = {
{ 255, 0, 0, 255 },
{ 0, 255, 0, 255 },
{ 0, 0, 255, 255 },
{ 255, 255, 255, 128 },
}
local colormap_24bpp = {
@ -45,6 +47,7 @@ local colormap_24bpp = {
{ 255, 0, 0 },
{ 0, 255, 0 },
{ 0, 0, 255 },
{ 255, 255, 255 },
}
local colormap_16bpp = {
@ -52,6 +55,7 @@ local colormap_16bpp = {
{ 255, 0, 0, 255 },
{ 0, 255, 0, 255 },
{ 0, 0, 255, 255 },
{ 255, 255, 255, 255 },
}
local colormap_by_color_format = {
@ -95,10 +99,11 @@ local _ = { 0, 0, 0, 127 }
local R = { 255, 0, 0, 255 }
local G = { 0, 255, 0, 255 }
local B = { 0, 0, 255, 255 }
local W = { 255, 255, 255, 128 }
local pixels_rgba_bt = {
{ _, _, _, _, _, B, _, B, },
{ _, _, _, _, _, B, B, B, },
{ W, W, _, _, _, B, _, B, },
{ W, W, _, _, _, B, B, B, },
{ _, _, G, G, G, B, _, B, },
{ _, _, G, _, G, B, B, B, },
{ _, R, G, _, _, _, _, _, },
@ -114,8 +119,8 @@ local pixels_rgba_tb = {
{ _, R, G, _, _, _, _, _, },
{ _, _, G, _, G, B, B, B, },
{ _, _, G, G, G, B, _, B, },
{ _, _, _, _, _, B, B, B, },
{ _, _, _, _, _, B, _, B, },
{ W, W, _, _, _, B, B, B, },
{ W, W, _, _, _, B, _, B, },
}
local pixels_rgba_by_scanline_order = {
@ -127,10 +132,11 @@ local _ = { 0, 0, 0 }
local R = { 255, 0, 0 }
local G = { 0, 255, 0 }
local B = { 0, 0, 255 }
local W = { 255, 255, 255 }
local pixels_rgb_bt = {
{ _, _, _, _, _, B, _, B, },
{ _, _, _, _, _, B, B, B, },
{ W, W, _, _, _, B, _, B, },
{ W, W, _, _, _, B, B, B, },
{ _, _, G, G, G, B, _, B, },
{ _, _, G, _, G, B, B, B, },
{ _, R, G, _, _, _, _, _, },
@ -146,8 +152,8 @@ local pixels_rgb_tb = {
{ _, R, G, _, _, _, _, _, },
{ _, _, G, _, G, B, B, B, },
{ _, _, G, G, G, B, _, B, },
{ _, _, _, _, _, B, B, B, },
{ _, _, _, _, _, B, _, B, },
{ W, W, _, _, _, B, B, B, },
{ W, W, _, _, _, B, _, B, },
}
local pixels_rgb_by_scanline_order = {