Skip to content

Commit e69f975

Browse files
dericedmichaelni
authored andcommitted
extend colorspace descriptions
Github: Closes #31
1 parent 210958c commit e69f975

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

ffv1.md

+37-3
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,6 @@ NumBytes is a non-negative integer that expresses the size in 8-bit octets of pa
148148

149149
# General Description
150150

151-
Each frame is split in 1 to 4 planes (Y, Cb, Cr, Alpha). In the case of the normal YCbCr colorspace the Y plane is coded first followed by the Cb and Cr planes, if an Alpha/transparency plane exists, it is coded last. In the case of the JPEG2000-RCT colorspace the lines are interleaved to improve caching efficiency since it is most likely that the RCT will immediately be converted to RGB during decoding; the interleaved coding order is also Y, Cb, Cr, Alpha.
152-
153151
Samples within a plane are coded in raster scan order (left->right, top->bottom). Each sample is predicted by the median predictor from samples in the same plane and the difference is stored see [Coding of the Sample Difference](#coding-of-the-sample-difference).
154152

155153
## Border
@@ -211,8 +209,23 @@ $$Q_{i}[a-b]=Table_{i}[(a-b)\&255]$$
211209

212210
## Colorspace
213211

212+
FFV1 supports two colorspaces: YCbCr and JPEG2000-RCT. Both colorspaces allow an optional Alpha plane that can be used to code transparency data.
213+
214+
### YCbCr
215+
216+
In YCbCr colorspace, the Cb and Cr planes are optional, but if used then MUST be used together. Omitting the Cb and Cr planes codes the frames in grayscale without color data. An FFV1 frame using YCbCr MUST use one of the following arrangements:
217+
218+
- Y
219+
- Y, Alpha
220+
- Y, Cb, Cr
221+
- Y, Cb, Cr, Alpha
222+
223+
When FFV1 uses the YCbCr colorspace, the Y plane MUST be coded first. If the Cb and Cr planes are used then they MUST be coded after the Y plane. If an Alpha (transparency) plane is used, then it MUST be coded last.
224+
214225
### JPEG2000-RCT
215226

227+
JPEG2000-RCT is a Reversible Color Transform that codes RGB (red, green, blue) planes losslessly in a modified YCbCr colorspace. Reversible conversions between YCbCr and RGB use the following formulae.
228+
216229
$$Cb=b-g$$
217230

218231
$$Cr=r-g$$
@@ -227,9 +240,30 @@ $$b=Cb+g$$
227240

228241
[@!ISO.15444-1.2016]
229242

243+
An FFV1 frame using JPEG2000-RCT MUST use one of the following arrangements:
244+
245+
- Y, Cb, Cr
246+
- Y, Cb, Cr, Alpha
247+
248+
When FFV1 uses the JPEG2000-RCT colorspace, the horizontal lines are interleaved to improve caching efficiency since it is most likely that the RCT will immediately be converted to RGB during decoding. The interleaved coding order is also Y, then Cb, then Cr, and then if used Alpha.
249+
250+
As an example, a frame that is two pixels wide and two pixels high, could be comprised of the following structure:
251+
252+
+------------------------+------------------------+
253+
| Pixel[1,1] | Pixel[2,1] |
254+
| Y[1,1] Cb[1,1] Cr[1,1] | Y[2,1] Cb[2,1] Cr[2,1] |
255+
+------------------------+------------------------+
256+
| Pixel[1,2] | Pixel[2,2] |
257+
| Y[1,2] Cb[1,2] Cr[1,2] | Y[2,2] Cb[2,2] Cr[2,2] |
258+
+------------------------+------------------------+
259+
260+
In JPEG2000-RCT colorspace, the coding order would be left to right and then top to bottom, with values interleaved by lines and stored in this order:
261+
262+
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]
263+
230264
## Coding of the sample difference
231265

232-
Instead of coding the n+1 bits of the sample difference with Huffman-, or Range coding (or n+2 bits, in the case of RCT), only the n (or n+1) 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 RCT or bits_per_raw_sample otherwise:
266+
Instead of coding the n+1 bits of the sample difference with Huffman or Range coding (or n+2 bits, in the case of RCT), only the n (or n+1) 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 RCT or bits_per_raw_sample otherwise:
233267

234268
$$coder\_input=\left[\left(sample\_difference+2^{bits-1}\right)\&\left(2^{bits}-1\right)\right]-2^{bits-1}$$
235269

0 commit comments

Comments
 (0)