get("#356") -- num2hex
get("#348") -- rgb functions
function hashImage(img)
local hash = 0
local w, h = img.width, img.height
for y = 0, h-1 do
for x = 0, w-1 do
local pix = img.getInt(x, y)
local r, g, b = rgb(pix)
local p = r+g*33+b*71
local scale = bit32.band(y*w+x, 0xFFFF)+1
--hash = (hash * a + pix) % 0x100000000
--a = (a * b) % 0x100000000
local arg = (p+1)*scale
hash = bit32.bxor(hash, arg)
--[[if x < 10 then
print("scale", scale, "pix", pix, "p", p, "arg", arg, "hash", hash)
end]]
end
--print("y", y, "hash", hash)
end
return num2hex(hash, 8)
endProbably fairly crappy (might cause hash collisions), but I guess it can be used for now
test run test run with input download show line numbers
Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #380 |
| Snippet name: | hashImage (include) |
| Eternal ID of this version: | #380/1 |
| Text MD5: | 0137480d9879d478d1cbaea509066e51 |
| Author: | stefan |
| Category: | hash functions |
| Type: | Lua code |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2015-02-17 20:35:12 |
| Source code size: | 681 bytes / 26 lines |
| Pitched / IR pitched: | No / Yes |
| Views / Downloads: | 1266 / 355 |
| Referenced in: | [show references] |