forked from VoxeLibre/VoxeLibre
Move encoding format heuristics from image:save() to image:encode()
This commit is contained in:
parent
3029147ed7
commit
4dd3833f3b
16
examples.lua
16
examples.lua
|
@ -14,6 +14,22 @@ local pixels = {
|
||||||
}
|
}
|
||||||
tga_encoder.image(pixels):save("bitmap_small.tga")
|
tga_encoder.image(pixels):save("bitmap_small.tga")
|
||||||
|
|
||||||
|
-- test that image can be encoded
|
||||||
|
local bitmap_small_0 = tga_encoder.image(pixels)
|
||||||
|
bitmap_small_0:encode()
|
||||||
|
assert(191 == #bitmap_small_0.data)
|
||||||
|
|
||||||
|
-- test that imbage can be encoded with parameters
|
||||||
|
local bitmap_small_1 = tga_encoder.image(pixels)
|
||||||
|
bitmap_small_1:encode(
|
||||||
|
{
|
||||||
|
colormap = {},
|
||||||
|
color_format = "B8G8R8",
|
||||||
|
compression = "RAW",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
assert(191 == #bitmap_small_1.data)
|
||||||
|
|
||||||
-- change a single pixel, then rescale the bitmap
|
-- change a single pixel, then rescale the bitmap
|
||||||
local pixels_orig = pixels
|
local pixels_orig = pixels
|
||||||
pixels_orig[4][4] = { 255, 255, 255 }
|
pixels_orig[4][4] = { 255, 255, 255 }
|
||||||
|
|
18
init.lua
18
init.lua
|
@ -549,15 +549,6 @@ function image:encode_footer()
|
||||||
end
|
end
|
||||||
|
|
||||||
function image:encode(properties)
|
function image:encode(properties)
|
||||||
self.data = ""
|
|
||||||
self:encode_header(properties) -- header
|
|
||||||
-- no color map and image id data
|
|
||||||
self:encode_data(properties) -- encode data
|
|
||||||
-- no extension or developer area
|
|
||||||
self:encode_footer() -- footer
|
|
||||||
end
|
|
||||||
|
|
||||||
function image:save(filename, properties)
|
|
||||||
local properties = properties or {}
|
local properties = properties or {}
|
||||||
properties.colormap = properties.colormap or {}
|
properties.colormap = properties.colormap or {}
|
||||||
properties.compression = properties.compression or "RAW"
|
properties.compression = properties.compression or "RAW"
|
||||||
|
@ -584,6 +575,15 @@ function image:save(filename, properties)
|
||||||
end
|
end
|
||||||
assert( nil ~= properties.color_format )
|
assert( nil ~= properties.color_format )
|
||||||
|
|
||||||
|
self.data = ""
|
||||||
|
self:encode_header(properties) -- header
|
||||||
|
-- no color map and image id data
|
||||||
|
self:encode_data(properties) -- encode data
|
||||||
|
-- no extension or developer area
|
||||||
|
self:encode_footer() -- footer
|
||||||
|
end
|
||||||
|
|
||||||
|
function image:save(filename, properties)
|
||||||
self:encode(properties)
|
self:encode(properties)
|
||||||
|
|
||||||
local f = assert(io.open(filename, "wb"))
|
local f = assert(io.open(filename, "wb"))
|
||||||
|
|
Loading…
Reference in New Issue