Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

17
LINES

< > BotCompany Repo | #1006582 // rgbDiff - see pixelDiff

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (9471L/52K).

1  
static float rgbDiff(RGB a, RGB b) {
2  
  return (float) (Math.abs(a.r-b.r) + Math.abs(a.g-b.g) + Math.abs(a.b-b.b))/3;
3  
}
4  
5  
// 0xRRGGBB - result is between 0 and 1
6  
static float rgbDiff(int a, int b) {
7  
  int r1 = (a >> 16) & 0xFF;
8  
  int g1 = (a >> 8) & 0xFF;
9  
  int b1 = a & 0xFF;
10  
  int r2 = (b >> 16) & 0xFF;
11  
  int g2 = (b >> 8) & 0xFF;
12  
  int b2 = b & 0xFF;
13  
  ret (Math.abs(r1-r2) + Math.abs(g1-g2) + Math.abs(b1-b2))
14  
    // hilarious micro-optimisation instead of just dividing
15  
    // (99.9% sure HotSpot does this anyway!)
16  
    *(1/(3f*255));
17  
}

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: 590 / 714
Version history: 5 change(s)
Referenced in: [show references]