1 | srecord noeq G22_RegionToSSIs(IImageRegion region) { |
2 | RGB 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 | |
52 | swappable IntRange selectHorizontalPart(L<IntRange> parts) { |
53 | ret first(parts); |
54 | } |
55 | } |
Began life as a copy of #1035608
download show line numbers debug dex old transpilations
Travelled to 1 computer(s): mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1035626 |
Snippet name: | G22_RegionToSSIs backup (creates incoherent SSIs) |
Eternal ID of this version: | #1035626/1 |
Text MD5: | 8eb8608ef0c7b5954a1b78edfe4d4f77 |
Author: | stefan |
Category: | javax / gazelle 22 |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-06-26 23:31:12 |
Source code size: | 1454 bytes / 55 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 149 / 138 |
Referenced in: | [show references] |