⚡ Encode multimaps from scanlines instead of canvas pixels
Reading the canvas per pixel made writing a multimap orders of magnitude slower than necessary.
This commit is contained in:
+6
-2
@@ -120,6 +120,7 @@ var
|
|||||||
height, width, x, y: Integer;
|
height, width, x, y: Integer;
|
||||||
run: Byte;
|
run: Byte;
|
||||||
state, newState: Boolean;
|
state, newState: Boolean;
|
||||||
|
row: PByte;
|
||||||
|
|
||||||
procedure DoWrite;
|
procedure DoWrite;
|
||||||
var
|
var
|
||||||
@@ -136,13 +137,16 @@ begin
|
|||||||
Data.Write(width, SizeOf(Integer));
|
Data.Write(width, SizeOf(Integer));
|
||||||
Data.Write(height, SizeOf(Integer));
|
Data.Write(height, SizeOf(Integer));
|
||||||
run := 0;
|
run := 0;
|
||||||
state := not (FGraphic.Canvas.Pixels[0,0] = clWhite);
|
state := True;
|
||||||
|
if (width > 0) and (height > 0) then
|
||||||
|
state := (PByte(FGraphic.ScanLine[0])[0] and $80) = 0;
|
||||||
if Assigned(FOnProgress) then FOnProgress(0, 0);
|
if Assigned(FOnProgress) then FOnProgress(0, 0);
|
||||||
for y := 0 to height - 1 do
|
for y := 0 to height - 1 do
|
||||||
begin
|
begin
|
||||||
|
row := FGraphic.ScanLine[y];
|
||||||
for x := 0 to width - 1 do
|
for x := 0 to width - 1 do
|
||||||
begin
|
begin
|
||||||
newState := not (FGraphic.Canvas.Pixels[x,y] = clWhite);
|
newState := (row[x shr 3] and ($80 shr (x and 7))) = 0;
|
||||||
if (state = newState) and (run < $7F) then
|
if (state = newState) and (run < $7F) then
|
||||||
begin
|
begin
|
||||||
inc(run);
|
inc(run);
|
||||||
|
|||||||
Reference in New Issue
Block a user