diff --git a/ffv1.md b/ffv1.md index f93a7f2..f6260e7 100644 --- a/ffv1.md +++ b/ffv1.md @@ -45,6 +45,8 @@ The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "S `RGB`: A reference to the method of storing the value of a `Pixel` by using three numeric values that represent Red, Green, and Blue. +`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. + `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. `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 ## Color spaces -FFV1 supports two color spaces: YCbCr and RGB. Both color spaces allow an optional Alpha `Plane` that can be used to code transparency data. +FFV1 supports several color spaces. They allow an optional Alpha `Plane` that can be used to code transparency data. 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. @@ -395,6 +397,10 @@ In JPEG2000-RCT, the coding order would be left to right and then top to bottom, 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] +### RGGB Color Filter Array + +(TODO) + ## Coding of the Sample Difference 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( ) { | } | ec | ur intra | ur + if (colorspace_type == 2) { | + for ( i = 0; i < 4; i++ ) { | + cfa_pattern [ i ] | ur + } | } | } | ``` @@ -810,16 +820,42 @@ If state_transition_delta is not present in the FFV1 bitstream, all Range coder ### colorspace_type -`colorspace_type` specifies the color space losslessly encoded, the Pixel transformation used by the encoder, as well as interleave method. +`colorspace_type` specifies the color space encoded, the pixel transformation used by the encoder, the extra plane content, as well as interleave method. -|value | color space losslessly encoded | transformation | interleave method | -|-------|:--------------------------------|:--------------------------------|:--------------------------------| -| 0 | YCbCr | No Pixel transformation | `Plane` then `Line` | -| 1 | RGB | JPEG2000-RCT | `Line` then `Plane` | -| Other | reserved for future use | reserved for future use | reserved for future use | +|value | color space encoded | pixel transformation | extra plane content | interleave method | +|-------|:------------------------|:------------------------|:------------------------|:------------------------| +| 0 | YCbCr | None | Transparency | `Plane` then `Line` | +| 1 | RGB | JPEG2000-RCT | Transparency | `Line` then `Plane` | +| 2 | RGGB Color Filter Array | JPEG2000-RCT | Transparency | `Line` then `Plane` | +| Other | reserved for future use | reserved for future use | reserved for future use | reserved for future use | Restrictions: 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. +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. + +### cfa_pattern + +`cfa_pattern` indicates the actual color filter array geometric pattern of the image sensor used to capture the single sensor color image. +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. + +|value | color | +|-------|:--------------------------------| +|0 | red | +|1 | green | +|2 | blue | + +Restrictions: +At least 1 component of each color MUST be present. + +As an example, a typical pattern is 0112, which implies: + +``` ++---+---+ +| R | G | ++---+---+ +| G | B | ++---+---+ +``` ### chroma_planes @@ -1161,7 +1197,8 @@ SliceContent( ) { | for( p = 0; p < primary_color_count; p++ ) | for( y = 0; y < plane_pixel_height[ p ]; y++ ) | Line( p, y ) | - } else if (colorspace_type == 1) { | + } else if (colorspace_type == 1 | + || colorspace_type == 2) { | for( y = 0; y < slice_pixel_height; y++ ) | for( p = 0; p < primary_color_count; p++ ) | Line( p, y ) | @@ -1171,7 +1208,7 @@ SliceContent( ) { | ### primary_color_count -`primary_color_count` is defined as `1 + ( chroma_planes ? 2 : 0 ) + ( alpha_plane ? 1 : 0 )`. +`primary_color_count` is defined as `1 + ( chroma_planes ? 2 : 0 ) + ( colorspace_type == 2 ? 1 : 0 ) + ( alpha_plane ? 1 : 0 )`. ### plane_pixel_height