I'm currently working on a OpenCL-Decoder for lossless JPEG (DNG, CR2, etc.). The standard imposes very few restrictions on how the components may be laid out (interleave vs. planar), which collides with the rather inflexible OpenCL-kernels.
Especially the concept of component identifiers seems to be unnecessarily complex, so I'm wondering if I got them right:
A SOF3-header (Start of Frame 3, non-differential, Huffman coding, Lossless (sequential)) contains some informations about each component. Those are:
i
(implicit): index of the componentC_i
: Component identifierH_i
/V_i
: Horizontal/Vertical sampling factorTq_i
: Quantization table destination selector
Each frame may be composed of several scans containing the encoded image data for at least one color component. Each SOS-header (Start of scan) declares which component(s) will be part of the particular scan. For each component one of the previously declared identifiers (C_i
) is used as back-reference (Cs_j
, Scan component selector). There are very few restrictions in the standard (B.2.3 Scan header syntax):
Rule 1:
Each
Cs_j
shall match one of theC_i
values specified in the frame header, and the ordering in the scan header shall follow the ordering in the frame header. IfNs
> 1, the order of interleaved components in the MCU isCs_1
first,Cs_2
second, etc.
Rule 2:
The value of
Cs_j
shall be different from the values ofCs_1
toCs_j-1
.
My questions are:
- Rule 1 disallows re-ordering of components (e.g. R|G|B in Frame, but B|G|R in scan). Is it allowed to create multiple scans, each containing a single component (planar configuration) while using an ordering of scan-B, scan-G, scan-R, rather than scan-R, scan-G, scan-B?
- Is it possible to skip components in a scan? e.g. R|G|B declared in Frame followed by scan-R|B then scan_G?
- Why are the components within a scan referenced by their identifier (
C_i
) rather than their indices (i
) within the frame header? Are there any restrictions for the identifiers beyond uniqueness or is it really valid to declare R:C_0=255, G:C_1=3, B:C_2=250?