| 1393 | |
| 1394 | |
| 1395 | static unsigned getHash(const unsigned char* data, size_t size, size_t pos) |
| 1396 | { |
| 1397 | unsigned result = 0; |
| 1398 | if (pos + 2 < size) |
| 1399 | { |
| 1400 | /*A simple shift and xor hash is used. Since the data of PNGs is dominated |
| 1401 | by zeroes due to the filters, a better hash does not have a significant |
| 1402 | effect on speed in traversing the chain, and causes more time spend on |
| 1403 | calculating the hash.*/ |
| 1404 | result ^= (unsigned)(data[pos + 0] << 0u); |
| 1405 | result ^= (unsigned)(data[pos + 1] << 4u); |
| 1406 | result ^= (unsigned)(data[pos + 2] << 8u); |
| 1407 | } else { |
| 1408 | size_t amount, i; |
| 1409 | if(pos >= size) return 0; |
| 1410 | amount = size - pos; |
| 1411 | for(i = 0; i < amount; i++) result ^= (unsigned)(data[pos + i] << (i * 8u)); |
| 1412 | } |
| 1413 | return result & HASH_BIT_MASK; |
| 1414 | } |
| 1415 | |
| 1416 | static unsigned countZeros(const unsigned char* data, size_t size, size_t pos) |
| 1417 | { |