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

39
LINES

< > BotCompany Repo | #1034798 // HashBufferedImage - makes a 64 bit hash of an image (fast but not as good as MD5)

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

Transpiled version (8035L) is out of date.

1  
// The hash for an image without alpha channel is guaranteed to be
2  
// identical for a completely opaque image with alpha.
3  
srecord noeq HashBufferedImage(BufferedImage img) {
4  
  long hash;
5  
  
6  
  long get() {
7  
    if (img == null) ret hash;
8  
    
9  
    var gp = grabbableIntPixels_fastOrSlow(img);
10  
    bool hasAlpha = hasAlpha(img);
11  
    
12  
    var ping = pingSource();
13  
    int[] pixelsIn = gp.data;
14  
    int w = gp.w, h = gp.h;
15  
    int scanlineExtra = gp.scanlineStride-w;
16  
    int iIn = gp.offset;
17  
18  
    addToHash(w);
19  
    addToHash(h);
20  
    
21  
    for y to h: {
22  
      for x to w: {
23  
        int packed = pixelsIn[iIn++];
24  
        if (!hasAlpha) packed |= 0xFF000000;
25  
        addToHash(packed);
26  
      }
27  
28  
      iIn += scanlineExtra;
29  
      ping?!;
30  
    }
31  
    
32  
    ret hash;
33  
  }
34  
  
35  
  void addToHash(long x) {
36  
    hash = boostHashCombine64(hash, x);
37  
    printVars ifdef HashBufferedImage_debug(x := longToHex(x), +hash);
38  
  }
39  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1034798
Snippet name: HashBufferedImage - makes a 64 bit hash of an image (fast but not as good as MD5)
Eternal ID of this version: #1034798/8
Text MD5: 088589a5c62c2301a77bd2dd5dd1178e
Author: stefan
Category: javax / imaging
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-03-10 22:57:41
Source code size: 941 bytes / 39 lines
Pitched / IR pitched: No / No
Views / Downloads: 141 / 247
Version history: 7 change(s)
Referenced in: [show references]