0

Support BT470BG untyped matrix from macOS.

For matrices that macOS doesn't recognize it'll return a value of the
form "YCbCrMatrix#n" where n seems to correspond to the ISO
23001-8:2016 id; see VideoColorSpace::MatrixID. We could add
generalized code to handle this, but it's rarely seen so favor
simplicity.

This mostly just documents how macOS handles unknown matrices in
case its relevant to a future reader.

R=ccameron

Change-Id: Ibd78200888c77cb1cd6d51d12e9f45e028322789
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6495005
Reviewed-by: ccameron chromium <ccameron@chromium.org>
Commit-Queue: Dale Curtis <dalecurtis@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1454058}
This commit is contained in:
Dale Curtis
2025-04-30 11:03:01 -07:00
committed by Chromium LUCI CQ
parent ee4797315c
commit 9fc37d7059

@ -243,8 +243,29 @@ gfx::ColorSpace::MatrixID GetCoreVideoMatrix(CFTypeRef matrix_untyped) {
auto matrix_id = gfx::ColorSpace::MatrixID::INVALID;
if (!GetImageBufferProperty(matrix_untyped, GetSupportedImageMatrix(),
&matrix_id)) {
DLOG(ERROR) << "Failed to find CVImageBufferRef YUV matrix: "
<< matrix_untyped;
CFStringRef value_as_string =
base::apple::CFCast<CFStringRef>(matrix_untyped);
if (value_as_string) {
// For matrices that macOS doesn't recognize it'll return a value of the
// form "YCbCrMatrix#n" where n seems to correspond to the ISO
// 23001-8:2016 id; see VideoColorSpace::MatrixID. We could add
// generalized code to handle this, but it's rarely seen so favor
// simplicity.
//
// Note: We don't include this value in GetSupportedImageMatrix() since
// we only want to translate this value when it comes from macOS.
// Note 2: The space after the number is intentional. Presumably it's to
// leave room for two digit matrix IDs.
if (CFStringCompare(value_as_string, CFSTR("YCbCrMatrix#5 "), 0)) {
return gfx::ColorSpace::MatrixID::BT470BG;
}
DLOG(ERROR) << "Failed to find CVImageBufferRef YUV matrix: \""
<< value_as_string << "\"";
} else {
DLOG(ERROR) << "Failed to find CVImageBufferRef YUV matrix: "
<< matrix_untyped;
}
}
return matrix_id;
}