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

Do not allow for monochrome + identity matrix #2667

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

vrabaud
Copy link
Collaborator

@vrabaud vrabaud commented Mar 5, 2025

This fixes #2639

@y-guyon y-guyon added this to the v1.2.1 milestone Mar 5, 2025
@vrabaud vrabaud force-pushed the main branch 5 times, most recently from 908cbfe to 6bf6a07 Compare March 6, 2025 15:05
@vrabaud vrabaud requested review from y-guyon and jzern March 6, 2025 15:06
@vrabaud vrabaud marked this pull request as ready for review March 6, 2025 15:06
Comment on lines 103 to 140
// Convert to a temporary PNG and read back, to have default matrix
// coefficients.
const std::string tmp_path = testing::TempDir() + "decoded_default.png";
ASSERT_TRUE(testutil::WriteImage(decoded.get(), tmp_path.c_str()));
const ImagePtr decoded_lossless =
ReadImageLossless(tmp_path, pixel_format, ignore_icc);

// Verify that the ground truth and decoded images are the same.
const ImagePtr ground_truth_lossless =
ReadImageLossless(file_path, pixel_format, ignore_icc);
const bool are_images_equal =
testutil::AreImagesEqual(*ground_truth_lossless, *decoded_lossless);

if (matrix_coefficients == AVIF_MATRIX_COEFFICIENTS_YCGCO) {
// AVIF_MATRIX_COEFFICIENTS_YCGCO is not a lossless transform.
ASSERT_FALSE(are_images_equal);
} else if (pixel_format == AVIF_PIXEL_FORMAT_YUV400) {
// For gray images, information is lost.
ASSERT_FALSE(are_images_equal);
} else {
ASSERT_TRUE(are_images_equal);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks unrelated to the test above because ASSERT_TRUE(testutil::AreImagesEqual(*image, *decoded));. Split into two units?

Copy link
Collaborator

@y-guyon y-guyon left a comment

Choose a reason for hiding this comment

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

Also add a CHANGELOG entry please

avifPixelFormat requested_format,
avifBool ignore_icc) {
ImagePtr image(avifImageCreateEmpty());
image->matrixCoefficients = AVIF_MATRIX_COEFFICIENTS_IDENTITY;
Copy link
Collaborator

Choose a reason for hiding this comment

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

You check !image after this line.

@@ -115,11 +115,11 @@ avifBool avifGetYUVColorSpaceInfo(const avifImage * image, avifYUVColorSpaceInfo
return AVIF_FALSE;
}

// Removing 400 here would break backward behavior but would respect the spec.
Copy link
Collaborator

Choose a reason for hiding this comment

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

But this is checked for later? What path does this break?

return image;
}

class LosslessTest
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add a comment about what the parameters are. Tuples are convenient in tests, but aren't self documenting like structs.

TEST_P(LosslessTest, EncodeDecodeMatrixCoefficients) {
const std::string& file_name = std::get<0>(GetParam());
const avifMatrixCoefficients matrix_coefficients =
static_cast<avifMatrixCoefficients>(std::get<1>(GetParam()));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can the test just take the enum types as params to avoid all the casting?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistent handling of identity matrix + monochrome b/w library & avifenc
3 participants