From patchwork Thu Aug 8 20:52:28 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: 14331 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 B509344A056 for ; Thu, 8 Aug 2019 23:55:43 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A230B68ABE9; Thu, 8 Aug 2019 23:55:43 +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 6F98968AB2E for ; Thu, 8 Aug 2019 23:55:34 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id n9so96340854wru.0 for ; Thu, 08 Aug 2019 13:55:34 -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=JNqxvjf99riGVoKPL74WxrYnmqkUUSi4Oir1GQRP4LY=; b=XHL+wlElvRj3HKxo38WYwZIvDJPDgBDsgJWMJLUJfOWIOTX8SnGN7y5J8g2Pt+UPSy JTPjeunss0nwLSyInO2uRVK899IAOBnJh3AIS+srBB10f+61JT+igCrlYEKjAKSaMdh9 FKL2ApH/Xn+oFu91F2+sUpF1Dzz4Ohq4CvsdNW7Y+HNrh/3LFK5fpk8ZJbKp1wFAyt0z npr2rn5C9lDMMpa25BVFFqEKDU5XI8V+Ww4BinLhldSTfRS0fJGGaP5BYfu+Qmf6dcUB 83auRFFTctM5KpvcBxHSAil/wI2kLMDFULURo/9iqcIelX+anQznYS6lJhANQtzxn6j2 MD9Q== 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=JNqxvjf99riGVoKPL74WxrYnmqkUUSi4Oir1GQRP4LY=; b=K5y61Wu/hZ3CDHCseEGwAiUWxJ1fKx9afxy98/Nwe6NG1EnGQshM4boWVGZ4n0NSZ8 IgHTOJYR8qSHMLT4nQy9epWSGLyWo1Ktuw3SilnAhVo5BKZS/u+xcYTJ7V+kU7NL0EgT C9dDEBfpWnbx6lrC8ZLzoGedEenAw0Jrzze9WojYsLcdwZJmaEwgVX1GrTCnLUOvm9IQ qcmnlZjnTNSG/XY9kGrOMp6DwPzF3bE2eNB1+OmRUsfx2h1ryJFfp4woE9rZtA5Ahbvt OvlIeXPZQBgJ5INfJMmmUxWpN2xfXMzhuDqIr5IYLKIUOtAW9KRjBldDv4lH/4AZ8MwH uBLg== X-Gm-Message-State: APjAAAX3DCHdDumrnKtGBwEN0KSf6L+JqQw0+/UX8DIF8HmM2qJq7ekp Yw4j4q6snV9mhjQqe3xMGsdVm/mJJ6o= X-Google-Smtp-Source: APXvYqzNAwsSVqZm4lkb05B6GIEI21UKAIzkeVOErPjbLkRp9m9xYiFu5gFyEdDLf3w1Uhp8p7N1Aw== X-Received: by 2002:adf:f584:: with SMTP id f4mr6335428wro.160.1565297733771; Thu, 08 Aug 2019 13:55:33 -0700 (PDT) Received: from localhost.localdomain ([2a02:587:2409:5200:1de8:6b2e:8289:ee0e]) by smtp.gmail.com with ESMTPSA id g25sm3446686wmk.18.2019.08.08.13.55.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Aug 2019 13:55:33 -0700 (PDT) From: velocityra@gmail.com X-Google-Original-From: velocityra@gmail To: ffmpeg-devel@ffmpeg.org Date: Thu, 8 Aug 2019 23:52:28 +0300 Message-Id: <20190808205233.16368-9-velocityra@gmail.com> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20190808205233.16368-1-velocityra@gmail.com> References: <20190808205233.16368-1-velocityra@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v11 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 Signed-off-by: Nick Renieris --- libavcodec/mjpegdec.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index 6391107f78..94cf73549d 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -412,13 +412,21 @@ 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; + /* Lossless JPEGs encoded in DNGs are commonly bayer-encoded. */ + if (s->lossless) { + if (nb_components == 1) { + /* They can 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 DNG decoder. */ + s->bayer = 1; + } else if (nb_components == 2) { + /* Or they 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. */ + s->bayer = 1; + width *= 2; + } } /* if different size, realloc/alloc picture */ @@ -1184,10 +1192,15 @@ 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) { + 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; i