From patchwork Mon Mar 23 13:09:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Ratiu X-Patchwork-Id: 11452913 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 729661731 for ; Mon, 23 Mar 2020 13:08:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5B8052072E for ; Mon, 23 Mar 2020 13:08:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728371AbgCWNIv (ORCPT ); Mon, 23 Mar 2020 09:08:51 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:35778 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728313AbgCWNIu (ORCPT ); Mon, 23 Mar 2020 09:08:50 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: aratiu) with ESMTPSA id F2FF029057E From: Adrian Ratiu To: Philipp Zabel Cc: Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ezequiel Garcia , kernel@collabora.com, kernel@pengutronix.de, Tim Harvey Subject: [PATCH 1/2] media: coda: jpeg: support optimized huffman tables Date: Mon, 23 Mar 2020 15:09:36 +0200 Message-Id: <20200323130937.3666244-2-adrian.ratiu@collabora.com> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200323130937.3666244-1-adrian.ratiu@collabora.com> References: <20200323130937.3666244-1-adrian.ratiu@collabora.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Each jpeg can have the huffman tables optimized for its specific content meaning that the table lenghts and values don't match the standard table of substitutions so there's no reason to hardcode and expect the sandard lenghts, otherwise we just end up rejecting optimized jpegs altogether. Tested on CODA960. Signed-off-by: Adrian Ratiu --- drivers/media/platform/coda/coda-jpeg.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/media/platform/coda/coda-jpeg.c b/drivers/media/platform/coda/coda-jpeg.c index 6a11b64efb6b..162ba28a6b95 100644 --- a/drivers/media/platform/coda/coda-jpeg.c +++ b/drivers/media/platform/coda/coda-jpeg.c @@ -343,7 +343,8 @@ int coda_jpeg_decode_header(struct coda_ctx *ctx, struct vb2_buffer *vb) v4l2_err(&dev->v4l2_dev, "missing Huffman table\n"); return -EINVAL; } - if (huffman_tables[i].length != ((i & 2) ? 178 : 28)) { + if (huffman_tables[i].length < 17 || + huffman_tables[i].length > 178) { v4l2_err(&dev->v4l2_dev, "invalid Huffman table %d length: %zu\n", i, huffman_tables[i].length); @@ -357,10 +358,12 @@ int coda_jpeg_decode_header(struct coda_ctx *ctx, struct vb2_buffer *vb) return -ENOMEM; ctx->params.jpeg_huff_tab = huff_tab; } - memcpy(huff_tab->luma_dc, huffman_tables[0].start, 16 + 12); - memcpy(huff_tab->chroma_dc, huffman_tables[1].start, 16 + 12); - memcpy(huff_tab->luma_ac, huffman_tables[2].start, 16 + 162); - memcpy(huff_tab->chroma_ac, huffman_tables[3].start, 16 + 162); + + memset(huff_tab, 0, sizeof(*huff_tab)); + memcpy(huff_tab->luma_dc, huffman_tables[0].start, huffman_tables[0].length); + memcpy(huff_tab->chroma_dc, huffman_tables[1].start, huffman_tables[1].length); + memcpy(huff_tab->luma_ac, huffman_tables[2].start, huffman_tables[2].length); + memcpy(huff_tab->chroma_ac, huffman_tables[3].start, huffman_tables[3].length); /* check scan header */ for (i = 0; i < scan_header.num_components; i++) { From patchwork Mon Mar 23 13:09:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Ratiu X-Patchwork-Id: 11452911 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7507E6CA for ; Mon, 23 Mar 2020 13:08:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5D95320753 for ; Mon, 23 Mar 2020 13:08:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728367AbgCWNIu (ORCPT ); Mon, 23 Mar 2020 09:08:50 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:35786 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728360AbgCWNIu (ORCPT ); Mon, 23 Mar 2020 09:08:50 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: aratiu) with ESMTPSA id DA357290580 From: Adrian Ratiu To: Philipp Zabel Cc: Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ezequiel Garcia , kernel@collabora.com, kernel@pengutronix.de, Tim Harvey Subject: [PATCH 2/2] media: coda: be more flexible wrt jpeg dimensions Date: Mon, 23 Mar 2020 15:09:37 +0200 Message-Id: <20200323130937.3666244-3-adrian.ratiu@collabora.com> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200323130937.3666244-1-adrian.ratiu@collabora.com> References: <20200323130937.3666244-1-adrian.ratiu@collabora.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Don't require jpeg dimensions to exactly match format dimensions, so we are able to decode and display a wider range jpegs instead of outright rejecting the ones which don't match. This is useful in applications which pass jpegs with arbitrary dimensions, where buffers can be reused to decode smaller jpegs without having to do expensive renegotiations. Signed-off-by: Adrian Ratiu --- drivers/media/platform/coda/coda-jpeg.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/drivers/media/platform/coda/coda-jpeg.c b/drivers/media/platform/coda/coda-jpeg.c index 162ba28a6b95..782a78dcaf4d 100644 --- a/drivers/media/platform/coda/coda-jpeg.c +++ b/drivers/media/platform/coda/coda-jpeg.c @@ -302,13 +302,6 @@ int coda_jpeg_decode_header(struct coda_ctx *ctx, struct vb2_buffer *vb) } q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); - if (header.frame.height != q_data_src->height || - header.frame.width != q_data_src->width) { - v4l2_err(&dev->v4l2_dev, - "dimensions don't match format: %dx%d\n", - header.frame.width, header.frame.height); - return -EINVAL; - } if (header.frame.num_components != 3) { v4l2_err(&dev->v4l2_dev,