4 ms·
> Because of this hash the algorythm seems to do something else than first described though. Instead of "a running array of the 64 pixels it previously encounte
by sltkr 5y ago
> Because of this hash the algorythm seems to do something else than first described though. Instead of "a running array of the 64 pixels it previously encountered", it's actually the previous 64 pixel _values_ previously encountered, which allows for much bigger jumpback.
It's somewhere in between. Because these values are hashed into single slots, assuming that hash codes are random, the probability that a value is still in the table after k intervening values is pow(63/64, k).
That means the table is unlikely to contain all 64 values, but it will also retain some older values. Since older values are less likely to be useful in the future the encoding performance is likely somewhat worse than if the algorithm used strictly the last 64 distinct values.
This means that the algorithm is a bit sensitive to hash collisions, which seem particularly likely for primary colors (i.e. with each of the components at value 0 or 255):
- Slot 0: black, ALL SHADES OF magenta (x ^ 0 ^ x = 0), yellow (etc.) and cyan.
- Slot 15: white (255 ^ 255 ^ 255 = 255), red (255 ^ 0 ^ 0 = 255), green (etc.), blue.
Except black and white, these are unlikely to occur often in photographic images but could well occur in bitmaps with a handcrafted palette, or when the RGB values are converted from a system with a lower color space. For example, the 16 color CGA palette maps to just 3 different slots.
- j-pb 5y agoYeah, one should probably add a randomisations step for each channel for good measure. With random byte->byte lookup tables those costs should be hidden by the cache. so hash = HR[r] ^ HG[g] ^ HB[b] ^ HA[a].
- ball_of_lint 5y agoIn an image with very limited colors you would have long runs of the same color and it would compress well from just the run-length encoding alone. Also, it's non-obvious that older values will be less useful. Going through the pixels in order like this doesn't preserve locality well, so older values may actually be closer to a given pixel than more recent ones.
- MauranKilom 5y ago> In an image with very limited colors you would have long runs of the same color and it would compress well from just the run-length encoding alone. ...unless those images are dithered. Which may be a relatively common thing to do in small color spaces!