+ rid.Format := ricfRGBA;
+
+ rid.Width := Width;
+ rid.Height := Height;
+ rid.Depth := CountSetBits(FormatDesc.Range.r or FormatDesc.Range.g or FormatDesc.Range.b or FormatDesc.Range.a);
+ rid.BitOrder := riboBitsInOrder;
+ rid.ByteOrder := riboLSBFirst;
+ rid.LineOrder := riloTopToBottom;
+ rid.LineEnd := rileTight;
+ rid.BitsPerPixel := Round(8 * FormatDesc.PixelSize);
+ rid.RedPrec := CountSetBits(FormatDesc.Range.r);
+ rid.GreenPrec := CountSetBits(FormatDesc.Range.g);
+ rid.BluePrec := CountSetBits(FormatDesc.Range.b);
+ rid.AlphaPrec := CountSetBits(FormatDesc.Range.a);
+ rid.RedShift := FormatDesc.Shift.r;
+ rid.GreenShift := FormatDesc.Shift.g;
+ rid.BlueShift := FormatDesc.Shift.b;
+ rid.AlphaShift := FormatDesc.Shift.a;
+
+ rid.MaskBitsPerPixel := 0;
+ rid.PaletteColorCount := 0;
+
+ aImage.DataDescription := rid;
+ aImage.CreateData;
+
+ Move(Data^, aImage.PixelData^, FormatDesc.GetSize(Dimension));
+
+ result := true;
+end;
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+function TglBitmap.AssignFromLazIntfImage(const aImage: TLazIntfImage): Boolean;
+var
+ f: TglBitmapFormat;
+ FormatDesc: TFormatDescriptor;
+ ImageData: PByte;
+ ImageSize: Integer;
+begin
+ result := false;
+ if not Assigned(aImage) then
+ exit;
+ for f := High(f) downto Low(f) do begin
+ FormatDesc := TFormatDescriptor.Get(f);
+ with aImage.DataDescription do
+ if FormatDesc.MaskMatch(
+ (QWord(1 shl RedPrec )-1) shl RedShift,
+ (QWord(1 shl GreenPrec)-1) shl GreenShift,
+ (QWord(1 shl BluePrec )-1) shl BlueShift,
+ (QWord(1 shl AlphaPrec)-1) shl AlphaShift) then
+ break;
+ end;
+
+ if (f = tfEmpty) then
+ exit;
+
+ ImageSize := FormatDesc.GetSize(aImage.Width, aImage.Height);
+ ImageData := GetMem(ImageSize);
+ try
+ Move(aImage.PixelData^, ImageData^, (aImage.Width * aImage.Height * aImage.DataDescription.BitsPerPixel) shr 3);
+ SetDataPointer(ImageData, f, aImage.Width, aImage.Height);
+ except
+ FreeMem(ImageData);
+ raise;
+ end;
+
+ result := true;
+end;
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+function TglBitmap.AssignAlphaToLazIntfImage(const aImage: TLazIntfImage): Boolean;
+var
+ rid: TRawImageDescription;
+ FormatDesc: TFormatDescriptor;
+ Pixel: TglBitmapPixelData;
+ x, y: Integer;
+ srcMD: Pointer;
+ src, dst: PByte;
+begin
+ result := false;
+ if not Assigned(aImage) or (Format = tfEmpty) then
+ exit;
+ FormatDesc := TFormatDescriptor.Get(Format);
+ if FormatDesc.IsCompressed or not FormatDesc.HasAlpha then
+ exit;