From patchwork Wed Aug 28 12:27:17 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: 14748 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 113A6449447 for ; Wed, 28 Aug 2019 15:36:52 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EC8F068AB27; Wed, 28 Aug 2019 15:36:51 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 886476800D8 for ; Wed, 28 Aug 2019 15:36:42 +0300 (EEST) Received: by mail-wr1-f50.google.com with SMTP id u16so2367550wrr.0 for ; Wed, 28 Aug 2019 05:36:42 -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=ZvAz41DOLwjpQw0Nx7Xy85u+M7m/O5hBu+FNLTo09BAR9wUDXQoo/fhkfdXlNaHdoQ WLgknnnZgsV6b75gXNRgVGrfjTlUQR3RVaFjzpk8/HmRq7uYxkZhl5mIJFVY4fP4Dgpk Jyyil/SToPU/96ez4is2qlUfM8HYpGI/inBQtJbGCCTHdV00eVs3gwyKZG72Brour5rM 2q1jJUbNClH1Su2UIzowZw1inu0NpTT1ci9J76W0mDFm5wJSazZg2wmmS6Gtc0yE0F18 8cT1y9KesHSQ+BKUszgGh/i3KKaNLLoGRsnQhkR5Z2cOperYPoQMLP+AheEY57w7aTKT mZiA== 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=mlHUiRbA1S+5Lsl2nwgM7EyRLWGFMIyY7i1AFGLiEMjORf8ktAInq8zAu6/nid39Tx Nu7/werHiiIWAxXjNOC/Wcp84jSVnVZkIgYFDYKekIbIFdyxzl4pF/N9aoHlH3y8gOsX D27yRPN0orIpiLK2ZscT8tXOm77nkjo6snt4nIexdlri6sN2CCDWHoFL5wokxSXG3+e4 /Jslw6jJuoFlIVZqtPAFe+cS9wskV7FN+WjvVf4QI0qe8nEvJL/Z8Nf8g4etKsC/Dbge W/bhIiItUR3NzJYjFbbgGZ8zw4XOV7176d3gFqB3XlWTvoKknU67DZK9WCw2E4llUZsj 3dzQ== X-Gm-Message-State: APjAAAX1zchophGY5lQAgkKGg4o+iIWQJFYzdgvPyTufPnc96lwCZbQh 8pyG2EN63fxYmewmcdinzo1B4pWv X-Google-Smtp-Source: APXvYqwz7ZQDbMoibq8W0RkMLkklwrnmwr/J1jxd5X0FRimAOnTpXNlKN2doBKYsViTVGo9K26pbdQ== X-Received: by 2002:adf:d1a4:: with SMTP id w4mr4039113wrc.331.1566995303715; Wed, 28 Aug 2019 05:28:23 -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.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Aug 2019 05:28:23 -0700 (PDT) From: Nick Renieris X-Google-Original-From: Nick Renieris To: ffmpeg-devel@ffmpeg.org Date: Wed, 28 Aug 2019 15:27:17 +0300 Message-Id: <20190828122723.19640-9-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 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");