We have as input a 8 or 12-bit image in Bayer format (RGGB CFA).
We can store it uncompressed as DNG without much problem by specifying CFA_PATTERN.
Now we want to compress it using lossless JPEG, and the problem is that CFA_PATTERN seems to assume SAMPLESPERPIXEL=1. That means JPEG receives an image as greyscale with lots of high frequencies due to Bayer pattern, so it performs very badly.
Is there a way to compress individual RGGB input channels as separate JPEG 'planes'?