Merge branch 'NoPreMultiplyBitmapTypes' into 'main'

Cocoa: Add new TCocoaBitmapTypes for non-premultiplied images

See merge request freepascal.org/lazarus/lazarus!358
This commit is contained in:
David Jenkins 2025-04-04 14:36:15 +00:00
commit ee2ad2ce49
2 changed files with 13 additions and 5 deletions

View File

@ -33,7 +33,9 @@ type
cbtARGB, // color bitmap with alpha channel first 8-8-8-8 A-R-G-B
cbtRGBA, // color bitmap with alpha channel last 8-8-8-8 R-G-B-A
cbtABGR, // color bitmap with alpha channel first 8-8-8-8 A-B-G-R
cbtBGRA // color bitmap with alpha channel last 8-8-8-8 B-G-R-A
cbtBGRA, // color bitmap with alpha channel last 8-8-8-8 B-G-R-A
cbtARGBN, // color bitmap with alpha channel first 8-8-8-8 A-R-G-B No premultiplication
cbtRGBAN // color bitmap with alpha channel last 8-8-8-8 R-G-B-A No premultiplication
);
const
@ -304,6 +306,7 @@ type
property Depth: Byte read FDepth;
property Width: Integer read FWidth;
property Height: Integer read FHeight;
property Alignment: TCocoaBitmapAlignment read FAlignment;
end;
// device context data for SaveDC/RestoreDC
@ -1188,9 +1191,14 @@ var
i: Integer;
lAlpha, lRed, lGreen, lBlue: Byte;
begin
if not (FType in [cbtARGB, cbtRGBA]) then Exit;
if not (FType in [cbtARGB, cbtRGBA, cbtARGBN, cbtRGBAN]) then Exit;
if FData = nil then Exit;
if FType = cbtARGBN then
FType := cbtARGB;
if FType = cbtRGBAN then
FType := cbtRGBA;
// Keep the original data in a copy, otherwise we cant get access to it
// because pre-multiplying destroys the original value if we had alpha=0
if FOriginalData <> nil then

View File

@ -836,7 +836,7 @@ begin
end;
// alpha
if ABitmap.BitmapType in [cbtARGB, cbtRGBA] then
if ABitmap.BitmapType in [cbtARGB, cbtARGBN, cbtRGBA, cbtRGBAN] then
ADesc.AlphaPrec := Prec;
case ABitmap.BitmapType of
@ -848,7 +848,7 @@ begin
Dec(Shift, Prec);
ADesc.BlueShift := Shift;
end;
cbtARGB: begin
cbtARGB, cbtARGBN: begin
Shift := 32 - Prec;
ADesc.AlphaShift := Shift;
Dec(Shift, Prec);
@ -858,7 +858,7 @@ begin
Dec(Shift, Prec);
ADesc.BlueShift := Shift;
end;
cbtRGBA: begin
cbtRGBA, cbtRGBAN: begin
Shift := 32 - Prec;
ADesc.RedShift := Shift;
Dec(Shift, Prec);