From patchwork Sat Aug 10 22:19:29 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: 14401 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 A1DF7448F16 for ; Sun, 11 Aug 2019 01:20:26 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8416268AC1A; Sun, 11 Aug 2019 01:20:26 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AD7EC68ABFA for ; Sun, 11 Aug 2019 01:20:17 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id r3so7646868wrt.3 for ; Sat, 10 Aug 2019 15:20:17 -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=6lyvwN1U7EcaMzRScayUP8v1zQvTKRy4bpBHCR7ZJ3E=; b=WQZ1bIZcBxv9ipfm9UQqq7rpp3Za1qDzABEPa61D1mWCbjC1Tt+Ez55BcMF8x0ngYp xbsEVZ7mckNO3NqxZunAqqm1O76cAnEk8qTtD3FtTJd881dQNXbI2zD0ysdrdmRo5T0i l0C3o6X8mr4nDtF97sN0q8VAOxautvAAJonO814AzH0dAkqVg9mIil0bwndIeWB9QbuF u1g3juQk3okAtPz+c7zoDNSH2otVlfUSc3PGGiVBKxfEI8FPJdOmEuI1uhWeFIAELQcg LJe5jaC/JZaKn64c/XFzQQtXDa5I6fcl3koJOuSzXdI4AwGo/5jjZfbuVdLdSckBEzj2 6Abw== 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=6lyvwN1U7EcaMzRScayUP8v1zQvTKRy4bpBHCR7ZJ3E=; b=pAbAfkd/b7DtmmSM/R0aFJiYn1lgWvCdpXbfCVJvVKOqZaAsGA1bpSF1mIt4bUW3An qxYZiqSTi6pzpBD+qcTld9s2aokzfbyXL3k+WvU7yGjcWsodSY7cSe4WEmLgSD77w27R UezjD5txVjp7C6W3C8yHn5nBSmd3uTr9zg0pOBirbbXXzF1z4/I5Qao8nAu0NLffQgVM s7no+puMkJhsTEVGze/vWxdOlBTJ2GM8KGHFQFCExeA21Jn7zMDfOOzG6dau9R+7BE46 wvpD3wruRwDS63CZafLhF/JEcjrPPYbPMHG+W7Hcq7QTvpBOe7P+p7K65JLpesWTqcb6 r3UA== X-Gm-Message-State: APjAAAWU+0c1syFZTXkjNQIiOZPw447DZgcZHjCNeJhTRZBVNvs6E6Ch mG8Imi2c/KW15oiiEZqEoWb/Tifh5DE= X-Google-Smtp-Source: APXvYqzArc05MQTG/CAHrjqfai6tiMwP9M6V9JLPaR+egvIjSVslU4BkS6YIn/K4zuOOx+BugXIFPw== X-Received: by 2002:adf:f40b:: with SMTP id g11mr33400564wro.81.1565475616988; Sat, 10 Aug 2019 15:20:16 -0700 (PDT) Received: from localhost.localdomain ([2a02:587:2409:5200:5c0b:c2fa:5389:82dd]) by smtp.gmail.com with ESMTPSA id q20sm40403233wrc.79.2019.08.10.15.20.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 10 Aug 2019 15:20:16 -0700 (PDT) From: Nick Renieris X-Google-Original-From: Nick Renieris To: ffmpeg-devel@ffmpeg.org Date: Sun, 11 Aug 2019 01:19:29 +0300 Message-Id: <20190810221934.44996-9-velocityra@gmail.com> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20190810221934.44996-1-velocityra@gmail.com> References: <20190810221934.44996-1-velocityra@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v13 09/14] lavc/mjpegdec: Enable decoding of single-component bayer images 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 Also, ensure no false positives when determining DNG bayer images, by setting them in tiff.c instead of relying on a heuristic. There's no way to determine this just from the JPEG data, so we have to pass this information from outside the MJPEG decoder. Signed-off-by: Nick Renieris --- libavcodec/mjpegdec.c | 32 +++++++++++++++++++++----------- libavcodec/tiff.c | 7 +++++++ 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index 6391107f78..0a920a7144 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -412,13 +412,17 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) return AVERROR_PATCHWELCOME; } - /* Lossless JPEGs encoded in DNGs are commonly bayer-encoded. They contain 2 - interleaved components and the width stored in their SOF3 markers is the - width of each one. We only output a single component, therefore we need - to adjust the output image width. */ - if (s->lossless == 1 && nb_components == 2) { - s->bayer = 1; - width *= 2; + if (s->bayer) { + if (nb_components == 2) { + /* Bayer images embedded in DNGs can contain 2 interleaved components and the + width stored in their SOF3 markers is the width of each one. We only output + a single component, therefore we need to adjust the output image width. We + handle the deinterleaving (but not the debayering) in this file. */ + width *= 2; + } + /* They can also contain 1 component, which is double the width and half the height + of the final image (rows are interleaved). We don't handle the decoding in this + file, but leave that to the TIFF/DNG decoder. */ } /* if different size, realloc/alloc picture */ @@ -1184,10 +1188,16 @@ static int ljpeg_decode_rgb_scan(MJpegDecodeContext *s, int nb_components, int p ptr[3*mb_x + 0] = buffer[mb_x][1] + ptr[3*mb_x + 1]; ptr[3*mb_x + 2] = buffer[mb_x][2] + ptr[3*mb_x + 1]; } - } else if (s->bayer && nb_components == 2) { - for (mb_x = 0; mb_x < width; mb_x++) { - ((uint16_t*)ptr)[2*mb_x + 0] = buffer[mb_x][0]; - ((uint16_t*)ptr)[2*mb_x + 1] = buffer[mb_x][1]; + } else if (s->bayer) { + if (nb_components == 1) { + /* Leave decoding to the TIFF/DNG decoder (see comment in ff_mjpeg_decode_sof) */ + for (mb_x = 0; mb_x < width; mb_x++) + ((uint16_t*)ptr)[mb_x] = buffer[mb_x][0]; + } else if (nb_components == 2) { + for (mb_x = 0; mb_x < width; mb_x++) { + ((uint16_t*)ptr)[2*mb_x + 0] = buffer[mb_x][0]; + ((uint16_t*)ptr)[2*mb_x + 1] = buffer[mb_x][1]; + } } } else { for(i=0; igb.buffer; jpkt.size = tile_byte_count; + if (s->is_bayer) { + MJpegDecodeContext *mjpegdecctx = s->avctx_mjpeg->priv_data; + /* We have to set this information here, there is no way to know if a given JPEG is a DNG-embedded + image or not from its own data (and we need that information when decoding it). */ + mjpegdecctx->bayer = 1; + } + ret = avcodec_send_packet(s->avctx_mjpeg, &jpkt); if (ret < 0) { av_log(avctx, AV_LOG_ERROR, "Error submitting a packet for decoding\n");