From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 38B2B4D3DF for ; Mon, 22 Dec 2025 14:38:22 +0000 (UTC) Authentication-Results: ffbox; dkim=fail (body hash mismatch (got b'kGAuGWHCEyuFL5Zwd7Zwn0y1soDOdjcbaew7aFxnfHA=', expected b'AIpgb5FjoL0lrNSOa/tmEpUXuXyUYozXySSi+Wd1ohY=')) header.d=ffmpeg.org header.i=@ffmpeg.org header.a=rsa-sha256 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1766414287; h=mime-version : to : date : message-id : reply-to : subject : list-id : list-archive : list-archive : list-help : list-owner : list-post : list-subscribe : list-unsubscribe : from : cc : content-type : content-transfer-encoding : from; bh=kGAuGWHCEyuFL5Zwd7Zwn0y1soDOdjcbaew7aFxnfHA=; b=N0vYI00eQO3FMeXtkEOf8VaE9v762Il/BPeyVrPgwxC6mnxoq+AmeQwNhTVd/niP33Nwt JGzhufeQTNnRvsHf2c/XE2B5GUyFtGsIBSy2p6TrwXm9IHlx3n9G+M9BnpL0twJqCCcxo1N AA5eHdiP94lxfSvlDutcBNBZ89oYVcFKiQHi4/J7LP2PdjRM0CM9vXCZczTipc5kMJsuI/e hUsNA1eVgBmOV+OQAfmGD00ELW2aM5b0ytMEad49kttK5kEEEnjNfgrrgtCuCoAm2BHat4T 6mCieBN8/RezViXwOy1JdMbANcvamz0UZ/PRpCKVAl8qfAfdyKXO0BmvDkFA== Received: from [172.20.0.2] (unknown [172.19.0.4]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 2D9DF690AC2; Mon, 22 Dec 2025 16:38:07 +0200 (EET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=ffmpeg.org; s=arc; t=1766414279; b=qpS7D8dxMcNwgFpuChQHvXZ+0I+ytB4C209Lt2TOWdBbMPfS4Rqf/TYg8gGJNQei1gW83 BtmiUevg9xlHAykwqXKLg9w6ejWT/xzkaIvi2Z/wrM/umviqpP4/rcdXM/NHo4qd78ZPlH+ ahUj9OBMGAU+6phiI715sOzWa5IfSrtgfbfpbcuI77A3xexRtIqvxKaSDdyp+qBX3S4wgP+ OPFC9+thXJe5hQffROhSexyICsxORskvks6SJ8oqBRO9xUJHCtOKAxC1mXUsw7DziIV0LfI MnoWE4uJM53qJ6IZiRLhnndbZRjG9ztp159uxIMn6b15KWBHZseQj5FqlMMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=ffmpeg.org; s=arc; t=1766414279; h=from : sender : reply-to : subject : date : message-id : to : cc : mime-version : content-type : content-transfer-encoding : content-id : content-description : resent-date : resent-from : resent-sender : resent-to : resent-cc : resent-message-id : in-reply-to : references : list-id : list-help : list-unsubscribe : list-subscribe : list-post : list-owner : list-archive; bh=6wezWy4wqF+VZsyn3tpbHpfHaBYGmhDOuQdl0L5425M=; b=KxDjUEzPHtuj9YRh3qNs9KLNMyMuHLOqPIrCrJRu9P1u/XHnHNNs4ZfAf06eEEFUJ1QTU AkKdbQTEVsi905zqvPOqMs9Lds9bNgXhYyOvvxy1PlMrYiZEENsQm5gIFY2HEL9ax2owB0n BFinpJzrfxLJfCLubEIpL1vOxkP4NJ59BrXCzEzGp/nw41IuQKgdf96Z10p/oC8yeY+EDuR 6IjhxDSrCaw3T+PZjRXq+LDT0aOONLQ0xFpy0lD4btAzIV6DJMu25/paARdDO2KDKJsxE39 3u4UjlySBM10emrmm7cjMXZ9/7mtoHYs075x85NQPpxPqf1iL/0JNjGEyCzA== ARC-Authentication-Results: i=1; ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none; dmarc=pass header.from=ffmpeg.org policy.dmarc=quarantine Authentication-Results: ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none (Message is not ARC signed); dmarc=pass (Used From Domain Record) header.from=ffmpeg.org policy.dmarc=quarantine DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1766414271; h=content-type : mime-version : content-transfer-encoding : from : to : reply-to : subject : date : from; bh=AIpgb5FjoL0lrNSOa/tmEpUXuXyUYozXySSi+Wd1ohY=; b=ACcdJjg2z6cJwlPJ7WMmZ7+SkC4t5ADDPJio5utnth0AjHPz9bk7mNJ6bPmy861eXUSz9 RrNjteHEquOYDFQGTnf1sAs0AAPxeHhWf/MqPn1v/6x4pFiSq0JL1Q7o55GUiR41S9Hds8L PIzPJbr+UZDSP0XFpziTizUGIX5Pmlshp1dGvkrU4M8hytICdinDaFT2PldEpv14zGfXQkn g/X53FgmeHIfHrzuq2Sw1pJg8QN9igDWff323TrM26Xb2OuFsUZW/1ohQ5M6w6U7ynOiDLn IMD0/EApQH2Bh535rxVZxpZDUB9LZ6VEYvz2XINUqEo9kzoh6Y4ItHcG2D7g== Received: from 55ca25703178 (code.ffmpeg.org [188.245.149.3]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 038146909B8 for ; Mon, 22 Dec 2025 16:37:50 +0200 (EET) MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Date: Mon, 22 Dec 2025 14:37:50 -0000 Message-ID: <176641427119.60.8939362701982294854@2cb04c0e5124> Message-ID-Hash: YQVDXSMFW42QGLLOSLSTNVC75B2G3YMV X-Message-ID-Hash: YQVDXSMFW42QGLLOSLSTNVC75B2G3YMV X-MailFrom: code@ffmpeg.org X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-ffmpeg-devel.ffmpeg.org-0; header-match-ffmpeg-devel.ffmpeg.org-1; header-match-ffmpeg-devel.ffmpeg.org-2; header-match-ffmpeg-devel.ffmpeg.org-3; emergency; member-moderation X-Mailman-Version: 3.3.10 Precedence: list Reply-To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] [PATCH] swscale/ops_internal: fix ff_sws_pack_op_decode() (PR #21263) List-Id: FFmpeg development discussions and patches Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Niklas Haas via ffmpeg-devel Cc: Niklas Haas Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Archived-At: List-Archive: List-Post: PR #21263 opened by Niklas Haas (haasn) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21263 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21263.patch This function was assuming that the bits are MSB-aligned, but they are LSB-aligned in both practice (and in the actual backend). Also update the documentation of SwsPackOp to make this clearer. Fixes an incorrect omission of a clamp after decoding e.g. rgb4, since the max value range was incorrectly determined as 0 as a result of unpacking the MSB bits instead of the LSB bits: bgr4 -> gray: [ u8 XXXX -> +XXX] SWS_OP_READ : 1 elem(s) packed >> 1 [ u8 .XXX -> +++X] SWS_OP_UNPACK : {1 2 1 0} [ u8 ...X -> +++X] SWS_OP_SWIZZLE : 2103 [ u8 ...X -> +++X] SWS_OP_CONVERT : u8 -> f32 [f32 ...X -> .++X] SWS_OP_LINEAR : dot3 [...] [f32 .XXX -> .++X] SWS_OP_DITHER : 16x16 matrix + {0 3 2 5} + [f32 .XXX -> .++X] SWS_OP_MIN : x <= {255 _ _ _} [f32 .XXX -> +++X] SWS_OP_CONVERT : f32 -> u8 [ u8 .XXX -> +++X] SWS_OP_WRITE : 1 elem(s) planar >> 0 (X = unused, + = exact, 0 = zero) >>From d93ed0e7ada69c32541a0688d50527cb62a68637 Mon Sep 17 00:00:00 2001 From: Niklas Haas Date: Mon, 22 Dec 2025 15:31:01 +0100 Subject: [PATCH] swscale/ops_internal: fix ff_sws_pack_op_decode() This function was assuming that the bits are MSB-aligned, but they are LSB-aligned in both practice (and in the actual backend). Also update the documentation of SwsPackOp to make this clearer. Fixes an incorrect omission of a clamp after decoding e.g. rgb4, since the max value range was incorrectly determined as 0 as a result of unpacking the MSB bits instead of the LSB bits: bgr4 -> gray: [ u8 XXXX -> +XXX] SWS_OP_READ : 1 elem(s) packed >> 1 [ u8 .XXX -> +++X] SWS_OP_UNPACK : {1 2 1 0} [ u8 ...X -> +++X] SWS_OP_SWIZZLE : 2103 [ u8 ...X -> +++X] SWS_OP_CONVERT : u8 -> f32 [f32 ...X -> .++X] SWS_OP_LINEAR : dot3 [...] [f32 .XXX -> .++X] SWS_OP_DITHER : 16x16 matrix + {0 3 2 5} + [f32 .XXX -> .++X] SWS_OP_MIN : x <= {255 _ _ _} [f32 .XXX -> +++X] SWS_OP_CONVERT : f32 -> u8 [ u8 .XXX -> +++X] SWS_OP_WRITE : 1 elem(s) planar >> 0 (X = unused, + = exact, 0 = zero) --- libswscale/ops.h | 4 ++++ libswscale/ops_internal.h | 4 +++- tests/ref/fate/sws-ops-list | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/libswscale/ops.h b/libswscale/ops.h index 6392d0ffdf..6fc7e60a02 100644 --- a/libswscale/ops.h +++ b/libswscale/ops.h @@ -109,6 +109,10 @@ typedef struct SwsReadWriteOp { } SwsReadWriteOp; typedef struct SwsPackOp { + /** + * Packed bits are assumed to be LSB-aligned within the underlying + * integer type; i.e. (msb) 0 ... X Y Z W (lsb). + */ uint8_t pattern[4]; /* bit depth pattern, from MSB to LSB */ } SwsPackOp; diff --git a/libswscale/ops_internal.h b/libswscale/ops_internal.h index 0071f78558..ba4c9b39da 100644 --- a/libswscale/ops_internal.h +++ b/libswscale/ops_internal.h @@ -39,7 +39,9 @@ static inline AVRational ff_sws_pixel_expand(SwsPixelType from, SwsPixelType to) static inline void ff_sws_pack_op_decode(const SwsOp *op, uint64_t mask[4], int shift[4]) { - const int size = ff_sws_pixel_type_size(op->type) * 8; + int size = 0; + for (int i = 0; i < 4; i++) + size += op->pack.pattern[i]; for (int i = 0; i < 4; i++) { const int bits = op->pack.pattern[i]; mask[i] = (UINT64_C(1) << bits) - 1; diff --git a/tests/ref/fate/sws-ops-list b/tests/ref/fate/sws-ops-list index b49f944794..a7d6149d8b 100644 --- a/tests/ref/fate/sws-ops-list +++ b/tests/ref/fate/sws-ops-list @@ -1 +1 @@ -e910ff7ceaeb64bfdbac3f652b67403f +ef1dd10af970984495f6008e43d0fe1b -- 2.49.1 _______________________________________________ ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org