X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=ycbcr.h;h=207be4e98a81963aae12a86f18ff9aa8e5a9000a;hp=4eb9e73185794fc0118ec2590e4303892dfa8595;hb=a2e7b432626b8a2c54cb1ff9d09203f50227fc07;hpb=80fc4a6e806e5638ae050c3020962137ca5fd76b diff --git a/ycbcr.h b/ycbcr.h index 4eb9e73..207be4e 100644 --- a/ycbcr.h +++ b/ycbcr.h @@ -21,7 +21,7 @@ // framebuffer, ie., the range [0.0,1.0] maps to [0,255] for 8-bit // and to [0,1023] (or [0_d,255.75_d] in BT.601 parlance) for 10-bit. // -// BT.701 (page 5) seems to agree with BT.601; it specifies range 16–235 for +// BT.709 (page 5) seems to agree with BT.601; it specifies range 16–235 for // 8-bit luma, and 64–940 for 10-bit luma. This would indicate, for a GPU, // that that for 8-bit mode, the range would be 16/255 to 235/255 // (0.06275 to 0.92157), while for 10-bit, it should be 64/1023 to 940/1023 @@ -29,12 +29,17 @@ // range, 10-bit goes out of range (white gets to 942), while if you select // 10-bit range, 8-bit gets only to 234, making true white impossible. // -// We currently support the 8-bit ranges only, since all of our Y'CbCr -// handling effects happen to support only 8-bit at the moment. We will need -// to fix this eventually, though, with an added field to YCbCrFormat. +// Thus, you will need to specify the actual precision of the Y'CbCr source +// (or destination); the num_levels field is the right place. Most people +// will want to simply set this to 256, as 8-bit Y'CbCr is the most common, +// but the right value will naturally depend on your input. +// +// We could use unsigned formats (e.g. GL_R8UI), which in a sense would +// solve all of this, but then we'd lose filtering. #include "image_format.h" +#include #include namespace movit { @@ -48,8 +53,8 @@ struct YCbCrFormat { // JPEG uses the Rec. 601 luma coefficients, but full range. bool full_range; - // Currently unused, but should be set to 256 for future expansion, - // indicating 8-bit interpretation (see file-level comment). + // Set to 2^n for n-bit Y'CbCr (e.g. 256 for 8-bit Y'CbCr). + // See file-level comment. int num_levels; // Sampling factors for chroma components. For no subsampling (4:4:4), @@ -71,7 +76,13 @@ float compute_chroma_offset(float pos, unsigned subsampling_factor, unsigned res // Given , compute the values needed to turn Y'CbCr into R'G'B'; // first subtract the returned offset, then left-multiply the returned matrix // (the scaling is already folded into it). -void compute_ycbcr_matrix(YCbCrFormat ycbcr_format, float *offset, Eigen::Matrix3d *ycbcr_to_rgb); +// +// is the data type you're rendering from; normally, it would should match +// , but for the special case of 10- and 12-bit Y'CbCr, +// we support storing it in 16-bit formats, which incurs extra scaling factors. +// You can get that scaling factor in if you want. +void compute_ycbcr_matrix(YCbCrFormat ycbcr_format, float *offset, Eigen::Matrix3d *ycbcr_to_rgb, + GLenum type = GL_UNSIGNED_BYTE, double *scale_factor = nullptr); } // namespace movit