Commit 15776ca1 authored by Nick Renieris's avatar Nick Renieris Committed by Paul B Mahol

lavc/tiff: Default-initialize WhiteLevel DNG tag value

Initialized to `(2 ^ BitsPerSample) - 1` as per the DNG Specification.

Also make sure that `BlackLevel < WhiteLevel`.

This fixes decoding for "X7 CinemaDNG" samples here:
- https://www.dji.com/gr/zenmuse-x7/info#downloadsSigned-off-by: 's avatarNick Renieris <velocityra@gmail.com>
parent 9280e4b2
...@@ -1776,6 +1776,7 @@ static int decode_frame(AVCodecContext *avctx, ...@@ -1776,6 +1776,7 @@ static int decode_frame(AVCodecContext *avctx,
GetByteContext stripsizes; GetByteContext stripsizes;
GetByteContext stripdata; GetByteContext stripdata;
int retry_for_subifd, retry_for_page; int retry_for_subifd, retry_for_page;
int is_dng;
bytestream2_init(&s->gb, avpkt->data, avpkt->size); bytestream2_init(&s->gb, avpkt->data, avpkt->size);
...@@ -1853,6 +1854,10 @@ again: ...@@ -1853,6 +1854,10 @@ again:
goto again; goto again;
} }
/* At this point we've decided on which (Sub)IFD to process */
is_dng = (s->tiff_type == TIFF_TYPE_DNG || s->tiff_type == TIFF_TYPE_CINEMADNG);
for (i = 0; i<s->geotag_count; i++) { for (i = 0; i<s->geotag_count; i++) {
const char *keyname = get_geokey_name(s->geotags[i].key); const char *keyname = get_geokey_name(s->geotags[i].key);
if (!keyname) { if (!keyname) {
...@@ -1870,10 +1875,22 @@ again: ...@@ -1870,10 +1875,22 @@ again:
} }
} }
if (is_dng) {
if (s->white_level == 0)
s->white_level = (1 << s->bpp) - 1; /* Default value as per the spec */
if (s->white_level <= s->black_level) {
av_log(avctx, AV_LOG_ERROR, "BlackLevel (%"PRId32") must be less than WhiteLevel (%"PRId32")\n",
s->black_level, s->white_level);
return AVERROR_INVALIDDATA;
}
}
if (!s->is_tiled && !s->strippos && !s->stripoff) { if (!s->is_tiled && !s->strippos && !s->stripoff) {
av_log(avctx, AV_LOG_ERROR, "Image data is missing\n"); av_log(avctx, AV_LOG_ERROR, "Image data is missing\n");
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
/* now we have the data and may start decoding */ /* now we have the data and may start decoding */
if ((ret = init_image(s, &frame)) < 0) if ((ret = init_image(s, &frame)) < 0)
return ret; return ret;
...@@ -1905,7 +1922,7 @@ again: ...@@ -1905,7 +1922,7 @@ again:
/* Handle DNG images with JPEG-compressed tiles */ /* Handle DNG images with JPEG-compressed tiles */
if ((s->tiff_type == TIFF_TYPE_DNG || s->tiff_type == TIFF_TYPE_CINEMADNG) && s->is_tiled) { if (is_dng && s->is_tiled) {
if (!s->is_jpeg) { if (!s->is_jpeg) {
avpriv_report_missing_feature(avctx, "DNG uncompressed tiled images"); avpriv_report_missing_feature(avctx, "DNG uncompressed tiled images");
return AVERROR_PATCHWELCOME; return AVERROR_PATCHWELCOME;
...@@ -2063,8 +2080,7 @@ again: ...@@ -2063,8 +2080,7 @@ again:
FFSWAP(int, p->linesize[0], p->linesize[1]); FFSWAP(int, p->linesize[0], p->linesize[1]);
} }
if (s->is_bayer && s->white_level && s->bpp == 16 && if (s->is_bayer && s->white_level && s->bpp == 16 && !is_dng) {
!(s->tiff_type == TIFF_TYPE_DNG || s->tiff_type == TIFF_TYPE_CINEMADNG)) {
uint16_t *dst = (uint16_t *)p->data[0]; uint16_t *dst = (uint16_t *)p->data[0];
for (i = 0; i < s->height; i++) { for (i = 0; i < s->height; i++) {
for (j = 0; j < s->width; j++) for (j = 0; j < s->width; j++)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment