-
Notifications
You must be signed in to change notification settings - Fork 3
Description
This issue is a loose collection of ideas to further improve the BCn encoders in this library. Some might work out, some might not. I just want to write them down to here for myself and others to pick up. If you have more ideas, feel free to comment below.
Ideas:
-
BC7: Implement size variations like Improve BC4 quality #90 did for BC4.
The idea here is a follows. Suppose all pixel values in a block are 0.0, 0.1, or 0.2. Further suppose that the palette we're working with has 4 colors. Then the best 4-color palette is
[0.0, 0.1, 0.2, 0.3]. However, this palette is very hard to reach for the current algorithm, because it will start with the endpoints 0.0 and 0.2 (and palette[0.0, 0.666, 1.333, 0.2]) The jump to the optimal endpoints is just too large. But we fix this by simulating a palette with a smaller size, 3 colors in this case. If the palette had 3 colors instead of 4, then[0.0, 0.1, 0.2]would be the perfect palette. The trick here is that we can simulate this 3-color palette by changing one endpoint.So size variations allow us to compute the endpoints for palettes with M<N colors even though we only have an N-color palette.
Note: Some palette sizees don't need to be checked. E.g. 2 is always unnecessary and 3 is unnecessary if we checked any M-color palette where M is odd. Also, refinement can be good enough to make the jump to N-1 in practice.
-
BC7: Reuse lines fits.
The BC7 encoder needs to compute a lot of line fits for scoring partitions and rotations. These lines could be reused in the actual compression that follows. Computing a line fit of 16 RGB colors takes around 150µs, so the saving isn't much. This may be relevant for Fast quality though.
-
BC7: Add special handling for blocks with few unique colors.
Especially if a block only has 2 unique colors, it should be possible to find an optimal encoding rather quickly since partitions can be largely ignored. For 3 and 4 colors it largely boils down to finding a partition such that each subset contains at most 2 unique colors.
This likely won't improve quality (expect for specific corner cases) and should only be done in higher quality modes.
-
BC4: Add special handling for blocks with few unique colors.
If a block only has a few unique colors (2-4), then the number of possible (and sensible) weights a palette could assign to those colors might be small enough to brute force. The idea here is that given weights, we can compute the optimal endpoints for those weights. So if there are only a few weight combinations to check, we can find optimal endpoints using brute force.