Libraryless. Click here for Pure Java version (10423L/58K).
1 | sinterface Decolorizer {
|
2 | int toGrayScale(int rgb); |
3 | |
4 | default int toGrayScale(Color color) {
|
5 | ret toGrayScale(colorToRGBInt(color)); |
6 | } |
7 | |
8 | srecord Red is Decolorizer {
|
9 | public int toGrayScale(int rgb) { ret (rgb >> 16) & 0xFF; }
|
10 | } |
11 | |
12 | srecord Green is Decolorizer {
|
13 | public int toGrayScale(int rgb) { ret (rgb >> 8) & 0xFF; }
|
14 | } |
15 | |
16 | srecord Blue is Decolorizer {
|
17 | public int toGrayScale(int rgb) { ret rgb & 0xFF; }
|
18 | } |
19 | |
20 | srecord Alpha is Decolorizer {
|
21 | public int toGrayScale(int rgb) { ret (rgb >> 24) & 0xFF; }
|
22 | } |
23 | |
24 | // just the average of the 3 channels |
25 | srecord Simple is Decolorizer {
|
26 | public int toGrayScale(int rgb) {
|
27 | int r = (rgb >> 16) & 0xFF; |
28 | int g = (rgb >> 8) & 0xFF; |
29 | int b = rgb & 0xFF; |
30 | ret (r+g+b+1)/3; |
31 | } |
32 | } |
33 | } |
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
| Snippet ID: | #1034177 |
| Snippet name: | Decolorizer |
| Eternal ID of this version: | #1034177/7 |
| Text MD5: | c586f5983147301b206087a71a2b996b |
| Transpilation MD5: | 05c57562e3d70589260b98f39ac7438d |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2022-08-02 20:35:45 |
| Source code size: | 822 bytes / 33 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 622 / 820 |
| Version history: | 6 change(s) |
| Referenced in: | [show references] |