FS#13718 - The image_save library (rocklua) can't correctly save an image with an odd resolution.

the image save script apparently does not like odd numbers for width

local bytesleft = linebytes - (bytesperpixel * w )

this should actually be pxleft since the image loop below returns pixels not bytes

tested on 1 bit 2 bit, 16 bit and 32 bit images in sim

Change-Id: Ic186c095c29d318dcfb7d76b83e07c75f1460584
This commit is contained in:
William Wilgus 2026-01-20 22:49:24 -05:00 committed by Solomon Peachy
parent 86f35f1b53
commit 530cad0c7a

View file

@ -188,8 +188,9 @@ do
for i=1, #fbuffer do fbuffer[i] = _NIL end -- reuse table
local imgdata = fbuffer
-- pad rows to a multiple of 4 bytes
local bytesleft = linebytes - (bytesperpixel * w)
-- pad rows to get even number of pixels
local pxleft = (linebytes - (bytesperpixel * w)) / bytesperpixel
local t_data = {}
local fs_bytes_E = s_bytesLE -- default save in Little Endian
@ -198,7 +199,7 @@ do
end
-- Bitmap lines start at bottom unless biHeight is negative
for point in _points(img, 1, h, w + bytesleft, 1, 1, 1, true) do
for point in _points(img, 1, h, w + pxleft, 1, 1, 1, true) do
imgdata[#imgdata + 1] = fs_bytes_E(bpp, point or 0)
if #fbuffer >= 31 then -- buffered write, increase # for performance