forked from edivando-fpc/BGRABitmap
-
Notifications
You must be signed in to change notification settings - Fork 5
/
bgramacbitmap.pas
118 lines (93 loc) · 3.91 KB
/
bgramacbitmap.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
{ ***************************************************************************
* *
* This file is part of BGRABitmap library which is distributed under the *
* modified LGPL. *
* *
* See the file COPYING.modifiedLGPL.txt, included in this distribution, *
* for details about the copyright. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* *
************************* BGRABitmap library ******************************
- Drawing routines with transparency and antialiasing with Lazarus.
Offers also various transforms.
- These routines allow to manipulate 32bit images in BGRA format or RGBA
format (depending on the platform).
- This code is under modified LGPL (see COPYING.modifiedLGPL.txt).
This means that you can link this library inside your programs for any purpose.
Only the included part of the code must remain LGPL.
- If you make some improvements to this library, please notify here:
http://www.lazarus.freepascal.org/index.php/topic,12037.0.html
********************* Contact : Circular at operamail.com *******************
******************************* CONTRIBUTOR(S) ******************************
- Edivando S. Santos Brasil | [email protected]
(Compatibility with FPC ($Mode objfpc/delphi) and delphi VCL 11/2018)
***************************** END CONTRIBUTOR(S) *****************************}
Unit BGRAMacBitmap;
{$i bgrabitmap.inc}{$H+}
interface
uses
Classes, SysUtils, BGRALCLBitmap, BGRAGraphics, BGRABitmapTypes;
type
{ TBGRAMacBitmap }
TBGRAMacBitmap = class(TBGRALCLBitmap)
procedure DataDrawOpaque(ACanvas: TCanvas; Rect: TRect; AData: Pointer;
ALineOrder: TRawImageLineOrder; AWidth, AHeight: integer); override;
end;
implementation
uses LCLType, GraphType, LCLIntf, FPImage;
procedure DataDrawOpaqueImplementation(ACanvas: TCanvas; Rect: TRect;
AData: Pointer; ALineOrder: TRawImageLineOrder; AWidth, AHeight: integer);
type
PARGB = ^TARGB;
TARGB = packed record
alpha,red,green,blue: byte;
end;
var
Temp: TBitmap;
RawImage: TRawImage;
BitmapHandle, MaskHandle: HBitmap;
CreateResult: boolean;
psrc: PBGRAPixel;
pdest: PARGB;
n: Integer;
begin
if (AHeight = 0) or (AWidth = 0) then
exit;
RawImage.Init;
RawImage.Description.Init_BPP32_A8R8G8B8_BIO_TTB(AWidth,AHeight);
RawImage.Description.Depth := 24;
RawImage.Description.AlphaPrec := 0;
RawImage.Description.LineOrder := ALineOrder;
RawImage.Description.LineEnd := rileDWordBoundary;
RawImage.CreateData(False);
psrc := PBGRAPixel(AData);
pdest := PARGB(RawImage.Data);
for n := AWidth*AHeight-1 downto 0 do
begin
pdest^.alpha := 255;
pdest^.red := psrc^.red;
pdest^.green := psrc^.green;
pdest^.blue := psrc^.blue;
inc(pdest);
inc(psrc);
end;
CreateResult := RawImage_CreateBitmaps(RawImage, BitmapHandle, MaskHandle, False);
RawImage.FreeData;
if not CreateResult then
raise FPImageException.Create('Failed to create bitmap handle');
Temp := TBitmap.Create;
Temp.Handle := BitmapHandle;
Temp.MaskHandle := MaskHandle;
ACanvas.StretchDraw(Rect, Temp);
Temp.Free;
end;
{ TBGRAMacBitmap }
procedure TBGRAMacBitmap.DataDrawOpaque(ACanvas: TCanvas; Rect: TRect;
AData: Pointer; ALineOrder: TRawImageLineOrder; AWidth, AHeight: integer);
begin
DataDrawOpaqueImplementation(ACanvas, Rect, AData, ALineOrder, AWidth, AHeight);
end;
end.