mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-07 01:06:02 +02:00
cocoa: properly fill RawImage description from cocoa bitmap object, properly initialize bitmap format and HasAlpha field
git-svn-id: trunk@33602 -
This commit is contained in:
parent
a69ef5286b
commit
8972794e3b
@ -127,9 +127,10 @@ type
|
||||
procedure SetInfo(AWidth, AHeight, ADepth, ABitsPerPixel: Integer;
|
||||
AAlignment: TCocoaBitmapAlignment; AType: TCocoaBitmapType);
|
||||
public
|
||||
// property BitsPerComponent: Integer read GetBitsPerComponent;
|
||||
property BitmapType: TCocoaBitmapType read FType;
|
||||
// property BytesPerRow: Integer read FBytesPerRow;
|
||||
property BitsPerPixel: Byte read FBitsPerPixel;
|
||||
property BitsPerSample: NSInteger read FBitsPerSample;
|
||||
property BytesPerRow: Integer read FBytesPerRow;
|
||||
// property CGImage: CGImageRef read FCGImage write SetCGImage;
|
||||
property ColorSpace: NSString read GetColorSpace;
|
||||
property Data: Pointer read FData;
|
||||
@ -271,6 +272,9 @@ type
|
||||
constructor TCocoaBitmap.Create(AWidth, AHeight, ADepth, ABitsPerPixel: Integer;
|
||||
AAlignment: TCocoaBitmapAlignment; AType: TCocoaBitmapType;
|
||||
AData: Pointer; ACopyData: Boolean);
|
||||
var
|
||||
HasAlpha: Boolean;
|
||||
BitmapFormat: NSBitmapFormat;
|
||||
begin
|
||||
SetInfo(AWidth, AHeight, ADepth, ABitsPerPixel, AAlignment, AType);
|
||||
|
||||
@ -290,6 +294,11 @@ begin
|
||||
FFreeData := False;
|
||||
end;
|
||||
|
||||
HasAlpha := AType in [cbtARGB, cbtRGBA, cbtBGRA];
|
||||
BitmapFormat := NSAlphaNonpremultipliedBitmapFormat;
|
||||
if AType = cbtARGB then
|
||||
BitmapFormat := BitmapFormat or NSAlphaFirstBitmapFormat;
|
||||
|
||||
// Create the associated NSImageRep
|
||||
imagerep := NSBitmapImageRep(NSBitmapImageRep.alloc.initWithBitmapDataPlanes_pixelsWide_pixelsHigh__colorSpaceName_bitmapFormat_bytesPerRow_bitsPerPixel(
|
||||
@FData, // planes, BitmapDataPlanes
|
||||
@ -297,10 +306,10 @@ begin
|
||||
FHeight,// height, PixelsHigh
|
||||
FbitsPerSample,// bitsPerSample, bps
|
||||
FsamplesPerPixel, // samplesPerPixel, sps
|
||||
False, // hasAlpha
|
||||
HasAlpha, // hasAlpha
|
||||
False, // isPlanar
|
||||
GetColorSpace, // colorSpaceName
|
||||
NSAlphaNonpremultipliedBitmapFormat, // bitmapFormat
|
||||
BitmapFormat, // bitmapFormat
|
||||
FBytesPerRow, // bytesPerRow
|
||||
FBitsPerPixel //bitsPerPixel
|
||||
));
|
||||
|
@ -317,7 +317,6 @@ end;
|
||||
function TCocoaWidgetSet.RawImage_DescriptionFromCocoaBitmap(out ADesc: TRawImageDescription; ABitmap: TCocoaBitmap): Boolean;
|
||||
var
|
||||
Prec, Shift, BPR: Byte;
|
||||
AlphaInfo: CGImageAlphaInfo;
|
||||
begin
|
||||
ADesc.Init;
|
||||
|
||||
@ -327,15 +326,18 @@ begin
|
||||
ADesc.Format := ricfRGBA;
|
||||
end;
|
||||
|
||||
{ ADesc.Width := CGImageGetWidth(ABitmap.CGImage);
|
||||
ADesc.Height := CGImageGetHeight(ABitmap.CGImage);
|
||||
with ABitmap.image.size do
|
||||
begin
|
||||
ADesc.Width := Round(width);
|
||||
ADesc.Height := Round(Height);
|
||||
end;
|
||||
|
||||
//ADesc.PaletteColorCount := 0;
|
||||
|
||||
ADesc.BitOrder := riboReversedBits;
|
||||
ADesc.ByteOrder := riboMSBFirst;
|
||||
|
||||
BPR := CGImageGetBytesPerRow(ABitmap.CGImage) and $FF;
|
||||
BPR := ABitmap.BytesPerRow;
|
||||
if BPR and $F = 0 then ADesc.LineEnd := rileDQWordBoundary // 128bit aligned
|
||||
else if BPR and $7 = 0 then ADesc.LineEnd := rileQWordBoundary // 64bit aligned
|
||||
else if BPR and $3 = 0 then ADesc.LineEnd := rileWordBoundary // 32bit aligned
|
||||
@ -343,43 +345,29 @@ begin
|
||||
else ADesc.LineEnd := rileTight;
|
||||
|
||||
ADesc.LineOrder := riloTopToBottom;
|
||||
ADesc.BitsPerPixel := CGImageGetBitsPerPixel(ABitmap.CGImage);
|
||||
ADesc.BitsPerPixel := ABitmap.BitsPerPixel;
|
||||
|
||||
ADesc.MaskBitOrder := riboReversedBits;
|
||||
ADesc.MaskBitsPerPixel := 1;
|
||||
ADesc.MaskLineEnd := rileByteBoundary;
|
||||
// ADesc.MaskShift := 0;
|
||||
|
||||
Prec := CGImageGetBitsPerComponent(ABitmap.CGImage) and $FF;
|
||||
AlphaInfo := CGImageGetAlphaInfo(ABitmap.CGImage);
|
||||
ADesc.Depth := ABitmap.Depth;
|
||||
Prec := ABitmap.BitsPerSample;
|
||||
|
||||
if AlphaInfo <> kCGImageAlphaOnly
|
||||
then begin
|
||||
ADesc.RedPrec := Prec;
|
||||
ADesc.GreenPrec := Prec;
|
||||
ADesc.BluePrec := Prec;
|
||||
end;
|
||||
ADesc.RedPrec := Prec;
|
||||
ADesc.GreenPrec := Prec;
|
||||
ADesc.BluePrec := Prec;
|
||||
|
||||
// gray or mono
|
||||
if ADesc.Format = ricfGray then Exit;
|
||||
|
||||
// alpha
|
||||
case AlphaInfo of
|
||||
kCGImageAlphaNone,
|
||||
kCGImageAlphaNoneSkipLast,
|
||||
kCGImageAlphaNoneSkipFirst: begin
|
||||
ADesc.Depth := Prec * 3;
|
||||
// ADesc.AlphaPrec := 0;
|
||||
end;
|
||||
else
|
||||
ADesc.Depth := Prec * 4;
|
||||
if ABitmap.BitmapType in [cbtARGB, cbtRGBA, cbtBGRA] then
|
||||
ADesc.AlphaPrec := Prec;
|
||||
end;
|
||||
|
||||
case AlphaInfo of
|
||||
kCGImageAlphaNone,
|
||||
kCGImageAlphaNoneSkipLast: begin
|
||||
// RGBx
|
||||
case ABitmap.BitmapType of
|
||||
cbtRGB: begin
|
||||
Shift := 32 - Prec;
|
||||
ADesc.RedShift := Shift;
|
||||
Dec(Shift, Prec);
|
||||
@ -387,18 +375,15 @@ begin
|
||||
Dec(Shift, Prec);
|
||||
ADesc.BlueShift := Shift;
|
||||
end;
|
||||
kCGImageAlphaNoneSkipFirst: begin
|
||||
// xRGB
|
||||
Shift := 0;
|
||||
cbtBGR: begin
|
||||
Shift := 32 - Prec;
|
||||
ADesc.BlueShift := Shift;
|
||||
Inc(Shift, Prec);
|
||||
Dec(Shift, Prec);
|
||||
ADesc.GreenShift := Shift;
|
||||
Inc(Shift, Prec);
|
||||
Dec(Shift, Prec);
|
||||
ADesc.RedShift := Shift;
|
||||
end;
|
||||
kCGImageAlphaPremultipliedFirst,
|
||||
kCGImageAlphaFirst: begin
|
||||
// ARGB
|
||||
cbtARGB: begin
|
||||
Shift := 32 - Prec;
|
||||
ADesc.AlphaShift := Shift;
|
||||
Dec(Shift, Prec);
|
||||
@ -408,9 +393,7 @@ begin
|
||||
Dec(Shift, Prec);
|
||||
ADesc.BlueShift := Shift;
|
||||
end;
|
||||
kCGImageAlphaPremultipliedLast,
|
||||
kCGImageAlphaLast: begin
|
||||
// RGBA
|
||||
cbtRGBA: begin
|
||||
Shift := 32 - Prec;
|
||||
ADesc.RedShift := Shift;
|
||||
Dec(Shift, Prec);
|
||||
@ -420,13 +403,19 @@ begin
|
||||
Dec(Shift, Prec);
|
||||
ADesc.AlphaShift := Shift;
|
||||
end;
|
||||
kCGImageAlphaOnly: begin
|
||||
// A
|
||||
//ADesc.AlphaShift := 0;
|
||||
cbtBGRA: begin
|
||||
Shift := 32 - Prec;
|
||||
ADesc.BlueShift := Shift;
|
||||
Dec(Shift, Prec);
|
||||
ADesc.GreenShift := Shift;
|
||||
Dec(Shift, Prec);
|
||||
ADesc.RedShift := Shift;
|
||||
Dec(Shift, Prec);
|
||||
ADesc.AlphaShift := Shift;
|
||||
end;
|
||||
end;
|
||||
|
||||
Result := True;}
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user