🐛 Fix art encoder writing corrupted images

The static RLE encoder read 16-bit pixels from the 32-bit working
image with a 16-bit stride, garbling every pixel and testing a green
channel bit as the visibility flag. The land encoder shifted every
diamond row to a constant or double-stride column. Both matched the
decoder on load and produced scrambled art on save. Also frees the
conversion image on the early exit paths.
This commit is contained in:
2026-11-15 22:06:50 +01:00
parent c1f5215fb4
commit c1967a8a41
+14 -9
View File
@@ -233,7 +233,7 @@ end;
procedure TArt.RefreshBuffer;
var
argbGraphic: TSingleImage;
i, x, y, lineWidth, start: Integer;
i, y, lineWidth, start: Integer;
iCurrentHeight, iCurrentWidth: Integer;
width, height: SmallInt;
color, run, offset: Word;
@@ -246,27 +246,32 @@ begin
FBuffer.Size := 0;
if FArtType = atLand then
begin
if (argbGraphic.Height <> 44) or (argbGraphic.Width <> 44) then Exit;
x := 21;
if (argbGraphic.Height <> 44) or (argbGraphic.Width <> 44) then
begin
argbGraphic.Free;
Exit;
end;
y := 0;
lineWidth := 2;
for i := 1 to 22 do
begin
Dec(x);
FBuffer.Write(PWordArray(argbGraphic.Bits + y * 44 * 2)^[x + i], lineWidth);
FBuffer.Write(PWordArray(argbGraphic.Bits + y * 44 * 2)^[22 - i], lineWidth);
Inc(y);
Inc(lineWidth, 2);
end;
for i := 1 to 22 do
begin
Dec(lineWidth, 2);
FBuffer.Write(PWordArray(argbGraphic.Bits + y * 44 * 2)^[x + i], lineWidth);
Inc(x);
FBuffer.Write(PWordArray(argbGraphic.Bits + y * 44 * 2)^[i - 1], lineWidth);
Inc(y);
end;
end else if FArtType = atStatic then
begin
if (argbGraphic.Height = 0) or (argbGraphic.Width = 0) then Exit;
if (argbGraphic.Height = 0) or (argbGraphic.Width = 0) then
begin
argbGraphic.Free;
Exit;
end;
width := argbGraphic.Width;
height := argbGraphic.Height;
FBuffer.Write(FHeader, SizeOf(LongInt));
@@ -283,7 +288,7 @@ begin
run := 0;
for iCurrentWidth := 0 to width - 1 do //process every pixel on the current line
begin
color := PWordArray(FGraphic.Bits + iCurrentHeight * width * 2)^[iCurrentWidth];
color := PWordArray(argbGraphic.Bits + iCurrentHeight * width * 2)^[iCurrentWidth];
if (color and $8000 = 0) and (run = 0) then //new visible pixel found
begin
FBuffer.Write(offset, SizeOf(Word));