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

Allow libyuv to use identity matrix with YUV 4:0:0 #1488

Merged
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
9 changes: 7 additions & 2 deletions src/reformat_libyuv.c
Original file line number Diff line number Diff line change
Expand Up @@ -737,8 +737,13 @@ static avifBool getLibYUVConversionFunction(avifPixelFormat yuvFormat,

static void getLibYUVConstants(const avifImage * image, const struct YuvConstants ** matrixYUV, const struct YuvConstants ** matrixYVU)
{
// Allow the identity matrix to be used with YUV 4:0:0. Replace the identity matrix with
// MatrixCoefficients 6 (BT.601).
const avifBool yuv400WithIdentityMatrix = (image->yuvFormat == AVIF_PIXEL_FORMAT_YUV400) &&
(image->matrixCoefficients == AVIF_MATRIX_COEFFICIENTS_IDENTITY);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In the Chromium CL, the condition I used is just image->yuvFormat == AVIF_PIXEL_FORMAT_YUV400. I am planning to change Chromium to match this condition.

const avifMatrixCoefficients matrixCoefficients = yuv400WithIdentityMatrix ? AVIF_MATRIX_COEFFICIENTS_BT601 : image->matrixCoefficients;
if (image->yuvRange == AVIF_RANGE_FULL) {
switch (image->matrixCoefficients) {
switch (matrixCoefficients) {
// BT.709 full range YuvConstants were added in libyuv version 1772.
// See https://chromium-review.googlesource.com/c/libyuv/libyuv/+/2646472.
case AVIF_MATRIX_COEFFICIENTS_BT709:
Expand Down Expand Up @@ -805,7 +810,7 @@ static void getLibYUVConstants(const avifImage * image, const struct YuvConstant
break;
}
} else { // image->yuvRange == AVIF_RANGE_LIMITED
switch (image->matrixCoefficients) {
switch (matrixCoefficients) {
case AVIF_MATRIX_COEFFICIENTS_BT709:
*matrixYUV = &kYuvH709Constants;
*matrixYVU = &kYvuH709Constants;
Expand Down
Loading