Libraryless. Click here for Pure Java version (11165L/64K).
1 | srecord noeq Hi15ImageStreaks(Hi15Image inputImage) { |
2 | // pixel indices of streak ends |
3 | new IntBuffer streakData; |
4 | int[] lineStarts; |
5 | gettable int w; |
6 | |
7 | run { |
8 | var streakData = this.streakData; |
9 | int w = this.w = inputImage.w(), h = inputImage.h(); |
10 | lineStarts = new int[h+1]; |
11 | short[] pixels = inputImage.pixels; |
12 | int iPixel = 0; |
13 | |
14 | for y to h: { |
15 | lineStarts[y] = streakData.size(); |
16 | int lineEnd = iPixel+w; |
17 | while (iPixel < lineEnd) { |
18 | short color = pixels[iPixel]; |
19 | do |
20 | ++iPixel; |
21 | while (iPixel < lineEnd && pixels[iPixel] == color); |
22 | streakData.add(iPixel); |
23 | } |
24 | } |
25 | |
26 | lineStarts[l(lineStarts)-1] = streakData.size(); |
27 | } |
28 | |
29 | selfType runAndReturn() { run(); this; } |
30 | |
31 | int nStreaks() { ret streakData.size(); } |
32 | int h() { ret lineStarts.length-1; } |
33 | |
34 | int lineEnd(int y) { ret lineStarts[y+1]; } |
35 | |
36 | L<Rect> streaksAsRects() { |
37 | ret listFromFunction(nStreaks(), iStreak -> { |
38 | int iPixel = iStreak == 0 ? 0 : streakData.get(iStreak-1); |
39 | int jPixel = streakData.get(iStreak++); |
40 | int w = w(); |
41 | ret rect(iPixel % w, iPixel/w, jPixel-iPixel, 1); |
42 | }); |
43 | } |
44 | } |
download show line numbers debug dex old transpilations
Travelled to 2 computer(s): elmgxqgtpvxh, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1036091 |
Snippet name: | Hi15ImageStreaks |
Eternal ID of this version: | #1036091/19 |
Text MD5: | 5b954d5a669571d42f8873dbf190cabc |
Transpilation MD5: | 30c4e796a9e0929fa691b1952f9b00d9 |
Author: | stefan |
Category: | javax / imaging |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-09-12 17:40:54 |
Source code size: | 1221 bytes / 44 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 147 / 273 |
Version history: | 18 change(s) |
Referenced in: | [show references] |