Libraryless. Click here for Pure Java version (8511L/49K).
1 | sclass HashedBWImage is IBWImage, MakesBWImage {
|
2 | BWImage image; // don't change this afterwards... |
3 | long hash; |
4 | bool hashComputed; |
5 | |
6 | *(BufferedImage image) { this(bwImage(image)); }
|
7 | *(BWImage *image) { assertNotNull(image); }
|
8 | |
9 | long hash() {
|
10 | while (!hashComputed) {
|
11 | synchronized {
|
12 | if (!hashComputed) {
|
13 | hash = hashBWImage(image); |
14 | set hashComputed; |
15 | } |
16 | } |
17 | } |
18 | |
19 | ret hash; |
20 | } |
21 | |
22 | equals HashedBWImage o {
|
23 | if (hash() != o.hash()) false; |
24 | if (!bwImagesIdentical(image, o.image)) {
|
25 | reportHashCollision(this, o); |
26 | false; |
27 | } |
28 | true; |
29 | } |
30 | |
31 | public int hashCode() { ret (int) hash(); }
|
32 | |
33 | public BWImage get aka getBWImage() { ret image; }
|
34 | |
35 | public int getWidth() { ret image.getWidth(); }
|
36 | public int getHeight() { ret image.getHeight(); }
|
37 | public BufferedImage getBufferedImage() { ret image.getBufferedImage(); }
|
38 | |
39 | // check that BWImage wasn't modified |
40 | void verify {
|
41 | if (hash != 0) |
42 | assertEquals(hash, hashBWImage(image)); |
43 | } |
44 | |
45 | S classNameForPrinting() { ret cnfp(this, selfType.class, "HashedBWImage"; }
|
46 | |
47 | toString { ret formatFunctionCall(classNameForPrinting(),
|
48 | w() + "*" + h() + "px", "hash " + longToHex(hash())); } |
49 | |
50 | // implement IBWImage |
51 | |
52 | public float getFloatPixel(int x, int y) { ret image.getFloatPixel(x, y); }
|
53 | public int getInt(int x, int y) { ret image.getInt(x, y); }
|
54 | } |
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
| Snippet ID: | #1034818 |
| Snippet name: | HashedBWImage - immutable BWImage with 64 bit contents hash |
| Eternal ID of this version: | #1034818/21 |
| Text MD5: | 782098e77a3250909cff04770fe6ae7a |
| Transpilation MD5: | cfd63ac6b96fead3c57a505fa3cfcf50 |
| Author: | stefan |
| Category: | javax / imaging |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2022-03-11 07:32:52 |
| Source code size: | 1467 bytes / 54 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 640 / 885 |
| Version history: | 20 change(s) |
| Referenced in: | [show references] |