forked from VoxeLibre/VoxeLibre
Do not encode images with illegal colormap indexes
This commit is contained in:
parent
4dd3833f3b
commit
bb68ceb38d
15
examples.lua
15
examples.lua
|
@ -164,3 +164,18 @@ local pixels = {
|
|||
{ _, _, _, K, _, _, _ },
|
||||
}
|
||||
tga_encoder.image(pixels):save("colormapped_B8G8R8A8.tga", {colormap=colormap})
|
||||
|
||||
-- encoding a colormapped image with illegal colormap indexes should error out
|
||||
local colormap = {
|
||||
{ 0, 0, 0, 0 },
|
||||
{ 0, 0, 0, 255 },
|
||||
}
|
||||
local status, message = pcall(
|
||||
function ()
|
||||
tga_encoder.image(pixels):encode({colormap=colormap})
|
||||
end
|
||||
)
|
||||
assert(
|
||||
false == status and
|
||||
"init.lua:36: colormap index 2 not in colormap of size 2" == message
|
||||
)
|
||||
|
|
12
init.lua
12
init.lua
|
@ -28,6 +28,18 @@ function image:encode_colormap_spec(properties)
|
|||
colormap_pixel_depth = pixel_depth_by_color_format[
|
||||
properties.color_format
|
||||
]
|
||||
-- ensure that each pixel references a legal colormap entry
|
||||
for _, row in ipairs(self.pixels) do
|
||||
for _, pixel in ipairs(row) do
|
||||
local colormap_index = pixel[1]
|
||||
if colormap_index >= #colormap then
|
||||
error(
|
||||
"colormap index " .. colormap_index ..
|
||||
" not in colormap of size " .. #colormap
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
local colormap_spec =
|
||||
string.char(0, 0) .. -- first entry index
|
||||
|
|
Loading…
Reference in New Issue