From patchwork Wed Aug 28 12:27:22 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: 14735 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 81BF0449447 for ; Wed, 28 Aug 2019 15:28:32 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5DBEC68AB2E; Wed, 28 Aug 2019 15:28:32 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E02DC68AB0B for ; Wed, 28 Aug 2019 15:28:30 +0300 (EEST) Received: by mail-wr1-f41.google.com with SMTP id t16so2319546wra.6 for ; Wed, 28 Aug 2019 05:28:30 -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 :mime-version:content-transfer-encoding; bh=FlY8vCjKnulE9C6hsuJEF92KBj03SM1bNsYMvP+ys5w=; b=uLI8DXbSrTLdgEeZagIRFUWCJbIY9uS+7w/XB9FdaoP4gTMyb0Z7gmwIyz5S5MKWvy ypFO6PU+BzO8feETghbMKQMGKZdYUd724u6sn98MTCiGuH4qJF1gJCnObrIkVqhuOnB/ flMsxVw22qzrFYDqQPbeR8dQW1v5tpWqewWoH2cJgwb1M6WB6Q1eeJQ6YzezkTTM5MlK FotrVcWQy892bmvJTigGxIBvRgnrSdqaEITKJbrncM47uwxilQZ6D+Fj07eZ+LrgqhKA MBhGitB9qfvNp8tt4+3oUKxCE68aZdC9xpiZTqGdOT0t+0b6vY2wHWn4FnnyGACntcQO b+ig== 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:mime-version:content-transfer-encoding; bh=FlY8vCjKnulE9C6hsuJEF92KBj03SM1bNsYMvP+ys5w=; b=qh47AptFExKmSt2Xw+d1eVkbWOqNbHiXk+V9qEb7mlVIQhQaAJbfKQ27C3Flo4JE6I it1tj96ltxhsaD/8VvJ/maIpohrzVq5/EVTpC7yjTJtpRBIEldVffMgrb+6qjqQBMnpj dNYT3Q8QxLtnwjRlkmm/FWcd4MQ/jL4YacREAD6PpWl5TYgBUWu0aY1HnSE3KAZ3x9yo 20+3KVWnC4HTvBD6DTw2eOs+f6MqlJ7bgLdJbmljrnbPw6GClvnRRezM3Ut3qvW2zEno RjuWpK+PcDKxIiNcYZFy8UT0RozwevuVqwk+hDa53HmzW1QMqvQ4rT7HONFGbHOTGASY IqJA== X-Gm-Message-State: APjAAAXqDDlh6hOuQLf7wD8ZBvReEzw3/oMSZ8TjLk2/0IAbUI8faOMD pYFrA7SgGazn+JLj8pu5tvbyPIc9 X-Google-Smtp-Source: APXvYqy9dkqJtHh/C8ZPdt87nkkwUogqC84Nf0R2EqQDSE0ptvL8AGG0rkth8lHjAqsvq1oFKUnY/w== X-Received: by 2002:a05:6000:cb:: with SMTP id q11mr4687390wrx.50.1566995310179; Wed, 28 Aug 2019 05:28:30 -0700 (PDT) Received: from localhost.localdomain ([2a02:587:240d:9b00:f046:3e76:1fc3:c038]) by smtp.gmail.com with ESMTPSA id a17sm2588958wmm.47.2019.08.28.05.28.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Aug 2019 05:28:29 -0700 (PDT) From: Nick Renieris X-Google-Original-From: Nick Renieris To: ffmpeg-devel@ffmpeg.org Date: Wed, 28 Aug 2019 15:27:22 +0300 Message-Id: <20190828122723.19640-14-velocityra@gmail.com> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20190828122723.19640-1-velocityra@gmail.com> References: <20190822125635.GD23202@sunshine.barsnick.net> <20190828122723.19640-1-velocityra@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v16 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Nick Renieris 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 dfaef1927d..c927400a40 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++)