Libraryless. Click here for Pure Java version (9471L/52K).
static float rgbDiff(RGB a, RGB b) { return (float) (Math.abs(a.r-b.r) + Math.abs(a.g-b.g) + Math.abs(a.b-b.b))/3; } // 0xRRGGBB - result is between 0 and 1 static float rgbDiff(int a, int b) { int r1 = (a >> 16) & 0xFF; int g1 = (a >> 8) & 0xFF; int b1 = a & 0xFF; int r2 = (b >> 16) & 0xFF; int g2 = (b >> 8) & 0xFF; int b2 = b & 0xFF; ret (Math.abs(r1-r2) + Math.abs(g1-g2) + Math.abs(b1-b2)) // hilarious micro-optimisation instead of just dividing // (99.9% sure HotSpot does this anyway!) *(1/(3f*255)); }
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1006582 |
| Snippet name: | rgbDiff - see pixelDiff |
| Eternal ID of this version: | #1006582/6 |
| Text MD5: | a7a814589bd6241450dbc5bba2959592 |
| Transpilation MD5: | 77260e2d966dcec303c135f98c3a1bde |
| Author: | stefan |
| Category: | javax / imaging |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2022-08-27 01:13:19 |
| Source code size: | 556 bytes / 17 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 836 / 1005 |
| Version history: | 5 change(s) |
| Referenced in: | [show references] |