apophysis/2.10/Source/BucketFillerThread.pas

148 lines
3.5 KiB
ObjectPascal
Raw Normal View History

2005-09-11 06:20:56 -04:00
unit BucketFillerThread;
interface
uses
Classes, Windows,
2006-03-02 12:27:20 -05:00
ControlPoint, Render, XForm;
2005-09-11 06:20:56 -04:00
type
TBucketFillerThread = class(TThread)
private
fcp: TControlPoint;
points: TPointsArray;
public
nrbatches: integer;
batchcounter: Pinteger;
BucketWidth, BucketHeight: integer;
2006-03-02 12:27:20 -05:00
camX0, camY0, camW, camH,
bws, bhs, cosa, sina, rcX, rcY: double;
2005-09-11 06:20:56 -04:00
Buckets: PBucketArray;
ColorMap: TColorMapArray;
CriticalSection: TRTLCriticalSection;
constructor Create(cp: TControlPoint);
destructor Destroy; override;
procedure Execute; override;
procedure AddPointsToBuckets(const points: TPointsArray);
2006-03-02 12:27:20 -05:00
procedure AddPointsToBucketsAngle(const points: TPointsArray);
2005-09-11 06:20:56 -04:00
end;
implementation
{ PixelRenderThread }
///////////////////////////////////////////////////////////////////////////////
procedure TBucketFillerThread.AddPointsToBuckets(const points: TPointsArray);
var
i: integer;
px, py: double;
2006-03-02 12:27:20 -05:00
// R: double;
// V1, v2, v3: integer;
2005-09-11 06:20:56 -04:00
Bucket: PBucket;
MapColor: PColorMapColor;
begin
2006-03-02 12:27:20 -05:00
for i := SUB_BATCH_SIZE - 1 downto 0 do begin
// if FStop then Exit;
px := points[i].x - camX0;
if (px < 0) or (px > camW) then continue;
py := points[i].y - camY0;
if (py < 0) or (py > camH) then continue;
Bucket := @TBucketArray(buckets^)[Round(bws * px) + Round(bhs * py) * BucketWidth];
MapColor := @ColorMap[Round(points[i].c * 255)];
2005-09-11 06:20:56 -04:00
2006-03-02 12:27:20 -05:00
Inc(Bucket.Red, MapColor.Red);
Inc(Bucket.Green, MapColor.Green);
Inc(Bucket.Blue, MapColor.Blue);
Inc(Bucket.Count);
end;
end;
2005-09-11 06:20:56 -04:00
///////////////////////////////////////////////////////////////////////////////
procedure TBucketFillerThread.AddPointsToBucketsAngle(const points: TPointsArray);
var
i: integer;
px, py: double;
Bucket: PBucket;
MapColor: PColorMapColor;
begin
for i := SUB_BATCH_SIZE - 1 downto 0 do begin
2006-03-02 12:27:20 -05:00
// if FStop then Exit;
2005-09-11 06:20:56 -04:00
2006-03-02 12:27:20 -05:00
px := points[i].x * cosa + points[i].y * sina + rcX;
if (px < 0) or (px > camW) then continue;
py := points[i].y * cosa - points[i].x * sina + rcY;
if (py < 0) or (py > camH) then continue;
2005-09-11 06:20:56 -04:00
2006-03-02 12:27:20 -05:00
Bucket := @TBucketArray(buckets^)[Round(bws * px) + Round(bhs * py) * BucketWidth];
MapColor := @ColorMap[Round(points[i].c * 255)];
2005-09-11 06:20:56 -04:00
2006-03-02 12:27:20 -05:00
Inc(Bucket.Red, MapColor.Red);
Inc(Bucket.Green, MapColor.Green);
Inc(Bucket.Blue, MapColor.Blue);
Inc(Bucket.Count);
end;
end;
2005-09-11 06:20:56 -04:00
///////////////////////////////////////////////////////////////////////////////
constructor TBucketFillerThread.Create(cp: TControlPoint);
var
i, n: integer;
2005-09-11 06:20:56 -04:00
begin
inherited Create(True);
Self.FreeOnTerminate := True;
Fcp := cp.Clone;
SetLength(Points, SUB_BATCH_SIZE);
2006-03-02 12:27:20 -05:00
fcp.Prepare;
2005-09-11 06:20:56 -04:00
end;
///////////////////////////////////////////////////////////////////////////////
destructor TBucketFillerThread.Destroy;
begin
FCP.Free;
2005-09-11 06:20:56 -04:00
inherited;
end;
///////////////////////////////////////////////////////////////////////////////
procedure TBucketFillerThread.Execute;
var
bc: integer;
2006-03-02 12:27:20 -05:00
AddPointsProc: procedure (const points: TPointsArray) of object;
2005-09-11 06:20:56 -04:00
begin
inherited;
if FCP.FAngle = 0 then
AddPointsProc := AddPointsToBuckets
else
AddPointsProc := AddPointsToBucketsAngle;
2006-03-02 12:27:20 -05:00
2005-09-11 06:20:56 -04:00
bc := 0;
while (not Terminated) and (bc < Nrbatches) do begin
fcp.iterateXYC(SUB_BATCH_SIZE, points);
try
EnterCriticalSection(CriticalSection);
2006-03-02 12:27:20 -05:00
AddPointsProc(Points);
2005-09-11 06:20:56 -04:00
Inc(batchcounter^);
bc := batchcounter^
finally
LeaveCriticalSection(CriticalSection);
end;
end;
end;
///////////////////////////////////////////////////////////////////////////////
end.