Libraryless. Click here for Pure Java version (15985L/93K).
1 | srecord noeq G22_RegionToSSIs(IImageRegion region) { |
2 | Color color; |
3 | L<SSI> ssis; |
4 | new L<GrowingSSI> growingSSIs; |
5 | |
6 | class GrowingSSI { |
7 | settable int y1; |
8 | new ShortBuffer data; |
9 | |
10 | int y2() { ret y1+l(data)/2; } |
11 | |
12 | SSI finish() { |
13 | ret new SSI(y1, y2()).data(data.toArray()) |
14 | .color(color); |
15 | } |
16 | } |
17 | |
18 | L<SSI> get() { |
19 | if (region == null) null; |
20 | |
21 | color = region.color(); |
22 | ssis = new L; |
23 | Rect r = region.bounds(); |
24 | int x1 = r.x1(), y1 = r.y1(), y2 = r.y2(), h = y2-y1, w = r.w; |
25 | for (int y = y1; y < y2; y++) { |
26 | reMutable y; |
27 | L<IntRange> streaks = genericStreaks(w, x -> region.contains(x1+x, y)); |
28 | |
29 | // finish SSIs |
30 | while (longerThan(growingSSIs, streaks)) |
31 | ssis.add(popLast(growingSSIs).finish()); |
32 | |
33 | // now we know that l(growingSSIs) <= l(streaks) |
34 | // start new SSIs |
35 | |
36 | for (int i = l(growingSSIs); i < l(streaks); i++) |
37 | growingSSIs.add(new GrowingSSI().y1(y)); |
38 | |
39 | // continue SSIs |
40 | for (ssi, range : unpair zipTwoLists(growingSSIs, streaks)) { |
41 | ssi.data.add(toShort_enforce(x1+range.start)); |
42 | ssi.data.add(toShort_enforce(x1+range.end)); |
43 | } |
44 | } |
45 | |
46 | for (ssi : cloneAndClear(growingSSIs)) |
47 | ssis.add(ssi.finish()); |
48 | |
49 | ret ssis; |
50 | } |
51 | } |
Began life as a copy of #1035605
download show line numbers debug dex old transpilations
Travelled to 2 computer(s): elmgxqgtpvxh, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1035608 |
Snippet name: | G22_RegionToSSIs - full conversion but possibly incoherent SSIs |
Eternal ID of this version: | #1035608/12 |
Text MD5: | 38b3992f71f3acd7d5868c1a88b5b0d0 |
Transpilation MD5: | 76f0cc7114531bd0a8f6921aeb9177cd |
Author: | stefan |
Category: | javax / gazelle 22 |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-07-25 10:50:13 |
Source code size: | 1360 bytes / 51 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 174 / 282 |
Version history: | 11 change(s) |
Referenced in: | [show references] |