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

24
LINES

< > BotCompany Repo | #1035835 // HashBinaryImage - makes a 64 bit hash of an IBinaryImage (compatible with HashBufferedImage)

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

Libraryless. Click here for Pure Java version (12666L/73K).

1  
srecord noeq HashBinaryImage(IBinaryImage img) {
2  
  long hash;
3  
  
4  
  long get() {
5  
    if (img == null) ret hash;
6  
    var img = this.img.toImage2B();
7  
    
8  
    int w = img.getWidth(), h = img.getHeight();
9  
    int n = w*h;
10  
    byte[] pixels = img.pixels;
11  
12  
    addToHash(w);
13  
    addToHash(h);
14  
    
15  
    for i to n:
16  
      addToHash((pixels[i/8] & (1 << (i & 7))) != 0 ? 0xFFFFFFFF : 0xFF000000);
17  
18  
    ret hash;
19  
  }
20  
  
21  
  void addToHash(long x) {
22  
    hash = boostHashCombine64(hash, x);
23  
  }
24  
}

Author comment

Began life as a copy of #1034815

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): elmgxqgtpvxh, mqqgnosmbjvj, wnsclhtenguj

No comments. add comment

Snippet ID: #1035835
Snippet name: HashBinaryImage - makes a 64 bit hash of an IBinaryImage (compatible with HashBufferedImage)
Eternal ID of this version: #1035835/4
Text MD5: 4ea07c5f99f6dd969950a206a50705db
Transpilation MD5: cfeca2e9e3af2d321301373c9fe8d5dd
Author: stefan
Category: javax / imaging
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-08-02 19:20:22
Source code size: 505 bytes / 24 lines
Pitched / IR pitched: No / No
Views / Downloads: 71 / 118
Version history: 3 change(s)
Referenced in: [show references]