@@ -342,8 +342,10 @@ static int vt_pixbuf_set_par(void *log_ctx,
CFNumberRef num = NULL, den = NULL;
AVRational avpar = src->sample_aspect_ratio;
- if (avpar.num == 0)
+ if (avpar.num == 0) {
+ CVBufferRemoveAttachment(pixbuf, kCVImageBufferPixelAspectRatioKey);
return 0;
+ }
av_reduce(&avpar.num, &avpar.den,
avpar.num, avpar.den,
@@ -423,7 +425,10 @@ static int vt_pixbuf_set_chromaloc(void *log_ctx,
kCVImageBufferChromaLocationTopFieldKey,
loc,
kCVAttachmentMode_ShouldPropagate);
- }
+ } else
+ CVBufferRemoveAttachment(
+ pixbuf,
+ kCVImageBufferChromaLocationTopFieldKey);
return 0;
}
@@ -534,52 +539,53 @@ static int vt_pixbuf_set_colorspace(void *log_ctx,
Float32 gamma = 0;
colormatrix = av_map_videotoolbox_color_matrix_from_av(src->colorspace);
- if (!colormatrix && src->colorspace != AVCOL_SPC_UNSPECIFIED)
- av_log(log_ctx, AV_LOG_WARNING, "Color space %s is not supported.\n", av_color_space_name(src->colorspace));
+ if (colormatrix)
+ CVBufferSetAttachment(pixbuf, kCVImageBufferYCbCrMatrixKey,
+ colormatrix, kCVAttachmentMode_ShouldPropagate);
+ else {
+ CVBufferRemoveAttachment(pixbuf, kCVImageBufferYCbCrMatrixKey);
+ if (src->colorspace != AVCOL_SPC_UNSPECIFIED)
+ av_log(log_ctx, AV_LOG_WARNING,
+ "Color space %s is not supported.\n",
+ av_color_space_name(src->colorspace));
+ }
colorpri = av_map_videotoolbox_color_primaries_from_av(src->color_primaries);
- if (!colorpri && src->color_primaries != AVCOL_PRI_UNSPECIFIED)
- av_log(log_ctx, AV_LOG_WARNING, "Color primaries %s is not supported.\n", av_color_primaries_name(src->color_primaries));
+ if (colorpri)
+ CVBufferSetAttachment(pixbuf, kCVImageBufferColorPrimariesKey,
+ colorpri, kCVAttachmentMode_ShouldPropagate);
+ else {
+ CVBufferRemoveAttachment(pixbuf, kCVImageBufferColorPrimariesKey);
+ if (src->color_primaries != AVCOL_SPC_UNSPECIFIED)
+ av_log(log_ctx, AV_LOG_WARNING,
+ "Color primaries %s is not supported.\n",
+ av_color_primaries_name(src->color_primaries));
+ }
colortrc = av_map_videotoolbox_color_trc_from_av(src->color_trc);
- if (!colortrc && src->color_trc != AVCOL_TRC_UNSPECIFIED)
- av_log(log_ctx, AV_LOG_WARNING, "Color transfer function %s is not supported.\n", av_color_transfer_name(src->color_trc));
+ if (colortrc)
+ CVBufferSetAttachment(pixbuf, kCVImageBufferTransferFunctionKey,
+ colorpri, kCVAttachmentMode_ShouldPropagate);
+ else {
+ CVBufferRemoveAttachment(pixbuf, kCVImageBufferTransferFunctionKey);
+ if (src->color_trc != AVCOL_TRC_UNSPECIFIED)
+ av_log(log_ctx, AV_LOG_WARNING,
+ "Color transfer function %s is not supported.\n",
+ av_color_transfer_name(src->color_trc));
+ }
if (src->color_trc == AVCOL_TRC_GAMMA22)
gamma = 2.2;
else if (src->color_trc == AVCOL_TRC_GAMMA28)
gamma = 2.8;
- if (colormatrix) {
- CVBufferSetAttachment(
- pixbuf,
- kCVImageBufferYCbCrMatrixKey,
- colormatrix,
- kCVAttachmentMode_ShouldPropagate);
- }
- if (colorpri) {
- CVBufferSetAttachment(
- pixbuf,
- kCVImageBufferColorPrimariesKey,
- colorpri,
- kCVAttachmentMode_ShouldPropagate);
- }
- if (colortrc) {
- CVBufferSetAttachment(
- pixbuf,
- kCVImageBufferTransferFunctionKey,
- colortrc,
- kCVAttachmentMode_ShouldPropagate);
- }
if (gamma != 0) {
CFNumberRef gamma_level = CFNumberCreate(NULL, kCFNumberFloat32Type, &gamma);
- CVBufferSetAttachment(
- pixbuf,
- kCVImageBufferGammaLevelKey,
- gamma_level,
- kCVAttachmentMode_ShouldPropagate);
+ CVBufferSetAttachment(pixbuf, kCVImageBufferGammaLevelKey,
+ gamma_level, kCVAttachmentMode_ShouldPropagate);
CFRelease(gamma_level);
- }
+ } else
+ CVBufferRemoveAttachment(pixbuf, kCVImageBufferGammaLevelKey);
return 0;
}