Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add Color Filter Array (Bayer) #100

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 41 additions & 7 deletions ffv1.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,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. Both color spaces 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.

Expand Down Expand Up @@ -395,6 +395,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]

### Color Filter Array

(TODO)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what coming here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some general introduction to CFA, order of planes... as for the 2 other colors spaces.


## 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:
Expand Down Expand Up @@ -722,6 +726,10 @@ Parameters( ) { |
for (i = 1; i < 256; i++) |
state_transition_delta[ i ] | sr
colorspace_type | ur
if (colorspace_type == 2) { |
for ( i = 0; i < 4; i++ ) { |
cfa_pattern [ i ] | ur
} |
if (version >= 1) |
bits_per_raw_sample | ur
chroma_planes | br
Expand Down Expand Up @@ -810,16 +818,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 | Color Filter Array | JPEG2000-RCT | Color difference | `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, transparency MUST be 1.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of transparency MUST be 1 you should use the defined name of this value which is alpha_plane. But this is a hack, since alpha_plane=1 implies that a transparency plane is present. You'd have to adjust the definition of alpha_plane (maybe rename it), so that you're not implying that there is a transparency plane when there isn't.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also should consider #47 (comment), which comments on the semantics of infrared scans stored in an alpha plane.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I "copied" the way RGB support is added, i.e. I keep previous spec as much as possible. I prepare another PR focused on this renaming, which should be merged before this one.


### 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 |
JeromeMartinez marked this conversation as resolved.
Show resolved Hide resolved

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

Expand Down