Skip to content

Commit a1fdf15

Browse files
committed
renmatrix: Classify corners via lookup in the region tracing scan
Scan each raster line of corner codes with the column kept on the stack and a static classification string identifying the stem corners at which a boundary trace starts; only those rare corners spill to variables. The scan order and discovery semantics are unchanged, producing identical paths.
1 parent 2e3705c commit a1fdf15

1 file changed

Lines changed: 38 additions & 16 deletions

File tree

src/renmatrix.ps.src

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,19 @@ begin
131131

132132
] readonly def
133133

134+
%
135+
% Corner codes at which a region boundary trace starts:
136+
%
137+
% 1 = black region stem corners: 0 0 1 0
138+
% * and *
139+
% 0 1 0 1
140+
%
141+
% 2 = white region stem corner: 1 1
142+
% *
143+
% 1 0
144+
%
145+
/renmatrix.stemclass <00010000000000000001000000000200> readonly def
146+
134147
/renmatrix {
135148

136149
256 dict begin
@@ -397,26 +410,35 @@ begin
397410
/abcdget { pixx 1 sub mul add abcdcache exch get } def
398411

399412
%
400-
% Construct paths by tracing regions avoiding duplication by using the cache
413+
% Construct paths by tracing regions, avoiding duplication by using
414+
% the cache. Each raster line of corner codes is scanned with the
415+
% column kept on the stack; stem corners are rare, so only they
416+
% spill to variables.
401417
%
402418
/paths [
403419
0 1 pixycomp 2 sub {
404420
/j exch def
405-
0 1 pixx 2 sub {
406-
/i exch def
407-
/k i j abcdget def
408-
k 2#0001 eq % Black region stem corners:
409-
k 2#1001 eq or { %
410-
//renmatrix.up i j cget 0 eq { % 0 0 1 0
411-
i j trace % * and *
412-
} if % 0 1 0 1
413-
} if
414-
k 2#1110 eq { % White region stem corner:
415-
//renmatrix.left i j cget 0 eq { %
416-
i j trace % 1 1
417-
} if % *
418-
} if % 1 0
419-
} for
421+
0
422+
abcdcache j abcdw mul abcdw getinterval { % i code
423+
//renmatrix.stemclass exch get % i class
424+
dup 0 ne {
425+
exch /i exch def % class
426+
1 eq { % Black region stem corner
427+
//renmatrix.up i j cget 0 eq {
428+
i j trace
429+
} if
430+
} { % White region stem corner
431+
//renmatrix.left i j cget 0 eq {
432+
i j trace
433+
} if
434+
} ifelse
435+
i
436+
} {
437+
pop
438+
} ifelse
439+
1 add
440+
} forall
441+
pop
420442
} for
421443
] def
422444

0 commit comments

Comments
 (0)