From patchwork Thu Aug 29 13:10:48 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: 14785 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 79DD044A068 for ; Thu, 29 Aug 2019 16:12:27 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4F82C687F37; Thu, 29 Aug 2019 16:12:27 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 010CB687F1C for ; Thu, 29 Aug 2019 16:12:22 +0300 (EEST) Received: by mail-wr1-f46.google.com with SMTP id g7so3406404wrx.2 for ; Thu, 29 Aug 2019 06:12:22 -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=TthsMKqUWSnEZS4ruHAIof26uccT1jzEVvpw14hW5gk=; b=Zp0szs40Im5IXvErHopeWnsdy/s+QR/Xy1ZVIyMz96a5YYp9ScmEKgG0c2UmS/Gcuw XJm7lypRFSOReKZaBzk0yFzWpX2P4oZCq/593ruBdhA2S/He+qk/airG85KLpioLSx2Q D7lp8GNBOlDX+vYab0++nwqYusRHePLgGLOFmkD7LpMPkJFPWUqong6U+sDgcNytX9ly EJUKhnFkQF6hcfOuHpORzVc/rQv6SLKM6rfdW4C64Wx54HFfoBKidKe6Bz6eSuizRXx8 7Hf/zebvwf25D9Tk+w9fCZdXGbT3O9ZfLP59IaKQOi6HGR2A8V+oAin7MR81tvRygH4k jNKg== 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=TthsMKqUWSnEZS4ruHAIof26uccT1jzEVvpw14hW5gk=; b=HT/t8LCklRIg66PX1Z/q4JCxzaj+bXeHVJJY8D09n00FJjK1wmwQEFjXMTyiUEnf2d MdVT39Pu7fIfEc/owzyh9g+tLtHMy1TrYf/rkWkOOW9FgGUbRinNaUjTR/L4IjHZt+Ax XoNJ7S8kYTzyMHM+dOLSI/1Xod8Ikhyxg4OPkJ7rAVjykuGnKo230D6PD0de+V4va3zB 7Tef9bI/DCdSCzB7oR2tM0JVqUEWAU9kNh98OH3fBkInny5wwaC3cuhSf1u1/5RezsMW jnDkixl+uu+rYXUcC2xUvJ5uvU3tX8ww2uc96fDZgjuYS2arMG9sxGfDrjWXkgT4gC45 8s8A== X-Gm-Message-State: APjAAAX3FretxFcZQwSfQgtOg5f+YGOt5WdIkdOvuilDNPB+lAdnBAJ0 DQ12r0LWs1HqaqKBDkGEa3EdajWj X-Google-Smtp-Source: APXvYqzo63oUg5TSWiKkzXV1+vB8/oZLEflTbTOEo+RqVIufBUHt6vL0KZd3q27wQNz0d5Lb+HGVmw== X-Received: by 2002:a5d:6888:: with SMTP id h8mr10988362wru.68.1567084341991; Thu, 29 Aug 2019 06:12:21 -0700 (PDT) Received: from localhost.localdomain ([2a02:587:240d:9b00:4ca1:2ce9:2e6c:c246]) by smtp.gmail.com with ESMTPSA id m17sm1676644wrs.9.2019.08.29.06.12.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Aug 2019 06:12:21 -0700 (PDT) From: Nick Renieris X-Google-Original-From: Nick Renieris To: ffmpeg-devel@ffmpeg.org Date: Thu, 29 Aug 2019 16:10:48 +0300 Message-Id: <20190829131054.16404-9-velocityra@gmail.com> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20190829131054.16404-1-velocityra@gmail.com> References: <20190829131054.16404-1-velocityra@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v17 09/15] 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");