Libraryless. Click here for Pure Java version (8511L/49K).
sclass HashedBWImage is IBWImage, MakesBWImage { BWImage image; // don't change this afterwards... long hash; bool hashComputed; *(BufferedImage image) { this(bwImage(image)); } *(BWImage *image) { assertNotNull(image); } long hash() { while (!hashComputed) { synchronized { if (!hashComputed) { hash = hashBWImage(image); set hashComputed; } } } ret hash; } equals HashedBWImage o { if (hash() != o.hash()) false; if (!bwImagesIdentical(image, o.image)) { reportHashCollision(this, o); false; } true; } public int hashCode() { ret (int) hash(); } public BWImage get aka getBWImage() { ret image; } public int getWidth() { ret image.getWidth(); } public int getHeight() { ret image.getHeight(); } public BufferedImage getBufferedImage() { ret image.getBufferedImage(); } // check that BWImage wasn't modified void verify { if (hash != 0) assertEquals(hash, hashBWImage(image)); } S classNameForPrinting() { ret cnfp(this, selfType.class, "HashedBWImage"; } toString { ret formatFunctionCall(classNameForPrinting(), w() + "*" + h() + "px", "hash " + longToHex(hash())); } // implement IBWImage public float getFloatPixel(int x, int y) { ret image.getFloatPixel(x, y); } public int getInt(int x, int y) { ret image.getInt(x, y); } }
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: | 639 / 884 |
| Version history: | 20 change(s) |
| Referenced in: | #1003674 - Standard Classes + Interfaces (LIVE continued in #1034167) #1034821 - IntegratedBWImage - immutable BWImage with 64 bit hash and IBWIntegralImage #1035844 - HashedImage2B - immutable Image2B with 64 bit contents hash. untested |