I created code that will work for TIFF predictors with bpc 2 and 4. Because there are no test images, the code is written so that it can work with bpc 1, 2, 4 and 8 (but not 16) and has been tested on what we have, which are the corner cases bpc 1 and 8. The bit sequence retrieval / assignment methods have tests so the risk is small.
If anyone wants to optimize the new code, it should be retested with the same method, i.e. disable the (faster) code for bpc 1 and 8. And if it comes out that optimization went wrong, we'll still have this code as a fallback. However optimization isn't really needed, almost all files "in the wild" are bpc 8.
I also did some slight optimizations of the existing code, p - bytesPerPixel >= 0 ? ... can be removed by starting the for loop at bytesPerPixel.