Skip to content

Commit f33f879

Browse files
Add Color Filter Array (Bayer) support
1 parent 92b9868 commit f33f879

1 file changed

Lines changed: 46 additions & 9 deletions

File tree

ffv1.md

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "S
4545

4646
`RGB`: A reference to the method of storing the value of a `Pixel` by using three numeric values that represent Red, Green, and Blue.
4747

48+
`RGGB Color Filter Array`: A reference to the method of storing the value of a `Pixel` by using four numeric values that represent Red, Green, Blue, and Green Difference.
49+
4850
`YCbCr`: A reference to the method of storing the value of a `Pixel` by using three numeric values that represent the luma of the `Pixel` (Y) and the chrominance of the `Pixel` (Cb and Cr). YCbCr word is used for historical reasons and currently references any color space relying on 1 luma `Sample` and 2 chrominance `Samples` e.g. YCbCr, YCgCo or ICtCp. Exact meaning of the three numeric values is unspecified.
4951

5052
`TBA`: To Be Announced. Used in reference to the development of future iterations of the FFV1 specification.
@@ -294,7 +296,7 @@ Background: in first implementations of FFV1 bitstream, the index for Cb and Cr
294296

295297
## Color spaces
296298

297-
FFV1 supports two color spaces: YCbCr and RGB. Both color spaces allow an optional Alpha `Plane` that can be used to code transparency data.
299+
FFV1 supports several color spaces. They allow an optional Alpha `Plane` that can be used to code transparency data.
298300

299301
The FFV1 bitstream interleaves data in an order determined by the color space. In YCbCr for each `Plane`, each `Line` is coded from top to bottom and for each `Line`, each `Sample` is coded from left to right. In JPEG2000-RCT for each `Line` from top to bottom, each `Plane` is coded and for each `Plane`, each `Sample` is encoded from left to right.
300302

@@ -395,6 +397,10 @@ In JPEG2000-RCT, the coding order would be left to right and then top to bottom,
395397

396398
Y[1,1] Y[2,1] Cb[1,1] Cb[2,1] Cr[1,1] Cr[2,1] Y[1,2] Y[2,2] Cb[1,2] Cb[2,2] Cr[1,2] Cr[2,2]
397399

400+
### RGGB Color Filter Array
401+
402+
(TODO)
403+
398404
## Coding of the Sample Difference
399405

400406
Instead of coding the n+1 bits of the Sample Difference with Huffman or Range coding (or n+2 bits, in the case of JPEG2000-RCT), only the n (or n+1, in the case of JPEG2000-RCT) least significant bits are used, since this is sufficient to recover the original `Sample`. In the equation below, the term "bits" represents bits_per_raw_sample+1 for JPEG2000-RCT or bits_per_raw_sample otherwise:
@@ -745,6 +751,10 @@ Parameters( ) { |
745751
} |
746752
ec | ur
747753
intra | ur
754+
if (colorspace_type == 2) { |
755+
for ( i = 0; i < 4; i++ ) { |
756+
cfa_pattern [ i ] | ur
757+
} |
748758
} |
749759
} |
750760
```
@@ -810,16 +820,42 @@ If state_transition_delta is not present in the FFV1 bitstream, all Range coder
810820

811821
### colorspace_type
812822

813-
`colorspace_type` specifies the color space losslessly encoded, the Pixel transformation used by the encoder, as well as interleave method.
823+
`colorspace_type` specifies the color space encoded, the pixel transformation used by the encoder, the extra plane content, as well as interleave method.
814824

815-
|value | color space losslessly encoded | transformation | interleave method |
816-
|-------|:--------------------------------|:--------------------------------|:--------------------------------|
817-
| 0 | YCbCr | No Pixel transformation | `Plane` then `Line` |
818-
| 1 | RGB | JPEG2000-RCT | `Line` then `Plane` |
819-
| Other | reserved for future use | reserved for future use | reserved for future use |
825+
|value | color space encoded | pixel transformation | extra plane content | interleave method |
826+
|-------|:------------------------|:------------------------|:------------------------|:------------------------|
827+
| 0 | YCbCr | None | Transparency | `Plane` then `Line` |
828+
| 1 | RGB | JPEG2000-RCT | Transparency | `Line` then `Plane` |
829+
| 2 | RGGB Color Filter Array | JPEG2000-RCT | Transparency | `Line` then `Plane` |
830+
| Other | reserved for future use | reserved for future use | reserved for future use | reserved for future use |
820831

821832
Restrictions:
822833
If `colorspace_type` is 1, then `chroma_planes` MUST be 1, `log2_h_chroma_subsample` MUST be 0, and `log2_v_chroma_subsample` MUST be 0.
834+
If `colorspace_type` is 2, then `chroma_planes` MUST be 1, `log2_h_chroma_subsample` MUST be 0, and `log2_v_chroma_subsample` MUST be 0.
835+
836+
### cfa_pattern
837+
838+
`cfa_pattern` indicates the actual color filter array geometric pattern of the image sensor used to capture the single sensor color image.
839+
The pattern has a fixed size of 4 values (fixed width of 2, fixed height of 2) and is provided per line top to bottom, and for each line left to right.
840+
841+
|value | color |
842+
|-------|:--------------------------------|
843+
|0 | red |
844+
|1 | green |
845+
|2 | blue |
846+
847+
Restrictions:
848+
At least 1 component of each color MUST be present.
849+
850+
As an example, a typical pattern is 0112, which implies:
851+
852+
```
853+
+---+---+
854+
| R | G |
855+
+---+---+
856+
| G | B |
857+
+---+---+
858+
```
823859

824860
### chroma_planes
825861

@@ -1161,7 +1197,8 @@ SliceContent( ) { |
11611197
for( p = 0; p < primary_color_count; p++ ) |
11621198
for( y = 0; y < plane_pixel_height[ p ]; y++ ) |
11631199
Line( p, y ) |
1164-
} else if (colorspace_type == 1) { |
1200+
} else if (colorspace_type == 1 |
1201+
|| colorspace_type == 2) { |
11651202
for( y = 0; y < slice_pixel_height; y++ ) |
11661203
for( p = 0; p < primary_color_count; p++ ) |
11671204
Line( p, y ) |
@@ -1171,7 +1208,7 @@ SliceContent( ) { |
11711208
11721209
### primary_color_count
11731210
1174-
`primary_color_count` is defined as `1 + ( chroma_planes ? 2 : 0 ) + ( alpha_plane ? 1 : 0 )`.
1211+
`primary_color_count` is defined as `1 + ( chroma_planes ? 2 : 0 ) + ( colorspace_type == 2 ? 1 : 0 ) + ( alpha_plane ? 1 : 0 )`.
11751212
11761213
### plane_pixel_height
11771214

0 commit comments

Comments
 (0)