4

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 component
  • C_i: Component identifier
  • H_i/V_i: Horizontal/Vertical sampling factor
  • Tq_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 the C_i values specified in the frame header, and the ordering in the scan header shall follow the ordering in the frame header. If Ns > 1, the order of interleaved components in the MCU is Cs_1 first, Cs_2 second, etc.

Rule 2:

The value of Cs_j shall be different from the values of Cs_1 to Cs_j-1.

My questions are:

  1. 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?
  2. 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?
  3. 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?
Kai Giebeler
  • 517
  • 6
  • 12
  • The answer to your question is likely to be found in the file format standard. The JPEG standard is, as you note, ambiguous. The JPEG standard does not even define that it uses RGB. In fact, for sequential and progressive JPEG YCbCr is normally used. – user3344003 Apr 11 '17 at 03:19
  • I didn't find an explanation in the standard - that's why I'm asking this question. I didn't call the standard "ambiguous" - I was just hoping for more restrictions and/or some explanations I might have missed to keep the decoder's complexity reasonable. RGB was just an example. In CR2 and DNG the JPEG components (2 or 4) do even correspond to alternating components of the Bayer CFA with manipulated image dimensions - only the number and order of the extracted sample values are meaningful. The colorimetric interpretation is left to the enclosing standard. JPEG itself is "color-blind". – Kai Giebeler Apr 11 '17 at 19:34
  • The standard is ambiguous. That is why there are various file formats that fill in gaps of the standard. I am not familiar with lossless standards as lossless JPEG modes are so rarely used. – user3344003 Apr 12 '17 at 00:22

0 Answers0