master #12

Merged
NO11 merged 149 commits from VoxeLibre/VoxeLibre:master into master 2021-11-12 22:46:33 +01:00
1 changed files with 16 additions and 3 deletions
Showing only changes of commit 23ca11c8e1 - Show all commits

View File

@ -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()