🐛 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:
+14
-9
@@ -233,7 +233,7 @@ end;
|
|||||||
procedure TArt.RefreshBuffer;
|
procedure TArt.RefreshBuffer;
|
||||||
var
|
var
|
||||||
argbGraphic: TSingleImage;
|
argbGraphic: TSingleImage;
|
||||||
i, x, y, lineWidth, start: Integer;
|
i, y, lineWidth, start: Integer;
|
||||||
iCurrentHeight, iCurrentWidth: Integer;
|
iCurrentHeight, iCurrentWidth: Integer;
|
||||||
width, height: SmallInt;
|
width, height: SmallInt;
|
||||||
color, run, offset: Word;
|
color, run, offset: Word;
|
||||||
@@ -246,27 +246,32 @@ begin
|
|||||||
FBuffer.Size := 0;
|
FBuffer.Size := 0;
|
||||||
if FArtType = atLand then
|
if FArtType = atLand then
|
||||||
begin
|
begin
|
||||||
if (argbGraphic.Height <> 44) or (argbGraphic.Width <> 44) then Exit;
|
if (argbGraphic.Height <> 44) or (argbGraphic.Width <> 44) then
|
||||||
x := 21;
|
begin
|
||||||
|
argbGraphic.Free;
|
||||||
|
Exit;
|
||||||
|
end;
|
||||||
y := 0;
|
y := 0;
|
||||||
lineWidth := 2;
|
lineWidth := 2;
|
||||||
for i := 1 to 22 do
|
for i := 1 to 22 do
|
||||||
begin
|
begin
|
||||||
Dec(x);
|
FBuffer.Write(PWordArray(argbGraphic.Bits + y * 44 * 2)^[22 - i], lineWidth);
|
||||||
FBuffer.Write(PWordArray(argbGraphic.Bits + y * 44 * 2)^[x + i], lineWidth);
|
|
||||||
Inc(y);
|
Inc(y);
|
||||||
Inc(lineWidth, 2);
|
Inc(lineWidth, 2);
|
||||||
end;
|
end;
|
||||||
for i := 1 to 22 do
|
for i := 1 to 22 do
|
||||||
begin
|
begin
|
||||||
Dec(lineWidth, 2);
|
Dec(lineWidth, 2);
|
||||||
FBuffer.Write(PWordArray(argbGraphic.Bits + y * 44 * 2)^[x + i], lineWidth);
|
FBuffer.Write(PWordArray(argbGraphic.Bits + y * 44 * 2)^[i - 1], lineWidth);
|
||||||
Inc(x);
|
|
||||||
Inc(y);
|
Inc(y);
|
||||||
end;
|
end;
|
||||||
end else if FArtType = atStatic then
|
end else if FArtType = atStatic then
|
||||||
begin
|
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;
|
width := argbGraphic.Width;
|
||||||
height := argbGraphic.Height;
|
height := argbGraphic.Height;
|
||||||
FBuffer.Write(FHeader, SizeOf(LongInt));
|
FBuffer.Write(FHeader, SizeOf(LongInt));
|
||||||
@@ -283,7 +288,7 @@ begin
|
|||||||
run := 0;
|
run := 0;
|
||||||
for iCurrentWidth := 0 to width - 1 do //process every pixel on the current line
|
for iCurrentWidth := 0 to width - 1 do //process every pixel on the current line
|
||||||
begin
|
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
|
if (color and $8000 = 0) and (run = 0) then //new visible pixel found
|
||||||
begin
|
begin
|
||||||
FBuffer.Write(offset, SizeOf(Word));
|
FBuffer.Write(offset, SizeOf(Word));
|
||||||
|
|||||||
Reference in New Issue
Block a user