In the absence of an explicitly coded minimal luminance, the current
code inferred it to be -1, an invalid value. Yet it did not check the
value lateron at all, so that if a valid maximum luminance is
encountered, but no minimal luminance, an invalid minimal luminance of
-1 is exported. If an minimal luminance element with a negative value is
present, it is exported, too. This can be simply fixed by adding a check
for the value of the element.
Yet given that a minimal luminance of zero Cd/m² is legal and can be
coded with a length of zero, we must not use a fake default value to
find out whether the element is present or not. Therefore this patch
uses an explicit counter for it.
While just at it, also check for max_luminance > min_luminance.
Reviewed-by: Ridley Combs <rcombs@rcombs.me>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
double white_x;
double white_y;
double max_luminance;
double white_x;
double white_y;
double max_luminance;
+ CountedElement min_luminance;
} MatroskaMasteringMeta;
typedef struct MatroskaTrackVideoColor {
} MatroskaMasteringMeta;
typedef struct MatroskaTrackVideoColor {
{ MATROSKA_ID_VIDEOCOLOR_BY, EBML_FLOAT, 0, 0, offsetof(MatroskaMasteringMeta, b_y) },
{ MATROSKA_ID_VIDEOCOLOR_WHITEX, EBML_FLOAT, 0, 0, offsetof(MatroskaMasteringMeta, white_x) },
{ MATROSKA_ID_VIDEOCOLOR_WHITEY, EBML_FLOAT, 0, 0, offsetof(MatroskaMasteringMeta, white_y) },
{ MATROSKA_ID_VIDEOCOLOR_BY, EBML_FLOAT, 0, 0, offsetof(MatroskaMasteringMeta, b_y) },
{ MATROSKA_ID_VIDEOCOLOR_WHITEX, EBML_FLOAT, 0, 0, offsetof(MatroskaMasteringMeta, white_x) },
{ MATROSKA_ID_VIDEOCOLOR_WHITEY, EBML_FLOAT, 0, 0, offsetof(MatroskaMasteringMeta, white_y) },
- { MATROSKA_ID_VIDEOCOLOR_LUMINANCEMIN, EBML_FLOAT, 0, 0, offsetof(MatroskaMasteringMeta, min_luminance), { .f=-1 } },
+ { MATROSKA_ID_VIDEOCOLOR_LUMINANCEMIN, EBML_FLOAT, 1, 0, offsetof(MatroskaMasteringMeta, min_luminance) },
{ MATROSKA_ID_VIDEOCOLOR_LUMINANCEMAX, EBML_FLOAT, 0, 0, offsetof(MatroskaMasteringMeta, max_luminance) },
CHILD_OF(matroska_track_video_color)
};
{ MATROSKA_ID_VIDEOCOLOR_LUMINANCEMAX, EBML_FLOAT, 0, 0, offsetof(MatroskaMasteringMeta, max_luminance) },
CHILD_OF(matroska_track_video_color)
};
mastering_meta->g_x > 0 && mastering_meta->g_y > 0 &&
mastering_meta->b_x > 0 && mastering_meta->b_y > 0 &&
mastering_meta->white_x > 0 && mastering_meta->white_y > 0;
mastering_meta->g_x > 0 && mastering_meta->g_y > 0 &&
mastering_meta->b_x > 0 && mastering_meta->b_y > 0 &&
mastering_meta->white_x > 0 && mastering_meta->white_y > 0;
- has_mastering_luminance = mastering_meta->max_luminance > 0;
+ has_mastering_luminance = mastering_meta->max_luminance >
+ mastering_meta->min_luminance.el.f &&
+ mastering_meta->min_luminance.el.f >= 0 &&
+ mastering_meta->min_luminance.count;
if (color->matrix_coefficients != AVCOL_SPC_RESERVED)
st->codecpar->color_space = color->matrix_coefficients;
if (color->matrix_coefficients != AVCOL_SPC_RESERVED)
st->codecpar->color_space = color->matrix_coefficients;
}
if (has_mastering_luminance) {
metadata->max_luminance = av_d2q(mastering_meta->max_luminance, INT_MAX);
}
if (has_mastering_luminance) {
metadata->max_luminance = av_d2q(mastering_meta->max_luminance, INT_MAX);
- metadata->min_luminance = av_d2q(mastering_meta->min_luminance, INT_MAX);
+ metadata->min_luminance = av_d2q(mastering_meta->min_luminance.el.f, INT_MAX);
metadata->has_luminance = 1;
}
}
metadata->has_luminance = 1;
}
}