Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp1042198lqt; Fri, 7 Jun 2024 06:37:23 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUtzb0ySURruf1EJnpWnztAZQgnXmFRKFhDMzxXgaDL352TWW98nM3b/ql75dVNvMpfqmC/UXbUgB1y0uLX7TL2xQdzU9xC2tJ4+/0qbw== X-Google-Smtp-Source: AGHT+IF8GUvpZGGz79CjYx+VmYJJTO755DsydkHzknH/4qu5JfeeQf4kPCGCbDEeBsYPhz2+2Ymn X-Received: by 2002:a9d:7cc2:0:b0:6f0:e596:5b52 with SMTP id 46e09a7af769-6f9571e7f0fmr2540884a34.6.1717767443144; Fri, 07 Jun 2024 06:37:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717767443; cv=pass; d=google.com; s=arc-20160816; b=bwSSP1iXS9hr1HsPl/v18pzrBPvTsSRM4kr6YLsLArPHFG/qNS6QSb0zfuhZFLgR5u x3DOOyfBoTSRyeEcnAFgUGGKRr8Tk8w1ANlkUrVxt2IFMiBKi89419Q6ok17VS8XkOIg kz1Z71uh4BVvYygdOf12n+pHoIxqswuqtLtJCD9XftAm9Xb4yggUiArvJ5jziNLmBKIJ hUcHvEEYlC/vYQrAmUv/0k0rWwivA6OBgdxL3SSG5Vt2xC12A47kBDu9i+B3zgfKtYoT DLEUhMRkwLe43pdgVhtJckU8tBJ07kFEjRU4idl+g221t9j51fVBOba+bYQ1r5C1Hgp2 4yog== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=dnlV6EZfbKSSOB5yAkozQxyQBhab8cR780BU+/JTZrQ=; fh=5DiuueyS1lAAqfho5bYx+Hd2/VuZEUnh7zjWzwl5vGk=; b=EVtebabNqFzqHRyr6bNz34UU6ZrJELMc5P83ntoBKhOoSlepBFzpYFUN/Vvm/MSLIN M4guDLPRSC/FXxo4ZoAl+KK4ISo3qUU10T6ddJsoI3DM1Yh+bu66a7cXboNvKFgJv/3j nlUPrTp4fJcltJT1j3qbwrrGkIfQu4wu7MW9ck8SHHG+j9i2IYw7ch29w8DlIYPgTeAQ bdv6kHsTqI2xyb7VDWd6mxpkoUQRgYXQd6O+I7WBjdgfj5XHw2oLDaRy7HHobJ7haJF8 K93mAwk7HWK4vOVzs7BX9uJZaBrBX4qmOva7WmD8F5BPcMgyKZYp1Dvsz3lOXVzE6wTP BWZQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=L6NYNlPj; arc=pass (i=1 spf=pass spfdomain=ti.com dkim=pass dkdomain=ti.com dmarc=pass fromdomain=ti.com); spf=pass (google.com: domain of linux-kernel+bounces-206172-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206172-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d75a77b69052e-44038b16902si40010541cf.330.2024.06.07.06.37.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 06:37:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-206172-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=L6NYNlPj; arc=pass (i=1 spf=pass spfdomain=ti.com dkim=pass dkdomain=ti.com dmarc=pass fromdomain=ti.com); spf=pass (google.com: domain of linux-kernel+bounces-206172-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206172-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id C408B1C24B31 for ; Fri, 7 Jun 2024 13:37:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0244419ADAD; Fri, 7 Jun 2024 13:33:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="L6NYNlPj" Received: from fllv0016.ext.ti.com (fllv0016.ext.ti.com [198.47.19.142]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 99415195978; Fri, 7 Jun 2024 13:33:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.142 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717767200; cv=none; b=dUayqq+4ZJATYRdq/426uM7GBaZoV1f4sRhRqJuk1GH9Grnmr4xcZk7hOdL7qKF7wlXVSoPo1NHlnFgCoeBSh/7TGnEDc3EvOz6MGwvRqAuiX4aF5CLmePaXASy0T4Iu1fHcVqa+5VJPHen+G4aZOIwY81KRCii/aaOaLCbVXDY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717767200; c=relaxed/simple; bh=sTv+4L8NPPBBpg+i+qz9cePrzDf4eKNTqM5Xda6LRw0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=O4KZQM1uqWYHSsgzYzsQJH8lNlqj7Gz0da5XV6VewDb0F0V08LEwz86FFZApmIn+RKgKIsLt7Il6WV4wAVwJiMmAXL2W8iFhlAy+WdvXJbnWaY8j+oeAE9XBH9K7n9y816B7GcxN64TGkuLOQsE+e8sm++Q6PfAGXIm3vZ/BhR8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=L6NYNlPj; arc=none smtp.client-ip=198.47.19.142 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Received: from lelv0265.itg.ti.com ([10.180.67.224]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 457DWsoO118337; Fri, 7 Jun 2024 08:32:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1717767174; bh=dnlV6EZfbKSSOB5yAkozQxyQBhab8cR780BU+/JTZrQ=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=L6NYNlPjRde1WkOLXLqkzPfOtF1fM01Iox5Db8LaU+PXPUP3EhmR0AJQgTT855PCg tTnKhY/zUIsqKBlWxrMXKA0TcDA8n1gwyMUoMGkd9zp2JBDjtBN/s3lVqfCEuBFLmg VlSqGMjGto1chRA//GNAmNzTk49pP8+u5raJiBZs= Received: from DLEE115.ent.ti.com (dlee115.ent.ti.com [157.170.170.26]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 457DWsWD017223 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 7 Jun 2024 08:32:54 -0500 Received: from DLEE103.ent.ti.com (157.170.170.33) by DLEE115.ent.ti.com (157.170.170.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Fri, 7 Jun 2024 08:32:54 -0500 Received: from lelvsmtp6.itg.ti.com (10.180.75.249) by DLEE103.ent.ti.com (157.170.170.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Fri, 7 Jun 2024 08:32:54 -0500 Received: from localhost (ti.dhcp.ti.com [172.24.227.95] (may be forged)) by lelvsmtp6.itg.ti.com (8.15.2/8.15.2) with ESMTP id 457DWrnp119514; Fri, 7 Jun 2024 08:32:54 -0500 From: Devarsh Thakkar To: , , , , , , CC: , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v13 12/13] media: imagination: Round to closest multiple for cropping region Date: Fri, 7 Jun 2024 19:02:53 +0530 Message-ID: <20240607133253.3559339-1-devarsht@ti.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20240607131900.3535250-1-devarsht@ti.com> References: <20240607131900.3535250-1-devarsht@ti.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 If neither of the flags to round down (V4L2_SEL_FLAG_LE) or round up (V4L2_SEL_FLAG_GE) are specified by the user, then round to nearest multiple of requested value while updating the crop rectangle coordinates. Use the rounding macro which gives preference to rounding down in case two nearest values (high and low) are possible to raise the probability of cropping rectangle falling inside the bound region. This complies with the VIDIOC_G_SELECTION, VIDIOC_S_SELECTION ioctl description as documented in v4l uapi [1] which specifies that driver should choose crop rectangle as close as possible if no flags are passed by user-space, as quoted below : "``0`` - The driver can adjust the rectangle size freely and shall choose a crop/compose rectangle as close as possible to the requested one." Link: https://www.kernel.org/doc/Documentation/userspace-api/media/v4l/vidioc-g-selection.rst [1] Signed-off-by: Devarsh Thakkar --- V9->V13: No change V8: Update commit message with specification reference V1->V7 (No change, patch introduced in V7) --- drivers/media/platform/imagination/e5010-jpeg-enc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/media/platform/imagination/e5010-jpeg-enc.c b/drivers/media/platform/imagination/e5010-jpeg-enc.c index 4b6fbe99d5ff..ea96b1bc5315 100644 --- a/drivers/media/platform/imagination/e5010-jpeg-enc.c +++ b/drivers/media/platform/imagination/e5010-jpeg-enc.c @@ -517,10 +517,10 @@ static int e5010_s_selection(struct file *file, void *fh, struct v4l2_selection switch (s->flags) { case 0: - s->r.width = round_down(s->r.width, queue->fmt->frmsize.step_width); - s->r.height = round_down(s->r.height, queue->fmt->frmsize.step_height); - s->r.left = round_down(s->r.left, queue->fmt->frmsize.step_width); - s->r.top = round_down(s->r.top, 2); + s->r.width = round_closest_down(s->r.width, queue->fmt->frmsize.step_width); + s->r.height = round_closest_down(s->r.height, queue->fmt->frmsize.step_height); + s->r.left = round_closest_down(s->r.left, queue->fmt->frmsize.step_width); + s->r.top = round_closest_down(s->r.top, 2); if (s->r.left + s->r.width > queue->width) s->r.width = round_down(s->r.width + s->r.left - queue->width, -- 2.39.1