mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-16 16:11:06 +01:00
Use RLE compression in tga_encoder
This commit is contained in:
parent
b88579b52e
commit
52e5c955f0
1 changed files with 16 additions and 3 deletions
19
init.lua
19
init.lua
|
@ -38,18 +38,31 @@ function image:encode_header()
|
||||||
self.data = self.data
|
self.data = self.data
|
||||||
.. string.char(0) -- image id
|
.. string.char(0) -- image id
|
||||||
.. string.char(0) -- color map type
|
.. string.char(0) -- color map type
|
||||||
.. string.char(2) -- image type (uncompressed true-color image = 2)
|
.. string.char(10) -- image type (RLE RGB = 10)
|
||||||
self:encode_colormap_spec() -- color map specification
|
self:encode_colormap_spec() -- color map specification
|
||||||
self:encode_image_spec() -- image specification
|
self:encode_image_spec() -- image specification
|
||||||
end
|
end
|
||||||
|
|
||||||
function image:encode_data()
|
function image:encode_data()
|
||||||
|
local current_pixel = ''
|
||||||
|
local previous_pixel = ''
|
||||||
|
local count = 1
|
||||||
|
local encoded = ''
|
||||||
|
local rle_packet = ''
|
||||||
for _, row in ipairs(self.pixels) do
|
for _, row in ipairs(self.pixels) do
|
||||||
for _, pixel in ipairs(row) do
|
for _, pixel in ipairs(row) do
|
||||||
self.data = self.data
|
current_pixel = string.char(pixel[3], pixel[2], pixel[1])
|
||||||
.. string.char(pixel[3], pixel[2], pixel[1])
|
if current_pixel ~= previous_pixel or count == 128 then
|
||||||
|
encoded = encoded .. rle_packet
|
||||||
|
count = 1
|
||||||
|
previous_pixel = current_pixel
|
||||||
|
else
|
||||||
|
count = count + 1
|
||||||
|
end
|
||||||
|
rle_packet = string.char(128 + count - 1) .. current_pixel
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
self.data = self.data .. encoded .. rle_packet
|
||||||
end
|
end
|
||||||
|
|
||||||
function image:encode_footer()
|
function image:encode_footer()
|
||||||
|
|
Loading…
Reference in a new issue