From patchwork Tue Aug 20 13:37:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: velocityra@gmail.com X-Patchwork-Id: 14617 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 201314481F9 for ; Tue, 20 Aug 2019 16:38:43 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0B70E68A980; Tue, 20 Aug 2019 16:38:43 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C79FE68AB40 for ; Tue, 20 Aug 2019 16:38:36 +0300 (EEST) Received: by mail-wr1-f45.google.com with SMTP id g17so12476448wrr.5 for ; Tue, 20 Aug 2019 06:38:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=c3kyGbDFFMizbpmRITmOquUFX52Qs1PaKoeV3p6A5L4=; b=jfSd1WalbwFSldxSVpJenp3Q4csfjVgRczgLDp5vh6ft3Sn5KbL+IwxwMPyVoARdKC bAuiwxF1p/5tojUhkq85rQQx1jIgGFCQXg5YjiQ7L6+TBAhs7XOw+hJmERgBqmrkJfEp HJ1K93p4p24kCYYFgNAfqD4/lDzqeuPVbXyr7L3E7QABxl+Noihm4rmv31PDDJ/bvVqc +InW/r8Ap79Saj80TY9EQtIQmIkd3CI77XWCtnPQlLGgr/egcGafZe/IFmtXR+DC06S/ 68ohB1ilwY0GAI/JDfPPy9S64M+xJ/w3s9EV00lKpteb8oZjH7xWQzmO3+s5K7KDPmyx sxLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=c3kyGbDFFMizbpmRITmOquUFX52Qs1PaKoeV3p6A5L4=; b=b0eTlPF6eKcH/bLQ23ZETXypkLCvHvnUQRG+NF+g4YTJbic3hGfg/6WZmSti4xaM2m XoyBMq0aGDgXxpjrGuxocZ84IyZEtFdE2Yiv8DuYqttHxZr2xbFzXI3kgh9bkSOD2M24 Efw2jetfe0fqVVQESmtif8ywjHiZVbMGXdX1Bdxmr7Nf8ehEJ971v+eF/fH3vZBX9BdZ JjA/HkOA84tyj7QuRQ7zvIMdc0KUN9R6Wx73CfWdfhxZkzq+OQPG33hr2Pn/t7LySoM8 skTrTBSNfuKyAKJbitluuvizs1twhGTzML2gnaORH5HQWuMHZuKGvam3A+hznz8EvgVl C6/A== X-Gm-Message-State: APjAAAVp5InOmfosGkQtO8F63qi6dbm0LKBlZXheJVc8G4VA01GKOenp 4qGt/gRrd8UMvY6RVWjE1hW9Wr9z X-Google-Smtp-Source: APXvYqz3zNGFqYeN3lAcGhwBCVFgeWXPJy7UNXiYhCZlojvgeY2SX5T/PvwNX5qi3UJdDR5VejnMlA== X-Received: by 2002:adf:fc03:: with SMTP id i3mr32169343wrr.48.1566308316026; Tue, 20 Aug 2019 06:38:36 -0700 (PDT) Received: from localhost.localdomain (ppp-94-66-223-133.home.otenet.gr. [94.66.223.133]) by smtp.gmail.com with ESMTPSA id t14sm11545882wrs.58.2019.08.20.06.38.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2019 06:38:35 -0700 (PDT) From: Nick Renieris To: ffmpeg-devel@ffmpeg.org Date: Tue, 20 Aug 2019 16:37:46 +0300 Message-Id: <20190820133747.30983-14-velocityra@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190820133747.30983-1-velocityra@gmail.com> References: <20190811144542.11704-13-velocityra@gmail.com> <20190820133747.30983-1-velocityra@gmail.com> Subject: [FFmpeg-devel] [PATCH v15 14/15] lavc/tiff: Default-initialize WhiteLevel DNG tag value X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Nick Renieris MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 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#downloads Signed-off-by: Nick Renieris --- libavcodec/tiff.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c index df2554be86..377662c897 100644 --- a/libavcodec/tiff.c +++ b/libavcodec/tiff.c @@ -1775,6 +1775,7 @@ static int decode_frame(AVCodecContext *avctx, GetByteContext stripsizes; GetByteContext stripdata; int retry_for_subifd, retry_for_page; + int is_dng; bytestream2_init(&s->gb, avpkt->data, avpkt->size); @@ -1843,6 +1844,10 @@ 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; igeotag_count; i++) { const char *keyname = get_geokey_name(s->geotags[i].key); if (!keyname) { @@ -1860,10 +1865,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) { av_log(avctx, AV_LOG_ERROR, "Image data is missing\n"); return AVERROR_INVALIDDATA; } + /* now we have the data and may start decoding */ if ((ret = init_image(s, &frame)) < 0) return ret; @@ -1895,7 +1912,7 @@ again: /* 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) { avpriv_report_missing_feature(avctx, "DNG uncompressed tiled images"); return AVERROR_PATCHWELCOME; @@ -2053,8 +2070,7 @@ again: FFSWAP(int, p->linesize[0], p->linesize[1]); } - if (s->is_bayer && s->white_level && s->bpp == 16 && - !(s->tiff_type == TIFF_TYPE_DNG || s->tiff_type == TIFF_TYPE_CINEMADNG)) { + if (s->is_bayer && s->white_level && s->bpp == 16 && !is_dng) { uint16_t *dst = (uint16_t *)p->data[0]; for (i = 0; i < s->height; i++) { for (j = 0; j < s->width; j++)