forked from edivando-fpc/BGRABitmap
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbgraqtbitmap.pas
148 lines (122 loc) · 4.86 KB
/
bgraqtbitmap.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
{ ***************************************************************************
* *
* 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 | mailedivando@gmail.com
(Compatibility with FPC ($Mode objfpc/delphi) and delphi VCL 11/2018)
***************************** END CONTRIBUTOR(S) *****************************}
unit BGRAQtBitmap;
//Unit should NOT be added to the 'uses' clause.
//It contains patches for Qt.
{$i bgrabitmap.inc}{$H+}
interface
uses
Classes, SysUtils, BGRALCLBitmap, Graphics,
GraphType, BGRABitmapTypes;
type
{ TBGRAQtBitmap }
TBGRAQtBitmap = class(TBGRALCLBitmap)
private
procedure SlowDrawTransparent(ABitmap: TBGRACustomBitmap;
ACanvas: TCanvas; ARect: TRect);
public
procedure DataDrawTransparent(ACanvas: TCanvas; Rect: TRect;
AData: Pointer; ALineOrder: TRawImageLineOrder; AWidth, AHeight: integer);
override;
procedure Draw(ACanvas: TCanvas; x, y: integer; Opaque: boolean = True); override;
procedure Draw(ACanvas: TCanvas; Rect: TRect; Opaque: boolean = True); override;
procedure GetImageFromCanvas(CanvasSource: TCanvas; x, y: integer); override;
end;
implementation
uses LCLType,
LCLIntf, IntfGraphics,
qtobjects, qt4,
FPImage;
procedure TBGRAQtBitmap.SlowDrawTransparent(ABitmap: TBGRACustomBitmap;
ACanvas: TCanvas; ARect: TRect);
begin
ACanvas.StretchDraw(ARect, ABitmap.Bitmap);
end;
procedure TBGRAQtBitmap.DataDrawTransparent(ACanvas: TCanvas; Rect: TRect;
AData: Pointer; ALineOrder: TRawImageLineOrder; AWidth, AHeight: integer);
var
Temp: TBGRALCLPtrBitmap;
begin
Temp := TBGRALCLPtrBitmap.Create(AWidth, AHeight, AData);
Temp.LineOrder := ALineOrder;
SlowDrawTransparent(Temp, ACanvas, Rect);
Temp.Free;
end;
procedure TBGRAQtBitmap.Draw(ACanvas: TCanvas; x, y: integer; Opaque: boolean);
begin
if self = nil then
exit;
if Opaque then
DataDrawOpaque(ACanvas, Rect(X, Y, X + Width, Y + Height), Data, FLineOrder,
FWidth, FHeight)
else
SlowDrawTransparent(Self, ACanvas, Rect(X, Y, X + Width, Y + Height));
end;
procedure TBGRAQtBitmap.Draw(ACanvas: TCanvas; Rect: TRect; Opaque: boolean);
begin
if self = nil then
exit;
if Opaque then
DataDrawOpaque(ACanvas, Rect, Data, FLineOrder, FWidth, FHeight)
else
SlowDrawTransparent(Self, ACanvas, Rect);
end;
procedure TBGRAQtBitmap.GetImageFromCanvas(CanvasSource: TCanvas; x, y: integer);
var
bmp: TBitmap;
Ofs: TPoint;
SrcX, SrcY: integer;
dcSource, dcDest: TQtDeviceContext;
B: Boolean;
begin
DiscardBitmapChange;
bmp := TBitmap.Create;
bmp.PixelFormat := pf24bit;
bmp.Width := Width;
bmp.Height := Height;
dcDest := TQtDeviceContext(bmp.Canvas.handle);
dcSource := TQtDeviceContext(CanvasSource.Handle);
LCLIntf.GetWindowOrgEx(CanvasSource.Handle, @Ofs);
SrcX := x + Ofs.X;
SrcY := y + Ofs.Y;
if (dcSource.vImage <> nil) and (dcSource.vImage.Handle <> nil) then
begin
// we must stop painting on device
B := QPainter_isActive(dcDest.Widget);
if B then
QPainter_end(dcDest.Widget);
TQtImage(bmp.Handle).CopyFrom(dcSource.vImage.Handle,
SrcX, SrcY, Width, Height);
if B then
QPainter_begin(dcDest.Widget, TQtImage(bmp.Handle).Handle);
end;
LoadFromRawImage(bmp.RawImage, 255, True);
bmp.Free;
InvalidateBitmap;
end;
end.