Libraryless. Click here for Pure Java version (15985L/93K).
srecord noeq G22_RegionToSSIs(IImageRegion region) { Color color; L<SSI> ssis; new L<GrowingSSI> growingSSIs; class GrowingSSI { settable int y1; new ShortBuffer data; int y2() { ret y1+l(data)/2; } SSI finish() { ret new SSI(y1, y2()).data(data.toArray()) .color(color); } } L<SSI> get() { if (region == null) null; color = region.color(); ssis = new L; Rect r = region.bounds(); int x1 = r.x1(), y1 = r.y1(), y2 = r.y2(), h = y2-y1, w = r.w; for (int y = y1; y < y2; y++) { reMutable y; L<IntRange> streaks = genericStreaks(w, x -> region.contains(x1+x, y)); // finish SSIs while (longerThan(growingSSIs, streaks)) ssis.add(popLast(growingSSIs).finish()); // now we know that l(growingSSIs) <= l(streaks) // start new SSIs for (int i = l(growingSSIs); i < l(streaks); i++) growingSSIs.add(new GrowingSSI().y1(y)); // continue SSIs for (ssi, range : unpair zipTwoLists(growingSSIs, streaks)) { ssi.data.add(toShort_enforce(x1+range.start)); ssi.data.add(toShort_enforce(x1+range.end)); } } for (ssi : cloneAndClear(growingSSIs)) ssis.add(ssi.finish()); ret ssis; } }
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: | 173 / 281 |
Version history: | 11 change(s) |
Referenced in: | #1003674 - Standard Classes + Interfaces (LIVE continued in #1034167) #1035626 - G22_RegionToSSIs backup (creates incoherent SSIs) #1035627 - G22_RegionToSSIs_v2 - full conversion with cohesion and fewest SSIs (WORKS) |