-
Notifications
You must be signed in to change notification settings - Fork 12
/
bgradefaultbitmap.pas
6304 lines (5647 loc) · 218 KB
/
bgradefaultbitmap.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{ ***************************************************************************
* *
* 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 BGRADefaultBitmap;
{$i bgrabitmap.inc}{$H+}
interface
{ This unit contains TBGRADefaultBitmap class. This class contains basic drawing routines,
and call functions from other units to perform advanced drawing functions. }
uses
SysUtils, Classes, Types, BGRATypes,{$IFNDEF FPC}GraphType,{$ENDIF} FPImage, BGRAGraphics, BGRABitmapTypes, FPImgCanv,
BGRACanvas, BGRACanvas2D, BGRAArrow, BGRAPen, BGRATransform, BGRATextBidi;
type
TBGRAPtrBitmap = class;
{=== TBGRABitmap reference ===}
{ TBGRADefaultBitmap }
{* This class is the base for all ''TBGRABitmap'' classes. It implements most
function to the exception from implementations specific to the
widgetset }{ in the doc, it is presented as
TBGRABitmap = class(TBGRACustomBitmap)
}
TBGRADefaultBitmap = class(TBGRACustomBitmap)
private
{ Bounds checking which are shared by drawing functions. These functions check
if the coordinates are visible and return true if it is the case, swap
coordinates if necessary and make them fit into the clipping rectangle }
function CheckHorizLineBounds(var x, y, x2: int32or64): boolean; //inline;
function CheckVertLineBounds(var x, y, y2: int32or64; out delta: int32or64): boolean; //inline;
function CheckRectBounds(var x,y,x2,y2: integer; minsize: integer): boolean; //inline;
function CheckAntialiasRectBounds(var x,y,x2,y2: single; w: single): boolean;
function GetCanvasBGRA: TBGRACanvas;
function GetCanvas2D: TBGRACanvas2D;
procedure GradientFillDithered(x, y, x2, y2: integer; c1, c2: TBGRAPixel;
gtype: TGradientType; o1, o2: TPointF; mode: TDrawMode;
gammaColorCorrection: boolean = True; Sinus: Boolean=False;
ditherAlgo: TDitheringAlgorithm = daFloydSteinberg); overload;
procedure GradientFillDithered(x, y, x2, y2: integer; gradient: TBGRACustomGradient;
gtype: TGradientType; o1, o2: TPointF; mode: TDrawMode;
Sinus: Boolean=False;
ditherAlgo: TDitheringAlgorithm = daFloydSteinberg); overload;
protected
FRefCount: integer; //reference counter (not related to interface reference counter)
//Pixel data
FData: PBGRAPixel; //pointer to pixels
FWidth, FHeight, FNbPixels: integer; //dimensions
FScanWidth, FScanHeight: integer; //possibility to reduce the zone being scanned
FDataModified: boolean; //if data image has changed so TBitmap should be updated
FLineOrder: TRawImageLineOrder;
FClipRect: TRect; //clipping (can be the whole image if there is no clipping)
//Scan
FScanPtr : PBGRAPixel; //current scan address
FScanCurX,FScanCurY: integer; //current scan coordinates
//GUI bitmap object
FBitmap: TBitmap;
FBitmapModified: boolean; //if TBitmap has changed so pixel data should be updated
FCanvasOpacity: byte; //opacity used with standard canvas functions
FAlphaCorrectionNeeded: boolean; //the alpha channel is not correct because standard functions do not
//take it into account
//FreePascal drawing routines
FCanvasFP: TFPImageCanvas;
FCanvasDrawModeFP: TDrawMode;
FCanvasPixelProcFP: procedure(x, y: int32or64; col: TBGRAPixel) of object;
//canvas-like with antialiasing and texturing
FCanvasBGRA: TBGRACanvas;
FCanvas2D: TBGRACanvas2D;
//drawing options
FEraseMode: boolean; //when polygons are erased instead of drawn
FFontHeight: integer;
FFontRenderer: TBGRACustomFontRenderer;
FPenStroker: TBGRAPenStroker;
//Pixel data
function GetRefCount: integer; override;
function GetScanLine(y: integer): PBGRAPixel; override; //don't forget to call InvalidateBitmap after modifications
function LoadFromRawImage(ARawImage: TRawImage; DefaultOpacity: byte;
AlwaysReplaceAlpha: boolean = False; RaiseErrorOnInvalidPixelFormat: boolean = True): boolean; virtual; abstract;
function GetDataPtr: PBGRAPixel; override;
procedure ClearTransparentPixels; override;
function GetScanlineFast(y: integer): PBGRAPixel; //inline;
function GetLineOrder: TRawImageLineOrder; override;
procedure SetLineOrder(AValue: TRawImageLineOrder); virtual;
function GetNbPixels: integer; override;
function GetWidth: integer; override;
function GetHeight: integer; override;
//GUI bitmap object
function GetBitmap: TBitmap; override;
function GetCanvas: TCanvas; override;
procedure DiscardBitmapChange; //inline;
procedure DoAlphaCorrection;
procedure SetCanvasOpacity(AValue: byte); override;
function GetCanvasOpacity: byte; override;
function GetCanvasAlphaCorrection: boolean; override;
procedure SetCanvasAlphaCorrection(const AValue: boolean); override;
procedure DoLoadFromBitmap; virtual;
//FreePascal drawing routines
function GetCanvasFP: TFPImageCanvas; override;
procedure SetCanvasDrawModeFP(const AValue: TDrawMode); override;
function GetCanvasDrawModeFP: TDrawMode; override;
{Allocation routines}
procedure ReallocData; virtual;
procedure FreeData; virtual;
function CreatePtrBitmap(AWidth,AHeight: integer; AData: PBGRAPixel): TBGRAPtrBitmap; virtual;
procedure RebuildBitmap; virtual; abstract;
procedure FreeBitmap; virtual;
procedure Init; virtual;
{TFPCustomImage}
procedure SetInternalColor(x, y: integer; const Value: TFPColor); override;
function GetInternalColor(x, y: integer): TFPColor; override;
procedure SetInternalPixel(x, y: integer; Value: integer); override;
function GetInternalPixel(x, y: integer): integer; override;
{Image functions}
function FineResample(NewWidth, NewHeight: integer): TBGRACustomBitmap;
function SimpleStretch(NewWidth, NewHeight: integer): TBGRACustomBitmap;
function CheckEmpty: boolean; override;
function CheckIsZero: boolean; override;
function GetHasTransparentPixels: boolean; override;
function GetHasSemiTransparentPixels: boolean; override;
function GetAverageColor: TColor; override;
function GetAveragePixel: TBGRAPixel; override;
//drawing
function GetPenJoinStyle: TPenJoinStyle; override;
procedure SetPenJoinStyle(const AValue: TPenJoinStyle); override;
function GetPenMiterLimit: single; override;
procedure SetPenMiterLimit(const AValue: single); override;
function GetCustomPenStyle: TBGRAPenStyle; override;
procedure SetCustomPenStyle(const AValue: TBGRAPenStyle); override;
procedure SetPenStyle(const AValue: TPenStyle); override;
function GetPenStyle: TPenStyle; override;
function GetLineCap: TPenEndCap; override;
procedure SetLineCap(AValue: TPenEndCap); override;
function GetPenStroker: TBGRACustomPenStroker; override;
function GetArrowEndSize: TPointF; override;
function GetArrowStartSize: TPointF; override;
procedure SetArrowEndSize(AValue: TPointF); override;
procedure SetArrowStartSize(AValue: TPointF); override;
function GetArrowEndOffset: single; override;
function GetArrowStartOffset: single; override;
procedure SetArrowEndOffset(AValue: single); override;
procedure SetArrowStartOffset(AValue: single); override;
function GetArrowEndRepeat: integer; override;
function GetArrowStartRepeat: integer; override;
procedure SetArrowEndRepeat(AValue: integer); override;
procedure SetArrowStartRepeat(AValue: integer); override;
function GetFontHeight: integer; override;
procedure SetFontHeight(AHeight: integer); override;
function GetFontFullHeight: integer; override;
procedure SetFontFullHeight(AHeight: integer); override;
function GetFontPixelMetric: TFontPixelMetric; override;
function GetFontRenderer: TBGRACustomFontRenderer; override;
procedure SetFontRenderer(AValue: TBGRACustomFontRenderer); override;
function CreateDefaultFontRenderer: TBGRACustomFontRenderer; virtual; abstract;
function GetFontAnchorVerticalOffset: single;
function GetFontAnchorRotatedOffset: TPointF; overload;
function GetFontAnchorRotatedOffset(ACustomOrientation: integer): TPointF; overload;
function GetClipRect: TRect; override;
procedure SetClipRect(const AValue: TRect); override;
function InternalGetPixelCycle256(ix,iy: int32or64; iFactX,iFactY: int32or64): TBGRAPixel;
function InternalGetPixel256(ix,iy: int32or64; iFactX,iFactY: int32or64; smoothBorder: boolean): TBGRAPixel;
function GetArrow: TBGRAArrow;
procedure InternalTextOutCurved(ACursor: TBGRACustomPathCursor; sUTF8: string; AColor: TBGRAPixel; ATexture: IBGRAScanner; AAlign: TAlignment; ALetterSpacing: single);
function CheckClippedRectBounds(var x,y,x2,y2: integer): boolean;
procedure InternalArc(cx,cy,rx,ry: single; StartAngleRad,EndAngleRad: Single; ABorderColor: TBGRAPixel; w: single;
AFillColor: TBGRAPixel; AOptions: TArcOptions; ADrawChord: boolean = false; ATexture: IBGRAScanner = nil); override;
public
{** Provides a canvas with opacity and antialiasing }
property CanvasBGRA: TBGRACanvas read GetCanvasBGRA;
{** Provides a canvas with 2d transformation and similar to HTML5. }
property Canvas2D: TBGRACanvas2D read GetCanvas2D;
{** For more properties, see parent class [[TBGRACustomBitmap and IBGRAScanner#TBGRACustomBitmap|TBGRACustomBitmap]] }
{==== Reference counting ====}
{** Adds a reference (this reference count is not the same as
the reference count of an interface, it changes only by
explicit calls }
function NewReference: TBGRACustomBitmap;
{** Free a reference. When the resulting reference count gets
to zero, the image is freed. The initial reference count
is equal to 1 }
procedure FreeReference;
{** Returns an object with a reference count equal to 1. Duplicate
this bitmap if necessary }
function GetUnique: TBGRACustomBitmap;
{ ** Allocate xor mask }
procedure NeedXorMask; override;
{ ** Free reference to xor mask }
procedure DiscardXorMask; override;
{==== Constructors ====}
{------------------------- Constructors from TFPCustomImage----------------}
{** Creates a new bitmap, initialize properties and bitmap data }
constructor Create(AWidth, AHeight: integer); overload; override;
{** Can only be called with an existing instance of ''TBGRABitmap''.
Sets the dimensions of an existing ''TBGRABitmap'' instance. }
procedure SetSize(AWidth, AHeight: integer); override;
{------------------------- Constructors from TBGRACustomBitmap-------------}
{** Creates an image of width and height equal to zero. In this case,
''Data'' = '''nil''' }
constructor Create; overload; override;
{** Creates an image by copying the content of a ''TFPCustomImage'' }
constructor Create(AFPImage: TFPCustomImage); overload; override;
{** Creates an image by copying the content of a ''TBitmap'' }
constructor Create(ABitmap: TBitmap; AUseTransparent: boolean = true); overload; override;
{** Creates an image of dimensions ''AWidth'' and ''AHeight'' and fills it with the opaque color ''Color'' }
constructor Create(AWidth, AHeight: integer; Color: TColor); overload; override;
{** Creates an image of dimensions ''AWidth'' and ''AHeight'' and fills it with ''Color'' }
constructor Create(AWidth, AHeight: integer; Color: TBGRAPixel); overload; override;
{** Creates an image by loading its content from the file ''AFilename''.
The encoding of the string is the default one for the operating system.
It is recommended to use the next constructor and UTF8 encoding }
constructor Create(AFilename: string); overload; override;
{** Creates an image by loading its content from the file ''AFilename''.
The boolean ''AIsUtf8Filename'' specifies if UTF8 encoding is assumed
for the filename }
constructor Create(AFilename: string; AIsUtf8: boolean); overload; override;
constructor Create(AFilename: string; AIsUtf8: boolean; AOptions: TBGRALoadingOptions); overload; override;
{** Creates an image by loading its content from the stream ''AStream'' }
constructor Create(AStream: TStream); overload; override;
{** Free the object and all its resources }
destructor Destroy; override;
{------------------------- Quasi-constructors -----------------------------}
{** Can only be called from an existing instance of ''TBGRABitmap''.
Creates a new instance with dimensions ''AWidth'' and ''AHeight'',
containing transparent pixels. }
function NewBitmap(AWidth, AHeight: integer): TBGRACustomBitmap; overload; override;
{** Can only be called from an existing instance of ''TBGRABitmap''.
Creates a new instance with dimensions ''AWidth'' and ''AHeight'',
and fills it with Color }
function NewBitmap(AWidth, AHeight: integer; Color: TBGRAPixel): TBGRACustomBitmap; overload; override;
{** Can only be called from an existing instance of ''TBGRABitmap''.
Creates a new instance with by loading its content
from the file ''Filename''. The encoding of the string
is the default one for the operating system }
function NewBitmap(Filename: string): TBGRACustomBitmap; overload; override;
{** Can only be called from an existing instance of ''TBGRABitmap''.
Creates a new instance with by loading its content
from the file ''Filename'' }
function NewBitmap(Filename: string; AIsUtf8: boolean): TBGRACustomBitmap; overload; override;
function NewBitmap(Filename: string; AIsUtf8: boolean; AOptions: TBGRALoadingOptions): TBGRACustomBitmap; overload; override;
{** Can only be called from an existing instance of ''TBGRABitmap''.
Creates an image by copying the content of a ''TFPCustomImage'' }
function NewBitmap(AFPImage: TFPCustomImage): TBGRACustomBitmap; overload; override;
{** Load image from a stream. The specified image reader is used }
procedure LoadFromStream(Str: TStream; Handler: TFPCustomImageReader; AOptions: TBGRALoadingOptions); overload; override;
{** Assign the content of the specified ''Source''. It can be a ''TBGRACustomBitmap'' or
a ''TFPCustomImage'' }
procedure Assign(Source: TPersistent); overload; override;
procedure Assign(Source: TBitmap; AUseTransparent: boolean); overload;
{** Stores the image in the stream without compression nor header }
procedure Serialize(AStream: TStream); override;
{** Reads the image in a stream that was previously serialized }
procedure Deserialize(AStream: TStream); override;
{** Stores an empty image (of size zero) }
class procedure SerializeEmpty(AStream: TStream);
{* Example:
<syntaxhighlight>
* var bmp1, bmp2: TBGRABitmap;
* begin
* bmp1 := TBGRABitmap.Create(100,100);
* bmp2 := bmp1.NewBitmap(100,100) as TBGRABitmap;
* ...
* end;</syntaxhighlight>
See tutorial 2 on [[BGRABitmap_tutorial_2|how to load and display an image]].
* See reference on [[TBGRACustomBitmap_and_IBGRAScanner#Load_and_save_files|loading and saving files]] }
{==== Pixel functions ====}
{** Checks if the specified point is in the clipping rectangle ''ClipRect'' }
function PtInClipRect(x, y: int32or64): boolean; inline;
{** Sets the pixel by replacing the content at (''x'',''y'') with the specified color.
Alpha value is set to 255 (opaque) }
procedure SetPixel(x, y: int32or64; c: TColor); overload; override;
{** Sets the pixel at (''x'',''y'') with the specified content }
procedure SetPixel(x, y: int32or64; c: TBGRAPixel); overload; override;
{** Applies a logical '''xor''' to the content of the pixel with the specified value.
This includes the alpha channel, so if you want to preserve the opacity, provide
a color ''c'' with alpha channel equal to zero }
procedure XorPixel(x, y: int32or64; c: TBGRAPixel); override;
{** Draws a pixel with gamma correction at (''x'',''y''). Pixel is supplied
in sRGB colorspace }
procedure DrawPixel(x, y: int32or64; c: TBGRAPixel); override;
{** Draws a pixel with the specified ''ADrawMode'' at (''x'',''y'').
Pixel is supplied in sRGB colorspace. Gamma correction may be applied
depending on the draw mode }{inherited
procedure DrawPixel(x, y: int32or64; c: TBGRAPixel; ADrawMode: TDrawMode); overload;
}{** Draws a pixel with gamma correction at (''x'',''y''). Pixel is supplied
in gamma expanded colorspace }
procedure DrawPixel(x, y: int32or64; ec: TExpandedPixel); override;
{** Draws a pixel without gamma correction at (''x'',''y''). Pixel is supplied
in sRGB colorspace }
procedure FastBlendPixel(x, y: int32or64; c: TBGRAPixel); override;
{** Erase the content of the pixel by reducing the value of the
alpha channel. ''alpha'' specifies how much to decrease.
If the resulting alpha reaches zero, the content
is replaced by ''BGRAPixelTransparent'' }
procedure ErasePixel(x, y: int32or64; alpha: byte); override;
{** Sets the alpha value at (''x'',''y''). If ''alpha'' = 0, the
pixel is replaced by ''BGRAPixelTransparent'' }
procedure AlphaPixel(x, y: int32or64; alpha: byte); override;
{** Returns the content of the specified pixel. If it is out of the
bounds of the picture, the result is ''BGRAPixelTransparent'' }
function GetPixel(x, y: int32or64): TBGRAPixel; override;
{** Computes the value of the pixel at a floating point coordiante
by interpolating the values of the pixels around it.
* There is a one pixel wide margin around the pixel where the pixels are
still considered inside. If ''smoothBorder'' is set to true, pixel fade
to transparent.
* If it is more out of the bounds, the result is ''BGRAPixelTransparent''.
* ''AResampleFilter'' specifies how pixels must be interpolated. Accepted
values are ''rfBox'', ''rfLinear'', ''rfHalfCosine'' and ''rfCosine'' }
function GetPixel(x, y: single; AResampleFilter: TResampleFilter = rfLinear; smoothBorder: boolean = true): TBGRAPixel; override;
{** Similar to previous ''GetPixel'' function, but the fractional part of
the coordinate is supplied with a number from 0 to 255. The actual
coordinate is (''x'' + ''fracX256''/256, ''y'' + ''fracY256''/256) }
function GetPixel256(x, y, fracX256,fracY256: int32or64; AResampleFilter: TResampleFilter = rfLinear; smoothBorder: boolean = true): TBGRAPixel; override;
{** Computes the value of the pixel at a floating point coordiante
by interpolating the values of the pixels around it. If the pixel
is out of bounds, the image is repeated.
* ''AResampleFilter'' specifies how pixels must be interpolated. Accepted
values are ''rfBox'', ''rfLinear'', ''rfHalfCosine'' and ''rfCosine'' }
function GetPixelCycle(x, y: single; AResampleFilter: TResampleFilter = rfLinear): TBGRAPixel; overload; override;
{** Similar to previous ''GetPixel'' function, but the fractional part of
the coordinate is supplied with a number from 0 to 255. The actual
coordinate is (''x'' + ''fracX256''/256, ''y'' + ''fracY256''/256) }
function GetPixelCycle256(x, y, fracX256,fracY256: int32or64; AResampleFilter: TResampleFilter = rfLinear): TBGRAPixel; overload; override;
{** Computes the value of the pixel at a floating point coordiante
by interpolating the values of the pixels around it. ''repeatX'' and
''repeatY'' specifies if the image is to be repeated or not.
* ''AResampleFilter'' specifies how pixels must be interpolated. Accepted
values are ''rfBox'', ''rfLinear'', ''rfHalfCosine'' and ''rfCosine'' }
function GetPixelCycle(x, y: single; AResampleFilter: TResampleFilter; repeatX: boolean; repeatY: boolean): TBGRAPixel; overload; override;
{** Similar to previous ''GetPixel'' function, but the fractional part of
the coordinate is supplied with a number from 0 to 255. The actual
coordinate is (''x'' + ''fracX256''/256, ''y'' + ''fracY256''/256) }
function GetPixelCycle256(x, y, fracX256,fracY256: int32or64; AResampleFilter: TResampleFilter; repeatX: boolean; repeatY: boolean): TBGRAPixel; overload; override;
{==== Drawing lines and polylines (integer coordinates) ====}
{* These functions do not take into account current pen style/cap/join.
See [[BGRABitmap tutorial 13|coordinate system]]. }
{** Replaces the content of the pixels at line ''y'' and
at columns ''x'' to ''x2'' included, using specified color }
procedure SetHorizLine(x, y, x2: int32or64; c: TBGRAPixel); override;
{** Applies xor to the pixels at line ''y'' and
at columns ''x'' to ''x2'' included, using specified color.
This includes the alpha channel, so if you want to preserve the
opacity, provide a color ''c'' with alpha channel equal to zero }
procedure XorHorizLine(x, y, x2: int32or64; c: TBGRAPixel); override;
{** Draws an horizontal line with gamma correction at line ''y'' and
at columns ''x'' to ''x2'' included, using specified color }
procedure DrawHorizLine(x, y, x2: int32or64; c: TBGRAPixel); override;
{** Draws an horizontal line with gamma correction at line ''y'' and
at columns ''x'' to ''x2'' included, using specified color }
procedure DrawHorizLine(x, y, x2: int32or64; ec: TExpandedPixel); override;
{** Draws an horizontal line with gamma correction at line ''y'' and
at columns ''x'' to ''x2'' included, using specified scanner
to get the source colors }{inherited
procedure DrawHorizLine(x, y, x2: int32or64; texture: IBGRAScanner); overload;
}{** Draws an horizontal line without gamma correction at line ''y'' and
at columns ''x'' to ''x2'' included, using specified color }
procedure FastBlendHorizLine(x, y, x2: int32or64; c: TBGRAPixel); override;
{** Draws an horizontal line at line ''y'' and
at columns ''x'' to ''x2'' included, using specified scanner
and the specified ''ADrawMode'' }
procedure HorizLine(x, y, x2: int32or64; texture: IBGRAScanner; ADrawMode : TDrawMode); override;
{** Draws an horizontal line at line ''y'' and
at columns ''x'' to ''x2'' included, using specified color
and the specified ''ADrawMode'' }{inherited
procedure HorizLine(x,y,x2: Int32or64; c: TBGRAPixel; ADrawMode: TDrawMode); overload;
}
{** Replaces the alpha value of the pixels at line ''y'' and
at columns ''x'' to ''x2'' included }
procedure AlphaHorizLine(x, y, x2: int32or64; alpha: byte); override;
{** Draws an horizontal line with gamma correction at line ''y'' and
at columns ''x'' to ''x2'' included, using specified color,
and with a transparency that increases with the color difference
with ''compare''. If the difference is greater than ''maxDiff'',
pixels are not changed }
procedure DrawHorizLineDiff(x, y, x2: int32or64; c, compare: TBGRAPixel;
maxDiff: byte); override;
{** Replaces a vertical line at column ''x'' and at row ''y'' to ''y2'' }
procedure SetVertLine(x, y, y2: int32or64; c: TBGRAPixel); override;
{** Xors a vertical line at column ''x'' and at row ''y'' to ''y2'' }
procedure XorVertLine(x, y, y2: int32or64; c: TBGRAPixel); override;
{** Draws a vertical line with gamma correction at column ''x'' and at row ''y'' to ''y2'' }
procedure DrawVertLine(x, y, y2: int32or64; c: TBGRAPixel); override;
{** Draws a vertical line without gamma correction at column ''x'' and at row ''y'' to ''y2'' }
procedure FastBlendVertLine(x, y, y2: int32or64; c: TBGRAPixel); override;
{** Replace alpha values in a vertical line at column ''x'' and at row ''y'' to ''y2'' }
procedure AlphaVertLine(x, y, y2: int32or64; alpha: byte); override;
{** Draws a vertical line with the specified draw mode at column ''x'' and at row ''y'' to ''y2'' }{inherited
procedure VertLine(x,y,y2: Int32or64; c: TBGRAPixel; ADrawMode: TDrawMode);
}
{** Draws an aliased line from (x1,y1) to (x2,y2) using Bresenham's algorithm
''c'' specifies the color. ''DrawLastPixel'' specifies if (x2,y2) must be drawn.
''ADrawMode'' specifies the mode to use when drawing the pixels }
procedure DrawLine(x1, y1, x2, y2: integer; c: TBGRAPixel; DrawLastPixel: boolean; ADrawMode: TDrawMode = dmDrawWithTransparency); override;
{** Draws an antialiased line from (x1,y1) to (x2,y2) using an improved version of Bresenham's algorithm
''c'' specifies the color. ''DrawLastPixel'' specifies if (x2,y2) must be drawn }
procedure DrawLineAntialias(x1, y1, x2, y2: integer; c: TBGRAPixel; DrawLastPixel: boolean); override;
{** Draws an antialiased line with two colors ''c1'' and ''c2'' as dashes of lenght ''dashLen'' }
procedure DrawLineAntialias(x1, y1, x2, y2: integer; c1, c2: TBGRAPixel; dashLen: integer; DrawLastPixel: boolean); override;
{** Draws an antialiased line with two colors ''c1'' and ''c2'' as dashes of lenght ''dashLen''.
''DashPos'' can be used to specify the start dash position and to retrieve the dash position at the end
of the line, in order to draw a polyline with consistent dashes }
procedure DrawLineAntialias(x1, y1, x2, y2: integer; c1, c2: TBGRAPixel; dashLen: integer; DrawLastPixel: boolean; var DashPos: integer); override;
{** Erases the line from (x1,y1) to (x2,y2) using Bresenham's algorithm.
''alpha'' specifies how much to decrease. If ''alpha'' = 0, nothing
is changed and if ''alpha'' = 255, all pixels become transparent.
''DrawListPixel'' specifies if (x2,y2) must be changed }
procedure EraseLine(x1, y1, x2, y2: integer; alpha: byte; DrawLastPixel: boolean); override;
{** Erases the line from (x1,y1) to (x2,y2) width antialiasing.
''alpha'' specifies how much to decrease. If ''alpha'' = 0, nothing
is changed and if ''alpha'' = 255, all pixels become transparent.
''DrawListPixel'' specifies if (x2,y2) must be changed }
procedure EraseLineAntialias(x1, y1, x2, y2: integer; alpha: byte; DrawLastPixel: boolean); override;
{==== Drawing lines and polylines (floating point coordinates) ====}
{* These functions use the current pen style/cap/join. The parameter ''w''
specifies the width of the line and the base unit for dashes.
See [[BGRABitmap tutorial 13|coordinate system]]. }
{** Draws a line from (x1,y1) to (x2,y2) using current pen style/cap/join }
procedure DrawLineAntialias(x1, y1, x2, y2: single; c: TBGRAPixel; w: single); override;
{** Draws a line from (x1,y1) to (x2,y2) using current pen style/cap/join.
''texture'' specifies the source color to use when filling the line }
procedure DrawLineAntialias(x1, y1, x2, y2: single; texture: IBGRAScanner; w: single); override;
{** Draws a line from (x1,y1) to (x2,y2) using current pen style/cap/join.
''Closed'' specifies if the end of the line is closed. If it is not closed,
a space is left so that the next line can fit }
procedure DrawLineAntialias(x1, y1, x2, y2: single; c: TBGRAPixel; w: single; ClosedCap: boolean); override;
{** Same as above with ''texture'' specifying the source color to use when filling the line }
procedure DrawLineAntialias(x1, y1, x2, y2: single; texture: IBGRAScanner; w: single; ClosedCap: boolean); override;
{** Draws a polyline using current pen style/cap/join }
procedure DrawPolyLineAntialias(const points: array of TPointF; c: TBGRAPixel; w: single); override;
{** Draws a polyline using current pen style/cap/join.
''texture'' specifies the source color to use when filling the line }
procedure DrawPolyLineAntialias(const points: array of TPointF; texture: IBGRAScanner; w: single); override;
{** Draws a polyline using current pen style/cap/join.
''Closed'' specifies if the end of the line is closed. If it is not closed,
a space is left so that the next line can fit }
procedure DrawPolyLineAntialias(const points: array of TPointF; c: TBGRAPixel; w: single; ClosedCap: boolean); override;
procedure DrawPolyLineAntialias(const points: array of TPointF; texture: IBGRAScanner; w: single; ClosedCap: boolean); override;
{** Draws a polyline using current pen style/cap/join.
''fillcolor'' specifies a color to fill the polygon formed by the points }
procedure DrawPolyLineAntialias(const points: array of TPointF; c: TBGRAPixel; w: single; fillcolor: TBGRAPixel); override;
{** Draws a polyline using current pen style/cap/join.
The last point considered as a join with the first point if it has
the same coordinate }
procedure DrawPolyLineAntialiasAutocycle(const points: array of TPointF; c: TBGRAPixel; w: single); override;
procedure DrawPolyLineAntialiasAutocycle(const points: array of TPointF; texture: IBGRAScanner; w: single); override;
{** Draws a polygon using current pen style/cap/join.
The polygon is always closed. You don't need to set the last point
to be the same as the first point }
procedure DrawPolygonAntialias(const points: array of TPointF; c: TBGRAPixel; w: single); override;
{** Draws a polygon using current pen style/cap/join.
The polygon is always closed. You don't need to set the last point
to be the same as the first point }
procedure DrawPolygonAntialias(const points: array of TPointF; texture: IBGRAScanner; w: single); override;
{** Draws a filled polygon using current pen style/cap/join.
The polygon is always closed. You don't need to set the last point
to be the same as the first point. }
procedure DrawPolygonAntialias(const points: array of TPointF; c: TBGRAPixel; w: single; fillcolor: TBGRAPixel); override;
{** Erases a line from (x1,y1) to (x2,y2) using current pen style/cap/join }
procedure EraseLineAntialias(x1, y1, x2, y2: single; alpha: byte; w: single); override;
{** Erases a line from (x1,y1) to (x2,y2) using current pen style/cap/join.
''Closed'' specifies if the end of the line is closed. If it is not closed,
a space is left so that the next line can fit }
procedure EraseLineAntialias(x1, y1, x2, y2: single; alpha: byte; w: single; Closed: boolean); override;
{** Erases a polyline using current pen style/cap/join }
procedure ErasePolyLineAntialias(const points: array of TPointF; alpha: byte; w: single); override;
{==== Rectangles (integer coordinates) ====}
{* The integer coordinates of rectangles interpreted such that
that the bottom/right pixels are not drawn. The width is equal
to x2-x, and pixels are drawn from x to x2-1. If x = x2, then nothing
is drawn. See [[BGRABitmap tutorial 13|coordinate system]].
* These functions do not take into account current pen style/cap/join.
They draw a continuous 1-pixel width border }
{** Draw a size border of a rectangle,
using the specified ''mode'' }
procedure Rectangle(x, y, x2, y2: integer; c: TBGRAPixel; mode: TDrawMode); override;
{** Draw a filled rectangle with a border of color ''BorderColor'',
using the specified ''mode'' }
procedure Rectangle(x, y, x2, y2: integer; BorderColor, FillColor: TBGRAPixel; mode: TDrawMode); override;
{** Fills completely a rectangle, without any border, with the specified ''mode'' }
procedure FillRect(x, y, x2, y2: integer; c: TBGRAPixel; mode: TDrawMode); overload; override;
{** Fills completely a rectangle, without any border, with the specified ''texture'' and
with the specified ''mode'' }
procedure FillRect(x, y, x2, y2: integer; texture: IBGRAScanner; mode: TDrawMode; AScanOffset: TPoint); overload; override;
procedure FillRect(x, y, x2, y2: integer; texture: IBGRAScanner; mode: TDrawMode; AScanOffset: TPoint; ditheringAlgorithm: TDitheringAlgorithm); overload; override;
{** Sets the alpha value within the specified rectangle }
procedure AlphaFillRect(x, y, x2, y2: integer; alpha: byte); override;
{** Draws a filled round rectangle, with corners having an elliptical diameter of ''DX'' and ''DY'' }
procedure RoundRect(X1, Y1, X2, Y2: integer; DX, DY: integer; BorderColor, FillColor: TBGRAPixel; ADrawMode: TDrawMode = dmDrawWithTransparency); override;
{** Draws a round rectangle, with corners having an elliptical diameter of ''DX'' and ''DY'' }
procedure RoundRect(X1, Y1, X2, Y2: integer; DX, DY: integer; BorderColor: TBGRAPixel; ADrawMode: TDrawMode = dmDrawWithTransparency); override;
{==== Rectangles and ellipses (floating point coordinates) ====}
{* These functions use the current pen style/cap/join. The parameter ''w''
specifies the width of the line and the base unit for dashes
* The coordinates are pixel-centered, so that when filling a rectangle,
if the supplied values are integers, the border will be half transparent.
If you want the border to be completely filled, you can subtract/add
0.5 to the coordinates to include the remaining thin border.
See [[BGRABitmap tutorial 13|coordinate system]]. }
{** Draws a rectangle with antialiasing and fills it with color ''back''.
Note that the pixel (x2,y2) is included contrary to integer coordinates }
procedure RectangleAntialias(x, y, x2, y2: single; c: TBGRAPixel; w: single; back: TBGRAPixel); override;
{** Draws a rectangle with antialiasing. Note that the pixel (x2,y2) is
included contrary to integer coordinates }
procedure RectangleAntialias(x, y, x2, y2: single; texture: IBGRAScanner; w: single); override;
{** Fills a rectangle with antialiasing. For example (-0.5,-0.5,0.5,0.5)
fills one pixel }
procedure FillRectAntialias(x, y, x2, y2: single; c: TBGRAPixel; pixelCenteredCoordinates: boolean = true); overload; override;
{** Fills a rectangle with a texture }
procedure FillRectAntialias(x, y, x2, y2: single; texture: IBGRAScanner; pixelCenteredCoordinates: boolean = true); overload; override;
{** Erases the content of a rectangle with antialiasing }
procedure EraseRectAntialias(x, y, x2, y2: single; alpha: byte; pixelCenteredCoordinates: boolean = true); override;
{** Draws a rounded rectangle border with antialiasing. The corners have an
elliptical radius of ''rx'' and ''ry''. ''options'' specifies how to
draw the corners. See [[BGRABitmap Geometry types|geometry types]] }
procedure RoundRectAntialias(x,y,x2,y2,rx,ry: single; c: TBGRAPixel; w: single; options: TRoundRectangleOptions = []); overload; override;
{** Draws a rounded rectangle border with the specified texture.
The corners have an elliptical radius of ''rx'' and ''ry''.
''options'' specifies how to draw the corners.
See [[BGRABitmap Geometry types|geometry types]] }
procedure RoundRectAntialias(x,y,x2,y2,rx,ry: single; texture: IBGRAScanner; w: single; options: TRoundRectangleOptions = []); overload; override;
{** Draws and fills a round rectangle }
procedure RoundRectAntialias(x,y,x2,y2,rx,ry: single; pencolor: TBGRAPixel; w: single; fillcolor: TBGRAPixel; options: TRoundRectangleOptions = []); overload; override;
{** Draws and fills a round rectangle with textures }
procedure RoundRectAntialias(x,y,x2,y2,rx,ry: single; penTexture: IBGRAScanner; w: single; fillTexture: IBGRAScanner; options: TRoundRectangleOptions = []); overload; override;
{** Fills a rounded rectangle with antialiasing. The corners have an
elliptical radius of ''rx'' and ''ry''. ''options'' specifies how to
draw the corners. See [[BGRABitmap Geometry types|geometry types]] }
procedure FillRoundRectAntialias(x,y,x2,y2,rx,ry: single; c: TBGRAPixel; options: TRoundRectangleOptions = []; pixelCenteredCoordinates: boolean = true); overload; override;
{** Fills a rounded rectangle with a texture }
procedure FillRoundRectAntialias(x,y,x2,y2,rx,ry: single; texture: IBGRAScanner; options: TRoundRectangleOptions = []; pixelCenteredCoordinates: boolean = true); overload; override;
{** Erases the content of a rounded rectangle with a texture }
procedure EraseRoundRectAntialias(x,y,x2,y2,rx,ry: single; alpha: byte; options: TRoundRectangleOptions = []; pixelCenteredCoordinates: boolean = true); overload; override;
{** Draws an ellipse with antialising. ''rx'' is the horizontal radius and
''ry'' the vertical radius }
procedure EllipseAntialias(x, y, rx, ry: single; c: TBGRAPixel; w: single); overload; override;
{** Draws an ellipse border with a ''texture'' }
procedure EllipseAntialias(x, y, rx, ry: single; texture: IBGRAScanner; w: single); overload; override;
{** Draws and fills an ellipse }
procedure EllipseAntialias(x, y, rx, ry: single; c: TBGRAPixel; w: single; back: TBGRAPixel); overload; override;
{** Fills an ellipse }
procedure FillEllipseAntialias(x, y, rx, ry: single; c: TBGRAPixel); overload; override;
{** Fills an ellipse with a ''texture'' }
procedure FillEllipseAntialias(x, y, rx, ry: single; texture: IBGRAScanner); overload; override;
{** Fills an ellipse with a gradient of color. ''outercolor'' specifies
the end color of the gradient on the border of the ellipse and
''innercolor'' the end color of the gradient at the center of the
ellipse }
procedure FillEllipseLinearColorAntialias(x, y, rx, ry: single; outercolor, innercolor: TBGRAPixel); override;
{** Erases the content of an ellipse }
procedure EraseEllipseAntialias(x, y, rx, ry: single; alpha: byte); override;
{==== Polygons and path ====}
procedure FillPoly(const points: array of TPointF; c: TBGRAPixel; drawmode: TDrawMode; APixelCenteredCoordinates: boolean = true); overload; override;
procedure FillPoly(const points: array of TPointF; texture: IBGRAScanner; drawmode: TDrawMode; APixelCenteredCoordinates: boolean = true); overload; override;
procedure FillPolyAntialias(const points: array of TPointF; c: TBGRAPixel; APixelCenteredCoordinates: boolean = true); overload; override;
procedure FillPolyAntialias(const points: array of TPointF; texture: IBGRAScanner; APixelCenteredCoordinates: boolean = true); overload; override;
procedure ErasePoly(const points: array of TPointF; alpha: byte; APixelCenteredCoordinates: boolean = true); override;
procedure ErasePolyAntialias(const points: array of TPointF; alpha: byte; APixelCenteredCoordinates: boolean = true); override;
procedure FillTriangleLinearColor(pt1,pt2,pt3: TPointF; c1,c2,c3: TBGRAPixel); override;
procedure FillTriangleLinearColorAntialias(pt1,pt2,pt3: TPointF; c1,c2,c3: TBGRAPixel); override;
procedure FillTriangleLinearMapping(pt1,pt2,pt3: TPointF; texture: IBGRAScanner; tex1, tex2, tex3: TPointF; TextureInterpolation: Boolean= True); override;
procedure FillTriangleLinearMappingLightness(pt1,pt2,pt3: TPointF; texture: IBGRAScanner; tex1, tex2, tex3: TPointF; light1,light2,light3: BGRAWord; TextureInterpolation: Boolean= True); override;
procedure FillTriangleLinearMappingAntialias(pt1,pt2,pt3: TPointF; texture: IBGRAScanner; tex1, tex2, tex3: TPointF); override;
procedure FillQuadLinearColor(pt1,pt2,pt3,pt4: TPointF; c1,c2,c3,c4: TBGRAPixel); override;
procedure FillQuadLinearColorAntialias(pt1,pt2,pt3,pt4: TPointF; c1,c2,c3,c4: TBGRAPixel); override;
procedure FillQuadLinearMapping(pt1,pt2,pt3,pt4: TPointF; texture: IBGRAScanner; tex1, tex2, tex3, tex4: TPointF; TextureInterpolation: Boolean= True; ACulling: TFaceCulling = fcNone); override;
procedure FillQuadLinearMappingLightness(pt1,pt2,pt3,pt4: TPointF; texture: IBGRAScanner; tex1, tex2, tex3, tex4: TPointF; light1,light2,light3,light4: BGRAWord; TextureInterpolation: Boolean= True); override;
procedure FillQuadLinearMappingAntialias(pt1,pt2,pt3,pt4: TPointF; texture: IBGRAScanner; tex1, tex2, tex3, tex4: TPointF; ACulling: TFaceCulling = fcNone); override;
procedure FillQuadPerspectiveMapping(pt1,pt2,pt3,pt4: TPointF; texture: IBGRAScanner; tex1, tex2, tex3, tex4: TPointF; ADrawMode: TDrawMode = dmDrawWithTransparency); override;
procedure FillQuadPerspectiveMapping(pt1,pt2,pt3,pt4: TPointF; texture: IBGRAScanner; tex1, tex2, tex3, tex4: TPointF; ACleanBorders: TRect; ADrawMode: TDrawMode = dmDrawWithTransparency); override;
procedure FillQuadPerspectiveMappingAntialias(pt1,pt2,pt3,pt4: TPointF; texture: IBGRAScanner; tex1, tex2, tex3, tex4: TPointF); override;
procedure FillQuadPerspectiveMappingAntialias(pt1,pt2,pt3,pt4: TPointF; texture: IBGRAScanner; tex1, tex2, tex3, tex4: TPointF; ACleanBorders: TRect); override;
procedure FillQuadAffineMapping(Orig,HAxis,VAxis: TPointF; AImage: TBGRACustomBitmap; APixelCenteredCoordinates: boolean = true; ADrawMode: TDrawMode = dmDrawWithTransparency; AOpacity: byte = 255); override;
procedure FillQuadAffineMappingAntialias(Orig,HAxis,VAxis: TPointF; AImage: TBGRACustomBitmap; APixelCenteredCoordinates: boolean = true; AOpacity: byte = 255); override;
procedure FillPolyLinearMapping(const points: array of TPointF; texture: IBGRAScanner; texCoords: array of TPointF; TextureInterpolation: Boolean); override;
procedure FillPolyLinearMappingLightness(const points: array of TPointF; texture: IBGRAScanner; texCoords: array of TPointF; lightnesses: array of BGRAWord; TextureInterpolation: Boolean); override;
procedure FillPolyLinearColor(const points: array of TPointF; AColors: array of TBGRAPixel); override;
procedure FillPolyPerspectiveMapping(const points: array of TPointF; const pointsZ: array of single; texture: IBGRAScanner; texCoords: array of TPointF; TextureInterpolation: Boolean; zbuffer: psingle = nil); override;
procedure FillPolyPerspectiveMappingLightness(const points: array of TPointF; const pointsZ: array of single; texture: IBGRAScanner; texCoords: array of TPointF; lightnesses: array of BGRAWord; TextureInterpolation: Boolean; zbuffer: psingle = nil); override;
procedure FillShape(shape: TBGRACustomFillInfo; c: TBGRAPixel; drawmode: TDrawMode); overload; override;
procedure FillShape(shape: TBGRACustomFillInfo; texture: IBGRAScanner; drawmode: TDrawMode); overload; override;
procedure FillShapeAntialias(shape: TBGRACustomFillInfo; c: TBGRAPixel); overload; override;
procedure FillShapeAntialias(shape: TBGRACustomFillInfo; texture: IBGRAScanner); overload; override;
procedure EraseShape(shape: TBGRACustomFillInfo; alpha: byte); override;
procedure EraseShapeAntialias(shape: TBGRACustomFillInfo; alpha: byte); override;
procedure DrawPath(APath: IBGRAPath; AStrokeColor: TBGRAPixel; AWidth: single; AFillColor: TBGRAPixel); overload; override;
procedure DrawPath(APath: IBGRAPath; AStrokeTexture: IBGRAScanner; AWidth: single; AFillColor: TBGRAPixel); overload; override;
procedure DrawPath(APath: IBGRAPath; AStrokeColor: TBGRAPixel; AWidth: single; AFillTexture: IBGRAScanner); overload; override;
procedure DrawPath(APath: IBGRAPath; AStrokeTexture: IBGRAScanner; AWidth: single; AFillTexture: IBGRAScanner); overload; override;
procedure DrawPath(APath: IBGRAPath; AStrokeColor: TBGRAPixel; AWidth: single); overload; override;
procedure DrawPath(APath: IBGRAPath; AStrokeTexture: IBGRAScanner; AWidth: single); overload; override;
procedure FillPath(APath: IBGRAPath; AFillColor: TBGRAPixel); overload; override;
procedure FillPath(APath: IBGRAPath; AFillTexture: IBGRAScanner); overload; override;
procedure ErasePath(APath: IBGRAPath; alpha: byte); overload; override;
procedure DrawPath(APath: IBGRAPath; AMatrix: TAffineMatrix; AStrokeColor: TBGRAPixel; AWidth: single; AFillColor: TBGRAPixel); overload; override;
procedure DrawPath(APath: IBGRAPath; AMatrix: TAffineMatrix; AStrokeTexture: IBGRAScanner; AWidth: single; AFillColor: TBGRAPixel); overload; override;
procedure DrawPath(APath: IBGRAPath; AMatrix: TAffineMatrix; AStrokeColor: TBGRAPixel; AWidth: single; AFillTexture: IBGRAScanner); overload; override;
procedure DrawPath(APath: IBGRAPath; AMatrix: TAffineMatrix; AStrokeTexture: IBGRAScanner; AWidth: single; AFillTexture: IBGRAScanner); overload; override;
procedure DrawPath(APath: IBGRAPath; AMatrix: TAffineMatrix; AStrokeColor: TBGRAPixel; AWidth: single); overload; override;
procedure DrawPath(APath: IBGRAPath; AMatrix: TAffineMatrix; AStrokeTexture: IBGRAScanner; AWidth: single); overload; override;
procedure FillPath(APath: IBGRAPath; AMatrix: TAffineMatrix; AFillColor: TBGRAPixel); overload; override;
procedure FillPath(APath: IBGRAPath; AMatrix: TAffineMatrix; AFillTexture: IBGRAScanner); overload; override;
procedure ErasePath(APath: IBGRAPath; AMatrix: TAffineMatrix; alpha: byte); overload; override;
procedure ArrowStartAsNone; override;
procedure ArrowStartAsClassic(AFlipped: boolean = false; ACut: boolean = false; ARelativePenWidth: single = 1); override;
procedure ArrowStartAsTriangle(ABackOffset: single = 0; ARounded: boolean = false; AHollow: boolean = false; AHollowPenWidth: single = 0.5); override;
procedure ArrowStartAsTail; override;
procedure ArrowEndAsNone; override;
procedure ArrowEndAsClassic(AFlipped: boolean = false; ACut: boolean = false; ARelativePenWidth: single = 1); override;
procedure ArrowEndAsTriangle(ABackOffset: single = 0; ARounded: boolean = false; AHollow: boolean = false; AHollowPenWidth: single = 0.5); override;
procedure ArrowEndAsTail; override;
{ Draws the UTF8 encoded string, with color c.
If align is taLeftJustify, (x,y) is the top-left corner.
If align is taCenter, (x,y) is at the top and middle of the text.
If align is taRightJustify, (x,y) is the top-right corner.
The value of FontOrientation is taken into account, so that the text may be rotated. }
procedure TextOut(x, y: single; sUTF8: string; c: TBGRAPixel; align: TAlignment; ARightToLeft: boolean); overload; override;
{ Same as above functions, except that the text is filled using texture.
The value of FontOrientation is taken into account, so that the text may be rotated. }
procedure TextOut(x, y: single; sUTF8: string; texture: IBGRAScanner; align: TAlignment; ARightToLeft: boolean); overload; override;
{ Same as above, except that the orientation is specified, overriding the value of the property FontOrientation. }
procedure TextOutAngle(x, y: single; orientationTenthDegCCW: integer; sUTF8: string; c: TBGRAPixel; align: TAlignment); overload; override;
procedure TextOutAngle(x, y: single; orientationTenthDegCCW: integer; sUTF8: string; texture: IBGRAScanner; align: TAlignment); overload; override;
procedure TextOutCurved(ACursor: TBGRACustomPathCursor; sUTF8: string; AColor: TBGRAPixel; AAlign: TAlignment; ALetterSpacing: single); overload; override;
procedure TextOutCurved(ACursor: TBGRACustomPathCursor; sUTF8: string; ATexture: IBGRAScanner; AAlign: TAlignment; ALetterSpacing: single); overload; override;
procedure TextMultiline(ALeft,ATop,AWidth: single; sUTF8: string; c: TBGRAPixel; AAlign: TBidiTextAlignment = btaNatural; AVertAlign: TTextLayout = tlTop; AParagraphSpacing: single = 0); overload; override;
procedure TextMultiline(ALeft,ATop,AWidth: single; sUTF8: string; ATexture: IBGRAScanner; AAlign: TBidiTextAlignment = btaNatural; AVertAlign: TTextLayout = tlTop; AParagraphSpacing: single = 0); overload; override;
{ Draw the UTF8 encoded string at the coordinate (x,y), clipped inside the rectangle ARect.
Additional style information is provided by the style parameter.
The color c or texture is used to fill the text. No rotation is applied. }
procedure TextRect(ARect: TRect; x, y: integer; sUTF8: string; style: TTextStyle; c: TBGRAPixel); overload; override;
procedure TextRect(ARect: TRect; x, y: integer; sUTF8: string; style: TTextStyle; texture: IBGRAScanner); overload; override;
{ Returns the total size of the string provided using the current font.
Orientation is not taken into account, so that the width is along the text. End of lines are stripped from the string. }
function TextSize(sUTF8: string): TSize; override;
{ Returns the affine box of the string provided using the current font.
Orientation is taken into account. End of lines are stripped from the string. }
function TextAffineBox(sUTF8: string): TAffineBox; override;
{ Returns the total size of a paragraph i.e. with BGRAWord break }
function TextSize(sUTF8: string; AMaxWidth: integer): TSize; override;
function TextSize(sUTF8: string; AMaxWidth: integer; ARightToLeft: boolean): TSize; override;
function TextFitInfo(sUTF8: string; AMaxWidth: integer): integer; override;
{Spline}
function ComputeClosedSpline(const APoints: array of TPointF; AStyle: TSplineStyle): ArrayOfTPointF; override;
function ComputeOpenedSpline(const APoints: array of TPointF; AStyle: TSplineStyle): ArrayOfTPointF; override;
function ComputeBezierCurve(const ACurve: TCubicBezierCurve): ArrayOfTPointF; overload; override;
function ComputeBezierCurve(const ACurve: TQuadraticBezierCurve): ArrayOfTPointF; overload; override;
function ComputeBezierSpline(const ASpline: array of TCubicBezierCurve): ArrayOfTPointF; overload; override;
function ComputeBezierSpline(const ASpline: array of TQuadraticBezierCurve): ArrayOfTPointF; overload; override;
function ComputeWidePolyline(const points: array of TPointF; w: single): ArrayOfTPointF; overload; override;
function ComputeWidePolyline(const points: array of TPointF; w: single; ClosedCap: boolean): ArrayOfTPointF; overload; override;
function ComputeWidePolygon(const points: array of TPointF; w: single): ArrayOfTPointF; overload; override;
function ComputeEllipseContour(x,y,rx,ry: single; quality: single = 1): ArrayOfTPointF; override;
function ComputeEllipseBorder(x,y,rx,ry,w: single; quality: single = 1): ArrayOfTPointF; override;
function ComputeArc65536(x,y,rx,ry: single; start65536,end65536: BGRAWord; quality: single = 1): ArrayOfTPointF; override;
function ComputeArcRad(x,y,rx,ry: single; startRad,endRad: single; quality: single = 1): ArrayOfTPointF; override;
function ComputeRoundRect(x1,y1,x2,y2,rx,ry: single; quality: single = 1): ArrayOfTPointF; overload; override;
function ComputeRoundRect(x1,y1,x2,y2,rx,ry: single; options: TRoundRectangleOptions; quality: single = 1): ArrayOfTPointF; overload; override;
function ComputePie65536(x,y,rx,ry: single; start65536,end65536: BGRAWord; quality: single = 1): ArrayOfTPointF; override;
function ComputePieRad(x,y,rx,ry: single; startRad,endRad: single; quality: single = 1): ArrayOfTPointF; override;
{Filling}
procedure NoClip; override;
procedure Fill(texture: IBGRAScanner; mode: TDrawMode); overload; override;
procedure Fill(texture: IBGRAScanner); overload; override;
procedure Fill(c: TBGRAPixel; start, Count: integer); overload; override;
procedure DrawPixels(c: TBGRAPixel; start, Count: integer); override;
procedure AlphaFill(alpha: byte; start, Count: integer); override;
procedure FillMask(x,y: integer; AMask: TBGRACustomBitmap; color: TBGRAPixel; ADrawMode: TDrawMode); override;
procedure FillMask(x,y: integer; AMask: TBGRACustomBitmap; texture: IBGRAScanner; ADrawMode: TDrawMode; AOpacity: byte = 255); override;
procedure FillClearTypeMask(x,y: integer; xThird: integer; AMask: TBGRACustomBitmap; color: TBGRAPixel; ARGBOrder: boolean = true); override;
procedure FillClearTypeMask(x,y: integer; xThird: integer; AMask: TBGRACustomBitmap; texture: IBGRAScanner; ARGBOrder: boolean = true); override;
procedure ReplaceColor(before, after: TColor); override;
procedure ReplaceColor(before, after: TBGRAPixel); override;
procedure ReplaceColor(ABounds: TRect; before, after: TColor); override;
procedure ReplaceColor(ABounds: TRect; before, after: TBGRAPixel); override;
procedure ReplaceTransparent(after: TBGRAPixel); override;
procedure ReplaceTransparent(ABounds: TRect; after: TBGRAPixel); override;
procedure ParallelFloodFill(X, Y: integer; Dest: TBGRACustomBitmap; Color: TBGRAPixel;
mode: TFloodfillMode; Tolerance: byte = 0); override;
procedure GradientFill(x, y, x2, y2: integer; c1, c2: TBGRAPixel;
gtype: TGradientType; o1, o2: TPointF; mode: TDrawMode;
gammaColorCorrection: boolean = True; Sinus: Boolean=False;
ditherAlgo: TDitheringAlgorithm = daNearestNeighbor); override;
procedure GradientFill(x, y, x2, y2: integer; gradient: TBGRACustomGradient;
gtype: TGradientType; o1, o2: TPointF; mode: TDrawMode;
Sinus: Boolean=False; ditherAlgo: TDitheringAlgorithm = daNearestNeighbor); override;
function CreateBrushTexture(ABrushStyle: TBrushStyle; APatternColor, ABackgroundColor: TBGRAPixel;
AWidth: integer = 8; AHeight: integer = 8; APenWidth: single = 1): TBGRACustomBitmap; override;
function ScanAtInteger(X,Y: integer): TBGRAPixel; override;
procedure ScanMoveTo(X,Y: Integer); override;
function ScanNextPixel: TBGRAPixel; override;
function ScanAt(X,Y: Single): TBGRAPixel; override;
function IsScanPutPixelsDefined: boolean; override;
procedure ScanPutPixels(pdest: PBGRAPixel; count: integer; mode: TDrawMode); override;
{Canvas drawing functions}
procedure Draw(ACanvas: TCanvas; x, y: integer; Opaque: boolean = True); overload; override;
procedure Draw(ACanvas: TCanvas; Rect: TRect; Opaque: boolean = True); overload; override;
procedure InvalidateBitmap; override; //call if you modify with Scanline
procedure LoadFromBitmapIfNeeded; override; //call to ensure that bitmap data is up to date
{BGRA bitmap functions}
procedure CrossFade(ARect: TRect; Source1, Source2: IBGRAScanner; AFadePosition: byte; mode: TDrawMode = dmDrawWithTransparency); overload; override;
procedure CrossFade(ARect: TRect; Source1, Source2: IBGRAScanner; AFadeMask: IBGRAScanner; mode: TDrawMode = dmDrawWithTransparency); overload; override;
procedure PutImage(x, y: integer; Source: TBGRACustomBitmap; mode: TDrawMode; AOpacity: byte = 255); overload; override;
procedure PutImageAffine(AMatrix: TAffineMatrix; Source: TBGRACustomBitmap; AOutputBounds: TRect; AResampleFilter: TResampleFilter; AMode: TDrawMode; AOpacity: Byte=255); overload; override;
function GetImageAffineBounds(AMatrix: TAffineMatrix; ASourceBounds: TRect; AClipOutput: boolean = true): TRect; overload; override;
function IsAffineRoughlyTranslation(AMatrix: TAffineMatrix; ASourceBounds: TRect): boolean; override;
procedure StretchPutImage(ARect: TRect; Source: TBGRACustomBitmap; mode: TDrawMode; AOpacity: byte = 255); override;
procedure BlendImage(x, y: integer; Source: TBGRACustomBitmap; operation: TBlendOperation); override;
procedure BlendImageOver(x, y: integer; Source: TBGRACustomBitmap; operation: TBlendOperation; AOpacity: byte = 255;
ALinearBlend: boolean = false); override;
function GetPart(ARect: TRect): TBGRACustomBitmap; override;
function GetPtrBitmap(Top,Bottom: Integer): TBGRACustomBitmap; override;
function Duplicate(DuplicateProperties: Boolean = False; DuplicateXorMask: Boolean = False) : TBGRACustomBitmap; override;
procedure CopyPropertiesTo(ABitmap: TBGRADefaultBitmap);
function Equals(comp: TBGRACustomBitmap): boolean; overload; override;
function Equals(comp: TBGRAPixel): boolean; overload; override;
function GetDifferenceBounds(ABitmap: TBGRACustomBitmap): TRect; override;
function MakeBitmapCopy(BackgroundColor: TColor): TBitmap; override;
function Resample(newWidth, newHeight: integer;
mode: TResampleMode = rmFineResample): TBGRACustomBitmap; override;
procedure VerticalFlip(ARect: TRect); overload; override;
procedure HorizontalFlip(ARect: TRect); overload; override;
function RotateCW: TBGRACustomBitmap; override;
function RotateCCW: TBGRACustomBitmap; override;
procedure Negative; override;
procedure NegativeRect(ABounds: TRect); override;
procedure LinearNegative; override;
procedure LinearNegativeRect(ABounds: TRect); override;
procedure InplaceGrayscale(AGammaCorrection: boolean = true); overload; override;
procedure InplaceGrayscale(ABounds: TRect; AGammaCorrection: boolean = true); overload; override;
procedure InplaceNormalize(AEachChannel: boolean = True); overload; override;
procedure InplaceNormalize(ABounds: TRect; AEachChannel: boolean = True); overload; override;
procedure SwapRedBlue; override;
procedure SwapRedBlue(ARect: TRect); override;
procedure GrayscaleToAlpha; override;
procedure AlphaToGrayscale; override;
procedure ApplyMask(mask: TBGRACustomBitmap; ARect: TRect; AMaskRectTopLeft: TPoint); overload; override;
function GetMaskFromAlpha: TBGRACustomBitmap; override;
procedure ApplyGlobalOpacity(alpha: byte); override;
procedure ApplyGlobalOpacity(ABounds: TRect; alpha: byte); override;
procedure ConvertToLinearRGB; override;
procedure ConvertFromLinearRGB; override;
procedure DrawCheckers(ARect: TRect; AColorEven,AColorOdd: TBGRAPixel);
{Filters}
function FilterSmartZoom3(Option: TMedianOption): TBGRACustomBitmap; override;
function FilterMedian(Option: TMedianOption): TBGRACustomBitmap; override;
function FilterSmooth: TBGRACustomBitmap; override;
function FilterSharpen(Amount: single = 1): TBGRACustomBitmap; overload; override;
function FilterSharpen(ABounds: TRect; Amount: single = 1): TBGRACustomBitmap; overload; override;
function FilterContour: TBGRACustomBitmap; override;
function FilterPixelate(pixelSize: integer; useResample: boolean; filter: TResampleFilter = rfLinear): TBGRACustomBitmap; override;
function FilterBlurRadial(radius: single; blurType: TRadialBlurType): TBGRACustomBitmap; overload; override;
function FilterBlurRadial(ABounds: TRect; radius: single; blurType: TRadialBlurType): TBGRACustomBitmap; overload; override;
function FilterBlurRadial(radiusX, radiusY: single; blurType: TRadialBlurType): TBGRACustomBitmap; overload; override;
function FilterBlurRadial(ABounds: TRect; radiusX, radiusY: single; blurType: TRadialBlurType): TBGRACustomBitmap; overload; override;
function FilterBlurMotion(distance: single; angle: single; oriented: boolean): TBGRACustomBitmap; overload; override;
function FilterBlurMotion(ABounds: TRect; distance: single; angle: single; oriented: boolean): TBGRACustomBitmap; overload; override;
function FilterCustomBlur(mask: TBGRACustomBitmap): TBGRACustomBitmap; overload; override;
function FilterCustomBlur(ABounds: TRect; mask: TBGRACustomBitmap): TBGRACustomBitmap; overload; override;
function FilterEmboss(angle: single; AStrength: integer= 64; AOptions: TEmbossOptions = []): TBGRACustomBitmap; overload; override;
function FilterEmboss(angle: single; ABounds: TRect; AStrength: integer= 64; AOptions: TEmbossOptions = []): TBGRACustomBitmap; overload; override;
function FilterEmbossHighlight(FillSelection: boolean): TBGRACustomBitmap; overload; override;
function FilterEmbossHighlight(FillSelection: boolean; BorderColor: TBGRAPixel): TBGRACustomBitmap; overload; override;
function FilterEmbossHighlight(FillSelection: boolean; BorderColor: TBGRAPixel; var Offset: TPoint): TBGRACustomBitmap; overload; override;
function FilterGrayscale: TBGRACustomBitmap; overload; override;
function FilterGrayscale(ABounds: TRect): TBGRACustomBitmap; overload; override;
function FilterNormalize(eachChannel: boolean = True): TBGRACustomBitmap; overload; override;
function FilterNormalize(ABounds: TRect; eachChannel: boolean = True): TBGRACustomBitmap; overload; override;
function FilterRotate(origin: TPointF; angle: single; correctBlur: boolean = false): TBGRACustomBitmap; override;
function FilterAffine(AMatrix: TAffineMatrix; correctBlur: boolean = false): TBGRACustomBitmap; override;
function FilterSphere: TBGRACustomBitmap; override;
function FilterTwirl(ACenter: TPoint; ARadius: Single; ATurn: Single=1; AExponent: Single=3): TBGRACustomBitmap; overload; override;
function FilterTwirl(ABounds: TRect; ACenter: TPoint; ARadius: Single; ATurn: Single=1; AExponent: Single=3): TBGRACustomBitmap; overload; override;
function FilterCylinder: TBGRACustomBitmap; override;
function FilterPlane: TBGRACustomBitmap; override;
end;
{ TBGRAPtrBitmap }
TBGRAPtrBitmap = class(TBGRADefaultBitmap)
protected
function GetLineOrder: TRawImageLineOrder; override;
procedure SetLineOrder(AValue: TRawImageLineOrder); override;
procedure ReallocData; override;
procedure FreeData; override;
procedure CannotResize;
procedure NotImplemented;
procedure RebuildBitmap; override;
function CreateDefaultFontRenderer: TBGRACustomFontRenderer; override; //to override
function LoadFromRawImage({%H-}ARawImage: TRawImage; {%H-}DefaultOpacity: byte;
{%H-}AlwaysReplaceAlpha: boolean=False; {%H-}RaiseErrorOnInvalidPixelFormat: boolean
=True): boolean; override; //to override
public
constructor Create(AWidth, AHeight: integer; AData: Pointer); overload;
function Duplicate(DuplicateProperties: Boolean = False; DuplicateXorMask: Boolean = False): TBGRACustomBitmap; override;
procedure SetDataPtr(AData: Pointer);
property LineOrder: TRawImageLineOrder Read GetLineOrder Write SetLineOrder;
procedure DataDrawTransparent({%H-}ACanvas: TCanvas; {%H-}Rect: TRect; {%H-}AData: Pointer;
{%H-}ALineOrder: TRawImageLineOrder; {%H-}AWidth, {%H-}AHeight: integer); override; //to override
procedure DataDrawOpaque({%H-}ACanvas: TCanvas; {%H-}Rect: TRect; {%H-}AData: Pointer;
{%H-}ALineOrder: TRawImageLineOrder; {%H-}AWidth, {%H-}AHeight: integer); override; //to override
procedure GetImageFromCanvas({%H-}CanvasSource: TCanvas; {%H-}x, {%H-}y: integer); override; //to override
procedure Assign({%H-}Source: TPersistent); override;
procedure TakeScreenshot({%H-}ARect: TRect); override;
procedure TakeScreenshotOfPrimaryMonitor; override;
procedure LoadFromDevice({%H-}DC: HDC); override;
procedure LoadFromDevice({%H-}DC: HDC; {%H-}ARect: TRect); override;
end;
var
DefaultTextStyle: TTextStyle;
procedure BGRAGradientFill(bmp: TBGRACustomBitmap; x, y, x2, y2: integer;
c1, c2: TBGRAPixel; gtype: TGradientType; o1, o2: TPointF; mode: TDrawMode;
gammaColorCorrection: boolean = True; Sinus: Boolean=False);
type
{ TBitmapTracker }
TBitmapTracker = class(TBitmap)
protected
FUser: TBGRADefaultBitmap;
procedure Changed(Sender: TObject); override;
public
constructor Create(AUser: TBGRADefaultBitmap); overload;
end;
implementation
uses Math, BGRAUTF8, BGRABlend, BGRAFilters, BGRAGradientScanner,
BGRAResample, BGRAPolygon, BGRAPolygonAliased,
BGRAPath, {$IFDEF FPC}FPReadPcx, FPWritePcx,{$ENDIF} FPReadXPM, FPWriteXPM,
BGRAReadBMP, BGRAReadJpeg,
BGRADithering, BGRAFilterScanner;
{ TBitmapTracker }
constructor TBitmapTracker.Create(AUser: TBGRADefaultBitmap);
begin
FUser := AUser;
inherited Create;
end;
procedure TBitmapTracker.Changed(Sender: TObject);
begin
if FUser <> nil then
begin
FUser.FBitmapModified := True;
FUser.FAlphaCorrectionNeeded := true;
end;
inherited Changed(Sender);
end;
{ TBGRADefaultBitmap }
function TBGRADefaultBitmap.CheckEmpty: boolean;
const
alphaMask = $ff shl TBGRAPixel_AlphaShift;
var
i: integer;
p: PBGRAPixel;
begin
p := Data;
for i := (NbPixels shr 1) - 1 downto 0 do
begin
if PInt64(p)^ and (alphaMask or (alphaMask shl 32)) <> 0 then
begin
Result := False;
exit;
end;
Inc(p,2);
end;
if Odd(NbPixels) and (p^.alpha <> 0) then
begin
Result := false;
exit;
end;
Result := True;