forked from freeonterminate/delphi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuBitmapScanLineHelper.pas
More file actions
59 lines (47 loc) · 1 KB
/
uBitmapScanLineHelper.pas
File metadata and controls
59 lines (47 loc) · 1 KB
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
unit uBitmapScanLineHelper;
interface
uses
FMX.Types;
type
TBitmapScanLineHelper = class helper for TBitmap
public
function BeginScanLine(const Row: Integer): Pointer;
procedure EndScanLine;
end;
implementation
uses
Generics.Collections, FMX.PixelFormats;
type
TBmpDataDic = TDictionary<TBitmap, TBitmapData>;
var
GBmpDataDic: TBmpDataDic = nil;
function TBitmapScanLineHelper.BeginScanLine(const Row: Integer): Pointer;
var
BmpData: TBitmapData;
begin
if (Map(TMapAccess.maReadWrite, BmpData)) then begin
GBmpDataDic.Add(Self, BmpData);
Result := BmpData.Data;
Inc(PByte(Result), Row * Width * GetPixelFormatBytes(PixelFormat));
end
else
Result := nil;
end;
procedure TBitmapScanLineHelper.EndScanLine;
var
BmpData: TBitmapData;
begin
if (GBmpDataDic.TryGetValue(Self, BmpData)) then begin
Unmap(BmpData);
GBmpDataDic.Remove(Self);
end;
end;
initialization
begin
GBmpDataDic := TBmpDataDic.Create;
end;
finalization
begin
GBmpDataDic.Free;
end;
end.