From c1967a8a41e7a84aa84666e1970c440c5f2c3cce Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Sat, 14 Nov 2026 22:45:01 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20art=20encoder=20writing=20?= =?UTF-8?q?corrupted=20images?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- UOLib/UArt.pas | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/UOLib/UArt.pas b/UOLib/UArt.pas index 3cffa41..5b7b3cd 100644 --- a/UOLib/UArt.pas +++ b/UOLib/UArt.pas @@ -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));