From patchwork Fri Mar 11 07:51:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Qian X-Patchwork-Id: 12777580 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CF486C433EF for ; Fri, 11 Mar 2022 07:54:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=TRMDnML9vq5+Qo7J4gVoi7GHKOT/SL0UjBJNvRwkXDU=; b=b1ZmWDvm9T4bzG e2l556yHVNzxa2kHkR+oitygDjjc8rpBswt5Z6lrbU/vnFNVMZITx5Mx9ZuFq69iYEKNWXwrsp3Ll rXsvZ6TpxXjD07lVxM+nv2BXP22OlKY2MfrU17KotCIyUYOo4sn+Ir6G0QrpvDRsSaeBvanOKEide iQyw51ET6GdlBa5mOEgrmhIzPMb9qWJ6Lf+EmDKVXagIl6G26bF5iOsBuZt458cYD4R3y8Kvgsnvz 45veIk5om9oVIC9mHzW95wQHUEiIDi2HIgkAiTJcPd+DmQ6u+Jz6ohM+g1UOWBm0Fwz2xBl+s+6IH xXm1whREyglHMS+5Kp9Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSa54-00FOrr-6k; Fri, 11 Mar 2022 07:52:58 +0000 Received: from mail-am6eur05on20609.outbound.protection.outlook.com ([2a01:111:f400:7e1b::609] helo=EUR05-AM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSa4g-00FOgY-Gh for linux-arm-kernel@lists.infradead.org; Fri, 11 Mar 2022 07:52:36 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GqqsjVK28CfMfzRUQh86mLAsRHATIVXXSPsDZmYiZFf0fRYohIp9eVBnTC2eSZTpWBvMRq7ub+1WoAMYgkwOjLqzhl/pcVA5HojLdZPDKZq0/jtvaILXaPgcydbK26AinVA2VFZDZao73AOCj95pCR6NojCApMGzSwiqPOSzbAxiq99k7ur02S4HCsCgIIczbzY7fz3HlIO/3lIEfmGgPYakydAJtF7hWODZosQNFewW9yXQlcRHt+EEATsQeOHQvnz3cu1vShEX2DBAqG2BoUwOuxVUIeXxZ1mxmDIFu/NnRUf7ynR9GksjhNLKMXkfzM9l8PqoABEBGgJKHCEfqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=VE9QcKGDoUZhfJe4o47yAi9yM9BKIcAXhlDwk+vQ/74=; b=hc4kelUFIYgdcRIeCXyCkNNdmUwnkIJCoWSf/vbMDv+UVxw9knVwHXf3LOg2zYq+afi0IhbQF9SSObQ46aMg3lGOXtq2AeXvHNsABsuLX6tUHynOhbUhYt06ucxrxcJY/9s6qzAa2fVD1S/A8YUPwNRm4DKHFddWeNBUToX6xlro3gSKvqOSX95sbT0n6zT53vsJVAZbQKdPa6y8z2nsjxn6VEwWn4b/S60kgkFxKGgmK9j+UBcAxdDO9RTTdu+J8os0LqbCc0X7W/HKq77+0qkMgM8i/uLqKQ6KnhzaMkM9PD/4Y5jf5v5YMpGQkgfeSD+OKx8g2PGtk/dgmwLB7A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VE9QcKGDoUZhfJe4o47yAi9yM9BKIcAXhlDwk+vQ/74=; b=q729wGKZXwOSzoV74M1+sjgoVESnsyA0j17PtzGY3hvgaTlcToNxdSLovrDdYBfoc0Ofd21y0pJ9z+hlDkrd3Wl6rmgV86B39tw0OwWo1DZ09JGZI7x0Qk0qKR+aoFU9cOsYynhf6kgdRb4o9coAi0GQ+uiHbzBXMsQ5ihJ2Eqg= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM6PR04MB6341.eurprd04.prod.outlook.com (2603:10a6:20b:d8::14) by DB7PR04MB4443.eurprd04.prod.outlook.com (2603:10a6:5:32::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14; Fri, 11 Mar 2022 07:52:31 +0000 Received: from AM6PR04MB6341.eurprd04.prod.outlook.com ([fe80::c39:69cf:c4ea:967]) by AM6PR04MB6341.eurprd04.prod.outlook.com ([fe80::c39:69cf:c4ea:967%5]) with mapi id 15.20.5061.022; Fri, 11 Mar 2022 07:52:31 +0000 From: Ming Qian To: mchehab@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, mirela.rabulea@oss.nxp.com Cc: hverkuil-cisco@xs4all.nl, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 2/5] media: imx-jpeg: Identify and handle precision correctly Date: Fri, 11 Mar 2022 15:51:44 +0800 Message-Id: X-Mailer: git-send-email 2.33.0 In-Reply-To: References: X-ClientProxiedBy: SGXP274CA0015.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:b8::27) To AM6PR04MB6341.eurprd04.prod.outlook.com (2603:10a6:20b:d8::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b88abc27-3188-4735-4e1f-08da033418b1 X-MS-TrafficTypeDiagnostic: DB7PR04MB4443:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1m9purfkm2vOqhSdvNO68oya4rtVBFVyXfZgLGEL9KA27NseaRMgGmfY+41POQ2Okrn2qwSh7G/ElYPHNQ1FsTVwCsOV4NnNSbYUibTXYEmNz4mXKh+Tv5lVC4u6UHVlcg53zZuad3QTvpBUmTdXnUa91TdxptrKJ/95WY+8XT8vtbaf1UwocHpqCvxNsezNzyCSdWKE4aldqjlEIhZ5WdZsCA8FlARqhYMDSZ9Bln0Px0CIdXQd2SQXmXFlrZQBpksFsaA89H+HzDDsi4131yJoLcE3kUNbYANdoupSkp6DPLsCkNebC9ebivCW4WF/eoo6uMOPZW6iFZ2rlpX4LchmrHkNZ4MazzXIMWTh2XLcf5h6AIktSsdbLeKaZRLq30haKXPN2wYbJmwuc9idzbpIcov6HOXSp0hFBSw001H16uGth7NRBhpYD8Tpk2ptXf0Kj4lAUcTxzVBaYqgGbTU040i13sxC8S6oNt7/UJYok0Je7Eotd5meoHtx69V1jA83hgq7Q8EPscZEF5fUCkNfA0lQi9gv5o3QX+KM7u9/8xItVaXp1fsxKaQ9Rus3PbuINGsOy8Uq23cr5RbgoJSgv6EjKd3WA61k2kRr6rv2EiesB+xD2dQpzOf60iPtH5vuRULBChK7ZsLqavZ5VrvtEPE9KesPD4teFZjL/3aHst3D9FnyzZc+YxNZ98T8V3/6l4N75Op+fSpxq0HNdA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM6PR04MB6341.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(7416002)(8936002)(26005)(52116002)(44832011)(2906002)(8676002)(6486002)(2616005)(508600001)(86362001)(4326008)(186003)(66946007)(6512007)(6506007)(5660300002)(66556008)(38350700002)(6666004)(38100700002)(66476007)(316002)(83380400001)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: s2tVwOUIQznyeevss/SAUXbElkGAFHbjm+YyxPPI4Vn17GhwkvOkX6MsgYqeMiYawpcwJAL1jtJyUf7LYQ+R2Y+sYFR8/N6F9tL+PATGDsda97MGF+JG4mxkf5Sb7MRMY5MbbB4BvJA6aAQUJoUNSIo5wEbnlGRLvCV3s3vsf18r69UBpkRn9FGBvrcxX2Ay3hhvZavNvovhRnFvzPD3tsEzZsv0k6WvFx3uMot3BNZaDZG5H6WKfNQsZjU4KYOF3hGdewzkYm54OeZrN9asI0Cm3H66ifdoSGYGQKQHbJN+JTloncKRzW9AK/EhdKyKydVbW8Pbipw2dGZWfI+Kguxqcydsi/nE9S9QQGWHR8WG8AAisNmYvTO8TSTKcZXdUvrlqqH+FCoQnZKIaQE8ZV3ihpgmXJ6RMonQ+lXeEzfmZGqwdMkUohUWQ2OPLo8trwrDjcjbtNo3CL51G0RmGBy12lKdEpkhb4Ha8g7KX/9IWvHVF59wzHRITHWZUM8n7jeFAVA40XEMRJayvYS5Z3uihHEFyL6ALDMCeuKHSA0UC+1PbzaoCUZX0DcfJ2TwvkawmYxZk2eyYxphopjB+HC/RcxoXph2aLJNNQRzu1N8IMlGOUM8cu8w0ETEPI9tjCtKAS75wkU/oXAba+0GnsJHoixWTau0SHt6iPgl4gcx34mpEpOdhEiuoW742IV9zqyGMh21xi/xbzobJpj4cKhIzJB/waeJzB9FviG9tXe92zXy37uGZg5xAchcL6LItPhhAGwHwgoNj2jii9L4AbZz2Dqy3pmyY6Bj4u/zWA6+nfTImFP3fTLfeDOdy6cujNzkRYIeu78mlFpX7FcuoYy7NLipFDURn71DB1p4rz2pQMtjht7Nfuk7jVgb4iTaHT9fndxkykwFjyOWUfTvLE6smNZhAxoRDakNfvD+ev8eBNnzYQGjxrtWcg8KzYjlNTSpZ2bkJOhSShodszhSpU6qOwDgY/IPFxF6CfJwAosiQhMRcx3NiWaRbEinhI8czqHdlP+0PRzins9DEjcerarcblvZxHlmzTe+qFjJdjhw4GP/PanNPqcg6vIBEzDY4k+3UdWX933Js2gNvzEhIC4+fR9XQGXzoo1gi8ywqzCR8SXOAFulRPw6H8mlfMkyCBtcVetJDnyihZT2yAgTv31od7w1GqPnoXsdVM/7ftxVZtEYWgRWKg5Ee+EdpCzee5FrGKcSKSnaM8cNMAJlRy2yE7QMcIkjdTtUzXG5oICVMuhYoP+6LH/dXYdMQ8CtGVBM9zcL8UaHhEQW36VvZS+dTNeAafFkx8rasRfG/iik7vcrpsNuxx/hs8y7e1OVwJtcsnmLqzLQSOdr8YTEnriIsyo2xS3AULM6YJjoyrjRwdghTDOrCUJ5/EEQt5b3zcl7EcBtikSWkKLUJYmScZARWWO5kMFG0qlqGG2BmNhQ2s1yRYYJgfpJ+4ueNL4LQNsGOzWYvWVJhCDQD2sZSenduwMrOlOc+/0zzCR6Pe4WiYF2HIV9HrwOUjCXzEIod+zndyXS+kvVXya6HgdDZWpTJNfKnSWPhgYcROYv/J8/zElxWOR2MvRm3hNoMshQAQUPgLzulPatMpwNVDyGskH6Z0QR5KQ2L5D9KwSs36I= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: b88abc27-3188-4735-4e1f-08da033418b1 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB6341.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2022 07:52:31.5364 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: xZXK1wC0UGnSNHHR9C/qVzIe/Y3VBfRGvpegw45uJazzQ/E7tfDIujyBZ7ZzujCh6kZfiGL6bVkppVz1nrNHDQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR04MB4443 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220310_235234_590092_2B185722 X-CRM114-Status: GOOD ( 19.92 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The decoder will save the precision that was detected from jpeg header and use it later, when choosing the pixel format and also calculate bytesperline according to precision. The 12bit jpeg is not supported yet, but driver shouldn't led to serious problem if user enqueue a 12 bit jpeg. And the 12bit jpeg is supported by hardware, driver may support it later. Signed-off-by: Ming Qian --- drivers/media/platform/imx-jpeg/mxc-jpeg.c | 37 +++++++++++++++------- drivers/media/platform/imx-jpeg/mxc-jpeg.h | 1 + 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/drivers/media/platform/imx-jpeg/mxc-jpeg.c b/drivers/media/platform/imx-jpeg/mxc-jpeg.c index d8d24c19f423..82b9b4630d9c 100644 --- a/drivers/media/platform/imx-jpeg/mxc-jpeg.c +++ b/drivers/media/platform/imx-jpeg/mxc-jpeg.c @@ -82,6 +82,7 @@ static const struct mxc_jpeg_fmt mxc_formats[] = { .h_align = 3, .v_align = 3, .flags = MXC_JPEG_FMT_TYPE_RAW, + .precision = 8, }, { .name = "ARGB", /* ARGBARGB packed format */ @@ -93,6 +94,7 @@ static const struct mxc_jpeg_fmt mxc_formats[] = { .h_align = 3, .v_align = 3, .flags = MXC_JPEG_FMT_TYPE_RAW, + .precision = 8, }, { .name = "YUV420", /* 1st plane = Y, 2nd plane = UV */ @@ -104,6 +106,7 @@ static const struct mxc_jpeg_fmt mxc_formats[] = { .h_align = 4, .v_align = 4, .flags = MXC_JPEG_FMT_TYPE_RAW, + .precision = 8, }, { .name = "YUV422", /* YUYV */ @@ -115,6 +118,7 @@ static const struct mxc_jpeg_fmt mxc_formats[] = { .h_align = 4, .v_align = 3, .flags = MXC_JPEG_FMT_TYPE_RAW, + .precision = 8, }, { .name = "YUV444", /* YUVYUV */ @@ -126,6 +130,7 @@ static const struct mxc_jpeg_fmt mxc_formats[] = { .h_align = 3, .v_align = 3, .flags = MXC_JPEG_FMT_TYPE_RAW, + .precision = 8, }, { .name = "Gray", /* Gray (Y8/Y12) or Single Comp */ @@ -137,6 +142,7 @@ static const struct mxc_jpeg_fmt mxc_formats[] = { .h_align = 3, .v_align = 3, .flags = MXC_JPEG_FMT_TYPE_RAW, + .precision = 8, }, }; @@ -1175,14 +1181,17 @@ static u32 mxc_jpeg_get_image_format(struct device *dev, for (i = 0; i < MXC_JPEG_NUM_FORMATS; i++) if (mxc_formats[i].subsampling == header->frame.subsampling && - mxc_formats[i].nc == header->frame.num_components) { + mxc_formats[i].nc == header->frame.num_components && + mxc_formats[i].precision == header->frame.precision) { fourcc = mxc_formats[i].fourcc; break; } if (fourcc == 0) { - dev_err(dev, "Could not identify image format nc=%d, subsampling=%d\n", + dev_err(dev, + "Could not identify image format nc=%d, subsampling=%d, precision=%d\n", header->frame.num_components, - header->frame.subsampling); + header->frame.subsampling, + header->frame.precision); return fourcc; } /* @@ -1208,18 +1217,22 @@ static void mxc_jpeg_bytesperline(struct mxc_jpeg_q_data *q, /* bytesperline unused for compressed formats */ q->bytesperline[0] = 0; q->bytesperline[1] = 0; - } else if (q->fmt->fourcc == V4L2_PIX_FMT_NV12M) { + } else if (q->fmt->subsampling == V4L2_JPEG_CHROMA_SUBSAMPLING_420) { /* When the image format is planar the bytesperline value * applies to the first plane and is divided by the same factor * as the width field for the other planes */ - q->bytesperline[0] = q->w * (precision / 8) * - (q->fmt->depth / 8); + q->bytesperline[0] = q->w * DIV_ROUND_UP(precision, 8); q->bytesperline[1] = q->bytesperline[0]; + } else if (q->fmt->subsampling == V4L2_JPEG_CHROMA_SUBSAMPLING_422) { + q->bytesperline[0] = q->w * DIV_ROUND_UP(precision, 8) * 2; + q->bytesperline[1] = 0; + } else if (q->fmt->subsampling == V4L2_JPEG_CHROMA_SUBSAMPLING_444) { + q->bytesperline[0] = q->w * DIV_ROUND_UP(precision, 8) * q->fmt->nc; + q->bytesperline[1] = 0; } else { - /* single plane formats */ - q->bytesperline[0] = q->w * (precision / 8) * - (q->fmt->depth / 8); + /* grayscale */ + q->bytesperline[0] = q->w * DIV_ROUND_UP(precision, 8); q->bytesperline[1] = 0; } } @@ -1353,7 +1366,7 @@ static int mxc_jpeg_parse(struct mxc_jpeg_ctx *ctx, struct vb2_buffer *vb) (fourcc >> 24) & 0xff); /* setup bytesperline/sizeimage for capture queue */ - mxc_jpeg_bytesperline(q_data_cap, header.frame.precision); + mxc_jpeg_bytesperline(q_data_cap, q_data_cap->fmt->precision); mxc_jpeg_sizeimage(q_data_cap); /* @@ -1509,7 +1522,7 @@ static void mxc_jpeg_set_default_params(struct mxc_jpeg_ctx *ctx) q[i]->h = MXC_JPEG_DEFAULT_HEIGHT; q[i]->w_adjusted = MXC_JPEG_DEFAULT_WIDTH; q[i]->h_adjusted = MXC_JPEG_DEFAULT_HEIGHT; - mxc_jpeg_bytesperline(q[i], 8); + mxc_jpeg_bytesperline(q[i], q[i]->fmt->precision); mxc_jpeg_sizeimage(q[i]); } } @@ -1651,7 +1664,7 @@ static int mxc_jpeg_try_fmt(struct v4l2_format *f, const struct mxc_jpeg_fmt *fm } /* calculate bytesperline & sizeimage into the tmp_q */ - mxc_jpeg_bytesperline(&tmp_q, 8); + mxc_jpeg_bytesperline(&tmp_q, fmt->precision); mxc_jpeg_sizeimage(&tmp_q); /* adjust user format according to our calculations */ diff --git a/drivers/media/platform/imx-jpeg/mxc-jpeg.h b/drivers/media/platform/imx-jpeg/mxc-jpeg.h index f53f004ba851..82b38cc2dfab 100644 --- a/drivers/media/platform/imx-jpeg/mxc-jpeg.h +++ b/drivers/media/platform/imx-jpeg/mxc-jpeg.h @@ -60,6 +60,7 @@ struct mxc_jpeg_fmt { int h_align; int v_align; u32 flags; + u8 precision; }; struct mxc_jpeg_desc {