From patchwork Fri Aug 9 16:29:54 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: 14366 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 654E84496BD for ; Fri, 9 Aug 2019 19:40:06 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4EDCA68ABB1; Fri, 9 Aug 2019 19:40:06 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 54AD368AB70 for ; Fri, 9 Aug 2019 19:40:00 +0300 (EEST) Received: by mail-wm1-f68.google.com with SMTP id v15so6346027wml.0 for ; Fri, 09 Aug 2019 09:40:00 -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=D7fAq2vzE+Yd4kwH1SUwP6dwPTZTd0ZpwTnDIZ2ueCVbx9z/3T49UM3iAtlGemE7xR /roP4Nuhwyddd34sOkvNe+w+H4mzdkXCHwuKSPuguMPAuDcAQR0yzVLiXbZpCES6ucR3 0XbCYFO5se0yfOfozoecchzJp1FW7CDzVXb9bxtf6GNwr8phqPcoQq2nn1EG3rYdWMAi EREMnZP0HkLznci7lMCrq/W4khVC4GxURuA4dcHfnB53TZuNSvAKfFztqWJV8ZYp8hhP 1S8hlyvC9HcLRK2AwHZDqwV5ZM0ShL4vXbNUtPQ2ZCZi6FynD9FNMpJkk29i+zE8rW+B 5vrQ== 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=ZuxKdLmG0xyL6ZQY34aGXHpzAPoNSdURnW/y68txshG+c8QOmw/XbBDy37TkE1xCPL SrexxpITUnovu/UhaDy7hIIVJTmDB0gNH4KOMiWzozC9PmTpE1OPYE+4PNBeJS2ZkPoc p2ZK0/6Bq0R5VIs3oRxHPwcxFhabHh12KZRHVzAeRLcHYP0yPYoK1THdeztgpKhYGqGX 1uTDauPCxHb1/5YeMtEh34rdXhGuoGXunTFTF08mfdm+XruJb8dwki3bAjx0LTysIrlP 3wJBD1xnU+sErSgJ+hD5FL8R8Pd/KpiVdX2VlNLJl6YAI6Bt2gY3ADPovTn7sLWYDpRZ 22RA== X-Gm-Message-State: APjAAAXihQRwlGs3OS14BVn+TklubmnOFMoLlDb8dfRcwm1gecZRP3XC muhVvo1ygqGCRqJ/N3DW9/R2fY8sbMY= X-Google-Smtp-Source: APXvYqwsf22xiz3M5dzDEG6Lh7GLPjkZ1Td2P6Fg2UewlT0DPVMP1f45x5vxBiY7pEn/0M6/lRQ7Ew== X-Received: by 2002:a7b:c313:: with SMTP id k19mr11438780wmj.2.1565368294132; Fri, 09 Aug 2019 09:31:34 -0700 (PDT) Received: from localhost.localdomain ([2a02:587:2409:5200:e9b3:b00d:2017:357c]) by smtp.gmail.com with ESMTPSA id u6sm6721745wml.9.2019.08.09.09.31.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Aug 2019 09:31:33 -0700 (PDT) From: Nick Renieris X-Google-Original-From: Nick Renieris To: ffmpeg-devel@ffmpeg.org Date: Fri, 9 Aug 2019 19:29:54 +0300 Message-Id: <20190809162959.17924-9-velocityra@gmail.com> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20190809162959.17924-1-velocityra@gmail.com> References: <20190808205233.16368-14-velocityra@gmail.com> <20190809162959.17924-1-velocityra@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v12 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");