From patchwork Tue Jun 4 10:48:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Devarsh Thakkar X-Patchwork-Id: 801520 Received: from lelv0143.ext.ti.com (lelv0143.ext.ti.com [198.47.23.248]) (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 A367D1448EE; Tue, 4 Jun 2024 10:48:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.248 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717498121; cv=none; b=kuQvUAt3ifRz71z7TH2ef/oAgLMez6j3Lt6dfMdknbpVYmElD084/154W5tvQNaETlzHMa7S5Yw5RbnN34yYGTI6cv8ByDXCm1af00I93F6C45zbGU9acPeId9dgQOg391q3yFt0g5htaVQ1LFy0gFU4xa95+qX3L8DayIuKYlI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717498121; c=relaxed/simple; bh=Stza1b/HPmOTwzjF47gsgOtMMlmo8/dcXyxXNARFc98=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kuWHs0YSld+1tCRSKIi6Svg83/fa9QatbmL7ZmwF8y2dwZp7KM7HLREJW4rPgGuHkECen8Z7kigXMP2i7gqK3t4densQ+Ukq+FCz5GmuGyq4T29XjD6fparZelgp28543IAAzQPux5ZyXY8GoZZM78JRO/b6HI4bVrja+zyx4Xw= 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=qQ8cVTbk; arc=none smtp.client-ip=198.47.23.248 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="qQ8cVTbk" Received: from fllv0034.itg.ti.com ([10.64.40.246]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id 454AmV5l103752; Tue, 4 Jun 2024 05:48:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1717498111; bh=HDl8R1qlwKKf4cy6Kmzm2DZ3pPj6g4R4N8oOeOWyP1Q=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=qQ8cVTbkc9Z9RrUCPxz8xSSLZiUNU22R03TrffgdsEtpNJfIvfGz71ONL/9ba6pWQ JQbbFGfDd32zHuIYI5rBnN/rKBejjJgHYMrNAQ7ZjaBq0xzwVIBVN7g1krIZEvjJyk 6GbMHUKLlyozn5Qcc636FO0kbZGBH4rxNxGBYGkI= Received: from DLEE112.ent.ti.com (dlee112.ent.ti.com [157.170.170.23]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 454AmVq0030296 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 4 Jun 2024 05:48:31 -0500 Received: from DLEE114.ent.ti.com (157.170.170.25) by DLEE112.ent.ti.com (157.170.170.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Tue, 4 Jun 2024 05:48:30 -0500 Received: from lelvsmtp6.itg.ti.com (10.180.75.249) by DLEE114.ent.ti.com (157.170.170.25) 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; Tue, 4 Jun 2024 05:48:31 -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 454AmUqu115017; Tue, 4 Jun 2024 05:48:30 -0500 From: Devarsh Thakkar To: , , , , , CC: , , , , , , , , , , , , Subject: [PATCH v12 03/13] media: v4l2-jpeg: Export reference quantization and huffman tables Date: Tue, 4 Jun 2024 16:18:29 +0530 Message-ID: <20240604104829.2248905-1-devarsht@ti.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20240604104001.2235082-1-devarsht@ti.com> References: <20240604104001.2235082-1-devarsht@ti.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Export reference quantization and huffman tables as provided in ITU-T.81 so that they can be re-used by other JPEG drivers. These are example tables provided in ITU-T.81 as reference tables and the JPEG encoders are free to use either these or their own proprietary tables. Also add necessary prefixes to be used for huffman tables in global header file. Signed-off-by: Devarsh Thakkar --- V12: Fix html-doc warnings by removing * from args V11: No change V10: Add description for new macros introduced in this patchset V1->V9: No change (Patch introduced in V7) --- drivers/media/v4l2-core/v4l2-jpeg.c | 162 +++++++++++++++++++++++++++- include/media/v4l2-jpeg.h | 28 +++++ 2 files changed, 189 insertions(+), 1 deletion(-) diff --git a/drivers/media/v4l2-core/v4l2-jpeg.c b/drivers/media/v4l2-core/v4l2-jpeg.c index 94435a7b6816..c2cbae73f93d 100644 --- a/drivers/media/v4l2-core/v4l2-jpeg.c +++ b/drivers/media/v4l2-core/v4l2-jpeg.c @@ -16,7 +16,7 @@ #include #include -MODULE_DESCRIPTION("V4L2 JPEG header parser helpers"); +MODULE_DESCRIPTION("V4L2 JPEG helpers"); MODULE_AUTHOR("Philipp Zabel "); MODULE_LICENSE("GPL"); @@ -52,6 +52,115 @@ MODULE_LICENSE("GPL"); #define COM 0xfffe /* comment */ #define TEM 0xff01 /* temporary */ +/* Luma and chroma qp tables to achieve 50% compression quality + * This is as per example in Annex K.1 of ITU-T.81 + */ +const u8 luma_qt[] = { + 16, 11, 10, 16, 24, 40, 51, 61, + 12, 12, 14, 19, 26, 58, 60, 55, + 14, 13, 16, 24, 40, 57, 69, 56, + 14, 17, 22, 29, 51, 87, 80, 62, + 18, 22, 37, 56, 68, 109, 103, 77, + 24, 35, 55, 64, 81, 104, 113, 92, + 49, 64, 78, 87, 103, 121, 120, 101, + 72, 92, 95, 98, 112, 100, 103, 99 +}; + +const u8 chroma_qt[] = { + 17, 18, 24, 47, 99, 99, 99, 99, + 18, 21, 26, 66, 99, 99, 99, 99, + 24, 26, 56, 99, 99, 99, 99, 99, + 47, 66, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99 +}; + +/* Zigzag scan pattern */ +const u8 zigzag[] = { + 0, 1, 8, 16, 9, 2, 3, 10, + 17, 24, 32, 25, 18, 11, 4, 5, + 12, 19, 26, 33, 40, 48, 41, 34, + 27, 20, 13, 6, 7, 14, 21, 28, + 35, 42, 49, 56, 57, 50, 43, 36, + 29, 22, 15, 23, 30, 37, 44, 51, + 58, 59, 52, 45, 38, 31, 39, 46, + 53, 60, 61, 54, 47, 55, 62, 63 +}; + +/* + * Contains the data that needs to be sent in the marker segment of an + * interchange format JPEG stream or an abbreviated format table specification + * data stream. Specifies the huffman table used for encoding the luminance DC + * coefficient differences. The table represents Table K.3 of ITU-T.81 + */ +const u8 luma_dc_ht[] = { + 0x00, 0x01, 0x05, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B +}; + +/* + * Contains the data that needs to be sent in the marker segment of an + * interchange format JPEG stream or an abbreviated format table specification + * data stream. Specifies the huffman table used for encoding the luminance AC + * coefficients. The table represents Table K.5 of ITU-T.81 + */ +const u8 luma_ac_ht[] = { + 0x00, 0x02, 0x01, 0x03, 0x03, 0x02, 0x04, 0x03, 0x05, 0x05, 0x04, 0x04, + 0x00, 0x00, 0x01, 0x7D, 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, + 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07, 0x22, 0x71, 0x14, 0x32, + 0x81, 0x91, 0xA1, 0x08, 0x23, 0x42, 0xB1, 0xC1, 0x15, 0x52, 0xD1, 0xF0, + 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0A, 0x16, 0x17, 0x18, 0x19, 0x1A, + 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, + 0x3A, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x53, 0x54, 0x55, + 0x56, 0x57, 0x58, 0x59, 0x5A, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, + 0x6A, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x83, 0x84, 0x85, + 0x86, 0x87, 0x88, 0x89, 0x8A, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, + 0x99, 0x9A, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xB2, + 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xC2, 0xC3, 0xC4, 0xC5, + 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, + 0xD9, 0xDA, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, + 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA +}; + +/* + * Contains the data that needs to be sent in the marker segment of an interchange format JPEG + * stream or an abbreviated format table specification data stream. + * Specifies the huffman table used for encoding the chrominance DC coefficient differences. + * The table represents Table K.4 of ITU-T.81 + */ +const u8 chroma_dc_ht[] = { + 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B +}; + +/* + * Contains the data that needs to be sent in the marker segment of an + * interchange format JPEG stream or an abbreviated format table specification + * data stream. Specifies the huffman table used for encoding the chrominance + * AC coefficients. The table represents Table K.6 of ITU-T.81 + */ +const u8 chroma_ac_ht[] = { + 0x00, 0x02, 0x01, 0x02, 0x04, 0x04, 0x03, 0x04, 0x07, 0x05, 0x04, 0x04, + 0x00, 0x01, 0x02, 0x77, 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, + 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71, 0x13, 0x22, 0x32, 0x81, + 0x08, 0x14, 0x42, 0x91, 0xA1, 0xB1, 0xC1, 0x09, 0x23, 0x33, 0x52, 0xF0, + 0x15, 0x62, 0x72, 0xD1, 0x0A, 0x16, 0x24, 0x34, 0xE1, 0x25, 0xF1, 0x17, + 0x18, 0x19, 0x1A, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x35, 0x36, 0x37, 0x38, + 0x39, 0x3A, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x53, 0x54, + 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, + 0x69, 0x6A, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x82, 0x83, + 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x92, 0x93, 0x94, 0x95, 0x96, + 0x97, 0x98, 0x99, 0x9A, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, + 0xAA, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xC2, 0xC3, + 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, + 0xD7, 0xD8, 0xD9, 0xDA, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, + 0xEA, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA +}; + /** * struct jpeg_stream - JPEG byte stream * @curr: current position in stream @@ -675,3 +784,54 @@ int v4l2_jpeg_parse_huffman_tables(void *buf, size_t len, return jpeg_parse_huffman_tables(&stream, huffman_tables); } EXPORT_SYMBOL_GPL(v4l2_jpeg_parse_huffman_tables); + +/** + * v4l2_jpeg_get_reference_quantization_tables - Get reference quantization + * tables as defined in ITU-T.81 + * @ref_luma_qt: Output variable pointing to luma quantization table + * @ref_chroma_qt: Output variable pointing to chroma quantization table + */ +void v4l2_jpeg_get_reference_quantization_tables(const u8 **ref_luma_qt, const + u8 **ref_chroma_qt) +{ + if (ref_luma_qt) + *ref_luma_qt = luma_qt; + if (ref_chroma_qt) + *ref_chroma_qt = chroma_qt; +} +EXPORT_SYMBOL_GPL(v4l2_jpeg_get_reference_quantization_tables); + +/** + * v4l2_jpeg_get_zig_zag_scan - Get zigzag scan table as defined in ITU-T.81 + * @ref_zigzag: Output variable pointing to zigzag scan table + */ +void v4l2_jpeg_get_zig_zag_scan(const u8 **ref_zigzag) +{ + if (ref_zigzag) + *ref_zigzag = zigzag; +} +EXPORT_SYMBOL_GPL(v4l2_jpeg_get_zig_zag_scan); + +/** + * v4l2_jpeg_get_reference_huffman_tables - Get reference huffman tables as + * defined in ITU-T.81 + * @ref_luma_dc_ht : Output variable pointing to huffman table for luma DC + * @ref_luma_ac_ht : Output variable pointing to huffman table for luma AC + * @ref_chroma_dc_ht : Output variable pointing to huffman table for chroma DC + * @ref_chroma_ac_ht : Output variable pointing to huffman table for chroma AC + */ +void v4l2_jpeg_get_reference_huffman_tables(const u8 **ref_luma_dc_ht, + const u8 **ref_luma_ac_ht, + const u8 **ref_chroma_dc_ht, + const u8 **ref_chroma_ac_ht) +{ + if (ref_luma_dc_ht) + *ref_luma_dc_ht = luma_dc_ht; + if (ref_luma_ac_ht) + *ref_luma_ac_ht = luma_ac_ht; + if (ref_chroma_dc_ht) + *ref_chroma_dc_ht = chroma_dc_ht; + if (ref_chroma_ac_ht) + *ref_chroma_ac_ht = chroma_ac_ht; +} +EXPORT_SYMBOL_GPL(v4l2_jpeg_get_reference_huffman_tables); diff --git a/include/media/v4l2-jpeg.h b/include/media/v4l2-jpeg.h index 2dba843ce3bd..b470bbffb73f 100644 --- a/include/media/v4l2-jpeg.h +++ b/include/media/v4l2-jpeg.h @@ -14,6 +14,30 @@ #define V4L2_JPEG_MAX_COMPONENTS 4 #define V4L2_JPEG_MAX_TABLES 4 +/* + * Prefixes used to generate huffman table class and destination identifiers as + * described below: + * + * V4L2_JPEG_LUM_HT | V4L2_JPEG_DC_HT : Prefix for Luma DC coefficients + * huffman table + * V4L2_JPEG_LUM_HT | V4L2_JPEG_AC_HT : Prefix for Luma AC coefficients + * huffman table + * V4L2_JPEG_CHR_HT | V4L2_JPEG_DC_HT : Prefix for Chroma DC coefficients + * huffman table + * V4L2_JPEG_CHR_HT | V4L2_JPEG_AC_HT : Prefix for Chroma AC coefficients + * huffman table + */ +#define V4L2_JPEG_LUM_HT 0x00 +#define V4L2_JPEG_CHR_HT 0x01 +#define V4L2_JPEG_DC_HT 0x00 +#define V4L2_JPEG_AC_HT 0x10 + +/* Length of reference huffman tables as provided in Table K.3 of ITU-T.81 */ +#define V4L2_JPEG_REF_HT_AC_LEN 178 +#define V4L2_JPEG_REF_HT_DC_LEN 28 + +/* Array size for 8x8 block of samples or DCT coefficient */ +#define V4L2_JPEG_PIXELS_IN_BLOCK 64 /** * struct v4l2_jpeg_reference - reference into the JPEG buffer @@ -154,4 +178,8 @@ int v4l2_jpeg_parse_quantization_tables(void *buf, size_t len, u8 precision, int v4l2_jpeg_parse_huffman_tables(void *buf, size_t len, struct v4l2_jpeg_reference *huffman_tables); +void v4l2_jpeg_get_reference_quantization_tables(const u8 **luma_qt, const u8 **chroma_qt); +void v4l2_jpeg_get_zig_zag_scan(const u8 **zigzag); +void v4l2_jpeg_get_reference_huffman_tables(const u8 **luma_dc_ht, const u8 **luma_ac_ht, + const u8 **chroma_dc_ht, const u8 **chroma_ac_ht); #endif From patchwork Tue Jun 4 10:50:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Devarsh Thakkar X-Patchwork-Id: 801519 Received: from lelv0142.ext.ti.com (lelv0142.ext.ti.com [198.47.23.249]) (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 EECA4142E86; Tue, 4 Jun 2024 10:50:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.249 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717498224; cv=none; b=jXfFqsDhHkGaMurqdodKdTQWJ7YT98mGCJkqaS4YtCg6ME8leNqL0Qau+FuidCD6TKE2bIJ95ZbmApnXmpVe/0RjZ3kTifU3ePkv4qrgXwep2rUdtplrQw+A5I0ZxzuZseESqhagjCeg3eJ4thvOEM/Buc9ncp7xfK+bXpoibRo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717498224; c=relaxed/simple; bh=ygrClUN+wLtnB93HUa74he4gGqXeYwgVUkg1JpSXjqo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MifMEa7zKz9H3Oa5jUSnWXJmu+25LUEp/H2f3ShA/lTlEhD4Mj6MFw3VAgQKypAfdzfrTRATHI5l21vbnOx84yYdk9pETGUTgyYwR4y3VUga76Ee5Df/sMgppg/TQ40sEPwgkpav3gqjc1+LQsi4iVwUFQxrlQ/u8lLJDTrFDPI= 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=Ksw2w3Zu; arc=none smtp.client-ip=198.47.23.249 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="Ksw2w3Zu" Received: from lelv0265.itg.ti.com ([10.180.67.224]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 454Ao9Kn004853; Tue, 4 Jun 2024 05:50:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1717498209; bh=zEvlh9TuKH2zNs1+d3XQC+Bhp+Z9aa1n5mYCny0NjbA=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=Ksw2w3Zu4tE9sghCclg+iWlqSzuLsvOIbDMSTI4JAiksRVWowSjqJSpOtVRKljS0w 02LpGtkivle2B77kzSoKAPmVM4qm6Y1iHl1U91xVe11rb2twEscLd2iwbqoFz7nCxv XEDjHGPFk7+XOpLR7Q4PPVfPksQ02TzHe+3B4Uwc= Received: from DFLE106.ent.ti.com (dfle106.ent.ti.com [10.64.6.27]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 454Ao9XP007129 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 4 Jun 2024 05:50:09 -0500 Received: from DFLE104.ent.ti.com (10.64.6.25) by DFLE106.ent.ti.com (10.64.6.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Tue, 4 Jun 2024 05:50:08 -0500 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) by DFLE104.ent.ti.com (10.64.6.25) 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; Tue, 4 Jun 2024 05:50:08 -0500 Received: from localhost (ti.dhcp.ti.com [172.24.227.95] (may be forged)) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 454Ao8N3070907; Tue, 4 Jun 2024 05:50:08 -0500 From: Devarsh Thakkar To: , , , , , CC: , , , , , , , , , , , , , , , Subject: [PATCH v12 05/13] media: imagination: Use exported tables from v4l2-jpeg core Date: Tue, 4 Jun 2024 16:20:07 +0530 Message-ID: <20240604105007.2251633-1-devarsht@ti.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20240604104001.2235082-1-devarsht@ti.com> References: <20240604104001.2235082-1-devarsht@ti.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Use exported huffman and quantization tables from v4l2-jpeg core library. Signed-off-by: Devarsh Thakkar --- V1->V12 (No change, patch introduced in V7) --- .../platform/imagination/e5010-jpeg-enc.c | 140 +++--------------- 1 file changed, 19 insertions(+), 121 deletions(-) diff --git a/drivers/media/platform/imagination/e5010-jpeg-enc.c b/drivers/media/platform/imagination/e5010-jpeg-enc.c index a9ad41f54ab6..e701d573a26a 100644 --- a/drivers/media/platform/imagination/e5010-jpeg-enc.c +++ b/drivers/media/platform/imagination/e5010-jpeg-enc.c @@ -32,116 +32,6 @@ #include "e5010-jpeg-enc.h" #include "e5010-jpeg-enc-hw.h" -/* Luma and chroma qp table to achieve 50% compression quality - * This is as per example in Annex K.1 of ITU-T.81 - */ -static const u8 luma_q_table[64] = { - 16, 11, 10, 16, 24, 40, 51, 61, - 12, 12, 14, 19, 26, 58, 60, 55, - 14, 13, 16, 24, 40, 57, 69, 56, - 14, 17, 22, 29, 51, 87, 80, 62, - 18, 22, 37, 56, 68, 109, 103, 77, - 24, 35, 55, 64, 81, 104, 113, 92, - 49, 64, 78, 87, 103, 121, 120, 101, - 72, 92, 95, 98, 112, 100, 103, 99 -}; - -static const u8 chroma_q_table[64] = { - 17, 18, 24, 47, 99, 99, 99, 99, - 18, 21, 26, 66, 99, 99, 99, 99, - 24, 26, 56, 99, 99, 99, 99, 99, - 47, 66, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99 -}; - -/* Zigzag scan pattern */ -static const u8 zigzag[64] = { - 0, 1, 8, 16, 9, 2, 3, 10, - 17, 24, 32, 25, 18, 11, 4, 5, - 12, 19, 26, 33, 40, 48, 41, 34, - 27, 20, 13, 6, 7, 14, 21, 28, - 35, 42, 49, 56, 57, 50, 43, 36, - 29, 22, 15, 23, 30, 37, 44, 51, - 58, 59, 52, 45, 38, 31, 39, 46, - 53, 60, 61, 54, 47, 55, 62, 63 -}; - -/* - * Contains the data that needs to be sent in the marker segment of an interchange format JPEG - * stream or an abbreviated format table specification data stream. - * Specifies the huffman table used for encoding the luminance DC coefficient differences. - * The table represents Table K.3 of ITU-T.81 - */ -static const u8 luma_dc_table[] = { - 0x00, 0x01, 0x05, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B -}; - -/* - * Contains the data that needs to be sent in the marker segment of an interchange format JPEG - * stream or an abbreviated format table specification data stream. - * Specifies the huffman table used for encoding the luminance AC coefficients. - * The table represents Table K.5 of ITU-T.81 - */ -static const u8 luma_ac_table[] = { - 0x00, 0x02, 0x01, 0x03, 0x03, 0x02, 0x04, 0x03, - 0x05, 0x05, 0x04, 0x04, 0x00, 0x00, 0x01, 0x7D, - 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, - 0x07, 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xA1, 0x08, 0x23, 0x42, 0xB1, 0xC1, 0x15, 0x52, - 0xD1, 0xF0, 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0A, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x25, - 0x26, 0x27, 0x28, 0x29, 0x2A, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x43, 0x44, 0x45, - 0x46, 0x47, 0x48, 0x49, 0x4A, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x63, 0x64, - 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x83, - 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, - 0x9A, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, - 0xB7, 0xB8, 0xB9, 0xBA, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xD2, 0xD3, - 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, - 0xE9, 0xEA, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA -}; - -/* - * Contains the data that needs to be sent in the marker segment of an interchange format JPEG - * stream or an abbreviated format table specification data stream. - * Specifies the huffman table used for encoding the chrominance DC coefficient differences. - * The table represents Table K.4 of ITU-T.81 - */ -static const u8 chroma_dc_table[] = { - 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B -}; - -/* - * Contains the data that needs to be sent in the marker segment of an interchange format JPEG - * stream or an abbreviated format table specification data stream. - * Specifies the huffman table used for encoding the chrominance AC coefficients. - * The table represents Table K.6 of ITU-T.81 - */ -static const u8 chroma_ac_table[] = { - 0x00, 0x02, 0x01, 0x02, 0x04, 0x04, 0x03, 0x04, - 0x07, 0x05, 0x04, 0x04, 0x00, 0x01, 0x02, 0x77, - 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, - 0x71, 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91, 0xA1, 0xB1, 0xC1, 0x09, 0x23, 0x33, - 0x52, 0xF0, 0x15, 0x62, 0x72, 0xD1, 0x0A, 0x16, 0x24, 0x34, 0xE1, 0x25, 0xF1, 0x17, 0x18, - 0x19, 0x1A, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x43, 0x44, - 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x63, - 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, - 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, - 0x98, 0x99, 0x9A, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xB2, 0xB3, 0xB4, - 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, - 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, - 0xE8, 0xE9, 0xEA, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA -}; - -#define JPEG_LUM_HT 0x00 -#define JPEG_CHR_HT 0x01 -#define JPEG_DC_HT 0x00 -#define JPEG_AC_HT 0x10 - /* forward declarations */ static const struct of_device_id e5010_of_match[]; @@ -270,6 +160,9 @@ static void calculate_qp_tables(struct e5010_context *ctx) { long long luminosity, contrast; int quality, i; + const u8 *luma_q_table, *chroma_q_table; + + v4l2_jpeg_get_reference_quantization_tables(&luma_q_table, &chroma_q_table); quality = 50 - ctx->quality; @@ -281,7 +174,7 @@ static void calculate_qp_tables(struct e5010_context *ctx) contrast *= INCREASE; } - for (i = 0; i < ARRAY_SIZE(luma_q_table); i++) { + for (i = 0; i < V4L2_JPEG_PIXELS_IN_BLOCK; i++) { long long delta = chroma_q_table[i] * contrast + luminosity; int val = (int)(chroma_q_table[i] + delta); @@ -927,41 +820,46 @@ static void encode_marker_segment(struct e5010_context *ctx, void *addr, unsigne { u8 *buffer = (u8 *)addr; int i; + const u8 *luma_dc_table, *chroma_dc_table, *luma_ac_table, *chroma_ac_table, *zigzag; + + v4l2_jpeg_get_reference_huffman_tables(&luma_dc_table, &luma_ac_table, &chroma_dc_table, + &chroma_ac_table); + v4l2_jpeg_get_zig_zag_scan(&zigzag); header_write(ctx, buffer, offset, 2, START_OF_IMAGE); header_write(ctx, buffer, offset, 2, DQT_MARKER); header_write(ctx, buffer, offset, 3, LQPQ << 4); - for (i = 0; i < PELS_IN_BLOCK; i++) + for (i = 0; i < V4L2_JPEG_PIXELS_IN_BLOCK; i++) header_write(ctx, buffer, offset, 1, ctx->luma_qp[zigzag[i]]); header_write(ctx, buffer, offset, 2, DQT_MARKER); header_write(ctx, buffer, offset, 3, (LQPQ << 4) | 1); - for (i = 0; i < PELS_IN_BLOCK; i++) + for (i = 0; i < V4L2_JPEG_PIXELS_IN_BLOCK; i++) header_write(ctx, buffer, offset, 1, ctx->chroma_qp[zigzag[i]]); /* Huffman tables */ header_write(ctx, buffer, offset, 2, DHT_MARKER); header_write(ctx, buffer, offset, 2, LH_DC); - header_write(ctx, buffer, offset, 1, JPEG_LUM_HT | JPEG_DC_HT); - for (i = 0 ; i < ARRAY_SIZE(luma_dc_table); i++) + header_write(ctx, buffer, offset, 1, V4L2_JPEG_LUM_HT | V4L2_JPEG_DC_HT); + for (i = 0 ; i < V4L2_JPEG_REF_HT_DC_LEN; i++) header_write(ctx, buffer, offset, 1, luma_dc_table[i]); header_write(ctx, buffer, offset, 2, DHT_MARKER); header_write(ctx, buffer, offset, 2, LH_AC); - header_write(ctx, buffer, offset, 1, JPEG_LUM_HT | JPEG_AC_HT); - for (i = 0 ; i < ARRAY_SIZE(luma_ac_table); i++) + header_write(ctx, buffer, offset, 1, V4L2_JPEG_LUM_HT | V4L2_JPEG_AC_HT); + for (i = 0 ; i < V4L2_JPEG_REF_HT_AC_LEN; i++) header_write(ctx, buffer, offset, 1, luma_ac_table[i]); header_write(ctx, buffer, offset, 2, DHT_MARKER); header_write(ctx, buffer, offset, 2, LH_DC); - header_write(ctx, buffer, offset, 1, JPEG_CHR_HT | JPEG_DC_HT); - for (i = 0 ; i < ARRAY_SIZE(chroma_dc_table); i++) + header_write(ctx, buffer, offset, 1, V4L2_JPEG_CHR_HT | V4L2_JPEG_DC_HT); + for (i = 0 ; i < V4L2_JPEG_REF_HT_DC_LEN; i++) header_write(ctx, buffer, offset, 1, chroma_dc_table[i]); header_write(ctx, buffer, offset, 2, DHT_MARKER); header_write(ctx, buffer, offset, 2, LH_AC); - header_write(ctx, buffer, offset, 1, JPEG_CHR_HT | JPEG_AC_HT); - for (i = 0 ; i < ARRAY_SIZE(chroma_ac_table); i++) + header_write(ctx, buffer, offset, 1, V4L2_JPEG_CHR_HT | V4L2_JPEG_AC_HT); + for (i = 0 ; i < V4L2_JPEG_REF_HT_AC_LEN; i++) header_write(ctx, buffer, offset, 1, chroma_ac_table[i]); } From patchwork Tue Jun 4 10:51:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Devarsh Thakkar X-Patchwork-Id: 801518 Received: from lelv0143.ext.ti.com (lelv0143.ext.ti.com [198.47.23.248]) (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 74F42144D00; Tue, 4 Jun 2024 10:51:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.248 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717498304; cv=none; b=F441D9mvDiH2jGynqOWfV3t9a7fBOPLwbnCcyBuYb3gl4R4xSVlBwxEqWDnnC9cmjXGYFg4fAk8xrr9VrQBbqmVjslQZh878IJWso9wsDFt3PecYgboWipXxM3eEW1Oubrlz/WSPmbq5M7z5i+bfnHN88WlEmIpFWhbAUlPmwu4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717498304; c=relaxed/simple; bh=5H4TcUpSxTjfANRWJBSgJ/tN3LuXrKy0u1q8b7GKM48=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qKoOUcR63MJzU7tyjtcNCGo9uQW1SHZSlYDv5lJYx+P0PCLT4CK7VrOq0i5TkestTVQcTix8mlqtfeVPVtXmuiOvDWRt+i5d+ZTg6B/tAMkDem6PfHqvsk0ALfKbwo05JyR3/OKZFoPDeLZza2CA62KNC8Rs5w+fq95ylJLn1As= 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=uYlZsMCp; arc=none smtp.client-ip=198.47.23.248 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="uYlZsMCp" Received: from fllv0034.itg.ti.com ([10.64.40.246]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id 454ApPwF104288; Tue, 4 Jun 2024 05:51:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1717498285; bh=frKIkup1rya8/oIVCuozYgIkw2YiLenjI5YJiYQbdwo=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=uYlZsMCpO6BmzI29pbfN5isqhCyS6MeEhchQVcV9XC4rTasy+ZAw59O8daz0q6ovI +vNr8ES3x82DCSiLF7igMc2FtCk/ZSzL1DIV+qotCk9UdoR3zFD7yG6JFBqRWnAJtp ANAGafJqWWacz5LDW2wUyIeYB4jrg8Fb4gsjvZy4= Received: from DFLE108.ent.ti.com (dfle108.ent.ti.com [10.64.6.29]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 454ApP1o032028 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 4 Jun 2024 05:51:25 -0500 Received: from DFLE109.ent.ti.com (10.64.6.30) by DFLE108.ent.ti.com (10.64.6.29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Tue, 4 Jun 2024 05:51:25 -0500 Received: from lelvsmtp6.itg.ti.com (10.180.75.249) by DFLE109.ent.ti.com (10.64.6.30) 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; Tue, 4 Jun 2024 05:51:25 -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 454ApOF8119625; Tue, 4 Jun 2024 05:51:25 -0500 From: Devarsh Thakkar To: , , , , , , , , , , , , , , CC: , , , , , , , , , , , , , , Subject: [PATCH v12 07/13] math.h: Add macros for rounding to closest value Date: Tue, 4 Jun 2024 16:21:24 +0530 Message-ID: <20240604105124.2253786-1-devarsht@ti.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20240604104001.2235082-1-devarsht@ti.com> References: <20240604104001.2235082-1-devarsht@ti.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Add below rounding related macros: round_closest_up(x, y) : Rounds x to closest multiple of y where y is a power of 2, with a preference to round up in case two nearest values are possible. round_closest_down(x, y) : Rounds x to closest multiple of y where y is a power of 2, with a preference to round down in case two nearest values are possible. roundclosest(x, y) : Rounds x to closest multiple of y, this macro should generally be used only when y is not multiple of 2 as otherwise round_closest* macros should be used which are much faster. Examples: * round_closest_up(17, 4) = 16 * round_closest_up(15, 4) = 16 * round_closest_up(14, 4) = 16 * round_closest_down(17, 4) = 16 * round_closest_down(15, 4) = 16 * round_closest_down(14, 4) = 12 * roundclosest(21, 5) = 20 * roundclosest(19, 5) = 20 * roundclosest(17, 5) = 15 Signed-off-by: Devarsh Thakkar Acked-by: Andy Shevchenko --- NOTE: This patch is inspired from the Mentor Graphics IPU driver [1] which uses similar macro locally and which is updated in further patch in the series to use this generic macro instead along with other drivers having similar requirements. Link: https://elixir.bootlin.com/linux/v6.8.9/source/drivers/gpu/ipu-v3/ipu-image-convert.c#L480 [1] V12: - Add Acked-by V11: - Fix commenting style per review comments and remove extra whitespace V10: - Update example comment to fix formatting issues as observed with html docs V9: - No change V8: - Add new macro to round to nearest value for non-multiple of 2 - Update commit message as suggested: V1->V6 (No change, patch introduced in V7) --- include/linux/math.h | 63 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/include/linux/math.h b/include/linux/math.h index dd4152711de7..79e3dfda77fc 100644 --- a/include/linux/math.h +++ b/include/linux/math.h @@ -34,6 +34,52 @@ */ #define round_down(x, y) ((x) & ~__round_mask(x, y)) +/** + * round_closest_up - round closest to be multiple of specified value (which is + * power of 2) with preference to rounding up + * @x: the value to round + * @y: multiple to round closest to (must be a power of 2) + * + * Rounds @x to closest multiple of @y (which must be a power of 2). + * The value can be either rounded up or rounded down depending upon rounded + * value's closeness to the specified value. If there are two closest possible + * values, i.e. the difference between the specified value and it's rounded up + * and rounded down values is same then preference is given to rounded up + * value. + * + * To perform arbitrary rounding to closest value (not multiple of 2), use + * roundclosest(). + * + * Examples: + * * round_closest_up(17, 4) = 16 + * * round_closest_up(15, 4) = 16 + * * round_closest_up(14, 4) = 16 + */ +#define round_closest_up(x, y) round_down((x) + (y) / 2, (y)) + +/** + * round_closest_down - round closest to be multiple of specified value (which + * is power of 2) with preference to rounding down + * @x: the value to round + * @y: multiple to round closest to (must be a power of 2) + * + * Rounds @x to closest multiple of @y (which must be a power of 2). + * The value can be either rounded up or rounded down depending upon rounded + * value's closeness to the specified value. If there are two closest possible + * values, i.e. the difference between the specified value and it's rounded up + * and rounded down values is same then preference is given to rounded up + * value. + * + * To perform arbitrary rounding to closest value (not multiple of 2), use + * roundclosest(). + * + * Examples: + * * round_closest_down(17, 4) = 16 + * * round_closest_down(15, 4) = 16 + * * round_closest_down(14, 4) = 12 + */ +#define round_closest_down(x, y) round_up((x) - (y) / 2, (y)) + #define DIV_ROUND_UP __KERNEL_DIV_ROUND_UP #define DIV_ROUND_DOWN_ULL(ll, d) \ @@ -77,6 +123,23 @@ } \ ) +/** + * roundclosest - round to nearest multiple + * @x: the value to round + * @y: multiple to round nearest to + * + * Rounds @x to nearest multiple of @y. + * The rounded value can be greater than or less than @x depending + * upon it's nearness to @x. If @y will always be a power of 2, consider + * using the faster round_closest_up() or round_closest_down(). + * + * Examples: + * * roundclosest(21, 5) = 20 + * * roundclosest(19, 5) = 20 + * * roundclosest(17, 5) = 15 + */ +#define roundclosest(x, y) rounddown((x) + (y) / 2, (y)) + /* * Divide positive or negative dividend by positive or negative divisor * and round to closest integer. Result is undefined for negative From patchwork Tue Jun 4 10:52:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Devarsh Thakkar X-Patchwork-Id: 801517 Received: from lelv0142.ext.ti.com (lelv0142.ext.ti.com [198.47.23.249]) (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 4FB6A144D03; Tue, 4 Jun 2024 10:52:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.249 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717498360; cv=none; b=bx4uD991TvfMcfVldWRShzsgiiZ+r3kfE7qYHUWtbuZPuetzcLYG/bIjARB9+Waa9FhnbC73ZTrIqoVqU2211VnQu19r7EVqykIdrEh9O0KAkQK4VmAhHV/GBW0+fbCh9lEMIZRvmDpoQjOvmGwFEpavy9qC6YgRGNjcKZ9Ph+g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717498360; c=relaxed/simple; bh=p8RmQjWju6YwnZ7CZmFezlveQX8QHnpPcm1uFVN4HLQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RLyiCMaxTRjGRGxmisaklWR1SkwmE5eRewsj/VJvlRA54sC3gLjoa0vPO9zA/3vXs/6fPnRQ4l9NSxnfaPBnGZyKbTJNxxQLN0i9BYDxVq8fe3hivgy4HHhDt8sbrC60N7E2AcmDM+WYN+t4iuB/C+tik8Dp6f2Ky0hp6wx7QgE= 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=ZcUM7Cah; arc=none smtp.client-ip=198.47.23.249 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="ZcUM7Cah" Received: from fllv0034.itg.ti.com ([10.64.40.246]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 454AqFMx005296; Tue, 4 Jun 2024 05:52:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1717498335; bh=fdbp4Ke8IMl5fhviwUSq+Cwwqel7fwsn4xw3/GtV4g0=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=ZcUM7Cahlrhn5uVPltGVWDcw/bB5IprFGWl+EY9fMtLAWekvUOG31ii3qdgn01/Cg ApFb+1k+2r/UsA4JN1RivyiyxlmkEJmA045CwvpM7HC0GAKKqWKekCM7ZpnwMcUK97 8UUYKnEun20nJKZywQkz+TMQkzdocg+U6BMaP8f0= Received: from DLEE115.ent.ti.com (dlee115.ent.ti.com [157.170.170.26]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 454AqFWZ032544 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 4 Jun 2024 05:52:15 -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; Tue, 4 Jun 2024 05:52:15 -0500 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) 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; Tue, 4 Jun 2024 05:52:15 -0500 Received: from localhost (ti.dhcp.ti.com [172.24.227.95] (may be forged)) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 454AqEr5074325; Tue, 4 Jun 2024 05:52:15 -0500 From: Devarsh Thakkar To: , , , , , , , , , , , , , , , , , , CC: , , , , , , , , , , , , , , Subject: [PATCH v12 09/13] Documentation: core-api: Add math.h macros and functions Date: Tue, 4 Jun 2024 16:22:14 +0530 Message-ID: <20240604105214.2255251-1-devarsht@ti.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20240604104001.2235082-1-devarsht@ti.com> References: <20240604104001.2235082-1-devarsht@ti.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Add documentation for rounding, scaling, absolute value and 32-bit division related macros and functions exported by math.h header file. Signed-off-by: Devarsh Thakkar Reviewed-by: Andy Shevchenko --- V12: Add Reviewed-by V11: Fix title for math function header V10: Patch introduced V1->V9 (No change) --- Documentation/core-api/kernel-api.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/core-api/kernel-api.rst b/Documentation/core-api/kernel-api.rst index ae92a2571388..7de494e76fa6 100644 --- a/Documentation/core-api/kernel-api.rst +++ b/Documentation/core-api/kernel-api.rst @@ -185,6 +185,12 @@ Division Functions .. kernel-doc:: lib/math/gcd.c :export: +Rounding, absolute value, division and 32-bit scaling functions +--------------------------------------------------------------- + +.. kernel-doc:: include/linux/math.h + :internal: + UUID/GUID --------- From patchwork Tue Jun 4 10:53:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Devarsh Thakkar X-Patchwork-Id: 801516 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 193D038B; Tue, 4 Jun 2024 10:53:27 +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=1717498409; cv=none; b=EA9p+qmvgB8sH2rMOMY4Oo6kQp8oqQUV/HBFB2BVEKci2Z2aq5MsrYljFTYRbDNicMaIMLK29O+jOeokmJ/sg0G0SNKK78Cb4xXOrrhfDq/kJyQ4DGF3HZwHjN1x3C5tmk7RfhfwiSFWbO+zla9aEYUco/21AgvSH4bAmoA+JlI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717498409; c=relaxed/simple; bh=EiWf4wFiIjCYYK9oYBVIGKDKC6ckMcj4EWCpgi0/ChE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Kz4G2Op4+JVB1EFzBfLBUzi2qzV3h0kVD/ym7wBYQFI4u6/RpmCaq6lGBV3LIBaqMwAlnFN+5d9Wrm74D1kz67ZeqjjUpZE68VKw5Cpv70xS9JbCgN02Nl4p9AH5vSLsvobiLzCeo7Cm6BEcYtuAWuNXV83PJuIMpaPRCk678JU= 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=YDGB/fk1; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="YDGB/fk1" Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 454ArDoY085968; Tue, 4 Jun 2024 05:53:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1717498393; bh=VH0U6ipfvCppDUeQDKUpcWDfD7uSeboDDJhYoTRy+XI=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=YDGB/fk1NJ0OqOSrWzHMLPMq+tqbJ77ElChnMjpPyfdQ7VDU3j49WIWkVAdMa5ZBh O+zNwUCKbyRG355xqBd7ATm+RfmI5lqNsVOJ4hCx4sohBDUO9u+GPhTHRIPfMQ13Gv vK7Z3IAud3EEilUX62juQvfST7ipM5MTGD1Qt0P8= Received: from DFLE113.ent.ti.com (dfle113.ent.ti.com [10.64.6.34]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 454ArD2g061520 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 4 Jun 2024 05:53:13 -0500 Received: from DFLE102.ent.ti.com (10.64.6.23) by DFLE113.ent.ti.com (10.64.6.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Tue, 4 Jun 2024 05:53:13 -0500 Received: from lelvsmtp6.itg.ti.com (10.180.75.249) by DFLE102.ent.ti.com (10.64.6.23) 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; Tue, 4 Jun 2024 05:53:12 -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 454ArCR2122146; Tue, 4 Jun 2024 05:53:12 -0500 From: Devarsh Thakkar To: , , , , , , , , , , , , , , , CC: , , , , , , , , , , , , , Subject: [PATCH v12 11/13] lib: math_kunit: Add tests for new macros related to rounding to nearest value Date: Tue, 4 Jun 2024 16:23:11 +0530 Message-ID: <20240604105311.2256898-1-devarsht@ti.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20240604104001.2235082-1-devarsht@ti.com> References: <20240604104001.2235082-1-devarsht@ti.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Add tests for round_closest_up/down and roundclosest macros which round to nearest multiple of specified argument. These are tested with kunit tool as shared here [1] : Link: https://gist.github.com/devarsht/3f9042825be3da4e133b8f4eda067876 [1] Signed-off-by: Devarsh Thakkar Acked-by: Andy Shevchenko --- V1->V12 (No change, patch introduced in V8) --- lib/math/math_kunit.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/lib/math/math_kunit.c b/lib/math/math_kunit.c index be27f2afb8e4..05022f010be6 100644 --- a/lib/math/math_kunit.c +++ b/lib/math/math_kunit.c @@ -70,6 +70,26 @@ static void round_down_test(struct kunit *test) KUNIT_EXPECT_EQ(test, round_down((1 << 30) - 1, 1 << 29), 1 << 29); } +static void round_closest_up_test(struct kunit *test) +{ + KUNIT_EXPECT_EQ(test, round_closest_up(17, 4), 16); + KUNIT_EXPECT_EQ(test, round_closest_up(15, 4), 16); + KUNIT_EXPECT_EQ(test, round_closest_up(14, 4), 16); + KUNIT_EXPECT_EQ(test, round_closest_up((1 << 30) - 1, 1 << 30), 1 << 30); + KUNIT_EXPECT_EQ(test, round_closest_up((1 << 30) + 1, 1 << 30), 1 << 30); + KUNIT_EXPECT_EQ(test, round_closest_up((1 << 30) - 1, 2), 1 << 30); +} + +static void round_closest_down_test(struct kunit *test) +{ + KUNIT_EXPECT_EQ(test, round_closest_down(17, 4), 16); + KUNIT_EXPECT_EQ(test, round_closest_down(15, 4), 16); + KUNIT_EXPECT_EQ(test, round_closest_down(14, 4), 12); + KUNIT_EXPECT_EQ(test, round_closest_down((1 << 30) - 1, 1 << 30), 1 << 30); + KUNIT_EXPECT_EQ(test, round_closest_down((1 << 30) + 1, 1 << 30), 1 << 30); + KUNIT_EXPECT_EQ(test, round_closest_down((1 << 30) - 1, 2), (1 << 30) - 2); +} + /* These versions can round to numbers that aren't a power of two */ static void roundup_test(struct kunit *test) { @@ -95,6 +115,18 @@ static void rounddown_test(struct kunit *test) KUNIT_EXPECT_EQ(test, rounddown(4, 3), 3); } +static void roundclosest_test(struct kunit *test) +{ + KUNIT_EXPECT_EQ(test, roundclosest(21, 5), 20); + KUNIT_EXPECT_EQ(test, roundclosest(19, 5), 20); + KUNIT_EXPECT_EQ(test, roundclosest(17, 5), 15); + KUNIT_EXPECT_EQ(test, roundclosest((1 << 30), 3), (1 << 30) - 1); + KUNIT_EXPECT_EQ(test, roundclosest((1 << 30) - 1, 1 << 29), 1 << 30); + + KUNIT_EXPECT_EQ(test, roundclosest(4, 3), 3); + KUNIT_EXPECT_EQ(test, roundclosest(5, 3), 6); +} + static void div_round_up_test(struct kunit *test) { KUNIT_EXPECT_EQ(test, DIV_ROUND_UP(0, 1), 0); @@ -272,8 +304,11 @@ static struct kunit_case math_test_cases[] = { KUNIT_CASE(int_sqrt_test), KUNIT_CASE(round_up_test), KUNIT_CASE(round_down_test), + KUNIT_CASE(round_closest_up_test), + KUNIT_CASE(round_closest_down_test), KUNIT_CASE(roundup_test), KUNIT_CASE(rounddown_test), + KUNIT_CASE(roundclosest_test), KUNIT_CASE(div_round_up_test), KUNIT_CASE(div_round_closest_test), KUNIT_CASE_PARAM(gcd_test, gcd_gen_params), From patchwork Tue Jun 4 10:53:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Devarsh Thakkar X-Patchwork-Id: 801515 Received: from lelv0143.ext.ti.com (lelv0143.ext.ti.com [198.47.23.248]) (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 E8320144D03; Tue, 4 Jun 2024 10:53:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.248 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717498434; cv=none; b=TokivlMN2TF90mZFYx91OJZHSHDToPfdoyeuORn5UNJEDZFdTMAQ5cqdNMki0oVR2pAhMnS5UjbYS+pPlAbpBBF9ipGd6IKBOs5iChzlmZKeBfBE88sZcZJy9s+1Oi042eS7ksDFAh3BXIgdYql2iVZtwC3vkqFvQMY0BPWttjI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717498434; c=relaxed/simple; bh=zIi+rQm13ErlIx/zeUByBpBclT5laiaNC0ssvXS+RKI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=R6eWnv839oeUH9s9tFb7PZBz0Q3Xyz/yOCNfE1Uxy6/5GHE1slv52Yj8UdkGvdA2EXFh70MoEGIHF6xsjU8nErsK+XgCI4S7d5s4RKVO0mlOeF7ap9PR+Lt9xkI8xxHwAS+jVsPAlPy0zCvCNJkNNZoEPAgcjT21B0EahzPC4bw= 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=CtLwSL70; arc=none smtp.client-ip=198.47.23.248 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="CtLwSL70" Received: from fllv0034.itg.ti.com ([10.64.40.246]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id 454Arb7N104586; Tue, 4 Jun 2024 05:53:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1717498417; bh=d3r0wLtyLKE2OgIyTtkCM29t6IlewSqA7H9LkkdsBPw=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=CtLwSL70keUHFBB50CFPyV9Xe97veEwA50r8GiS2g8ibyISqDgrThKS9IERvz/5Ui oNoNsbDrjjNuxt91C93nuS6iggmV1MQG9TKtzukpkENILf/5QDLj12f8O5We4iEhes U3p1G4b3SHuZHsbcgt2Na+cG3rH+ltMC0rDpColA= Received: from DLEE110.ent.ti.com (dlee110.ent.ti.com [157.170.170.21]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 454ArbZC033176 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 4 Jun 2024 05:53:37 -0500 Received: from DLEE101.ent.ti.com (157.170.170.31) by DLEE110.ent.ti.com (157.170.170.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Tue, 4 Jun 2024 05:53:37 -0500 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) by DLEE101.ent.ti.com (157.170.170.31) 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; Tue, 4 Jun 2024 05:53:37 -0500 Received: from localhost (ti.dhcp.ti.com [172.24.227.95] (may be forged)) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 454Arado075929; Tue, 4 Jun 2024 05:53:36 -0500 From: Devarsh Thakkar To: , , , , , , CC: , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v12 12/13] media: imagination: Round to closest multiple for cropping region Date: Tue, 4 Jun 2024 16:23:35 +0530 Message-ID: <20240604105335.2257629-1-devarsht@ti.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20240604104001.2235082-1-devarsht@ti.com> References: <20240604104001.2235082-1-devarsht@ti.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 --- V12: No change V11: No change V10: No change V9: 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 e701d573a26a..d65646f0c38c 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,