Libraryless. Click here for Pure Java version (6977L/40K).
1 | static BWImage gazelle22_borderImage(BWImage posterizedWithMeta) { |
2 | PosterizeBWImage op = cast getMetaSrc(posterizedWithMeta); |
3 | ret gazelle22_borderImage(op.img, posterizedWithMeta, op.brightnessLevels); |
4 | } |
5 | |
6 | static BWImage gazelle22_borderImage(BWImage unposterized, BWImage posterized, int brightnessLevels) { |
7 | assertSameSize(unposterized, posterized); |
8 | int w = posterized.getWidth(), h = posterized.getHeight(); |
9 | BWImage out = new(w*2+1, h*2+1); |
10 | int singleStep = iceil(doubleRatio(255, brightnessLevels-1)); |
11 | |
12 | for y to h: |
13 | for x to w: { |
14 | if (x < w-1) { |
15 | // check border with right neighbor |
16 | |
17 | int posterizedContrast = absDiff(posterized.getInt(x, y), |
18 | posterized.getInt(x+1, y)); |
19 | |
20 | float result; |
21 | if (posterizedContrast != 0) { |
22 | if (posterizedContrast > singleStep) result = 1f; |
23 | else { |
24 | int realContrast = absDiff(unposterized.getInt(x, y), |
25 | unposterized.getInt(x+1, y)); |
26 | result = floatRatio(realContrast, singleStep); |
27 | } |
28 | out.setPixel(x*2+1, y*2, result); |
29 | out.setPixel(x*2+1, y*2+1, result); |
30 | } |
31 | } |
32 | |
33 | if (y < h-1) { |
34 | // check border with bottom neighbor |
35 | |
36 | int posterizedContrast = absDiff(posterized.getInt(x, y), |
37 | posterized.getInt(x, y+1)); |
38 | |
39 | float result; |
40 | if (posterizedContrast != 0) { |
41 | if (posterizedContrast > singleStep) result = 1f; |
42 | else { |
43 | int realContrast = absDiff(unposterized.getInt(x, y), |
44 | unposterized.getInt(x+1, y)); |
45 | result = floatRatio(realContrast, singleStep); |
46 | } |
47 | out.setPixel(x*2, y*2+1, result); |
48 | out.setPixel(x*2+1, y*2+1, result); |
49 | } |
50 | } |
51 | } |
52 | |
53 | ret out; |
54 | } |
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1033934 |
Snippet name: | gazelle22_borderImage |
Eternal ID of this version: | #1033934/5 |
Text MD5: | 87534d412515d1c89f5c993b21ee75ce |
Transpilation MD5: | c23e8bc06316ec906d0851c27af1551e |
Author: | stefan |
Category: | javax / gazelle 22 |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-01-14 01:14:36 |
Source code size: | 1871 bytes / 54 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 139 / 217 |
Version history: | 4 change(s) |
Referenced in: | [show references] |