Skip to content

Commit

Permalink
avutil/hwcontext_videotoolbox: Set CVBuffer CGColorSpace
Browse files Browse the repository at this point in the history
In addition to the other properties, try to obtain the right
CGColorSpace and set it as well, else it could lead to a CVBuffer
tagged as BT.2020 but with a CGColorSpace indicating BT.709.

Therefore it is essential for consistency to set a colorspace
according to the other values, or if none can be obtained (for example
because the other values are all unspecified) unset it as well.

Fix #10884

Signed-off-by: Zhao Zhili <[email protected]>
  • Loading branch information
ePirat authored and quink-black committed Jul 5, 2024
1 parent b4f9fcc commit cd9ceae
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions libavutil/hwcontext_videotoolbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ CFStringRef av_map_videotoolbox_color_trc_from_av(enum AVColorTransferCharacteri
static int vt_pixbuf_set_colorspace(void *log_ctx,
CVPixelBufferRef pixbuf, const AVFrame *src)
{
CGColorSpaceRef colorspace = NULL;
CFStringRef colormatrix = NULL, colorpri = NULL, colortrc = NULL;
Float32 gamma = 0;

Expand Down Expand Up @@ -587,6 +588,21 @@ static int vt_pixbuf_set_colorspace(void *log_ctx,
} else
CVBufferRemoveAttachment(pixbuf, kCVImageBufferGammaLevelKey);

if (__builtin_available(macOS 10.8, iOS 10, *)) {
CFDictionaryRef attachments = CVBufferCopyAttachments(pixbuf, kCVAttachmentMode_ShouldPropagate);
if (attachments) {
colorspace = CVImageBufferCreateColorSpaceFromAttachments(attachments);
CFRelease(attachments);
}
}

if (colorspace) {
CVBufferSetAttachment(pixbuf, kCVImageBufferCGColorSpaceKey,
colorspace, kCVAttachmentMode_ShouldPropagate);
CFRelease(colorspace);
} else
CVBufferRemoveAttachment(pixbuf, kCVImageBufferCGColorSpaceKey);

return 0;
}

Expand Down

0 comments on commit cd9ceae

Please sign in to comment.