Fix macOS pixel format: use ARGB byte order in all raw ScanLine blending

On macOS Cocoa, TBitmap.pf32bit stores pixels in ARGB order
   (byte0=A, byte1=R, byte2=G, byte3=B) rather than BGRA used on
   Linux/Windows. All raw ScanLine pixel blending and channel mapping
   is now guarded with { DARWIN} to use the correct offsets.

   Also fix PortAudio library discovery on macOS: probe .dylib names
   (including Homebrew paths) before falling through to .so/.dll.
This commit is contained in:
Uladzimir Karpenka
2026-05-28 21:47:54 +03:00
parent 4f127a30ad
commit a02d35fcce
8 changed files with 132 additions and 24 deletions
+40 -13
View File
@@ -472,12 +472,17 @@ begin
Inc(Row, RR.Left * 4);
for X := RR.Left to RR.Right - 1 do
begin
BB := Row[0];
BG := Row[1];
BR := Row[2];
{$IFDEF DARWIN}
BB := Row[3]; BG := Row[2]; BR := Row[1];
Row[1] := Byte((SR * Alpha + BR * (255 - Alpha)) div 255);
Row[2] := Byte((SG * Alpha + BG * (255 - Alpha)) div 255);
Row[3] := Byte((SB * Alpha + BB * (255 - Alpha)) div 255);
{$ELSE}
BB := Row[0]; BG := Row[1]; BR := Row[2];
Row[0] := Byte((SB * Alpha + BB * (255 - Alpha)) div 255);
Row[1] := Byte((SG * Alpha + BG * (255 - Alpha)) div 255);
Row[2] := Byte((SR * Alpha + BR * (255 - Alpha)) div 255);
{$ENDIF}
Inc(Row, 4);
end;
end;
@@ -574,9 +579,15 @@ begin
if SpPts[Col].Y <= Row then
begin
Off := Col * 4;
RowPtr[Off] := (GradB * Alpha + RowPtr[Off] * (200 - Alpha)) div 200;
RowPtr[Off + 1] := (GradG * Alpha + RowPtr[Off + 1] * (200 - Alpha)) div 200;
RowPtr[Off + 2] := (GradR * Alpha + RowPtr[Off + 2] * (200 - Alpha)) div 200;
{$IFDEF DARWIN}
RowPtr[Off+1] := (GradR * Alpha + RowPtr[Off+1] * (200 - Alpha)) div 200;
RowPtr[Off+2] := (GradG * Alpha + RowPtr[Off+2] * (200 - Alpha)) div 200;
RowPtr[Off+3] := (GradB * Alpha + RowPtr[Off+3] * (200 - Alpha)) div 200;
{$ELSE}
RowPtr[Off] := (GradB * Alpha + RowPtr[Off] * (200 - Alpha)) div 200;
RowPtr[Off+1] := (GradG * Alpha + RowPtr[Off+1] * (200 - Alpha)) div 200;
RowPtr[Off+2] := (GradR * Alpha + RowPtr[Off+2] * (200 - Alpha)) div 200;
{$ENDIF}
end;
end;
finally
@@ -984,21 +995,37 @@ begin
Src := PByte(FLabelBitmap.ScanLine[Y]);
for X := 0 to FLabelBitmap.Width - 1 do
begin
A := Max(Src[0], Max(Src[1], Src[2]));
{$IFDEF DARWIN}
// ARGB: byte0=A, byte1=R, byte2=G, byte3=B
A := Max(Src[1], Max(Src[2], Src[3]));
if A < 6 then A := 0;
if A > 0 then
begin
Buf[I] := Byte(Min(255, Src[2] * 255 div A));
Buf[I + 1] := Byte(Min(255, Src[1] * 255 div A));
Buf[I + 2] := Byte(Min(255, Src[0] * 255 div A));
Buf[I] := Byte(Min(255, Src[1] * 255 div A)); // R
Buf[I + 1] := Byte(Min(255, Src[2] * 255 div A)); // G
Buf[I + 2] := Byte(Min(255, Src[3] * 255 div A)); // B
A := Byte(Min(255, A + (255 - A) div 3));
end
else
begin
Buf[I] := 0;
Buf[I + 1] := 0;
Buf[I + 2] := 0;
Buf[I] := 0; Buf[I + 1] := 0; Buf[I + 2] := 0;
end;
{$ELSE}
// BGRA: byte0=B, byte1=G, byte2=R
A := Max(Src[0], Max(Src[1], Src[2]));
if A < 6 then A := 0;
if A > 0 then
begin
Buf[I] := Byte(Min(255, Src[2] * 255 div A)); // R
Buf[I + 1] := Byte(Min(255, Src[1] * 255 div A)); // G
Buf[I + 2] := Byte(Min(255, Src[0] * 255 div A)); // B
A := Byte(Min(255, A + (255 - A) div 3));
end
else
begin
Buf[I] := 0; Buf[I + 1] := 0; Buf[I + 2] := 0;
end;
{$ENDIF}
Buf[I + 3] := A;
Inc(Src, 4);
Inc(I, 4);