Fix waterfall BGRA color pipeline

This commit is contained in:
2026-04-22 22:27:06 +03:00
parent 77d380acfd
commit 4c48f22447
+85 -10
View File
@@ -646,7 +646,86 @@ begin
R := Round(((C0 shr 16) and $FF) * (1.0 - T) + ((C1 shr 16) and $FF) * T);
G := Round(((C0 shr 8) and $FF) * (1.0 - T) + ((C1 shr 8) and $FF) * T);
B := Round((C0 and $FF) * (1.0 - T) + (C1 and $FF) * T);
Result := (R shl 16) or (G shl 8) or B;
// Для сырого буфера водопада нужен BGRA32 в памяти:
// LongWord = $AARRGGBB, в little-endian байты идут как B,G,R,A.
Result := ($FF shl 24) or (R shl 16) or (G shl 8) or B;
end;
function WaterfallEnhancedColorThetis(ValueDB, LowDB, HighDB: Double): LongWord;
var
Overall, Local: Double;
R, G, B: Integer;
begin
if ValueDB <= LowDB then
begin
Result := $FF000000;
Exit;
end;
if ValueDB >= HighDB then
begin
Result := ($FF shl 24) or (255 shl 16) or (124 shl 8) or 192;
Exit;
end;
Overall := (ValueDB - LowDB) / Max(1E-9, HighDB - LowDB);
if Overall < (2.0 / 9.0) then
begin
Local := Overall / (2.0 / 9.0);
R := 0;
G := 0;
B := Round(Local * 255.0);
end
else if Overall < (3.0 / 9.0) then
begin
Local := (Overall - (2.0 / 9.0)) / (1.0 / 9.0);
R := 0;
G := Round(Local * 255.0);
B := 255;
end
else if Overall < (4.0 / 9.0) then
begin
Local := (Overall - (3.0 / 9.0)) / (1.0 / 9.0);
R := 0;
G := 255;
B := Round((1.0 - Local) * 255.0);
end
else if Overall < (5.0 / 9.0) then
begin
Local := (Overall - (4.0 / 9.0)) / (1.0 / 9.0);
R := Round(Local * 255.0);
G := 255;
B := 0;
end
else if Overall < (7.0 / 9.0) then
begin
Local := (Overall - (5.0 / 9.0)) / (2.0 / 9.0);
R := 255;
G := Round((1.0 - Local) * 255.0);
B := 0;
end
else if Overall < (8.0 / 9.0) then
begin
Local := (Overall - (7.0 / 9.0)) / (1.0 / 9.0);
R := 255;
G := 0;
B := Round(Local * 255.0);
end
else
begin
Local := (Overall - (8.0 / 9.0)) / (1.0 / 9.0);
R := Round((0.75 + 0.25 * (1.0 - Local)) * 255.0);
G := Round(Local * 255.0 * 0.5);
B := 255;
end;
R := EnsureRange(R, 0, 255);
G := EnsureRange(G, 0, 255);
B := EnsureRange(B, 0, 255);
// Для сырого буфера водопада нужен BGRA32 в памяти:
// LongWord = $AARRGGBB, в little-endian байты идут как B,G,R,A.
Result := ($FF shl 24) or (R shl 16) or (G shl 8) or B;
end;
constructor TWisdomBuildThread.Create(const ADirectory: string);
@@ -2695,13 +2774,9 @@ begin
V := Trunc((dB - WfLow) * InvRange);
if V < 0 then V := 0;
if V > 255 then V := 255;
// WFALL_PALETTE задана в RGB-логике, а в буфере нужен BGRA.
// Поэтому меняем R/B местами и добавляем alpha=255.
Pal := WFALL_PALETTE[V];
Px^ := ((Pal and $000000FF) shl 16) or
(Pal and $0000FF00) or
((Pal and $00FF0000) shr 16) or
$FF000000;
// Thetis default waterfall uses its enhanced color scheme, not a flat lookup table.
Pal := WaterfallEnhancedColorThetis(dB, WfLow, WfHigh);
Px^ := Pal;
Inc(Px);
WatSrcF := WatSrcF + Step;
end;
@@ -2729,9 +2804,9 @@ begin
if RowPtr = nil then begin Inc(Src, W); Continue; end;
for Col := 0 to W - 1 do
begin
RowPtr[0] := Byte(Src^ shr 16); // B
RowPtr[0] := Byte(Src^); // B
RowPtr[1] := Byte(Src^ shr 8); // G
RowPtr[2] := Byte(Src^); // R
RowPtr[2] := Byte(Src^ shr 16); // R
if BPPi >= 4 then RowPtr[3] := $FF;
Inc(Src); Inc(RowPtr, BPPi);
end;