1 | {
|
---|
2 | /**************************************************************************\
|
---|
3 | bgrabitmap.pas
|
---|
4 | --------------
|
---|
5 | Free easy-to-use memory bitmap 32-bit,
|
---|
6 | 8-bit for each channel, transparency.
|
---|
7 | Channels can be in the following orders:
|
---|
8 | - B G R A (recommended for Windows, required for fpGUI)
|
---|
9 | - R G B A (recommended for Gtk and MacOS)
|
---|
10 |
|
---|
11 | - Drawing primitives
|
---|
12 | - Resample
|
---|
13 | - Reference counter
|
---|
14 | - Drawing on LCL canvas
|
---|
15 | - Loading and saving images
|
---|
16 |
|
---|
17 | Note : line order can change, so if you access
|
---|
18 | directly to bitmap data, check LineOrder value
|
---|
19 | or use Scanline to compute position.
|
---|
20 |
|
---|
21 |
|
---|
22 | --> Include BGRABitmap and BGRABitmapTypes in the 'uses' clause.
|
---|
23 |
|
---|
24 | ****************************************************************************
|
---|
25 | * *
|
---|
26 | * This file is part of BGRABitmap library which is distributed under the *
|
---|
27 | * modified LGPL. *
|
---|
28 | * *
|
---|
29 | * See the file COPYING.modifiedLGPL.txt, included in this distribution, *
|
---|
30 | * for details about the copyright. *
|
---|
31 | * *
|
---|
32 | * This program is distributed in the hope that it will be useful, *
|
---|
33 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
---|
34 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
---|
35 | * *
|
---|
36 | ****************************************************************************
|
---|
37 | }
|
---|
38 |
|
---|
39 | unit BGRABitmap;
|
---|
40 |
|
---|
41 | {$mode objfpc}{$H+}
|
---|
42 | {$i bgrabitmap.inc}
|
---|
43 |
|
---|
44 | interface
|
---|
45 |
|
---|
46 | { Compiler directives are used to include the best version according
|
---|
47 | to the platform }
|
---|
48 |
|
---|
49 | uses
|
---|
50 | Classes, SysUtils,
|
---|
51 | {$IFDEF BGRABITMAP_USE_FPGUI}
|
---|
52 | BGRAfpGUIBitmap,
|
---|
53 | {$ELSE}
|
---|
54 | {$IFDEF BGRABITMAP_USE_LCL}
|
---|
55 | {$IFDEF LCLwin32}
|
---|
56 | BGRAWinBitmap,
|
---|
57 | {$ELSE}
|
---|
58 | {$IFDEF LCLgtk}
|
---|
59 | BGRAGtkBitmap,
|
---|
60 | {$ELSE}
|
---|
61 | {$IFDEF LCLgtk2}
|
---|
62 | BGRAGtkBitmap,
|
---|
63 | {$ELSE}
|
---|
64 | {$IFDEF LCLqt}
|
---|
65 | BGRAQtBitmap,
|
---|
66 | {$ELSE}
|
---|
67 | {$IFDEF DARWIN}
|
---|
68 | BGRAMacBitmap,
|
---|
69 | {$ELSE}
|
---|
70 | BGRALCLBitmap,
|
---|
71 | {$ENDIF}
|
---|
72 | {$ENDIF}
|
---|
73 | {$ENDIF}
|
---|
74 | {$ENDIF}
|
---|
75 | {$ENDIF}
|
---|
76 | {$ELSE}
|
---|
77 | BGRANoGuiBitmap,
|
---|
78 | {$ENDIF}
|
---|
79 | {$ENDIF}
|
---|
80 | BGRAGraphics;
|
---|
81 |
|
---|
82 | type
|
---|
83 | {$IFDEF BGRABITMAP_USE_FPGUI}
|
---|
84 | TBGRABitmap = class(TBGRAfpGUIBitmap);
|
---|
85 | {$ELSE}
|
---|
86 | {$IFDEF BGRABITMAP_USE_LCL}
|
---|
87 | {$IFDEF LCLwin32}
|
---|
88 | TBGRABitmap = class(TBGRAWinBitmap);
|
---|
89 | {$ELSE}
|
---|
90 | {$IFDEF LCLgtk}
|
---|
91 | TBGRABitmap = class(TBGRAGtkBitmap);
|
---|
92 | {$ELSE}
|
---|
93 | {$IFDEF LCLgtk2}
|
---|
94 | TBGRABitmap = class(TBGRAGtkBitmap);
|
---|
95 | {$ELSE}
|
---|
96 | {$IFDEF LCLqt}
|
---|
97 | TBGRABitmap = class(TBGRAQtBitmap);
|
---|
98 | {$ELSE}
|
---|
99 | {$IFDEF DARWIN}
|
---|
100 | TBGRABitmap = class(TBGRAMacBitmap);
|
---|
101 | {$ELSE}
|
---|
102 | TBGRABitmap = class(TBGRALCLBitmap);
|
---|
103 | {$ENDIF}
|
---|
104 | {$ENDIF}
|
---|
105 | {$ENDIF}
|
---|
106 | {$ENDIF}
|
---|
107 | {$ENDIF}
|
---|
108 | {$ELSE}
|
---|
109 | TBGRABitmap = class(TBGRANoGUIBitmap);
|
---|
110 | {$ENDIF}
|
---|
111 | {$ENDIF}
|
---|
112 |
|
---|
113 | // draw a bitmap from pure data
|
---|
114 | procedure BGRABitmapDraw(ACanvas: TCanvas; Rect: TRect; AData: Pointer;
|
---|
115 | VerticalFlip: boolean; AWidth, AHeight: integer; Opaque: boolean);
|
---|
116 |
|
---|
117 | { Replace the content of the variable Destination with the variable
|
---|
118 | Temp and frees previous object contained in Destination.
|
---|
119 |
|
---|
120 | This function is useful as a shortcut for :
|
---|
121 |
|
---|
122 | var
|
---|
123 | temp: TBGRABitmap;
|
---|
124 | begin
|
---|
125 | ...
|
---|
126 | temp := someBmp.Filter... as TBGRABitmap;
|
---|
127 | someBmp.Free;
|
---|
128 | someBmp := temp;
|
---|
129 | end;
|
---|
130 |
|
---|
131 | which becomes :
|
---|
132 |
|
---|
133 | begin
|
---|
134 | ...
|
---|
135 | BGRAReplace(someBmp, someBmp.Filter... );
|
---|
136 | end;
|
---|
137 | }
|
---|
138 | procedure BGRAReplace(var Destination: TBGRABitmap; Temp: TObject);
|
---|
139 |
|
---|
140 | implementation
|
---|
141 |
|
---|
142 | uses BGRABitmapTypes, BGRAReadBMP, BGRAReadBmpMioMap, BGRAReadGif,
|
---|
143 | BGRAReadIco, BGRAReadJpeg, BGRAReadLzp, BGRAReadPCX,
|
---|
144 | BGRAReadPng, BGRAReadPSD, BGRAReadTGA, BGRAReadXPM,
|
---|
145 | BGRAWriteLzp;
|
---|
146 |
|
---|
147 | var
|
---|
148 | tempBmp: TBGRABitmap;
|
---|
149 |
|
---|
150 | procedure BGRABitmapDraw(ACanvas: TCanvas; Rect: TRect; AData: Pointer;
|
---|
151 | VerticalFlip: boolean; AWidth, AHeight: integer; Opaque: boolean);
|
---|
152 | var
|
---|
153 | LineOrder: TRawImageLineOrder;
|
---|
154 | begin
|
---|
155 | if tempBmp = nil then
|
---|
156 | tempBmp := TBGRABitmap.Create;
|
---|
157 | if VerticalFlip then
|
---|
158 | LineOrder := riloBottomToTop
|
---|
159 | else
|
---|
160 | LineOrder := riloTopToBottom;
|
---|
161 | if Opaque then
|
---|
162 | tempBmp.DataDrawOpaque(ACanvas, Rect, AData, LineOrder, AWidth, AHeight)
|
---|
163 | else
|
---|
164 | tempBmp.DataDrawTransparent(ACanvas, Rect, AData, LineOrder, AWidth, AHeight);
|
---|
165 | end;
|
---|
166 |
|
---|
167 | procedure BGRAReplace(var Destination: TBGRABitmap; Temp: TObject);
|
---|
168 | begin
|
---|
169 | Destination.Free;
|
---|
170 | Destination := Temp as TBGRABitmap;
|
---|
171 | end;
|
---|
172 |
|
---|
173 | initialization
|
---|
174 |
|
---|
175 | //this variable is assigned to access appropriate functions
|
---|
176 | //depending on the platform
|
---|
177 | BGRABitmapFactory := TBGRABitmap;
|
---|
178 |
|
---|
179 | finalization
|
---|
180 |
|
---|
181 | tempBmp.Free;
|
---|
182 |
|
---|
183 | end.
|
---|
184 |
|
---|