12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931 |
- unit GR32_Polygons;
- (* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1 or LGPL 2.1 with linking exception
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * Alternatively, the contents of this file may be used under the terms of the
- * Free Pascal modified version of the GNU Lesser General Public License
- * Version 2.1 (the "FPC modified LGPL License"), in which case the provisions
- * of this license are applicable instead of those above.
- * Please see the file LICENSE.txt for additional information concerning this
- * license.
- *
- * The Original Code is Vectorial Polygon Rasterizer for Graphics32
- *
- * The Initial Developer of the Original Code is
- * Mattias Andersson <[email protected]>
- *
- * Portions created by the Initial Developer are Copyright (C) 2008-2012
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * ***** END LICENSE BLOCK ***** *)
- interface
- {$I GR32.inc}
- uses
- Types, GR32, GR32_Containers, GR32_VPR, GR32_Transforms, GR32_Resamplers;
- type
- { Polygon join style }
- TJoinStyle = (jsMiter, jsBevel, jsRound);
- { Polygon end style }
- TEndStyle = (esButt, esSquare, esRound);
- { Polygon fill mode }
- TPolyFillMode = (pfAlternate, pfWinding, pfEvenOdd = 0, pfNonZero);
- { TCustomPolygonRenderer }
- TCustomPolygonRenderer = class(TThreadPersistent)
- public
- constructor Create; override;
- procedure PolyPolygonFS(const Points: TArrayOfArrayOfFloatPoint;
- const ClipRect: TFloatRect; Transformation: TTransformation); overload; virtual;
- procedure PolyPolygonFS(const Points: TArrayOfArrayOfFloatPoint;
- const ClipRect: TFloatRect); overload; virtual;
- procedure PolygonFS(const Points: TArrayOfFloatPoint;
- const ClipRect: TFloatRect; Transformation: TTransformation); overload; virtual;
- procedure PolygonFS(const Points: TArrayOfFloatPoint;
- const ClipRect: TFloatRect); overload; virtual;
- // procedure PolyPolygonXS(const Points: TArrayOfArrayOfFixedPoint; const ClipRect: TFixedRect; Transformation: TTransformation); virtual; overload;
- // procedure PolyPolygonXS(const Points: TArrayOfArrayOfFixedPoint; const ClipRect: TFixedRect); virtual; overload;
- end;
- TCustomPolygonRendererClass = class of TCustomPolygonRenderer;
- TCustomPolygonFiller = class;
- { TPolygonRenderer32 }
- TPolygonRenderer32 = class(TCustomPolygonRenderer)
- private
- FBitmap: TBitmap32;
- FFillMode: TPolyFillMode;
- FColor: TColor32;
- FFiller: TCustomPolygonFiller;
- procedure SetColor(const Value: TColor32);
- procedure SetFillMode(const Value: TPolyFillMode);
- procedure SetFiller(const Value: TCustomPolygonFiller);
- protected
- procedure SetBitmap(const Value: TBitmap32); virtual;
- public
- constructor Create(Bitmap: TBitmap32; Fillmode: TPolyFillMode = pfWinding); reintroduce; overload;
- procedure PolygonFS(const Points: TArrayOfFloatPoint); overload; virtual;
- procedure PolyPolygonFS(const Points: TArrayOfArrayOfFloatPoint); overload; virtual;
- property Bitmap: TBitmap32 read FBitmap write SetBitmap;
- property FillMode: TPolyFillMode read FFillMode write SetFillMode;
- property Color: TColor32 read FColor write SetColor;
- property Filler: TCustomPolygonFiller read FFiller write SetFiller;
- end;
- TPolygonRenderer32Class = class of TPolygonRenderer32;
- { TPolygonRenderer32VPR }
- { Polygon renderer based on VPR. Computes exact coverages for optimal anti-aliasing. }
- TFillProc = procedure(Coverage: PSingleArray; AlphaValues: PColor32Array; Count: Integer; Color: TColor32);
- TPolygonRenderer32VPR = class(TPolygonRenderer32)
- private
- FFillProc: TFillProc;
- procedure UpdateFillProcs;
- protected
- procedure RenderSpan(const Span: TValueSpan; DstY: Integer); virtual;
- procedure FillSpan(const Span: TValueSpan; DstY: Integer); virtual;
- function GetRenderSpan: TRenderSpanEvent; virtual;
- public
- procedure PolyPolygonFS(const Points: TArrayOfArrayOfFloatPoint;
- const ClipRect: TFloatRect); override;
- end;
- { TPolygonRenderer32LCD }
- TPolygonRenderer32LCD = class(TPolygonRenderer32VPR)
- protected
- procedure RenderSpan(const Span: TValueSpan; DstY: Integer); override;
- public
- procedure PolyPolygonFS(const Points: TArrayOfArrayOfFloatPoint;
- const ClipRect: TFloatRect); override;
- end;
- { TPolygonRenderer32LCD2 }
- TPolygonRenderer32LCD2 = class(TPolygonRenderer32LCD)
- public
- procedure RenderSpan(const Span: TValueSpan; DstY: Integer); override;
- end;
- { TCustomPolygonFiller }
- TFillLineEvent = procedure(Dst: PColor32; DstX, DstY, Length: Integer; AlphaValues: PColor32) of object;
- TCustomPolygonFiller = class
- private
- protected
- function GetFillLine: TFillLineEvent; virtual; abstract;
- public
- procedure BeginRendering; virtual;
- procedure EndRendering; virtual;
- property FillLine: TFillLineEvent read GetFillLine;
- end;
- { TCallbackPolygonFiller }
- TCallbackPolygonFiller = class(TCustomPolygonFiller)
- private
- FFillLineEvent: TFillLineEvent;
- protected
- function GetFillLine: TFillLineEvent; override;
- public
- property FillLineEvent: TFillLineEvent read FFillLineEvent write FFillLineEvent;
- end;
- { TInvertPolygonFiller }
- TInvertPolygonFiller = class(TCustomPolygonFiller)
- protected
- function GetFillLine: TFillLineEvent; override;
- procedure FillLineBlend(Dst: PColor32; DstX, DstY, Length: Integer; AlphaValues: PColor32);
- end;
- { TBitmapPolygonFiller }
- TBitmapPolygonFiller = class(TCustomPolygonFiller)
- private
- FPattern: TCustomBitmap32;
- FOffsetY: Integer;
- FOffsetX: Integer;
- protected
- function GetFillLine: TFillLineEvent; override;
- procedure FillLineOpaque(Dst: PColor32; DstX, DstY, Length: Integer; AlphaValues: PColor32);
- procedure FillLineBlend(Dst: PColor32; DstX, DstY, Length: Integer; AlphaValues: PColor32);
- procedure FillLineBlendMasterAlpha(Dst: PColor32; DstX, DstY, Length: Integer; AlphaValues: PColor32);
- procedure FillLineCustomCombine(Dst: PColor32; DstX, DstY, Length: Integer; AlphaValues: PColor32);
- public
- property Pattern: TCustomBitmap32 read FPattern write FPattern;
- property OffsetX: Integer read FOffsetX write FOffsetX;
- property OffsetY: Integer read FOffsetY write FOffsetY;
- end;
- { TSamplerFiller }
- TSamplerFiller = class(TCustomPolygonFiller)
- private
- FSampler: TCustomSampler;
- FGetSample: TGetSampleInt;
- procedure SetSampler(const Value: TCustomSampler);
- protected
- procedure SamplerChanged; virtual;
- function GetFillLine: TFillLineEvent; override;
- procedure SampleLineOpaque(Dst: PColor32; DstX, DstY, Length: Integer; AlphaValues: PColor32);
- public
- constructor Create(Sampler: TCustomSampler = nil); reintroduce; virtual;
- procedure BeginRendering; override;
- procedure EndRendering; override;
- property Sampler: TCustomSampler read FSampler write SetSampler;
- end;
- procedure PolyPolygonFS(Bitmap: TBitmap32; const Points: TArrayOfArrayOfFloatPoint;
- Color: TColor32; FillMode: TPolyFillMode = pfAlternate;
- Transformation: TTransformation = nil); overload;
- procedure PolygonFS(Bitmap: TBitmap32; const Points: TArrayOfFloatPoint;
- Color: TColor32; FillMode: TPolyFillMode = pfAlternate;
- Transformation: TTransformation = nil); overload;
- procedure PolyPolygonFS(Bitmap: TBitmap32; const Points: TArrayOfArrayOfFloatPoint;
- Filler: TCustomPolygonFiller; FillMode: TPolyFillMode = pfAlternate;
- Transformation: TTransformation = nil); overload;
- procedure PolygonFS(Bitmap: TBitmap32; const Points: TArrayOfFloatPoint;
- Filler: TCustomPolygonFiller; FillMode: TPolyFillMode = pfAlternate;
- Transformation: TTransformation = nil); overload;
- procedure PolyPolygonFS_LCD(Bitmap: TBitmap32; const Points: TArrayOfArrayOfFloatPoint;
- Color: TColor32; FillMode: TPolyFillMode = pfAlternate;
- Transformation: TTransformation = nil); overload;
- procedure PolygonFS_LCD(Bitmap: TBitmap32; const Points: TArrayOfFloatPoint;
- Color: TColor32; FillMode: TPolyFillMode = pfAlternate;
- Transformation: TTransformation = nil); overload;
- procedure PolyPolygonFS_LCD2(Bitmap: TBitmap32; const Points: TArrayOfArrayOfFloatPoint;
- Color: TColor32; FillMode: TPolyFillMode = pfAlternate;
- Transformation: TTransformation = nil); overload;
- procedure PolygonFS_LCD2(Bitmap: TBitmap32; const Points: TArrayOfFloatPoint;
- Color: TColor32; FillMode: TPolyFillMode = pfAlternate;
- Transformation: TTransformation = nil); overload;
- procedure PolyPolygonFS(Bitmap: TBitmap32; const Points: TArrayOfArrayOfFloatPoint;
- ClipRect: TRect; Color: TColor32; FillMode: TPolyFillMode = pfAlternate;
- Transformation: TTransformation = nil); overload;
- procedure PolygonFS(Bitmap: TBitmap32; const Points: TArrayOfFloatPoint;
- ClipRect: TRect; Color: TColor32; FillMode: TPolyFillMode = pfAlternate;
- Transformation: TTransformation = nil); overload;
- procedure PolyPolygonFS(Bitmap: TBitmap32; const Points: TArrayOfArrayOfFloatPoint;
- ClipRect: TRect; Filler: TCustomPolygonFiller; FillMode: TPolyFillMode = pfAlternate;
- Transformation: TTransformation = nil); overload;
- procedure PolygonFS(Bitmap: TBitmap32; const Points: TArrayOfFloatPoint;
- ClipRect: TRect; Filler: TCustomPolygonFiller; FillMode: TPolyFillMode = pfAlternate;
- Transformation: TTransformation = nil); overload;
- procedure PolyPolygonFS_LCD(Bitmap: TBitmap32; const Points: TArrayOfArrayOfFloatPoint;
- ClipRect: TRect; Color: TColor32; FillMode: TPolyFillMode = pfAlternate;
- Transformation: TTransformation = nil); overload;
- procedure PolygonFS_LCD(Bitmap: TBitmap32; const Points: TArrayOfFloatPoint;
- ClipRect: TRect; Color: TColor32; FillMode: TPolyFillMode = pfAlternate;
- Transformation: TTransformation = nil); overload;
- procedure PolyPolygonFS_LCD2(Bitmap: TBitmap32; const Points: TArrayOfArrayOfFloatPoint;
- ClipRect: TRect; Color: TColor32; FillMode: TPolyFillMode = pfAlternate;
- Transformation: TTransformation = nil); overload;
- procedure PolygonFS_LCD2(Bitmap: TBitmap32; const Points: TArrayOfFloatPoint;
- ClipRect: TRect; Color: TColor32; FillMode: TPolyFillMode = pfAlternate;
- Transformation: TTransformation = nil); overload;
- procedure PolyPolylineFS(Bitmap: TBitmap32; const Points: TArrayOfArrayOfFloatPoint;
- Color: TColor32; Closed: Boolean = False; StrokeWidth: TFloat = 1.0;
- JoinStyle: TJoinStyle = jsMiter; EndStyle: TEndStyle = esButt;
- MiterLimit: TFloat = 4.0; Transformation: TTransformation = nil); overload;
- procedure PolyPolylineFS(Bitmap: TBitmap32; const Points: TArrayOfArrayOfFloatPoint;
- Filler: TCustomPolygonFiller; Closed: Boolean = False; StrokeWidth: TFloat = 1.0;
- JoinStyle: TJoinStyle = jsMiter; EndStyle: TEndStyle = esButt;
- MiterLimit: TFloat = 4.0; Transformation: TTransformation = nil); overload;
- procedure PolylineFS(Bitmap: TBitmap32; const Points: TArrayOfFloatPoint;
- Color: TColor32; Closed: Boolean = False; StrokeWidth: TFloat = 1.0;
- JoinStyle: TJoinStyle = jsMiter; EndStyle: TEndStyle = esButt;
- MiterLimit: TFloat = 4.0; Transformation: TTransformation = nil); overload;
- procedure PolylineFS(Bitmap: TBitmap32; const Points: TArrayOfFloatPoint;
- Filler: TCustomPolygonFiller; Closed: Boolean = False; StrokeWidth: TFloat = 1.0;
- JoinStyle: TJoinStyle = jsMiter; EndStyle: TEndStyle = esButt;
- MiterLimit: TFloat = 4.0; Transformation: TTransformation = nil); overload;
- //Filled only Dashes ...
- procedure DashLineFS(Bitmap: TBitmap32; const Points: TArrayOfFloatPoint;
- const Dashes: TArrayOfFloat; Color: TColor32;
- Closed: Boolean = False; Width: TFloat = 1.0); overload;
- procedure DashLineFS(Bitmap: TBitmap32; const Points: TArrayOfFloatPoint;
- const Dashes: TArrayOfFloat; FillColor, StrokeColor: TColor32;
- Closed: Boolean; Width: TFloat; StrokeWidth: TFloat = 2.0); overload;
- //Filled and stroked Dashes ...
- procedure DashLineFS(Bitmap: TBitmap32; const Points: TArrayOfFloatPoint;
- const Dashes: TArrayOfFloat; Filler: TCustomPolygonFiller;
- Closed: Boolean = False; Width: TFloat = 1.0); overload;
- procedure DashLineFS(Bitmap: TBitmap32; const Points: TArrayOfFloatPoint;
- const Dashes: TArrayOfFloat; Filler: TCustomPolygonFiller; StrokeColor: TColor32;
- Closed: Boolean; Width: TFloat; StrokeWidth: TFloat = 2.0); overload;
- procedure PolyPolygonXS(Bitmap: TBitmap32; const Points: TArrayOfArrayOfFixedPoint;
- Color: TColor32; FillMode: TPolyFillMode = pfAlternate;
- Transformation: TTransformation = nil); overload;
- procedure PolygonXS(Bitmap: TBitmap32; const Points: TArrayOfFixedPoint;
- Color: TColor32; FillMode: TPolyFillMode = pfAlternate;
- Transformation: TTransformation = nil); overload;
- procedure PolyPolygonXS(Bitmap: TBitmap32; const Points: TArrayOfArrayOfFixedPoint;
- Filler: TCustomPolygonFiller; FillMode: TPolyFillMode = pfAlternate;
- Transformation: TTransformation = nil); overload;
- procedure PolygonXS(Bitmap: TBitmap32; const Points: TArrayOfFixedPoint;
- Filler: TCustomPolygonFiller; FillMode: TPolyFillMode = pfAlternate;
- Transformation: TTransformation = nil); overload;
- procedure PolyPolygonXS_LCD(Bitmap: TBitmap32; const Points: TArrayOfArrayOfFixedPoint;
- Color: TColor32; FillMode: TPolyFillMode = pfAlternate;
- Transformation: TTransformation = nil); overload;
- procedure PolygonXS_LCD(Bitmap: TBitmap32; const Points: TArrayOfFixedPoint;
- Color: TColor32; FillMode: TPolyFillMode = pfAlternate;
- Transformation: TTransformation = nil);
- procedure PolyPolygonXS_LCD2(Bitmap: TBitmap32; const Points: TArrayOfArrayOfFixedPoint;
- Color: TColor32; FillMode: TPolyFillMode = pfAlternate;
- Transformation: TTransformation = nil); overload;
- procedure PolygonXS_LCD2(Bitmap: TBitmap32; const Points: TArrayOfFixedPoint;
- Color: TColor32; FillMode: TPolyFillMode = pfAlternate;
- Transformation: TTransformation = nil);
- procedure PolyPolylineXS(Bitmap: TBitmap32; const Points: TArrayOfArrayOfFixedPoint;
- Color: TColor32; Closed: Boolean = False; StrokeWidth: TFixed = $10000;
- JoinStyle: TJoinStyle = jsMiter; EndStyle: TEndStyle = esButt;
- MiterLimit: TFixed = $40000; Transformation: TTransformation = nil); overload;
- procedure PolyPolylineXS(Bitmap: TBitmap32; const Points: TArrayOfArrayOfFixedPoint;
- Filler: TCustomPolygonFiller; Closed: Boolean = False; StrokeWidth: TFixed = $10000;
- JoinStyle: TJoinStyle = jsMiter; EndStyle: TEndStyle = esButt;
- MiterLimit: TFixed = $40000; Transformation: TTransformation = nil); overload;
- procedure PolylineXS(Bitmap: TBitmap32; const Points: TArrayOfFixedPoint;
- Color: TColor32; Closed: Boolean = False; StrokeWidth: TFixed = $10000;
- JoinStyle: TJoinStyle = jsMiter; EndStyle: TEndStyle = esButt;
- MiterLimit: TFixed = $40000; Transformation: TTransformation = nil); overload;
- procedure PolylineXS(Bitmap: TBitmap32; const Points: TArrayOfFixedPoint;
- Filler: TCustomPolygonFiller; Closed: Boolean = False; StrokeWidth: TFixed = $10000;
- JoinStyle: TJoinStyle = jsMiter; EndStyle: TEndStyle = esButt;
- MiterLimit: TFixed = $40000; Transformation: TTransformation = nil); overload;
- //Filled only Dashes ...
- procedure DashLineXS(Bitmap: TBitmap32; const Points: TArrayOfFixedPoint;
- const Dashes: TArrayOfFixed; Color: TColor32;
- Closed: Boolean = False; Width: TFixed = $10000); overload;
- procedure DashLineXS(Bitmap: TBitmap32; const Points: TArrayOfFixedPoint;
- const Dashes: TArrayOfFixed; FillColor, StrokeColor: TColor32;
- Closed: Boolean; Width: TFixed; StrokeWidth: TFixed = $20000); overload;
- //Filled and stroked Dashes ...
- procedure DashLineXS(Bitmap: TBitmap32; const Points: TArrayOfFixedPoint;
- const Dashes: TArrayOfFixed; Filler: TCustomPolygonFiller;
- Closed: Boolean = False; Width: TFixed = $10000); overload;
- procedure DashLineXS(Bitmap: TBitmap32; const Points: TArrayOfFixedPoint;
- const Dashes: TArrayOfFixed; Filler: TCustomPolygonFiller; StrokeColor: TColor32;
- Closed: Boolean; Width: TFixed; StrokeWidth: TFixed = $20000); overload;
- // fill entire bitmap with a given polygon filler
- procedure FillBitmap(Bitmap: TBitmap32; Filler: TCustomPolygonFiller);
- { Registration routines }
- procedure RegisterPolygonRenderer(PolygonRendererClass: TCustomPolygonRendererClass);
- var
- PolygonRendererList: TClassList;
- DefaultPolygonRendererClass: TPolygonRenderer32Class = TPolygonRenderer32VPR;
- implementation
- uses
- Math, SysUtils, GR32_Math, GR32_LowLevel, GR32_Blend,
- GR32_VectorUtils;
- resourcestring
- RCStrNoSamplerSpecified = 'No sampler specified!';
- type
- TBitmap32Access = class(TBitmap32);
- procedure RegisterPolygonRenderer(PolygonRendererClass: TCustomPolygonRendererClass);
- begin
- if not Assigned(PolygonRendererList) then PolygonRendererList := TClassList.Create;
- PolygonRendererList.Add(PolygonRendererClass);
- end;
- // routines for color filling:
- procedure MakeAlphaNonZeroUP(Coverage: PSingleArray; AlphaValues: PColor32Array;
- Count: Integer; Color: TColor32);
- var
- I: Integer;
- M, V: Cardinal;
- Last: TFloat;
- C: TColor32Entry absolute Color;
- begin
- M := C.A * $101;
- Last := Infinity;
- for I := 0 to Count - 1 do
- begin
- if PInteger(@Last)^ <> PInteger(@Coverage[I])^ then
- begin
- Last := Coverage[I];
- V := Abs(Round(Last * $10000));
- if V > $10000 then V := $10000;
- V := V * M shr 24;
- {$IFDEF USEGR32GAMMA}
- V := GAMMA_TABLE[V];
- {$ENDIF}
- C.A := V;
- end;
- AlphaValues[I] := Color;
- end;
- end;
- (*
- procedure MakeAlphaNonZeroUP(Coverage: PSingleArray; AlphaValues: PColor32Array;
- Count: Integer; Color: TColor32);
- var
- I: Integer;
- M, V, C: Cardinal;
- begin
- M := Color shr 24 * $101;
- C := Color and $00ffffff;
- for I := 0 to Count - 1 do
- begin
- V := Abs(Round(Coverage[I] * $10000));
- if V > $10000 then V := $10000;
- {$IFDEF USEGR32GAMMA}
- V := GAMMA_TABLE[V * M shr 24];
- AlphaValues[I] := (V shl 24) or C;
- {$ELSE}
- AlphaValues[I] := (V * M and $ff000000) or C;
- {$ENDIF}
- end;
- end;
- *)
- procedure MakeAlphaEvenOddUP(Coverage: PSingleArray; AlphaValues: PColor32Array;
- Count: Integer; Color: TColor32);
- var
- I: Integer;
- M, V: Cardinal;
- Last: TFloat;
- C: TColor32Entry absolute Color;
- begin
- M := C.A * $101;
- Last := Infinity;
- for I := 0 to Count - 1 do
- begin
- if PInteger(@Last)^ <> PInteger(@Coverage[I])^ then
- begin
- Last := Coverage[I];
- V := Abs(Round(Coverage[I] * $10000));
- V := V and $01ffff;
- if V >= $10000 then
- V := V xor $1ffff;
- V := V * M shr 24;
- {$IFDEF USEGR32GAMMA}
- V := GAMMA_TABLE[V];
- {$ENDIF}
- C.A := V;
- end;
- AlphaValues[I] := Color;
- end;
- end;
- procedure MakeAlphaNonZeroP(Value: Single; AlphaValues: PColor32Array;
- Count: Integer; Color: TColor32);
- var
- M, V: Cardinal;
- C: TColor32Entry absolute Color;
- begin
- M := C.A * $101;
- V := Abs(Round(Value * $10000));
- if V > $10000 then V := $10000;
- V := V * M shr 24;
- {$IFDEF USEGR32GAMMA}
- V := GAMMA_TABLE[V];
- {$ENDIF}
- C.A := V;
- FillLongWord(AlphaValues[0], Count, Color);
- end;
- procedure MakeAlphaEvenOddP(Value: Single; AlphaValues: PColor32Array;
- Count: Integer; Color: TColor32);
- var
- M, V: Cardinal;
- C: TColor32Entry absolute Color;
- begin
- M := C.A * $101;
- V := Abs(Round(Value * $10000));
- V := V and $01ffff;
- if V > $10000 then V := V xor $1ffff;
- V := V * M shr 24;
- {$IFDEF USEGR32GAMMA}
- V := GAMMA_TABLE[V];
- {$ENDIF}
- C.A := V;
- FillLongWord(AlphaValues[0], Count, Color);
- end;
- // polygon filler routines (extract alpha only):
- procedure MakeAlphaNonZeroUPF(Coverage: PSingleArray; AlphaValues: PColor32Array;
- Count: Integer; Color: TColor32);
- var
- I: Integer;
- V: Integer;
- begin
- for I := 0 to Count - 1 do
- begin
- V := Clamp(Round(Abs(Coverage[I]) * 256));
- {$IFDEF USEGR32GAMMA}
- V := GAMMA_TABLE[V];
- {$ENDIF}
- AlphaValues[I] := V;
- end;
- end;
- procedure MakeAlphaEvenOddUPF(Coverage: PSingleArray; AlphaValues: PColor32Array;
- Count: Integer; Color: TColor32);
- var
- I: Integer;
- V: Integer;
- begin
- for I := 0 to Count - 1 do
- begin
- V := Round(Abs(Coverage[I]) * 256);
- V := V and $000001ff;
- if V >= $100 then V := V xor $1ff;
- {$IFDEF USEGR32GAMMA}
- V := GAMMA_TABLE[V];
- {$ENDIF}
- AlphaValues[I] := V;
- end;
- end;
- procedure MakeAlphaNonZeroPF(Value: Single; AlphaValues: PColor32Array;
- Count: Integer; Color: TColor32);
- var
- V: Integer;
- begin
- V := Clamp(Round(Abs(Value) * 256));
- {$IFDEF USEGR32GAMMA}
- V := GAMMA_TABLE[V];
- {$ENDIF}
- FillLongWord(AlphaValues[0], Count, V);
- end;
- procedure MakeAlphaEvenOddPF(Value: Single; AlphaValues: PColor32Array;
- Count: Integer; Color: TColor32);
- var
- V: Integer;
- begin
- V := Round(Abs(Value) * 256);
- V := V and $000001ff;
- if V >= $100 then V := V xor $1ff;
- {$IFDEF USEGR32GAMMA}
- V := GAMMA_TABLE[V];
- {$ENDIF}
- FillLongWord(AlphaValues[0], Count, V);
- end;
- procedure PolyPolygonFS(Bitmap: TBitmap32; const Points: TArrayOfArrayOfFloatPoint;
- Color: TColor32; FillMode: TPolyFillMode; Transformation: TTransformation);
- var
- Renderer: TPolygonRenderer32VPR;
- begin
- Renderer := TPolygonRenderer32VPR.Create;
- try
- Renderer.Bitmap := Bitmap;
- Renderer.Color := Color;
- Renderer.FillMode := FillMode;
- Renderer.PolyPolygonFS(Points, FloatRect(Bitmap.ClipRect), Transformation);
- finally
- Renderer.Free;
- end;
- end;
- procedure PolygonFS(Bitmap: TBitmap32; const Points: TArrayOfFloatPoint;
- Color: TColor32; FillMode: TPolyFillMode; Transformation: TTransformation);
- var
- Renderer: TPolygonRenderer32VPR;
- begin
- Renderer := TPolygonRenderer32VPR.Create;
- try
- Renderer.Bitmap := Bitmap;
- Renderer.Color := Color;
- Renderer.FillMode := FillMode;
- Renderer.PolygonFS(Points, FloatRect(Bitmap.ClipRect), Transformation);
- finally
- Renderer.Free;
- end;
- end;
- procedure PolyPolygonFS(Bitmap: TBitmap32; const Points: TArrayOfArrayOfFloatPoint;
- Filler: TCustomPolygonFiller; FillMode: TPolyFillMode; Transformation: TTransformation);
- var
- Renderer: TPolygonRenderer32VPR;
- begin
- if not Assigned(Filler) then Exit;
- Renderer := TPolygonRenderer32VPR.Create;
- try
- Renderer.Bitmap := Bitmap;
- Renderer.Filler := Filler;
- Renderer.FillMode := FillMode;
- Renderer.PolyPolygonFS(Points, FloatRect(Bitmap.ClipRect), Transformation);
- finally
- Renderer.Free;
- end;
- end;
- procedure PolygonFS(Bitmap: TBitmap32; const Points: TArrayOfFloatPoint;
- Filler: TCustomPolygonFiller; FillMode: TPolyFillMode; Transformation: TTransformation);
- var
- Renderer: TPolygonRenderer32VPR;
- begin
- if not Assigned(Filler) then Exit;
- Renderer := TPolygonRenderer32VPR.Create;
- try
- Renderer.Bitmap := Bitmap;
- Renderer.Filler := Filler;
- Renderer.FillMode := FillMode;
- Renderer.PolygonFS(Points, FloatRect(Bitmap.ClipRect), Transformation);
- finally
- Renderer.Free;
- end;
- end;
- procedure PolygonFS_LCD(Bitmap: TBitmap32; const Points: TArrayOfFloatPoint;
- Color: TColor32; FillMode: TPolyFillMode; Transformation: TTransformation);
- var
- Renderer: TPolygonRenderer32LCD;
- begin
- Renderer := TPolygonRenderer32LCD.Create;
- try
- Renderer.Bitmap := Bitmap;
- Renderer.FillMode := FillMode;
- Renderer.Color := Color;
- Renderer.PolygonFS(Points, FloatRect(Bitmap.ClipRect), Transformation);
- finally
- Renderer.Free;
- end;
- end;
- procedure PolyPolygonFS_LCD(Bitmap: TBitmap32; const Points: TArrayOfArrayOfFloatPoint;
- Color: TColor32; FillMode: TPolyFillMode; Transformation: TTransformation);
- var
- Renderer: TPolygonRenderer32LCD;
- begin
- Renderer := TPolygonRenderer32LCD.Create;
- try
- Renderer.Bitmap := Bitmap;
- Renderer.FillMode := FillMode;
- Renderer.Color := Color;
- Renderer.PolyPolygonFS(Points, FloatRect(Bitmap.ClipRect), Transformation);
- finally
- Renderer.Free;
- end;
- end;
- procedure PolygonFS_LCD2(Bitmap: TBitmap32; const Points: TArrayOfFloatPoint;
- Color: TColor32; FillMode: TPolyFillMode; Transformation: TTransformation);
- var
- Renderer: TPolygonRenderer32LCD2;
- begin
- Renderer := TPolygonRenderer32LCD2.Create;
- try
- Renderer.Bitmap := Bitmap;
- Renderer.FillMode := FillMode;
- Renderer.Color := Color;
- Renderer.PolygonFS(Points, FloatRect(Bitmap.ClipRect), Transformation);
- finally
- Renderer.Free;
- end;
- end;
- procedure PolyPolygonFS_LCD2(Bitmap: TBitmap32; const Points: TArrayOfArrayOfFloatPoint;
- Color: TColor32; FillMode: TPolyFillMode; Transformation: TTransformation);
- var
- Renderer: TPolygonRenderer32LCD2;
- begin
- Renderer := TPolygonRenderer32LCD2.Create;
- try
- Renderer.Bitmap := Bitmap;
- Renderer.FillMode := FillMode;
- Renderer.Color := Color;
- Renderer.PolyPolygonFS(Points, FloatRect(Bitmap.ClipRect), Transformation);
- finally
- Renderer.Free;
- end;
- end;
- procedure PolyPolygonFS(Bitmap: TBitmap32; const Points: TArrayOfArrayOfFloatPoint;
- ClipRect: TRect; Color: TColor32; FillMode: TPolyFillMode;
- Transformation: TTransformation);
- var
- Renderer: TPolygonRenderer32VPR;
- IntersectedClipRect: TRect;
- begin
- Renderer := TPolygonRenderer32VPR.Create;
- try
- Renderer.Bitmap := Bitmap;
- Renderer.Color := Color;
- Renderer.FillMode := FillMode;
- GR32.IntersectRect(IntersectedClipRect, Bitmap.ClipRect, ClipRect);
- Renderer.PolyPolygonFS(Points, FloatRect(IntersectedClipRect), Transformation);
- finally
- Renderer.Free;
- end;
- end;
- procedure PolygonFS(Bitmap: TBitmap32; const Points: TArrayOfFloatPoint;
- ClipRect: TRect; Color: TColor32; FillMode: TPolyFillMode;
- Transformation: TTransformation);
- var
- Renderer: TPolygonRenderer32VPR;
- IntersectedClipRect: TRect;
- begin
- Renderer := TPolygonRenderer32VPR.Create;
- try
- Renderer.Bitmap := Bitmap;
- Renderer.Color := Color;
- Renderer.FillMode := FillMode;
- GR32.IntersectRect(IntersectedClipRect, Bitmap.ClipRect, ClipRect);
- Renderer.PolygonFS(Points, FloatRect(IntersectedClipRect), Transformation);
- finally
- Renderer.Free;
- end;
- end;
- procedure PolyPolygonFS(Bitmap: TBitmap32; const Points: TArrayOfArrayOfFloatPoint;
- ClipRect: TRect; Filler: TCustomPolygonFiller; FillMode: TPolyFillMode;
- Transformation: TTransformation);
- var
- Renderer: TPolygonRenderer32VPR;
- IntersectedClipRect: TRect;
- begin
- if not Assigned(Filler) then Exit;
- Renderer := TPolygonRenderer32VPR.Create;
- try
- Renderer.Bitmap := Bitmap;
- Renderer.Filler := Filler;
- Renderer.FillMode := FillMode;
- GR32.IntersectRect(IntersectedClipRect, Bitmap.ClipRect, ClipRect);
- Renderer.PolyPolygonFS(Points, FloatRect(IntersectedClipRect), Transformation);
- finally
- Renderer.Free;
- end;
- end;
- procedure PolygonFS(Bitmap: TBitmap32; const Points: TArrayOfFloatPoint;
- ClipRect: TRect; Filler: TCustomPolygonFiller; FillMode: TPolyFillMode;
- Transformation: TTransformation);
- var
- Renderer: TPolygonRenderer32VPR;
- IntersectedClipRect: TRect;
- begin
- if not Assigned(Filler) then Exit;
- Renderer := TPolygonRenderer32VPR.Create;
- try
- Renderer.Bitmap := Bitmap;
- Renderer.Filler := Filler;
- Renderer.FillMode := FillMode;
- GR32.IntersectRect(IntersectedClipRect, Bitmap.ClipRect, ClipRect);
- Renderer.PolygonFS(Points, FloatRect(IntersectedClipRect), Transformation);
- finally
- Renderer.Free;
- end;
- end;
- procedure PolygonFS_LCD(Bitmap: TBitmap32; const Points: TArrayOfFloatPoint;
- ClipRect: TRect; Color: TColor32; FillMode: TPolyFillMode;
- Transformation: TTransformation);
- var
- Renderer: TPolygonRenderer32LCD;
- IntersectedClipRect: TRect;
- begin
- Renderer := TPolygonRenderer32LCD.Create;
- try
- Renderer.Bitmap := Bitmap;
- Renderer.FillMode := FillMode;
- Renderer.Color := Color;
- GR32.IntersectRect(IntersectedClipRect, Bitmap.ClipRect, ClipRect);
- Renderer.PolygonFS(Points, FloatRect(IntersectedClipRect), Transformation);
- finally
- Renderer.Free;
- end;
- end;
- procedure PolyPolygonFS_LCD(Bitmap: TBitmap32;
- const Points: TArrayOfArrayOfFloatPoint; ClipRect: TRect; Color: TColor32;
- FillMode: TPolyFillMode; Transformation: TTransformation);
- var
- Renderer: TPolygonRenderer32LCD;
- IntersectedClipRect: TRect;
- begin
- Renderer := TPolygonRenderer32LCD.Create;
- try
- Renderer.Bitmap := Bitmap;
- Renderer.FillMode := FillMode;
- Renderer.Color := Color;
- GR32.IntersectRect(IntersectedClipRect, Bitmap.ClipRect, ClipRect);
- Renderer.PolyPolygonFS(Points, FloatRect(IntersectedClipRect), Transformation);
- finally
- Renderer.Free;
- end;
- end;
- procedure PolygonFS_LCD2(Bitmap: TBitmap32; const Points: TArrayOfFloatPoint;
- ClipRect: TRect; Color: TColor32; FillMode: TPolyFillMode;
- Transformation: TTransformation);
- var
- Renderer: TPolygonRenderer32LCD2;
- IntersectedClipRect: TRect;
- begin
- Renderer := TPolygonRenderer32LCD2.Create;
- try
- Renderer.Bitmap := Bitmap;
- Renderer.FillMode := FillMode;
- Renderer.Color := Color;
- GR32.IntersectRect(IntersectedClipRect, Bitmap.ClipRect, ClipRect);
- Renderer.PolygonFS(Points, FloatRect(IntersectedClipRect), Transformation);
- finally
- Renderer.Free;
- end;
- end;
- procedure PolyPolygonFS_LCD2(Bitmap: TBitmap32;
- const Points: TArrayOfArrayOfFloatPoint; ClipRect: TRect; Color: TColor32;
- FillMode: TPolyFillMode; Transformation: TTransformation);
- var
- Renderer: TPolygonRenderer32LCD2;
- IntersectedClipRect: TRect;
- begin
- Renderer := TPolygonRenderer32LCD2.Create;
- try
- Renderer.Bitmap := Bitmap;
- Renderer.FillMode := FillMode;
- Renderer.Color := Color;
- GR32.IntersectRect(IntersectedClipRect, Bitmap.ClipRect, ClipRect);
- Renderer.PolyPolygonFS(Points, FloatRect(IntersectedClipRect), Transformation);
- finally
- Renderer.Free;
- end;
- end;
- procedure PolyPolylineFS(Bitmap: TBitmap32; const Points: TArrayOfArrayOfFloatPoint;
- Color: TColor32; Closed: Boolean; StrokeWidth: TFloat;
- JoinStyle: TJoinStyle; EndStyle: TEndStyle;
- MiterLimit: TFloat; Transformation: TTransformation);
- var
- Dst: TArrayOfArrayOfFloatPoint;
- begin
- Dst := BuildPolyPolyLine(Points, Closed, StrokeWidth, JoinStyle, EndStyle, MiterLimit);
- PolyPolygonFS(Bitmap, Dst, Color, pfWinding, Transformation);
- end;
- procedure PolyPolylineFS(Bitmap: TBitmap32; const Points: TArrayOfArrayOfFloatPoint;
- Filler: TCustomPolygonFiller; Closed: Boolean = False; StrokeWidth: TFloat = 1.0;
- JoinStyle: TJoinStyle = jsMiter; EndStyle: TEndStyle = esButt;
- MiterLimit: TFloat = 4.0; Transformation: TTransformation = nil);
- var
- Dst: TArrayOfArrayOfFloatPoint;
- begin
- Dst := BuildPolyPolyLine(Points, Closed, StrokeWidth, JoinStyle, EndStyle, MiterLimit);
- PolyPolygonFS(Bitmap, Dst, Filler, pfWinding, Transformation);
- end;
- procedure PolylineFS(Bitmap: TBitmap32; const Points: TArrayOfFloatPoint;
- Color: TColor32; Closed: Boolean; StrokeWidth: TFloat;
- JoinStyle: TJoinStyle; EndStyle: TEndStyle;
- MiterLimit: TFloat; Transformation: TTransformation);
- begin
- PolyPolylineFS(Bitmap, PolyPolygon(Points), Color, Closed, StrokeWidth,
- JoinStyle, EndStyle, MiterLimit, Transformation);
- end;
- procedure PolylineFS(Bitmap: TBitmap32; const Points: TArrayOfFloatPoint;
- Filler: TCustomPolygonFiller; Closed: Boolean = False; StrokeWidth: TFloat = 1.0;
- JoinStyle: TJoinStyle = jsMiter; EndStyle: TEndStyle = esButt;
- MiterLimit: TFloat = 4.0; Transformation: TTransformation = nil);
- begin
- PolyPolylineFS(Bitmap, PolyPolygon(Points), Filler, Closed, StrokeWidth,
- JoinStyle, EndStyle, MiterLimit, Transformation);
- end;
- procedure DashLineFS(Bitmap: TBitmap32; const Points: TArrayOfFloatPoint;
- const Dashes: TArrayOfFloat; Color: TColor32;
- Closed: Boolean = False; Width: TFloat = 1.0);
- var
- MultiPoly: TArrayOfArrayOfFloatPoint;
- begin
- MultiPoly := GR32_VectorUtils.BuildDashedLine(Points, Dashes, 0, Closed);
- PolyPolylineFS(Bitmap, MultiPoly, Color, False, Width);
- end;
- procedure DashLineFS(Bitmap: TBitmap32; const Points: TArrayOfFloatPoint;
- const Dashes: TArrayOfFloat; FillColor, StrokeColor: TColor32;
- Closed: Boolean; Width: TFloat; StrokeWidth: TFloat = 2.0);
- var
- MultiPoly: TArrayOfArrayOfFloatPoint;
- begin
- MultiPoly := GR32_VectorUtils.BuildDashedLine(Points, Dashes, 0, Closed);
- MultiPoly := BuildPolyPolyLine(MultiPoly, False, Width);
- PolyPolygonFS(Bitmap, MultiPoly, FillColor);
- PolyPolylineFS(Bitmap, MultiPoly, StrokeColor, True, StrokeWidth);
- end;
- procedure DashLineFS(Bitmap: TBitmap32; const Points: TArrayOfFloatPoint;
- const Dashes: TArrayOfFloat; Filler: TCustomPolygonFiller;
- Closed: Boolean = False; Width: TFloat = 1.0);
- var
- MultiPoly: TArrayOfArrayOfFloatPoint;
- begin
- MultiPoly := GR32_VectorUtils.BuildDashedLine(Points, Dashes, 0, Closed);
- PolyPolylineFS(Bitmap, MultiPoly, Filler, False, Width);
- end;
- procedure DashLineFS(Bitmap: TBitmap32; const Points: TArrayOfFloatPoint;
- const Dashes: TArrayOfFloat; Filler: TCustomPolygonFiller; StrokeColor: TColor32;
- Closed: Boolean; Width: TFloat; StrokeWidth: TFloat = 2.0);
- var
- MultiPoly: TArrayOfArrayOfFloatPoint;
- begin
- MultiPoly := GR32_VectorUtils.BuildDashedLine(Points, Dashes, 0, Closed);
- MultiPoly := BuildPolyPolyLine(MultiPoly, False, Width);
- PolyPolygonFS(Bitmap, MultiPoly, Filler);
- PolyPolylineFS(Bitmap, MultiPoly, StrokeColor, True, StrokeWidth);
- end;
- procedure PolyPolygonXS(Bitmap: TBitmap32; const Points: TArrayOfArrayOfFixedPoint;
- Color: TColor32; FillMode: TPolyFillMode; Transformation: TTransformation);
- var
- Renderer: TPolygonRenderer32VPR;
- begin
- Renderer := TPolygonRenderer32VPR.Create;
- try
- Renderer.Bitmap := Bitmap;
- Renderer.Color := Color;
- Renderer.FillMode := FillMode;
- Renderer.PolyPolygonFS(FixedPointToFloatPoint(Points),
- FloatRect(Bitmap.ClipRect), Transformation);
- finally
- Renderer.Free;
- end;
- end;
- procedure PolygonXS(Bitmap: TBitmap32; const Points: TArrayOfFixedPoint;
- Color: TColor32; FillMode: TPolyFillMode; Transformation: TTransformation);
- var
- Renderer: TPolygonRenderer32VPR;
- begin
- Renderer := TPolygonRenderer32VPR.Create;
- try
- Renderer.Bitmap := Bitmap;
- Renderer.Color := Color;
- Renderer.FillMode := FillMode;
- Renderer.PolygonFS(FixedPointToFloatPoint(Points),
- FloatRect(Bitmap.ClipRect), Transformation);
- finally
- Renderer.Free;
- end;
- end;
- procedure PolyPolygonXS(Bitmap: TBitmap32; const Points: TArrayOfArrayOfFixedPoint;
- Filler: TCustomPolygonFiller; FillMode: TPolyFillMode; Transformation: TTransformation);
- var
- Renderer: TPolygonRenderer32VPR;
- begin
- Renderer := TPolygonRenderer32VPR.Create;
- try
- Renderer.Bitmap := Bitmap;
- Renderer.Filler := Filler;
- Renderer.FillMode := FillMode;
- Renderer.PolyPolygonFS(FixedPointToFloatPoint(Points),
- FloatRect(Bitmap.ClipRect), Transformation);
- finally
- Renderer.Free;
- end;
- end;
- procedure PolygonXS(Bitmap: TBitmap32; const Points: TArrayOfFixedPoint;
- Filler: TCustomPolygonFiller; FillMode: TPolyFillMode; Transformation: TTransformation);
- var
- Renderer: TPolygonRenderer32VPR;
- begin
- Renderer := TPolygonRenderer32VPR.Create;
- try
- Renderer.Bitmap := Bitmap;
- Renderer.Filler := Filler;
- Renderer.FillMode := FillMode;
- Renderer.PolygonFS(FixedPointToFloatPoint(Points),
- FloatRect(Bitmap.ClipRect), Transformation);
- finally
- Renderer.Free;
- end;
- end;
- procedure PolygonXS_LCD(Bitmap: TBitmap32; const Points: TArrayOfFixedPoint;
- Color: TColor32; FillMode: TPolyFillMode; Transformation: TTransformation);
- var
- Renderer: TPolygonRenderer32LCD;
- begin
- Renderer := TPolygonRenderer32LCD.Create;
- try
- Renderer.Bitmap := Bitmap;
- Renderer.FillMode := FillMode;
- Renderer.Color := Color;
- Renderer.PolygonFS(FixedPointToFloatPoint(Points),
- FloatRect(Bitmap.ClipRect), Transformation);
- finally
- Renderer.Free;
- end;
- end;
- procedure PolyPolygonXS_LCD(Bitmap: TBitmap32; const Points: TArrayOfArrayOfFixedPoint;
- Color: TColor32; FillMode: TPolyFillMode; Transformation: TTransformation);
- var
- Renderer: TPolygonRenderer32LCD;
- begin
- Renderer := TPolygonRenderer32LCD.Create;
- try
- Renderer.Bitmap := Bitmap;
- Renderer.FillMode := FillMode;
- Renderer.Color := Color;
- Renderer.PolyPolygonFS(FixedPointToFloatPoint(Points),
- FloatRect(Bitmap.ClipRect), Transformation);
- finally
- Renderer.Free;
- end;
- end;
- procedure PolygonXS_LCD2(Bitmap: TBitmap32; const Points: TArrayOfFixedPoint;
- Color: TColor32; FillMode: TPolyFillMode; Transformation: TTransformation);
- var
- Renderer: TPolygonRenderer32LCD2;
- begin
- Renderer := TPolygonRenderer32LCD2.Create;
- try
- Renderer.Bitmap := Bitmap;
- Renderer.FillMode := FillMode;
- Renderer.Color := Color;
- Renderer.PolygonFS(FixedPointToFloatPoint(Points),
- FloatRect(Bitmap.ClipRect), Transformation);
- finally
- Renderer.Free;
- end;
- end;
- procedure PolyPolygonXS_LCD2(Bitmap: TBitmap32; const Points: TArrayOfArrayOfFixedPoint;
- Color: TColor32; FillMode: TPolyFillMode; Transformation: TTransformation);
- var
- Renderer: TPolygonRenderer32LCD2;
- begin
- Renderer := TPolygonRenderer32LCD2.Create;
- try
- Renderer.Bitmap := Bitmap;
- Renderer.FillMode := FillMode;
- Renderer.Color := Color;
- Renderer.PolyPolygonFS(FixedPointToFloatPoint(Points),
- FloatRect(Bitmap.ClipRect), Transformation);
- finally
- Renderer.Free;
- end;
- end;
- procedure PolyPolylineXS(Bitmap: TBitmap32; const Points: TArrayOfArrayOfFixedPoint;
- Color: TColor32; Closed: Boolean; StrokeWidth: TFixed;
- JoinStyle: TJoinStyle; EndStyle: TEndStyle;
- MiterLimit: TFixed; Transformation: TTransformation);
- var
- Dst: TArrayOfArrayOfFixedPoint;
- begin
- Dst := BuildPolyPolyLine(Points, Closed, StrokeWidth, JoinStyle, EndStyle,
- MiterLimit);
- PolyPolygonXS(Bitmap, Dst, Color, pfWinding, Transformation);
- end;
- procedure PolyPolylineXS(Bitmap: TBitmap32; const Points: TArrayOfArrayOfFixedPoint;
- Filler: TCustomPolygonFiller; Closed: Boolean = False;
- StrokeWidth: TFixed = $10000; JoinStyle: TJoinStyle = jsMiter;
- EndStyle: TEndStyle = esButt; MiterLimit: TFixed = $40000;
- Transformation: TTransformation = nil);
- var
- Dst: TArrayOfArrayOfFixedPoint;
- begin
- Dst := BuildPolyPolyLine(Points, Closed, StrokeWidth, JoinStyle, EndStyle,
- MiterLimit);
- PolyPolygonXS(Bitmap, Dst, Filler, pfWinding, Transformation);
- end;
- procedure PolylineXS(Bitmap: TBitmap32; const Points: TArrayOfFixedPoint;
- Color: TColor32; Closed: Boolean; StrokeWidth: TFixed;
- JoinStyle: TJoinStyle; EndStyle: TEndStyle;
- MiterLimit: TFixed; Transformation: TTransformation);
- begin
- PolyPolylineXS(Bitmap, PolyPolygon(Points), Color,
- Closed, StrokeWidth, JoinStyle, EndStyle,
- MiterLimit, Transformation);
- end;
- procedure PolylineXS(Bitmap: TBitmap32; const Points: TArrayOfFixedPoint;
- Filler: TCustomPolygonFiller; Closed: Boolean = False;
- StrokeWidth: TFixed = $10000; JoinStyle: TJoinStyle = jsMiter;
- EndStyle: TEndStyle = esButt; MiterLimit: TFixed = $40000;
- Transformation: TTransformation = nil);
- begin
- PolyPolylineXS(Bitmap, PolyPolygon(Points), Filler, Closed, StrokeWidth,
- JoinStyle, EndStyle, MiterLimit, Transformation);
- end;
- procedure DashLineXS(Bitmap: TBitmap32; const Points: TArrayOfFixedPoint;
- const Dashes: TArrayOfFixed; Color: TColor32;
- Closed: Boolean = False; Width: TFixed = $10000);
- var
- MultiPoly: TArrayOfArrayOfFixedPoint;
- begin
- MultiPoly := GR32_VectorUtils.BuildDashedLine(Points, Dashes, 0, Closed);
- PolyPolylineXS(Bitmap, MultiPoly, Color, False, Width);
- end;
- procedure DashLineXS(Bitmap: TBitmap32; const Points: TArrayOfFixedPoint;
- const Dashes: TArrayOfFixed; FillColor, StrokeColor: TColor32;
- Closed: Boolean; Width: TFixed; StrokeWidth: TFixed = $20000);
- var
- MultiPoly: TArrayOfArrayOfFixedPoint;
- begin
- MultiPoly := GR32_VectorUtils.BuildDashedLine(Points, Dashes, 0, Closed);
- PolyPolylineXS(Bitmap, MultiPoly, FillColor, False, Width);
- MultiPoly := BuildPolyPolyLine(MultiPoly, False, Width);
- PolyPolylineXS(Bitmap, MultiPoly, StrokeColor, True, strokeWidth);
- end;
- procedure DashLineXS(Bitmap: TBitmap32; const Points: TArrayOfFixedPoint;
- const Dashes: TArrayOfFixed; Filler: TCustomPolygonFiller;
- Closed: Boolean = False; Width: TFixed = $10000);
- var
- MultiPoly: TArrayOfArrayOfFixedPoint;
- begin
- MultiPoly := GR32_VectorUtils.BuildDashedLine(Points, Dashes, 0, Closed);
- PolyPolylineXS(Bitmap, MultiPoly, Filler, False, Width);
- end;
- procedure DashLineXS(Bitmap: TBitmap32; const Points: TArrayOfFixedPoint;
- const Dashes: TArrayOfFixed; Filler: TCustomPolygonFiller; StrokeColor: TColor32;
- Closed: Boolean; Width: TFixed; StrokeWidth: TFixed = $20000);
- var
- MultiPoly: TArrayOfArrayOfFixedPoint;
- begin
- MultiPoly := GR32_VectorUtils.BuildDashedLine(Points, Dashes, 0, Closed);
- PolyPolylineXS(Bitmap, MultiPoly, Filler, False, Width);
- MultiPoly := BuildPolyPolyLine(MultiPoly, False, Width);
- PolyPolylineXS(Bitmap, MultiPoly, StrokeColor, True, StrokeWidth);
- end;
- procedure FillBitmap(Bitmap: TBitmap32; Filler: TCustomPolygonFiller);
- var
- AlphaValues: PColor32;
- Y: Integer;
- begin
- {$IFDEF USESTACKALLOC}
- AlphaValues := StackAlloc(Bitmap.Width * SizeOf(TColor32));
- {$ELSE}
- GetMem(AlphaValues, Bitmap.Width * SizeOf(TColor32));
- {$ENDIF}
- FillLongword(AlphaValues^, Bitmap.Width, $FF);
- Filler.BeginRendering;
- for Y := 0 to Bitmap.Height - 1 do
- Filler.FillLine(PColor32(Bitmap.ScanLine[y]), 0, y, Bitmap.Width, AlphaValues);
- Filler.EndRendering;
- {$IFDEF USESTACKALLOC}
- StackFree(AlphaValues);
- {$ELSE}
- FreeMem(AlphaValues);
- {$ENDIF}
- end;
- { LCD sub-pixel rendering (see http://www.grc.com/cttech.htm) }
- type
- PRGBTriple = ^TRGBTriple;
- TRGBTriple = packed record
- B, G, R: Byte;
- end;
- PRGBTripleArray = ^TRGBTripleArray;
- TRGBTripleArray = array [0..0] of TRGBTriple;
- TMakeAlphaProcLCD = procedure(Coverage: PSingleArray; AlphaValues: SysUtils.PByteArray;
- Count: Integer; Color: TColor32);
- procedure MakeAlphaNonZeroLCD(Coverage: PSingleArray; AlphaValues: SysUtils.PByteArray;
- Count: Integer; Color: TColor32);
- var
- I: Integer;
- M, V: Cardinal;
- Last: TFloat;
- C: TColor32Entry absolute Color;
- begin
- M := C.A * 86; // 86 = 258 / 3
- Last := Infinity;
- V := 0;
- AlphaValues[0] := 0;
- AlphaValues[1] := 0;
- for I := 0 to Count - 1 do
- begin
- if PInteger(@Last)^ <> PInteger(@Coverage[I])^ then
- begin
- Last := Coverage[I];
- V := Abs(Round(Last * $10000));
- if V > $10000 then V := $10000;
- V := V * M shr 24;
- end;
- Inc(AlphaValues[I], V);
- {$IFDEF USEGR32GAMMA}
- AlphaValues[I] := GAMMA_TABLE[AlphaValues[I]];
- {$ENDIF}
- Inc(AlphaValues[I + 1], V);
- AlphaValues[I + 2] := V;
- end;
- AlphaValues[Count + 2] := 0;
- AlphaValues[Count + 3] := 0;
- end;
- procedure MakeAlphaEvenOddLCD(Coverage: PSingleArray; AlphaValues: SysUtils.PByteArray;
- Count: Integer; Color: TColor32);
- var
- I: Integer;
- M, V: Cardinal;
- Last: TFloat;
- begin
- M := Color shr 24 * 86; // 86 = 258 / 3
- Last := Infinity;
- V := 0;
- AlphaValues[0] := 0;
- AlphaValues[1] := 0;
- for I := 0 to Count - 1 do
- begin
- if PInteger(@Last)^ <> PInteger(@Coverage[I])^ then
- begin
- Last := Coverage[I];
- V := Abs(Round(Coverage[I] * $10000));
- V := V and $01ffff;
- if V >= $10000 then V := V xor $1ffff;
- V := V * M shr 24;
- end;
- Inc(AlphaValues[I], V);
- {$IFDEF USEGR32GAMMA}
- AlphaValues[I] := GAMMA_TABLE[AlphaValues[I]];
- {$ENDIF}
- Inc(AlphaValues[I + 1], V);
- AlphaValues[I + 2] := V;
- end;
- AlphaValues[Count + 2] := 0;
- AlphaValues[Count + 3] := 0;
- end;
- procedure MakeAlphaNonZeroLCD2(Coverage: PSingleArray; AlphaValues: SysUtils.PByteArray;
- Count: Integer; Color: TColor32);
- var
- I: Integer;
- begin
- MakeAlphaNonZeroLCD(Coverage, AlphaValues, Count, Color);
- AlphaValues[Count + 2] := (AlphaValues[Count] + AlphaValues[Count + 1]) div 3;
- AlphaValues[Count + 3] := AlphaValues[Count + 1] div 3;
- for I := Count + 1 downto 2 do
- begin
- AlphaValues[I] := (AlphaValues[I] + AlphaValues[I - 1] + AlphaValues[I - 2]) div 3;
- end;
- AlphaValues[1] := (AlphaValues[0] + AlphaValues[1]) div 3;
- AlphaValues[0] := AlphaValues[0] div 3;
- end;
- procedure MakeAlphaEvenOddLCD2(Coverage: PSingleArray; AlphaValues: SysUtils.PByteArray;
- Count: Integer; Color: TColor32);
- var
- I: Integer;
- begin
- MakeAlphaEvenOddLCD(Coverage, AlphaValues, Count, Color);
- AlphaValues[Count + 2] := (AlphaValues[Count] + AlphaValues[Count + 1]) div 3;
- AlphaValues[Count + 3] := AlphaValues[Count + 1] div 3;
- for I := Count + 1 downto 2 do
- begin
- AlphaValues[I] := (AlphaValues[I] + AlphaValues[I - 1] + AlphaValues[I - 2]) div 3;
- end;
- AlphaValues[1] := (AlphaValues[0] + AlphaValues[1]) div 3;
- AlphaValues[0] := AlphaValues[0] div 3;
- end;
- procedure CombineLineLCD(Weights: PRGBTripleArray; Dst: PColor32Array; Color: TColor32; Count: Integer);
- var
- I: Integer;
- {$IFDEF TEST_BLENDMEMRGB128SSE4}
- Weights64: UInt64;
- {$ENDIF}
- begin
- I := 0;
- while Count <> 0 do
- {$IFDEF TEST_BLENDMEMRGB128SSE4}
- if (Count shr 1) = 0 then
- {$ENDIF}
- begin
- if PColor32(@Weights[I])^ = $FFFFFFFF then
- Dst[I] := Color
- else
- BlendMemRGB(Color, Dst[I], PColor32(@Weights[I])^);
- Dec(Count);
- Inc(I);
- end
- {$IFDEF TEST_BLENDMEMRGB128SSE4}
- else
- begin
- Weights64 := (UInt64(PColor32(@Weights[I + 1])^) shl 32) or
- PColor32(@Weights[I])^;
- if Weights64 = $FFFFFFFFFFFFFFFF then
- begin
- Dst[I] := Color;
- Dst[I + 1] := Color;
- end
- else
- BlendMemRGB128(Color, Dst[I], Weights64);
- Dec(Count, 2);
- Inc(I, 2);
- end
- {$ENDIF};
- EMMS;
- end;
- { TCustomPolygonFiller }
- procedure TCustomPolygonFiller.BeginRendering;
- begin
- // implemented by descendants
- end;
- procedure TCustomPolygonFiller.EndRendering;
- begin
- // implemented by descendants
- end;
- { TCallbackPolygonFiller }
- function TCallbackPolygonFiller.GetFillLine: TFillLineEvent;
- begin
- Result := FFillLineEvent;
- end;
- { TInvertPolygonFiller }
- procedure TInvertPolygonFiller.FillLineBlend(Dst: PColor32; DstX, DstY,
- Length: Integer; AlphaValues: PColor32);
- var
- X: Integer;
- BlendMemEx: TBlendMemEx;
- begin
- BlendMemEx := BLEND_MEM_EX[cmBlend]^;
- for X := DstX to DstX + Length - 1 do
- begin
- BlendMemEx(InvertColor(Dst^), Dst^, AlphaValues^);
- EMMS;
- Inc(Dst);
- Inc(AlphaValues);
- end;
- end;
- function TInvertPolygonFiller.GetFillLine: TFillLineEvent;
- begin
- Result := FillLineBlend;
- end;
- { TBitmapPolygonFiller }
- procedure TBitmapPolygonFiller.FillLineOpaque(Dst: PColor32; DstX, DstY,
- Length: Integer; AlphaValues: PColor32);
- var
- PatternX, PatternY, X: Integer;
- OpaqueAlpha: TColor32;
- Src: PColor32;
- BlendMemEx: TBlendMemEx;
- begin
- PatternX := (DstX - OffsetX) mod FPattern.Width;
- if PatternX < 0 then PatternX := (FPattern.Width + PatternX) mod FPattern.Width;
- PatternY := (DstY - OffsetY) mod FPattern.Height;
- if PatternY < 0 then PatternY := (FPattern.Height + PatternY) mod FPattern.Height;
- Src := @FPattern.Bits[PatternX + PatternY * FPattern.Width];
- if Assigned(AlphaValues) then
- begin
- OpaqueAlpha := TColor32($FF shl 24);
- BlendMemEx := BLEND_MEM_EX[FPattern.CombineMode]^;
- for X := DstX to DstX + Length - 1 do
- begin
- BlendMemEx(Src^ and $00FFFFFF or OpaqueAlpha, Dst^, AlphaValues^);
- Inc(Dst); Inc(Src); Inc(PatternX);
- if PatternX >= FPattern.Width then
- begin
- PatternX := 0;
- Src := @FPattern.Bits[PatternX + PatternY * FPattern.Width];
- end;
- Inc(AlphaValues);
- end
- end
- else
- for X := DstX to DstX + Length - 1 do
- begin
- Dst^ := Src^;
- Inc(Dst); Inc(Src); Inc(PatternX);
- if PatternX >= FPattern.Width then
- begin
- PatternX := 0;
- Src := @FPattern.Bits[PatternX + PatternY * FPattern.Width];
- end;
- end;
- end;
- procedure TBitmapPolygonFiller.FillLineBlend(Dst: PColor32; DstX, DstY, Length: Integer; AlphaValues: PColor32);
- var
- PatternX, PatternY, X: Integer;
- Src: PColor32;
- BlendMemEx: TBlendMemEx;
- BlendMem: TBlendMem;
- begin
- PatternX := (DstX - OffsetX) mod FPattern.Width;
- if PatternX < 0 then PatternX := (FPattern.Width + PatternX) mod FPattern.Width;
- PatternY := (DstY - OffsetY) mod FPattern.Height;
- if PatternY < 0 then PatternY := (FPattern.Height + PatternY) mod FPattern.Height;
- Src := @FPattern.Bits[PatternX + PatternY * FPattern.Width];
- if Assigned(AlphaValues) then
- begin
- BlendMemEx := BLEND_MEM_EX[FPattern.CombineMode]^;
- for X := DstX to DstX + Length - 1 do
- begin
- BlendMemEx(Src^, Dst^, AlphaValues^);
- Inc(Dst); Inc(Src); Inc(PatternX);
- if PatternX >= FPattern.Width then
- begin
- PatternX := 0;
- Src := @FPattern.Bits[PatternX + PatternY * FPattern.Width];
- end;
- Inc(AlphaValues);
- end
- end
- else
- begin
- BlendMem := BLEND_MEM[FPattern.CombineMode]^;
- for X := DstX to DstX + Length - 1 do
- begin
- BlendMem(Src^, Dst^);
- Inc(Dst); Inc(Src); Inc(PatternX);
- if PatternX >= FPattern.Width then
- begin
- PatternX := 0;
- Src := @FPattern.Bits[PatternX + PatternY * FPattern.Width];
- end;
- end;
- end;
- end;
- procedure TBitmapPolygonFiller.FillLineBlendMasterAlpha(Dst: PColor32; DstX, DstY,
- Length: Integer; AlphaValues: PColor32);
- var
- PatternX, PatternY, X: Integer;
- Src: PColor32;
- BlendMemEx: TBlendMemEx;
- begin
- PatternX := (DstX - OffsetX) mod FPattern.Width;
- if PatternX < 0 then PatternX := (FPattern.Width + PatternX) mod FPattern.Width;
- PatternY := (DstY - OffsetY) mod FPattern.Height;
- if PatternY < 0 then PatternY := (FPattern.Height + PatternY) mod FPattern.Height;
- Src := @FPattern.Bits[PatternX + PatternY * FPattern.Width];
- BlendMemEx := BLEND_MEM_EX[FPattern.CombineMode]^;
- if Assigned(AlphaValues) then
- for X := DstX to DstX + Length - 1 do
- begin
- BlendMemEx(Src^, Dst^, Div255(AlphaValues^ * FPattern.MasterAlpha));
- Inc(Dst); Inc(Src); Inc(PatternX);
- if PatternX >= FPattern.Width then
- begin
- PatternX := 0;
- Src := @FPattern.Bits[PatternX + PatternY * FPattern.Width];
- end;
- Inc(AlphaValues);
- end
- else
- for X := DstX to DstX + Length - 1 do
- begin
- BlendMemEx(Src^, Dst^, FPattern.MasterAlpha);
- Inc(Dst); Inc(Src); Inc(PatternX);
- if PatternX >= FPattern.Width then
- begin
- PatternX := 0;
- Src := @FPattern.Bits[PatternX + PatternY * FPattern.Width];
- end;
- end;
- end;
- procedure TBitmapPolygonFiller.FillLineCustomCombine(Dst: PColor32; DstX, DstY,
- Length: Integer; AlphaValues: PColor32);
- var
- PatternX, PatternY, X: Integer;
- Src: PColor32;
- begin
- PatternX := (DstX - OffsetX) mod FPattern.Width;
- if PatternX < 0 then PatternX := (FPattern.Width + PatternX) mod FPattern.Width;
- PatternY := (DstY - OffsetY) mod FPattern.Height;
- if PatternY < 0 then PatternY := (FPattern.Height + PatternY) mod FPattern.Height;
- Src := @FPattern.Bits[PatternX + PatternY * FPattern.Width];
- if Assigned(AlphaValues) then
- for X := DstX to DstX + Length - 1 do
- begin
- FPattern.OnPixelCombine(Src^, Dst^, Div255(AlphaValues^ * FPattern.MasterAlpha));
- Inc(Dst); Inc(Src); Inc(PatternX);
- if PatternX >= FPattern.Width then
- begin
- PatternX := 0;
- Src := @FPattern.Bits[PatternX + PatternY * FPattern.Width];
- end;
- Inc(AlphaValues);
- end
- else
- for X := DstX to DstX + Length - 1 do
- begin
- FPattern.OnPixelCombine(Src^, Dst^, FPattern.MasterAlpha);
- Inc(Dst); Inc(Src); Inc(PatternX);
- if PatternX >= FPattern.Width then
- begin
- PatternX := 0;
- Src := @FPattern.Bits[PatternX + PatternY * FPattern.Width];
- end;
- end;
- end;
- function TBitmapPolygonFiller.GetFillLine: TFillLineEvent;
- begin
- if not Assigned(FPattern) then
- begin
- Result := nil;
- end
- else if FPattern.DrawMode = dmOpaque then
- Result := FillLineOpaque
- else if FPattern.DrawMode = dmBlend then
- begin
- if FPattern.MasterAlpha = 255 then
- Result := FillLineBlend
- else
- Result := FillLineBlendMasterAlpha;
- end
- else if (FPattern.DrawMode = dmCustom) and Assigned(FPattern.OnPixelCombine) then
- begin
- Result := FillLineCustomCombine;
- end
- else
- Result := nil;
- end;
- { TSamplerFiller }
- constructor TSamplerFiller.Create(Sampler: TCustomSampler = nil);
- begin
- inherited Create;
- FSampler := Sampler;
- SamplerChanged;
- end;
- procedure TSamplerFiller.EndRendering;
- begin
- if Assigned(FSampler) then
- FSampler.FinalizeSampling
- else
- raise Exception.Create(RCStrNoSamplerSpecified);
- end;
- procedure TSamplerFiller.SampleLineOpaque(Dst: PColor32; DstX, DstY,
- Length: Integer; AlphaValues: PColor32);
- var
- X: Integer;
- BlendMemEx: TBlendMemEx;
- begin
- BlendMemEx := BLEND_MEM_EX[cmBlend]^;
- for X := DstX to DstX + Length - 1 do
- begin
- BlendMemEx(FGetSample(X, DstY) and $00FFFFFF or $FF000000, Dst^, AlphaValues^);
- EMMS;
- Inc(Dst);
- Inc(AlphaValues);
- end;
- end;
- procedure TSamplerFiller.SamplerChanged;
- begin
- if Assigned(FSampler) then
- FGetSample := FSampler.GetSampleInt;
- end;
- procedure TSamplerFiller.BeginRendering;
- begin
- if Assigned(FSampler) then
- FSampler.PrepareSampling
- else
- raise Exception.Create(RCStrNoSamplerSpecified);
- end;
- function TSamplerFiller.GetFillLine: TFillLineEvent;
- begin
- Result := SampleLineOpaque;
- end;
- procedure TSamplerFiller.SetSampler(const Value: TCustomSampler);
- begin
- if FSampler <> Value then
- begin
- FSampler := Value;
- SamplerChanged;
- end;
- end;
- { TCustomPolygonRenderer }
- constructor TCustomPolygonRenderer.Create;
- begin
- end;
- procedure TCustomPolygonRenderer.PolygonFS(
- const Points: TArrayOfFloatPoint; const ClipRect: TFloatRect;
- Transformation: TTransformation);
- begin
- PolyPolygonFS(PolyPolygon(Points), ClipRect, Transformation);
- end;
- procedure TCustomPolygonRenderer.PolygonFS(
- const Points: TArrayOfFloatPoint; const ClipRect: TFloatRect);
- begin
- PolyPolygonFS(PolyPolygon(Points), ClipRect);
- end;
- procedure TCustomPolygonRenderer.PolyPolygonFS(
- const Points: TArrayOfArrayOfFloatPoint; const ClipRect: TFloatRect);
- begin
- // implemented by descendants
- end;
- procedure TCustomPolygonRenderer.PolyPolygonFS(
- const Points: TArrayOfArrayOfFloatPoint; const ClipRect: TFloatRect;
- Transformation: TTransformation);
- var
- APoints: TArrayOfArrayOfFloatPoint;
- begin
- if Assigned(Transformation) then
- APoints := TransformPolyPolygon(Points, Transformation)
- else
- APoints := Points;
- PolyPolygonFS(APoints, ClipRect);
- end;
- { TPolygonRenderer32 }
- constructor TPolygonRenderer32.Create(Bitmap: TBitmap32;
- Fillmode: TPolyFillMode);
- begin
- inherited Create;
- FBitmap := Bitmap;
- FFillMode := Fillmode;
- end;
- procedure TPolygonRenderer32.PolygonFS(const Points: TArrayOfFloatPoint);
- begin
- PolyPolygonFS(PolyPolygon(Points), FloatRect(FBitmap.ClipRect));
- end;
- procedure TPolygonRenderer32.PolyPolygonFS(const Points: TArrayOfArrayOfFloatPoint);
- begin
- PolyPolygonFS(Points, FloatRect(FBitmap.ClipRect));
- end;
- procedure TPolygonRenderer32.SetBitmap(const Value: TBitmap32);
- begin
- if FBitmap <> Value then
- begin
- FBitmap := Value;
- Changed;
- end;
- end;
- procedure TPolygonRenderer32.SetColor(const Value: TColor32);
- begin
- if FColor <> Value then
- begin
- FColor := Value;
- Changed;
- end;
- end;
- procedure TPolygonRenderer32.SetFiller(const Value: TCustomPolygonFiller);
- begin
- if FFiller <> Value then
- begin
- FFiller := Value;
- Changed;
- end;
- end;
- procedure TPolygonRenderer32.SetFillMode(const Value: TPolyFillMode);
- begin
- if FFillMode <> Value then
- begin
- FFillMode := Value;
- Changed;
- end;
- end;
- { TPolygonRenderer32VPR }
- {$IFDEF USESTACKALLOC}
- {$W+}
- {$ENDIF}
- procedure TPolygonRenderer32VPR.FillSpan(const Span: TValueSpan; DstY: Integer);
- var
- AlphaValues: PColor32Array;
- Count: Integer;
- begin
- Count := Span.X2 - Span.X1 + 1;
- {$IFDEF USESTACKALLOC}
- AlphaValues := StackAlloc(Count * SizeOf(TColor32));
- {$ELSE}
- GetMem(AlphaValues, Count * SizeOf(TColor32));
- {$ENDIF}
- FFillProc(Span.Values, AlphaValues, Count, FColor);
- FFiller.FillLine(@Bitmap.ScanLine[DstY][Span.X1], Span.X1, DstY, Count,
- PColor32(AlphaValues));
- EMMS;
- {$IFDEF USESTACKALLOC}
- StackFree(AlphaValues);
- {$ELSE}
- FreeMem(AlphaValues);
- {$ENDIF}
- end;
- {$IFDEF USESTACKALLOC}
- {$W-}
- {$ENDIF}
- function TPolygonRenderer32VPR.GetRenderSpan: TRenderSpanEvent;
- begin
- if Assigned(FFiller) then
- Result := FillSpan
- else
- Result := RenderSpan;
- end;
- procedure TPolygonRenderer32VPR.PolyPolygonFS(
- const Points: TArrayOfArrayOfFloatPoint; const ClipRect: TFloatRect);
- {$IFDEF CHANGENOTIFICATIONS}
- var
- I: Integer;
- {$ENDIF}
- begin
- UpdateFillProcs;
- if Assigned(FFiller) then
- begin
- FFiller.BeginRendering;
- RenderPolyPolygon(Points, ClipRect, GetRenderSpan());
- FFiller.EndRendering;
- end
- else
- RenderPolyPolygon(Points, ClipRect, GetRenderSpan());
- {$IFDEF CHANGENOTIFICATIONS}
- if TBitmap32Access(Bitmap).UpdateCount = 0 then
- for I := 0 to High(Points) do
- if Length(Points[I]) > 0 then
- Bitmap.Changed(MakeRect(PolygonBounds(Points[I])));
- {$ENDIF}
- end;
- {$W+}
- procedure TPolygonRenderer32VPR.RenderSpan(const Span: TValueSpan;
- DstY: Integer);
- var
- AlphaValues: PColor32Array;
- Count: Integer;
- begin
- Count := Span.X2 - Span.X1 + 1;
- {$IFDEF USESTACKALLOC}
- AlphaValues := StackAlloc(Count * SizeOf(TColor32));
- {$ELSE}
- GetMem(AlphaValues, Count * SizeOf(TColor32));
- {$ENDIF}
- FFillProc(Span.Values, AlphaValues, Count, FColor);
- if Bitmap.CombineMode = cmMerge then
- MergeLine(@AlphaValues[0], @Bitmap.ScanLine[DstY][Span.X1], Count) else
- BlendLine(@AlphaValues[0], @Bitmap.ScanLine[DstY][Span.X1], Count);
- EMMS;
- {$IFDEF USESTACKALLOC}
- StackFree(AlphaValues);
- {$ELSE}
- FreeMem(AlphaValues);
- {$ENDIF}
- end;
- {$W-}
- procedure TPolygonRenderer32VPR.UpdateFillProcs;
- const
- FillProcs: array [Boolean, TPolyFillMode] of TFillProc = (
- (MakeAlphaEvenOddUP, MakeAlphaNonZeroUP),
- (MakeAlphaEvenOddUPF, MakeAlphaNonZeroUPF)
- );
- begin
- FFillProc := FillProcs[Assigned(FFiller), FillMode];
- end;
- { TPolygonRenderer32LCD }
- procedure TPolygonRenderer32LCD.PolyPolygonFS(
- const Points: TArrayOfArrayOfFloatPoint; const ClipRect: TFloatRect);
- var
- R: TFloatRect;
- APoints: TArrayOfArrayOfFloatPoint;
- {$IFDEF CHANGENOTIFICATIONS}
- I: Integer;
- {$ENDIF}
- begin
- APoints := ScalePolyPolygon(Points, 3, 1);
- R.Top := ClipRect.Top;
- R.Bottom := ClipRect.Bottom;
- R.Left := ClipRect.Left * 3;
- R.Right := ClipRect.Right * 3;
- RenderPolyPolygon(APoints, R, RenderSpan);
- {$IFDEF CHANGENOTIFICATIONS}
- if TBitmap32Access(Bitmap).UpdateCount = 0 then
- for I := 0 to High(Points) do
- if length(Points[I]) > 0 then
- Bitmap.Changed(MakeRect(PolygonBounds(Points[I])));
- {$ENDIF}
- end;
- {$W+}
- procedure TPolygonRenderer32LCD.RenderSpan(const Span: TValueSpan;
- DstY: Integer);
- const
- PADDING = 5;
- var
- AlphaValues: SysUtils.PByteArray;
- Count: Integer;
- X1, Offset: Integer;
- const
- MakeAlpha: array [TPolyFillMode] of TMakeAlphaProcLCD = (MakeAlphaEvenOddLCD, MakeAlphaNonZeroLCD);
- begin
- Count := Span.X2 - Span.X1 + 1;
- X1 := DivMod(Span.X1, 3, Offset);
- // Left Padding + Right Padding + Filter Width = 2 + 2 + 2 = 6
- {$IFDEF USESTACKALLOC}
- AlphaValues := StackAlloc((Count + 6 + PADDING) * SizeOf(Byte));
- {$ELSE}
- GetMem(AlphaValues, (Count + 6 + PADDING) * SizeOf(Byte));
- {$ENDIF}
- AlphaValues[0] := 0;
- AlphaValues[1] := 0;
- if (X1 > 0) then
- begin
- Dec(X1);
- Inc(Offset, 3);
- AlphaValues[2] := 0;
- AlphaValues[3] := 0;
- AlphaValues[4] := 0;
- end;
- MakeAlpha[FFillMode](Span.Values, PByteArray(@AlphaValues[PADDING]), Count, FColor);
- CombineLineLCD(@AlphaValues[PADDING - Offset], PColor32Array(@Bitmap.ScanLine[DstY][X1]), FColor, (Count + Offset + 2) div 3);
- {$IFDEF USESTACKALLOC}
- StackFree(AlphaValues);
- {$ELSE}
- FreeMem(AlphaValues);
- {$ENDIF}
- end;
- {$W-}
- { TPolygonRenderer32LCD2 }
- {$W+}
- procedure TPolygonRenderer32LCD2.RenderSpan(const Span: TValueSpan;
- DstY: Integer);
- const
- PADDING = 5;
- var
- AlphaValues: SysUtils.PByteArray;
- Count: Integer;
- X1, Offset: Integer;
- const
- MakeAlpha: array [TPolyFillMode] of TMakeAlphaProcLCD = (MakeAlphaEvenOddLCD2, MakeAlphaNonZeroLCD2);
- begin
- Count := Span.X2 - Span.X1 + 1;
- X1 := DivMod(Span.X1, 3, Offset);
- // Left Padding + Right Padding + Filter Width = 2 + 2 + 2 = 6
- {$IFDEF USESTACKALLOC}
- AlphaValues := StackAlloc((Count + 6 + PADDING) * SizeOf(Byte));
- {$ELSE}
- GetMem(AlphaValues, (Count + 6 + PADDING) * SizeOf(Byte));
- {$ENDIF}
- AlphaValues[0] := 0;
- AlphaValues[1] := 0;
- if (X1 > 0) then
- begin
- Dec(X1);
- Inc(Offset, 3);
- AlphaValues[2] := 0;
- AlphaValues[3] := 0;
- AlphaValues[4] := 0;
- end;
- Dec(Offset, 1);
- MakeAlpha[FFillMode](Span.Values, PByteArray(@AlphaValues[PADDING]), Count, FColor);
- Inc(Count);
- CombineLineLCD(@AlphaValues[PADDING - Offset], PColor32Array(@Bitmap.ScanLine[DstY][X1]), FColor, (Count + Offset + 2) div 3);
- {$IFDEF USESTACKALLOC}
- StackFree(AlphaValues);
- {$ELSE}
- FreeMem(AlphaValues);
- {$ENDIF}
- end;
- {$W-}
- initialization
- RegisterPolygonRenderer(TPolygonRenderer32VPR);
- RegisterPolygonRenderer(TPolygonRenderer32LCD);
- RegisterPolygonRenderer(TPolygonRenderer32LCD2);
- finalization
- PolygonRendererList.Free;
- end.
|