After having progressed on the other fronts, I return to the colorspace decomposition where I'm now addressing another "low hanging fruit" : that is, some way to gain a bit more space with relatively little effort, and without risk of expansion. I guess the average gain would be in the 10 to 20% range but this depends a lot on the data. This is a small gain but not negligible and the required effort is modest : it's a small permutation based on already known data.
As mentioned before, the 3RGB encoding pipeline breaks the image in 8×8 tiles and the first step is to compute the min and max values of each block, in parallel, for the individual R, G & B components.
Then, the 3 blocks (R,G,B) are transformed to the new colorspace by applying two nested σα transforms. Since we know the min and max values of each block, we can apply the generalised algorithm (see Extension to unequal boundaries) which swaps the operands: the smallest range is output after the sum.
We can go a bit further and pre-swap the block pointers: this simple step takes the swap out of the inner loop, which runs faster.
There are 6 permutations for RGB:
- B G R
- B R G
- G B R
- G R B
- R B G
- R G B
A little bubble sort would be enough but we don't need to go so far : two of the components are reproduced verbatim (at worst) so we just need to find the largest limit and map it to the intermediary sum (which is not directly transmitted)
Another parameter comes into play: the second σα transform applies to the sum of two components, so we could evaluate
- B + G
- B + R
- R + G
but if we already know, for example, that B is the largest value, then B+G > R and B+R > G.
This leaves us with only 3 practical combinations:
- σα( σα(B, G), R)
- σα( σα(G, R), B)
- σα( σα(R, B), G)
with the function σα(a,b) returning the sum a+b, and range(a)>range(b) (the modified b is sent on the bitstream).
Does the order of the two smaller ranges matter ? I think it's better to have the highest difference possible between the operands, so the general formula would be
σα( σα(max, med), min)
See the rest of the algorithm at Basic algorithm for one block